book3s_64_slb.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #ifdef __LITTLE_ENDIAN__
  20. #error Need to fix SLB shadow accesses in little endian mode
  21. #endif
  22. #define SHADOW_SLB_ESID(num) (SLBSHADOW_SAVEAREA + (num * 0x10))
  23. #define SHADOW_SLB_VSID(num) (SLBSHADOW_SAVEAREA + (num * 0x10) + 0x8)
  24. #define UNBOLT_SLB_ENTRY(num) \
  25. ld r9, SHADOW_SLB_ESID(num)(r12); \
  26. /* Invalid? Skip. */; \
  27. rldicl. r0, r9, 37, 63; \
  28. beq slb_entry_skip_ ## num; \
  29. xoris r9, r9, SLB_ESID_V@h; \
  30. std r9, SHADOW_SLB_ESID(num)(r12); \
  31. slb_entry_skip_ ## num:
  32. #define REBOLT_SLB_ENTRY(num) \
  33. ld r10, SHADOW_SLB_ESID(num)(r11); \
  34. cmpdi r10, 0; \
  35. beq slb_exit_skip_ ## num; \
  36. oris r10, r10, SLB_ESID_V@h; \
  37. ld r9, SHADOW_SLB_VSID(num)(r11); \
  38. slbmte r9, r10; \
  39. std r10, SHADOW_SLB_ESID(num)(r11); \
  40. slb_exit_skip_ ## num:
  41. /******************************************************************************
  42. * *
  43. * Entry code *
  44. * *
  45. *****************************************************************************/
  46. .macro LOAD_GUEST_SEGMENTS
  47. /* Required state:
  48. *
  49. * MSR = ~IR|DR
  50. * R13 = PACA
  51. * R1 = host R1
  52. * R2 = host R2
  53. * R3 = shadow vcpu
  54. * all other volatile GPRS = free except R4, R6
  55. * SVCPU[CR] = guest CR
  56. * SVCPU[XER] = guest XER
  57. * SVCPU[CTR] = guest CTR
  58. * SVCPU[LR] = guest LR
  59. */
  60. /* Remove LPAR shadow entries */
  61. #if SLB_NUM_BOLTED == 3
  62. ld r12, PACA_SLBSHADOWPTR(r13)
  63. /* Remove bolted entries */
  64. UNBOLT_SLB_ENTRY(0)
  65. UNBOLT_SLB_ENTRY(1)
  66. UNBOLT_SLB_ENTRY(2)
  67. #else
  68. #error unknown number of bolted entries
  69. #endif
  70. /* Flush SLB */
  71. li r10, 0
  72. slbmte r10, r10
  73. slbia
  74. /* Fill SLB with our shadow */
  75. lbz r12, SVCPU_SLB_MAX(r3)
  76. mulli r12, r12, 16
  77. addi r12, r12, SVCPU_SLB
  78. add r12, r12, r3
  79. /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
  80. li r11, SVCPU_SLB
  81. add r11, r11, r3
  82. slb_loop_enter:
  83. ld r10, 0(r11)
  84. rldicl. r0, r10, 37, 63
  85. beq slb_loop_enter_skip
  86. ld r9, 8(r11)
  87. slbmte r9, r10
  88. slb_loop_enter_skip:
  89. addi r11, r11, 16
  90. cmpd cr0, r11, r12
  91. blt slb_loop_enter
  92. slb_do_enter:
  93. .endm
  94. /******************************************************************************
  95. * *
  96. * Exit code *
  97. * *
  98. *****************************************************************************/
  99. .macro LOAD_HOST_SEGMENTS
  100. /* Register usage at this point:
  101. *
  102. * R1 = host R1
  103. * R2 = host R2
  104. * R12 = exit handler id
  105. * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64]
  106. * SVCPU.* = guest *
  107. * SVCPU[CR] = guest CR
  108. * SVCPU[XER] = guest XER
  109. * SVCPU[CTR] = guest CTR
  110. * SVCPU[LR] = guest LR
  111. *
  112. */
  113. /* Restore bolted entries from the shadow and fix it along the way */
  114. /* We don't store anything in entry 0, so we don't need to take care of it */
  115. slbia
  116. isync
  117. #if SLB_NUM_BOLTED == 3
  118. ld r11, PACA_SLBSHADOWPTR(r13)
  119. REBOLT_SLB_ENTRY(0)
  120. REBOLT_SLB_ENTRY(1)
  121. REBOLT_SLB_ENTRY(2)
  122. #else
  123. #error unknown number of bolted entries
  124. #endif
  125. slb_do_exit:
  126. .endm