hyp-stub.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Hypervisor stub
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. * Author: Marc Zyngier <marc.zyngier@arm.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/linkage.h>
  21. #include <asm/assembler.h>
  22. #include <asm/ptrace.h>
  23. #include <asm/virt.h>
  24. .text
  25. .align 11
  26. ENTRY(__hyp_stub_vectors)
  27. ventry el2_sync_invalid // Synchronous EL2t
  28. ventry el2_irq_invalid // IRQ EL2t
  29. ventry el2_fiq_invalid // FIQ EL2t
  30. ventry el2_error_invalid // Error EL2t
  31. ventry el2_sync_invalid // Synchronous EL2h
  32. ventry el2_irq_invalid // IRQ EL2h
  33. ventry el2_fiq_invalid // FIQ EL2h
  34. ventry el2_error_invalid // Error EL2h
  35. ventry el1_sync // Synchronous 64-bit EL1
  36. ventry el1_irq_invalid // IRQ 64-bit EL1
  37. ventry el1_fiq_invalid // FIQ 64-bit EL1
  38. ventry el1_error_invalid // Error 64-bit EL1
  39. ventry el1_sync_invalid // Synchronous 32-bit EL1
  40. ventry el1_irq_invalid // IRQ 32-bit EL1
  41. ventry el1_fiq_invalid // FIQ 32-bit EL1
  42. ventry el1_error_invalid // Error 32-bit EL1
  43. ENDPROC(__hyp_stub_vectors)
  44. .align 11
  45. el1_sync:
  46. mrs x1, esr_el2
  47. lsr x1, x1, #26
  48. cmp x1, #0x16
  49. b.ne 2f // Not an HVC trap
  50. cbz x0, 1f
  51. msr vbar_el2, x0 // Set vbar_el2
  52. b 2f
  53. 1: mrs x0, vbar_el2 // Return vbar_el2
  54. 2: eret
  55. ENDPROC(el1_sync)
  56. .macro invalid_vector label
  57. \label:
  58. b \label
  59. ENDPROC(\label)
  60. .endm
  61. invalid_vector el2_sync_invalid
  62. invalid_vector el2_irq_invalid
  63. invalid_vector el2_fiq_invalid
  64. invalid_vector el2_error_invalid
  65. invalid_vector el1_sync_invalid
  66. invalid_vector el1_irq_invalid
  67. invalid_vector el1_fiq_invalid
  68. invalid_vector el1_error_invalid
  69. /*
  70. * __hyp_set_vectors: Call this after boot to set the initial hypervisor
  71. * vectors as part of hypervisor installation. On an SMP system, this should
  72. * be called on each CPU.
  73. *
  74. * x0 must be the physical address of the new vector table, and must be
  75. * 2KB aligned.
  76. *
  77. * Before calling this, you must check that the stub hypervisor is installed
  78. * everywhere, by waiting for any secondary CPUs to be brought up and then
  79. * checking that is_hyp_mode_available() is true.
  80. *
  81. * If not, there is a pre-existing hypervisor, some CPUs failed to boot, or
  82. * something else went wrong... in such cases, trying to install a new
  83. * hypervisor is unlikely to work as desired.
  84. *
  85. * When you call into your shiny new hypervisor, sp_el2 will contain junk,
  86. * so you will need to set that to something sensible at the new hypervisor's
  87. * initialisation entry point.
  88. */
  89. ENTRY(__hyp_get_vectors)
  90. mov x0, xzr
  91. // fall through
  92. ENTRY(__hyp_set_vectors)
  93. hvc #0
  94. ret
  95. ENDPROC(__hyp_get_vectors)
  96. ENDPROC(__hyp_set_vectors)