book3s_32_sr.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright SUSE Linux Products GmbH 2009
  16. *
  17. * Authors: Alexander Graf <agraf@suse.de>
  18. */
  19. /******************************************************************************
  20. * *
  21. * Entry code *
  22. * *
  23. *****************************************************************************/
  24. .macro LOAD_GUEST_SEGMENTS
  25. /* Required state:
  26. *
  27. * MSR = ~IR|DR
  28. * R1 = host R1
  29. * R2 = host R2
  30. * R3 = shadow vcpu
  31. * all other volatile GPRS = free except R4, R6
  32. * SVCPU[CR] = guest CR
  33. * SVCPU[XER] = guest XER
  34. * SVCPU[CTR] = guest CTR
  35. * SVCPU[LR] = guest LR
  36. */
  37. #define XCHG_SR(n) lwz r9, (SVCPU_SR+(n*4))(r3); \
  38. mtsr n, r9
  39. XCHG_SR(0)
  40. XCHG_SR(1)
  41. XCHG_SR(2)
  42. XCHG_SR(3)
  43. XCHG_SR(4)
  44. XCHG_SR(5)
  45. XCHG_SR(6)
  46. XCHG_SR(7)
  47. XCHG_SR(8)
  48. XCHG_SR(9)
  49. XCHG_SR(10)
  50. XCHG_SR(11)
  51. XCHG_SR(12)
  52. XCHG_SR(13)
  53. XCHG_SR(14)
  54. XCHG_SR(15)
  55. /* Clear BATs. */
  56. #define KVM_KILL_BAT(n, reg) \
  57. mtspr SPRN_IBAT##n##U,reg; \
  58. mtspr SPRN_IBAT##n##L,reg; \
  59. mtspr SPRN_DBAT##n##U,reg; \
  60. mtspr SPRN_DBAT##n##L,reg; \
  61. li r9, 0
  62. KVM_KILL_BAT(0, r9)
  63. KVM_KILL_BAT(1, r9)
  64. KVM_KILL_BAT(2, r9)
  65. KVM_KILL_BAT(3, r9)
  66. .endm
  67. /******************************************************************************
  68. * *
  69. * Exit code *
  70. * *
  71. *****************************************************************************/
  72. .macro LOAD_HOST_SEGMENTS
  73. /* Register usage at this point:
  74. *
  75. * R1 = host R1
  76. * R2 = host R2
  77. * R12 = exit handler id
  78. * R13 = shadow vcpu - SHADOW_VCPU_OFF
  79. * SVCPU.* = guest *
  80. * SVCPU[CR] = guest CR
  81. * SVCPU[XER] = guest XER
  82. * SVCPU[CTR] = guest CTR
  83. * SVCPU[LR] = guest LR
  84. *
  85. */
  86. /* Restore BATs */
  87. /* We only overwrite the upper part, so we only restoree
  88. the upper part. */
  89. #define KVM_LOAD_BAT(n, reg, RA, RB) \
  90. lwz RA,(n*16)+0(reg); \
  91. lwz RB,(n*16)+4(reg); \
  92. mtspr SPRN_IBAT##n##U,RA; \
  93. mtspr SPRN_IBAT##n##L,RB; \
  94. lwz RA,(n*16)+8(reg); \
  95. lwz RB,(n*16)+12(reg); \
  96. mtspr SPRN_DBAT##n##U,RA; \
  97. mtspr SPRN_DBAT##n##L,RB; \
  98. lis r9, BATS@ha
  99. addi r9, r9, BATS@l
  100. tophys(r9, r9)
  101. KVM_LOAD_BAT(0, r9, r10, r11)
  102. KVM_LOAD_BAT(1, r9, r10, r11)
  103. KVM_LOAD_BAT(2, r9, r10, r11)
  104. KVM_LOAD_BAT(3, r9, r10, r11)
  105. /* Restore Segment Registers */
  106. /* 0xc - 0xf */
  107. li r0, 4
  108. mtctr r0
  109. LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc))
  110. lis r4, 0xc000
  111. 3: mtsrin r3, r4
  112. addi r3, r3, 0x111 /* increment VSID */
  113. addis r4, r4, 0x1000 /* address of next segment */
  114. bdnz 3b
  115. /* 0x0 - 0xb */
  116. /* 'current->mm' needs to be in r4 */
  117. tophys(r4, r2)
  118. lwz r4, MM(r4)
  119. tophys(r4, r4)
  120. /* This only clobbers r0, r3, r4 and r5 */
  121. bl switch_mmu_context
  122. .endm