blob: 5aa7ec607b9e3d3b7bb48dfdcd3341a55ac00dda [file] [log] [blame]
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -07001/*
Tejun Heo130ace12009-02-06 00:57:48 +09002 * 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 pda) of the
10 * operations here; the indirect forms are better handled in C, since
11 * they're generally too large to inline anyway.
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070012 */
13
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070014#include <asm/errno.h>
Brian Gerst9af45652009-01-19 00:38:58 +090015#include <asm/percpu.h>
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080016#include <asm/processor-flags.h>
17#include <asm/segment.h>
Denys Vlasenko63332a82015-04-24 17:31:33 +020018#include <asm/asm-offsets.h>
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070019
20#include <xen/interface/xen.h>
21
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080022#include "xen-asm.h"
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070023
Jeremy Fitzhardinge997409d2008-07-08 15:07:00 -070024ENTRY(xen_adjust_exception_frame)
Tejun Heo130ace12009-02-06 00:57:48 +090025 mov 8+0(%rsp), %rcx
26 mov 8+8(%rsp), %r11
Jeremy Fitzhardinge997409d2008-07-08 15:07:00 -070027 ret $16
28
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070029hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
30/*
Tejun Heo130ace12009-02-06 00:57:48 +090031 * Xen64 iret frame:
32 *
33 * ss
34 * rsp
35 * rflags
36 * cs
37 * rip <-- standard iret frame
38 *
39 * flags
40 *
41 * rcx }
42 * r11 }<-- pushed by hypercall page
43 * rsp->rax }
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070044 */
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070045ENTRY(xen_iret)
46 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700471: jmp hypercall_iret
48ENDPATCH(xen_iret)
49RELOC(xen_iret, 1b+1)
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070050
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070051ENTRY(xen_sysret64)
Tejun Heo130ace12009-02-06 00:57:48 +090052 /*
53 * We're already on the usermode stack at this point, but
54 * still with the kernel gs, so we can easily switch back
55 */
Ingo Molnarc38e5032015-03-17 14:42:59 +010056 movq %rsp, PER_CPU_VAR(rsp_scratch)
Denys Vlasenko63332a82015-04-24 17:31:33 +020057 movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070058
59 pushq $__USER_DS
Ingo Molnarc38e5032015-03-17 14:42:59 +010060 pushq PER_CPU_VAR(rsp_scratch)
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070061 pushq %r11
62 pushq $__USER_CS
63 pushq %rcx
64
65 pushq $VGCF_in_syscall
661: jmp hypercall_iret
67ENDPATCH(xen_sysret64)
68RELOC(xen_sysret64, 1b+1)
69
70ENTRY(xen_sysret32)
Tejun Heo130ace12009-02-06 00:57:48 +090071 /*
72 * We're already on the usermode stack at this point, but
73 * still with the kernel gs, so we can easily switch back
74 */
Ingo Molnarc38e5032015-03-17 14:42:59 +010075 movq %rsp, PER_CPU_VAR(rsp_scratch)
Denys Vlasenko63332a82015-04-24 17:31:33 +020076 movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070077
78 pushq $__USER32_DS
Ingo Molnarc38e5032015-03-17 14:42:59 +010079 pushq PER_CPU_VAR(rsp_scratch)
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070080 pushq %r11
81 pushq $__USER32_CS
82 pushq %rcx
83
Jeremy Fitzhardinge6aaf5d62009-11-25 13:15:38 -080084 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700851: jmp hypercall_iret
86ENDPATCH(xen_sysret32)
87RELOC(xen_sysret32, 1b+1)
88
89/*
Tejun Heo130ace12009-02-06 00:57:48 +090090 * Xen handles syscall callbacks much like ordinary exceptions, which
91 * means we have:
92 * - kernel gs
93 * - kernel rsp
94 * - an iret-like stack frame on the stack (including rcx and r11):
95 * ss
96 * rsp
97 * rflags
98 * cs
99 * rip
100 * r11
101 * rsp->rcx
102 *
103 * In all the entrypoints, we undo all that to make it look like a
104 * CPU-generated syscall/sysenter and jump to the normal entrypoint.
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700105 */
106
107.macro undo_xen_syscall
Tejun Heo130ace12009-02-06 00:57:48 +0900108 mov 0*8(%rsp), %rcx
109 mov 1*8(%rsp), %r11
110 mov 5*8(%rsp), %rsp
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700111.endm
112
113/* Normal 64-bit system call target */
114ENTRY(xen_syscall_target)
115 undo_xen_syscall
116 jmp system_call_after_swapgs
117ENDPROC(xen_syscall_target)
118
119#ifdef CONFIG_IA32_EMULATION
120
121/* 32-bit compat syscall target */
122ENTRY(xen_syscall32_target)
123 undo_xen_syscall
124 jmp ia32_cstar_target
125ENDPROC(xen_syscall32_target)
126
127/* 32-bit compat sysenter target */
128ENTRY(xen_sysenter_target)
129 undo_xen_syscall
130 jmp ia32_sysenter_target
131ENDPROC(xen_sysenter_target)
132
133#else /* !CONFIG_IA32_EMULATION */
134
135ENTRY(xen_syscall32_target)
136ENTRY(xen_sysenter_target)
Tejun Heo130ace12009-02-06 00:57:48 +0900137 lea 16(%rsp), %rsp /* strip %rcx, %r11 */
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700138 mov $-ENOSYS, %rax
Jeremy Fitzhardinge6aaf5d62009-11-25 13:15:38 -0800139 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700140 jmp hypercall_iret
141ENDPROC(xen_syscall32_target)
142ENDPROC(xen_sysenter_target)
143
144#endif /* CONFIG_IA32_EMULATION */