xen-asm_64.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Asm versions of Xen pv-ops, suitable for direct use.
  4. *
  5. * We only bother with direct forms (ie, vcpu in pda) of the
  6. * operations here; the indirect forms are better handled in C.
  7. */
  8. #include <asm/errno.h>
  9. #include <asm/percpu.h>
  10. #include <asm/processor-flags.h>
  11. #include <asm/segment.h>
  12. #include <asm/asm-offsets.h>
  13. #include <asm/thread_info.h>
  14. #include <asm/asm.h>
  15. #include <xen/interface/xen.h>
  16. #include <linux/init.h>
  17. #include <linux/linkage.h>
  18. .macro xen_pv_trap name
  19. ENTRY(xen_\name)
  20. pop %rcx
  21. pop %r11
  22. jmp \name
  23. END(xen_\name)
  24. _ASM_NOKPROBE(xen_\name)
  25. .endm
  26. xen_pv_trap divide_error
  27. xen_pv_trap debug
  28. xen_pv_trap xendebug
  29. xen_pv_trap int3
  30. xen_pv_trap xennmi
  31. xen_pv_trap overflow
  32. xen_pv_trap bounds
  33. xen_pv_trap invalid_op
  34. xen_pv_trap device_not_available
  35. xen_pv_trap double_fault
  36. xen_pv_trap coprocessor_segment_overrun
  37. xen_pv_trap invalid_TSS
  38. xen_pv_trap segment_not_present
  39. xen_pv_trap stack_segment
  40. xen_pv_trap general_protection
  41. xen_pv_trap page_fault
  42. xen_pv_trap spurious_interrupt_bug
  43. xen_pv_trap coprocessor_error
  44. xen_pv_trap alignment_check
  45. #ifdef CONFIG_X86_MCE
  46. xen_pv_trap machine_check
  47. #endif /* CONFIG_X86_MCE */
  48. xen_pv_trap simd_coprocessor_error
  49. #ifdef CONFIG_IA32_EMULATION
  50. xen_pv_trap entry_INT80_compat
  51. #endif
  52. xen_pv_trap hypervisor_callback
  53. __INIT
  54. ENTRY(xen_early_idt_handler_array)
  55. i = 0
  56. .rept NUM_EXCEPTION_VECTORS
  57. pop %rcx
  58. pop %r11
  59. jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
  60. i = i + 1
  61. .fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
  62. .endr
  63. END(xen_early_idt_handler_array)
  64. __FINIT
  65. hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
  66. /*
  67. * Xen64 iret frame:
  68. *
  69. * ss
  70. * rsp
  71. * rflags
  72. * cs
  73. * rip <-- standard iret frame
  74. *
  75. * flags
  76. *
  77. * rcx }
  78. * r11 }<-- pushed by hypercall page
  79. * rsp->rax }
  80. */
  81. ENTRY(xen_iret)
  82. pushq $0
  83. jmp hypercall_iret
  84. ENTRY(xen_sysret64)
  85. /*
  86. * We're already on the usermode stack at this point, but
  87. * still with the kernel gs, so we can easily switch back
  88. */
  89. movq %rsp, PER_CPU_VAR(rsp_scratch)
  90. movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
  91. pushq $__USER_DS
  92. pushq PER_CPU_VAR(rsp_scratch)
  93. pushq %r11
  94. pushq $__USER_CS
  95. pushq %rcx
  96. pushq $VGCF_in_syscall
  97. jmp hypercall_iret
  98. /*
  99. * Xen handles syscall callbacks much like ordinary exceptions, which
  100. * means we have:
  101. * - kernel gs
  102. * - kernel rsp
  103. * - an iret-like stack frame on the stack (including rcx and r11):
  104. * ss
  105. * rsp
  106. * rflags
  107. * cs
  108. * rip
  109. * r11
  110. * rsp->rcx
  111. */
  112. /* Normal 64-bit system call target */
  113. ENTRY(xen_syscall_target)
  114. popq %rcx
  115. popq %r11
  116. /*
  117. * Neither Xen nor the kernel really knows what the old SS and
  118. * CS were. The kernel expects __USER_DS and __USER_CS, so
  119. * report those values even though Xen will guess its own values.
  120. */
  121. movq $__USER_DS, 4*8(%rsp)
  122. movq $__USER_CS, 1*8(%rsp)
  123. jmp entry_SYSCALL_64_after_hwframe
  124. ENDPROC(xen_syscall_target)
  125. #ifdef CONFIG_IA32_EMULATION
  126. /* 32-bit compat syscall target */
  127. ENTRY(xen_syscall32_target)
  128. popq %rcx
  129. popq %r11
  130. /*
  131. * Neither Xen nor the kernel really knows what the old SS and
  132. * CS were. The kernel expects __USER32_DS and __USER32_CS, so
  133. * report those values even though Xen will guess its own values.
  134. */
  135. movq $__USER32_DS, 4*8(%rsp)
  136. movq $__USER32_CS, 1*8(%rsp)
  137. jmp entry_SYSCALL_compat_after_hwframe
  138. ENDPROC(xen_syscall32_target)
  139. /* 32-bit compat sysenter target */
  140. ENTRY(xen_sysenter_target)
  141. mov 0*8(%rsp), %rcx
  142. mov 1*8(%rsp), %r11
  143. mov 5*8(%rsp), %rsp
  144. jmp entry_SYSENTER_compat
  145. ENDPROC(xen_sysenter_target)
  146. #else /* !CONFIG_IA32_EMULATION */
  147. ENTRY(xen_syscall32_target)
  148. ENTRY(xen_sysenter_target)
  149. lea 16(%rsp), %rsp /* strip %rcx, %r11 */
  150. mov $-ENOSYS, %rax
  151. pushq $0
  152. jmp hypercall_iret
  153. ENDPROC(xen_syscall32_target)
  154. ENDPROC(xen_sysenter_target)
  155. #endif /* CONFIG_IA32_EMULATION */