book3s_64_rmhandlers.S 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #include <asm/ppc_asm.h>
  20. #include <asm/kvm_asm.h>
  21. #include <asm/reg.h>
  22. #include <asm/page.h>
  23. #include <asm/asm-offsets.h>
  24. #include <asm/exception-64s.h>
  25. /*****************************************************************************
  26. * *
  27. * Real Mode handlers that need to be in low physical memory *
  28. * *
  29. ****************************************************************************/
  30. .macro INTERRUPT_TRAMPOLINE intno
  31. .global kvmppc_trampoline_\intno
  32. kvmppc_trampoline_\intno:
  33. mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
  34. /*
  35. * First thing to do is to find out if we're coming
  36. * from a KVM guest or a Linux process.
  37. *
  38. * To distinguish, we check a magic byte in the PACA
  39. */
  40. mfspr r13, SPRN_SPRG_PACA /* r13 = PACA */
  41. std r12, PACA_KVM_SCRATCH0(r13)
  42. mfcr r12
  43. stw r12, PACA_KVM_SCRATCH1(r13)
  44. lbz r12, PACA_KVM_IN_GUEST(r13)
  45. cmpwi r12, KVM_GUEST_MODE_NONE
  46. bne ..kvmppc_handler_hasmagic_\intno
  47. /* No KVM guest? Then jump back to the Linux handler! */
  48. lwz r12, PACA_KVM_SCRATCH1(r13)
  49. mtcr r12
  50. ld r12, PACA_KVM_SCRATCH0(r13)
  51. mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
  52. b kvmppc_resume_\intno /* Get back original handler */
  53. /* Now we know we're handling a KVM guest */
  54. ..kvmppc_handler_hasmagic_\intno:
  55. /* Should we just skip the faulting instruction? */
  56. cmpwi r12, KVM_GUEST_MODE_SKIP
  57. beq kvmppc_handler_skip_ins
  58. /* Let's store which interrupt we're handling */
  59. li r12, \intno
  60. /* Jump into the SLB exit code that goes to the highmem handler */
  61. b kvmppc_handler_trampoline_exit
  62. .endm
  63. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
  64. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
  65. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
  66. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_SEGMENT
  67. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
  68. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_SEGMENT
  69. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
  70. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
  71. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
  72. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
  73. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
  74. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
  75. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
  76. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
  77. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
  78. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX
  79. /*
  80. * Bring us back to the faulting code, but skip the
  81. * faulting instruction.
  82. *
  83. * This is a generic exit path from the interrupt
  84. * trampolines above.
  85. *
  86. * Input Registers:
  87. *
  88. * R12 = free
  89. * R13 = PACA
  90. * PACA.KVM.SCRATCH0 = guest R12
  91. * PACA.KVM.SCRATCH1 = guest CR
  92. * SPRG_SCRATCH0 = guest R13
  93. *
  94. */
  95. kvmppc_handler_skip_ins:
  96. /* Patch the IP to the next instruction */
  97. mfsrr0 r12
  98. addi r12, r12, 4
  99. mtsrr0 r12
  100. /* Clean up all state */
  101. lwz r12, PACA_KVM_SCRATCH1(r13)
  102. mtcr r12
  103. ld r12, PACA_KVM_SCRATCH0(r13)
  104. mfspr r13, SPRN_SPRG_SCRATCH0
  105. /* And get back into the code */
  106. RFI
  107. /*
  108. * This trampoline brings us back to a real mode handler
  109. *
  110. * Input Registers:
  111. *
  112. * R5 = SRR0
  113. * R6 = SRR1
  114. * LR = real-mode IP
  115. *
  116. */
  117. .global kvmppc_handler_lowmem_trampoline
  118. kvmppc_handler_lowmem_trampoline:
  119. mtsrr0 r5
  120. mtsrr1 r6
  121. blr
  122. kvmppc_handler_lowmem_trampoline_end:
  123. /*
  124. * Call a function in real mode
  125. *
  126. * Input Registers:
  127. *
  128. * R3 = function
  129. * R4 = MSR
  130. * R5 = CTR
  131. *
  132. */
  133. _GLOBAL(kvmppc_rmcall)
  134. mtmsr r4 /* Disable relocation, so mtsrr
  135. doesn't get interrupted */
  136. mtctr r5
  137. mtsrr0 r3
  138. mtsrr1 r4
  139. RFI
  140. /*
  141. * Activate current's external feature (FPU/Altivec/VSX)
  142. */
  143. #define define_load_up(what) \
  144. \
  145. _GLOBAL(kvmppc_load_up_ ## what); \
  146. subi r1, r1, INT_FRAME_SIZE; \
  147. mflr r3; \
  148. std r3, _LINK(r1); \
  149. mfmsr r4; \
  150. std r31, GPR3(r1); \
  151. mr r31, r4; \
  152. li r5, MSR_DR; \
  153. oris r5, r5, MSR_EE@h; \
  154. andc r4, r4, r5; \
  155. mtmsr r4; \
  156. \
  157. bl .load_up_ ## what; \
  158. \
  159. mtmsr r31; \
  160. ld r3, _LINK(r1); \
  161. ld r31, GPR3(r1); \
  162. addi r1, r1, INT_FRAME_SIZE; \
  163. mtlr r3; \
  164. blr
  165. define_load_up(fpu)
  166. #ifdef CONFIG_ALTIVEC
  167. define_load_up(altivec)
  168. #endif
  169. #ifdef CONFIG_VSX
  170. define_load_up(vsx)
  171. #endif
  172. .global kvmppc_trampoline_lowmem
  173. kvmppc_trampoline_lowmem:
  174. .long kvmppc_handler_lowmem_trampoline - _stext
  175. .global kvmppc_trampoline_enter
  176. kvmppc_trampoline_enter:
  177. .long kvmppc_handler_trampoline_enter - _stext
  178. #include "book3s_64_slb.S"