xen-asm.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Asm versions of Xen pv-ops, suitable for either direct use or
  3. * inlining. The inline versions are the same as the direct-use
  4. * versions, with the pre- and post-amble chopped off.
  5. *
  6. * This code is encoded for size rather than absolute efficiency, with
  7. * a view to being able to inline as much as possible.
  8. *
  9. * We only bother with direct forms (ie, vcpu in percpu data) of the
  10. * operations here; the indirect forms are better handled in C, since
  11. * they're generally too large to inline anyway.
  12. */
  13. #include <asm/asm-offsets.h>
  14. #include <asm/percpu.h>
  15. #include <asm/processor-flags.h>
  16. #include "xen-asm.h"
  17. /*
  18. * Enable events. This clears the event mask and tests the pending
  19. * event status with one and operation. If there are pending events,
  20. * then enter the hypervisor to get them handled.
  21. */
  22. ENTRY(xen_irq_enable_direct)
  23. /* Unmask events */
  24. movb $0, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
  25. /*
  26. * Preempt here doesn't matter because that will deal with any
  27. * pending interrupts. The pending check may end up being run
  28. * on the wrong CPU, but that doesn't hurt.
  29. */
  30. /* Test for pending */
  31. testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending
  32. jz 1f
  33. 2: call check_events
  34. 1:
  35. ENDPATCH(xen_irq_enable_direct)
  36. ret
  37. ENDPROC(xen_irq_enable_direct)
  38. RELOC(xen_irq_enable_direct, 2b+1)
  39. /*
  40. * Disabling events is simply a matter of making the event mask
  41. * non-zero.
  42. */
  43. ENTRY(xen_irq_disable_direct)
  44. movb $1, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
  45. ENDPATCH(xen_irq_disable_direct)
  46. ret
  47. ENDPROC(xen_irq_disable_direct)
  48. RELOC(xen_irq_disable_direct, 0)
  49. /*
  50. * (xen_)save_fl is used to get the current interrupt enable status.
  51. * Callers expect the status to be in X86_EFLAGS_IF, and other bits
  52. * may be set in the return value. We take advantage of this by
  53. * making sure that X86_EFLAGS_IF has the right value (and other bits
  54. * in that byte are 0), but other bits in the return value are
  55. * undefined. We need to toggle the state of the bit, because Xen and
  56. * x86 use opposite senses (mask vs enable).
  57. */
  58. ENTRY(xen_save_fl_direct)
  59. testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
  60. setz %ah
  61. addb %ah, %ah
  62. ENDPATCH(xen_save_fl_direct)
  63. ret
  64. ENDPROC(xen_save_fl_direct)
  65. RELOC(xen_save_fl_direct, 0)
  66. /*
  67. * In principle the caller should be passing us a value return from
  68. * xen_save_fl_direct, but for robustness sake we test only the
  69. * X86_EFLAGS_IF flag rather than the whole byte. After setting the
  70. * interrupt mask state, it checks for unmasked pending events and
  71. * enters the hypervisor to get them delivered if so.
  72. */
  73. ENTRY(xen_restore_fl_direct)
  74. #ifdef CONFIG_X86_64
  75. testw $X86_EFLAGS_IF, %di
  76. #else
  77. testb $X86_EFLAGS_IF>>8, %ah
  78. #endif
  79. setz PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
  80. /*
  81. * Preempt here doesn't matter because that will deal with any
  82. * pending interrupts. The pending check may end up being run
  83. * on the wrong CPU, but that doesn't hurt.
  84. */
  85. /* check for unmasked and pending */
  86. cmpw $0x0001, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending
  87. jnz 1f
  88. 2: call check_events
  89. 1:
  90. ENDPATCH(xen_restore_fl_direct)
  91. ret
  92. ENDPROC(xen_restore_fl_direct)
  93. RELOC(xen_restore_fl_direct, 2b+1)
  94. /*
  95. * Force an event check by making a hypercall, but preserve regs
  96. * before making the call.
  97. */
  98. check_events:
  99. #ifdef CONFIG_X86_32
  100. push %eax
  101. push %ecx
  102. push %edx
  103. call xen_force_evtchn_callback
  104. pop %edx
  105. pop %ecx
  106. pop %eax
  107. #else
  108. push %rax
  109. push %rcx
  110. push %rdx
  111. push %rsi
  112. push %rdi
  113. push %r8
  114. push %r9
  115. push %r10
  116. push %r11
  117. call xen_force_evtchn_callback
  118. pop %r11
  119. pop %r10
  120. pop %r9
  121. pop %r8
  122. pop %rdi
  123. pop %rsi
  124. pop %rdx
  125. pop %rcx
  126. pop %rax
  127. #endif
  128. ret