2 Asm versions of Xen pv-ops, suitable for either direct use or inlining.
3 The inline versions are the same as the direct-use versions, with the
4 pre- and post-amble chopped off.
6 This code is encoded for size rather than absolute efficiency,
7 with a view to being able to inline as much as possible.
9 We only bother with direct forms (ie, vcpu in pda) of the operations
10 here; the indirect forms are better handled in C, since they're
11 generally too large to inline anyway.
14 #include <linux/linkage.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/processor-flags.h>
18 #include <asm/errno.h>
19 #include <asm/segment.h>
21 #include <xen/interface/xen.h>
23 #define RELOC(x, v) .globl x##_reloc; x##_reloc=v
24 #define ENDPATCH(x) .globl x##_end; x##_end=.
26 /* Pseudo-flag used for virtual NMI, which we don't implement yet */
27 #define XEN_EFLAGS_NMI 0x80000000
31 x86-64 does not yet support direct access to percpu variables
32 via a segment override, so we just need to make sure this code
36 #define PER_CPU_VAR(var, off) 0xdeadbeef
40 Enable events. This clears the event mask and tests the pending
41 event status with one and operation. If there are pending
42 events, then enter the hypervisor to get them handled.
44 ENTRY(xen_irq_enable_direct)
48 movb $0, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask)
50 /* Preempt here doesn't matter because that will deal with
51 any pending interrupts. The pending check may end up being
52 run on the wrong CPU, but that doesn't hurt. */
54 /* Test for pending */
55 testb $0xff, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_pending)
60 ENDPATCH(xen_irq_enable_direct)
62 ENDPROC(xen_irq_enable_direct)
63 RELOC(xen_irq_enable_direct, 2b+1)
66 Disabling events is simply a matter of making the event mask
69 ENTRY(xen_irq_disable_direct)
72 movb $1, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask)
73 ENDPATCH(xen_irq_disable_direct)
75 ENDPROC(xen_irq_disable_direct)
76 RELOC(xen_irq_disable_direct, 0)
79 (xen_)save_fl is used to get the current interrupt enable status.
80 Callers expect the status to be in X86_EFLAGS_IF, and other bits
81 may be set in the return value. We take advantage of this by
82 making sure that X86_EFLAGS_IF has the right value (and other bits
83 in that byte are 0), but other bits in the return value are
84 undefined. We need to toggle the state of the bit, because
85 Xen and x86 use opposite senses (mask vs enable).
87 ENTRY(xen_save_fl_direct)
90 testb $0xff, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask)
93 ENDPATCH(xen_save_fl_direct)
95 ENDPROC(xen_save_fl_direct)
96 RELOC(xen_save_fl_direct, 0)
99 In principle the caller should be passing us a value return
100 from xen_save_fl_direct, but for robustness sake we test only
101 the X86_EFLAGS_IF flag rather than the whole byte. After
102 setting the interrupt mask state, it checks for unmasked
103 pending events and enters the hypervisor to get them delivered
106 ENTRY(xen_restore_fl_direct)
109 testb $X86_EFLAGS_IF>>8, %ah
110 setz PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask)
111 /* Preempt here doesn't matter because that will deal with
112 any pending interrupts. The pending check may end up being
113 run on the wrong CPU, but that doesn't hurt. */
115 /* check for unmasked and pending */
116 cmpw $0x0001, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_pending)
120 ENDPATCH(xen_restore_fl_direct)
122 ENDPROC(xen_restore_fl_direct)
123 RELOC(xen_restore_fl_direct, 2b+1)
127 Force an event check by making a hypercall,
128 but preserve regs before making the call.
140 call xen_force_evtchn_callback
152 ENTRY(xen_adjust_exception_frame)
157 hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
165 rip <-- standard iret frame
170 r11 }<-- pushed by hypercall page
175 1: jmp hypercall_iret
177 RELOC(xen_iret, 1b+1)
180 sysexit is not used for 64-bit processes, so it's
181 only ever used to return to 32-bit compat userspace.
191 1: jmp hypercall_iret
192 ENDPATCH(xen_sysexit)
193 RELOC(xen_sysexit, 1b+1)
196 /* We're already on the usermode stack at this point, but still
197 with the kernel gs, so we can easily switch back */
198 movq %rsp, %gs:pda_oldrsp
199 movq %gs:pda_kernelstack,%rsp
207 pushq $VGCF_in_syscall
208 1: jmp hypercall_iret
209 ENDPATCH(xen_sysret64)
210 RELOC(xen_sysret64, 1b+1)
213 /* We're already on the usermode stack at this point, but still
214 with the kernel gs, so we can easily switch back */
215 movq %rsp, %gs:pda_oldrsp
216 movq %gs:pda_kernelstack, %rsp
224 pushq $VGCF_in_syscall
225 1: jmp hypercall_iret
226 ENDPATCH(xen_sysret32)
227 RELOC(xen_sysret32, 1b+1)
230 Xen handles syscall callbacks much like ordinary exceptions,
234 - an iret-like stack frame on the stack (including rcx and r11):
243 In all the entrypoints, we undo all that to make it look
244 like a CPU-generated syscall/sysenter and jump to the normal
248 .macro undo_xen_syscall
254 /* Normal 64-bit system call target */
255 ENTRY(xen_syscall_target)
257 jmp system_call_after_swapgs
258 ENDPROC(xen_syscall_target)
260 #ifdef CONFIG_IA32_EMULATION
262 /* 32-bit compat syscall target */
263 ENTRY(xen_syscall32_target)
265 jmp ia32_cstar_target
266 ENDPROC(xen_syscall32_target)
268 /* 32-bit compat sysenter target */
269 ENTRY(xen_sysenter_target)
271 jmp ia32_sysenter_target
272 ENDPROC(xen_sysenter_target)
274 #else /* !CONFIG_IA32_EMULATION */
276 ENTRY(xen_syscall32_target)
277 ENTRY(xen_sysenter_target)
278 lea 16(%rsp), %rsp /* strip %rcx,%r11 */
280 pushq $VGCF_in_syscall
282 ENDPROC(xen_syscall32_target)
283 ENDPROC(xen_sysenter_target)
285 #endif /* CONFIG_IA32_EMULATION */