book3s_64_rmhandlers.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_EXMC + EX_R12)(r13)
  42. mfcr r12
  43. stw r12, (PACA_EXMC + EX_CCR)(r13)
  44. lbz r12, PACA_KVM_IN_GUEST(r13)
  45. cmpwi r12, 0
  46. bne ..kvmppc_handler_hasmagic_\intno
  47. /* No KVM guest? Then jump back to the Linux handler! */
  48. lwz r12, (PACA_EXMC + EX_CCR)(r13)
  49. mtcr r12
  50. ld r12, (PACA_EXMC + EX_R12)(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. /* Unset guest state */
  56. li r12, 0
  57. stb r12, PACA_KVM_IN_GUEST(r13)
  58. std r1, (PACA_EXMC+EX_R9)(r13)
  59. std r10, (PACA_EXMC+EX_R10)(r13)
  60. std r11, (PACA_EXMC+EX_R11)(r13)
  61. std r2, (PACA_EXMC+EX_R13)(r13)
  62. mfsrr0 r10
  63. mfsrr1 r11
  64. /* Restore R1/R2 so we can handle faults */
  65. ld r1, PACAR1(r13)
  66. ld r2, (PACA_EXMC+EX_SRR0)(r13)
  67. /* Let's store which interrupt we're handling */
  68. li r12, \intno
  69. /* Jump into the SLB exit code that goes to the highmem handler */
  70. b kvmppc_handler_trampoline_exit
  71. .endm
  72. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
  73. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
  74. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
  75. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_SEGMENT
  76. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
  77. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_SEGMENT
  78. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
  79. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
  80. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
  81. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
  82. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
  83. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
  84. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
  85. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
  86. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
  87. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX
  88. /*
  89. * This trampoline brings us back to a real mode handler
  90. *
  91. * Input Registers:
  92. *
  93. * R6 = SRR0
  94. * R7 = SRR1
  95. * LR = real-mode IP
  96. *
  97. */
  98. .global kvmppc_handler_lowmem_trampoline
  99. kvmppc_handler_lowmem_trampoline:
  100. mtsrr0 r6
  101. mtsrr1 r7
  102. blr
  103. kvmppc_handler_lowmem_trampoline_end:
  104. .global kvmppc_trampoline_lowmem
  105. kvmppc_trampoline_lowmem:
  106. .long kvmppc_handler_lowmem_trampoline - _stext
  107. .global kvmppc_trampoline_enter
  108. kvmppc_trampoline_enter:
  109. .long kvmppc_handler_trampoline_enter - _stext
  110. #include "book3s_64_slb.S"