book3s_64_slb.S 3.9 KB

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