Merge tag 's390-5.8-4' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
[linux-2.6-microblaze.git] / arch / x86 / xen / xen-asm_64.S
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
9 #include <asm/errno.h>
10 #include <asm/percpu.h>
11 #include <asm/processor-flags.h>
12 #include <asm/segment.h>
13 #include <asm/asm-offsets.h>
14 #include <asm/thread_info.h>
15 #include <asm/asm.h>
16
17 #include <xen/interface/xen.h>
18
19 #include <linux/init.h>
20 #include <linux/linkage.h>
21
22 .macro xen_pv_trap name
23 SYM_CODE_START(xen_\name)
24         pop %rcx
25         pop %r11
26         jmp  \name
27 SYM_CODE_END(xen_\name)
28 _ASM_NOKPROBE(xen_\name)
29 .endm
30
31 xen_pv_trap asm_exc_divide_error
32 xen_pv_trap asm_xenpv_exc_debug
33 xen_pv_trap asm_exc_int3
34 xen_pv_trap asm_xenpv_exc_nmi
35 xen_pv_trap asm_exc_overflow
36 xen_pv_trap asm_exc_bounds
37 xen_pv_trap asm_exc_invalid_op
38 xen_pv_trap asm_exc_device_not_available
39 xen_pv_trap asm_exc_double_fault
40 xen_pv_trap asm_exc_coproc_segment_overrun
41 xen_pv_trap asm_exc_invalid_tss
42 xen_pv_trap asm_exc_segment_not_present
43 xen_pv_trap asm_exc_stack_segment
44 xen_pv_trap asm_exc_general_protection
45 xen_pv_trap asm_exc_page_fault
46 xen_pv_trap asm_exc_spurious_interrupt_bug
47 xen_pv_trap asm_exc_coprocessor_error
48 xen_pv_trap asm_exc_alignment_check
49 #ifdef CONFIG_X86_MCE
50 xen_pv_trap asm_exc_machine_check
51 #endif /* CONFIG_X86_MCE */
52 xen_pv_trap asm_exc_simd_coprocessor_error
53 #ifdef CONFIG_IA32_EMULATION
54 xen_pv_trap entry_INT80_compat
55 #endif
56 xen_pv_trap asm_exc_xen_hypervisor_callback
57
58         __INIT
59 SYM_CODE_START(xen_early_idt_handler_array)
60         i = 0
61         .rept NUM_EXCEPTION_VECTORS
62         pop %rcx
63         pop %r11
64         jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
65         i = i + 1
66         .fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
67         .endr
68 SYM_CODE_END(xen_early_idt_handler_array)
69         __FINIT
70
71 hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
72 /*
73  * Xen64 iret frame:
74  *
75  *      ss
76  *      rsp
77  *      rflags
78  *      cs
79  *      rip             <-- standard iret frame
80  *
81  *      flags
82  *
83  *      rcx             }
84  *      r11             }<-- pushed by hypercall page
85  * rsp->rax             }
86  */
87 SYM_CODE_START(xen_iret)
88         pushq $0
89         jmp hypercall_iret
90 SYM_CODE_END(xen_iret)
91
92 SYM_CODE_START(xen_sysret64)
93         /*
94          * We're already on the usermode stack at this point, but
95          * still with the kernel gs, so we can easily switch back.
96          *
97          * tss.sp2 is scratch space.
98          */
99         movq %rsp, PER_CPU_VAR(cpu_tss_rw + TSS_sp2)
100         movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
101
102         pushq $__USER_DS
103         pushq PER_CPU_VAR(cpu_tss_rw + TSS_sp2)
104         pushq %r11
105         pushq $__USER_CS
106         pushq %rcx
107
108         pushq $VGCF_in_syscall
109         jmp hypercall_iret
110 SYM_CODE_END(xen_sysret64)
111
112 /*
113  * Xen handles syscall callbacks much like ordinary exceptions, which
114  * means we have:
115  * - kernel gs
116  * - kernel rsp
117  * - an iret-like stack frame on the stack (including rcx and r11):
118  *      ss
119  *      rsp
120  *      rflags
121  *      cs
122  *      rip
123  *      r11
124  * rsp->rcx
125  */
126
127 /* Normal 64-bit system call target */
128 SYM_FUNC_START(xen_syscall_target)
129         popq %rcx
130         popq %r11
131
132         /*
133          * Neither Xen nor the kernel really knows what the old SS and
134          * CS were.  The kernel expects __USER_DS and __USER_CS, so
135          * report those values even though Xen will guess its own values.
136          */
137         movq $__USER_DS, 4*8(%rsp)
138         movq $__USER_CS, 1*8(%rsp)
139
140         jmp entry_SYSCALL_64_after_hwframe
141 SYM_FUNC_END(xen_syscall_target)
142
143 #ifdef CONFIG_IA32_EMULATION
144
145 /* 32-bit compat syscall target */
146 SYM_FUNC_START(xen_syscall32_target)
147         popq %rcx
148         popq %r11
149
150         /*
151          * Neither Xen nor the kernel really knows what the old SS and
152          * CS were.  The kernel expects __USER32_DS and __USER32_CS, so
153          * report those values even though Xen will guess its own values.
154          */
155         movq $__USER32_DS, 4*8(%rsp)
156         movq $__USER32_CS, 1*8(%rsp)
157
158         jmp entry_SYSCALL_compat_after_hwframe
159 SYM_FUNC_END(xen_syscall32_target)
160
161 /* 32-bit compat sysenter target */
162 SYM_FUNC_START(xen_sysenter_target)
163         /*
164          * NB: Xen is polite and clears TF from EFLAGS for us.  This means
165          * that we don't need to guard against single step exceptions here.
166          */
167         popq %rcx
168         popq %r11
169
170         /*
171          * Neither Xen nor the kernel really knows what the old SS and
172          * CS were.  The kernel expects __USER32_DS and __USER32_CS, so
173          * report those values even though Xen will guess its own values.
174          */
175         movq $__USER32_DS, 4*8(%rsp)
176         movq $__USER32_CS, 1*8(%rsp)
177
178         jmp entry_SYSENTER_compat_after_hwframe
179 SYM_FUNC_END(xen_sysenter_target)
180
181 #else /* !CONFIG_IA32_EMULATION */
182
183 SYM_FUNC_START_ALIAS(xen_syscall32_target)
184 SYM_FUNC_START(xen_sysenter_target)
185         lea 16(%rsp), %rsp      /* strip %rcx, %r11 */
186         mov $-ENOSYS, %rax
187         pushq $0
188         jmp hypercall_iret
189 SYM_FUNC_END(xen_sysenter_target)
190 SYM_FUNC_END_ALIAS(xen_syscall32_target)
191
192 #endif  /* CONFIG_IA32_EMULATION */