blob: f22667abf7b9d54d475edd08ffcdac8ba79b4cf3 [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>
Denys Vlasenko3a232082015-04-24 17:31:35 +020019#include <asm/thread_info.h>
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070020
21#include <xen/interface/xen.h>
22
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080023#include "xen-asm.h"
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070024
Jeremy Fitzhardinge997409d2008-07-08 15:07:00 -070025ENTRY(xen_adjust_exception_frame)
Tejun Heo130ace12009-02-06 00:57:48 +090026 mov 8+0(%rsp), %rcx
27 mov 8+8(%rsp), %r11
Jeremy Fitzhardinge997409d2008-07-08 15:07:00 -070028 ret $16
29
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070030hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
31/*
Tejun Heo130ace12009-02-06 00:57:48 +090032 * Xen64 iret frame:
33 *
34 * ss
35 * rsp
36 * rflags
37 * cs
38 * rip <-- standard iret frame
39 *
40 * flags
41 *
42 * rcx }
43 * r11 }<-- pushed by hypercall page
44 * rsp->rax }
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070045 */
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070046ENTRY(xen_iret)
47 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700481: jmp hypercall_iret
49ENDPATCH(xen_iret)
50RELOC(xen_iret, 1b+1)
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070051
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070052ENTRY(xen_sysret64)
Tejun Heo130ace12009-02-06 00:57:48 +090053 /*
54 * We're already on the usermode stack at this point, but
55 * still with the kernel gs, so we can easily switch back
56 */
Ingo Molnarc38e5032015-03-17 14:42:59 +010057 movq %rsp, PER_CPU_VAR(rsp_scratch)
Denys Vlasenko3a232082015-04-24 17:31:35 +020058 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070059
60 pushq $__USER_DS
Ingo Molnarc38e5032015-03-17 14:42:59 +010061 pushq PER_CPU_VAR(rsp_scratch)
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070062 pushq %r11
63 pushq $__USER_CS
64 pushq %rcx
65
66 pushq $VGCF_in_syscall
671: jmp hypercall_iret
68ENDPATCH(xen_sysret64)
69RELOC(xen_sysret64, 1b+1)
70
71ENTRY(xen_sysret32)
Tejun Heo130ace12009-02-06 00:57:48 +090072 /*
73 * We're already on the usermode stack at this point, but
74 * still with the kernel gs, so we can easily switch back
75 */
Ingo Molnarc38e5032015-03-17 14:42:59 +010076 movq %rsp, PER_CPU_VAR(rsp_scratch)
Denys Vlasenko3a232082015-04-24 17:31:35 +020077 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070078
79 pushq $__USER32_DS
Ingo Molnarc38e5032015-03-17 14:42:59 +010080 pushq PER_CPU_VAR(rsp_scratch)
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070081 pushq %r11
82 pushq $__USER32_CS
83 pushq %rcx
84
Jeremy Fitzhardinge6aaf5d62009-11-25 13:15:38 -080085 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700861: jmp hypercall_iret
87ENDPATCH(xen_sysret32)
88RELOC(xen_sysret32, 1b+1)
89
90/*
Tejun Heo130ace12009-02-06 00:57:48 +090091 * Xen handles syscall callbacks much like ordinary exceptions, which
92 * means we have:
93 * - kernel gs
94 * - kernel rsp
95 * - an iret-like stack frame on the stack (including rcx and r11):
96 * ss
97 * rsp
98 * rflags
99 * cs
100 * rip
101 * r11
102 * rsp->rcx
103 *
104 * In all the entrypoints, we undo all that to make it look like a
105 * CPU-generated syscall/sysenter and jump to the normal entrypoint.
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700106 */
107
108.macro undo_xen_syscall
Tejun Heo130ace12009-02-06 00:57:48 +0900109 mov 0*8(%rsp), %rcx
110 mov 1*8(%rsp), %r11
111 mov 5*8(%rsp), %rsp
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700112.endm
113
114/* Normal 64-bit system call target */
115ENTRY(xen_syscall_target)
116 undo_xen_syscall
Ingo Molnarb2502b42015-06-08 08:42:03 +0200117 jmp entry_SYSCALL_64_after_swapgs
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700118ENDPROC(xen_syscall_target)
119
120#ifdef CONFIG_IA32_EMULATION
121
122/* 32-bit compat syscall target */
123ENTRY(xen_syscall32_target)
124 undo_xen_syscall
Ingo Molnar2cd23552015-06-08 08:28:07 +0200125 jmp entry_SYSCALL_compat
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700126ENDPROC(xen_syscall32_target)
127
128/* 32-bit compat sysenter target */
129ENTRY(xen_sysenter_target)
130 undo_xen_syscall
Ingo Molnar4c8cd0c2015-06-08 08:33:56 +0200131 jmp entry_SYSENTER_compat
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700132ENDPROC(xen_sysenter_target)
133
134#else /* !CONFIG_IA32_EMULATION */
135
136ENTRY(xen_syscall32_target)
137ENTRY(xen_sysenter_target)
Tejun Heo130ace12009-02-06 00:57:48 +0900138 lea 16(%rsp), %rsp /* strip %rcx, %r11 */
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700139 mov $-ENOSYS, %rax
Jeremy Fitzhardinge6aaf5d62009-11-25 13:15:38 -0800140 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700141 jmp hypercall_iret
142ENDPROC(xen_syscall32_target)
143ENDPROC(xen_sysenter_target)
144
145#endif /* CONFIG_IA32_EMULATION */