Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Compatibility mode system call entry point for x86-64. | |
3 | * | |
4 | * Copyright 2000-2002 Andi Kleen, SuSE Labs. | |
5 | */ | |
6 | ||
d36f9479 | 7 | #include "calling.h" |
e2d5df93 | 8 | #include <asm/asm-offsets.h> |
1da177e4 LT |
9 | #include <asm/current.h> |
10 | #include <asm/errno.h> | |
11 | #include <asm/ia32_unistd.h> | |
12 | #include <asm/thread_info.h> | |
13 | #include <asm/segment.h> | |
2601e64d | 14 | #include <asm/irqflags.h> |
1ce6f868 | 15 | #include <asm/asm.h> |
63bcff2a | 16 | #include <asm/smap.h> |
1da177e4 | 17 | #include <linux/linkage.h> |
d7e7528b | 18 | #include <linux/err.h> |
1da177e4 | 19 | |
5cbf1565 RM |
20 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
21 | #include <linux/elf-em.h> | |
22 | #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE) | |
23 | #define __AUDIT_ARCH_LE 0x40000000 | |
24 | ||
25 | #ifndef CONFIG_AUDITSYSCALL | |
24e35800 JB |
26 | #define sysexit_audit ia32_ret_from_sys_call |
27 | #define sysretl_audit ia32_ret_from_sys_call | |
5cbf1565 RM |
28 | #endif |
29 | ||
ea714547 JO |
30 | .section .entry.text, "ax" |
31 | ||
2be29982 JF |
32 | #ifdef CONFIG_PARAVIRT |
33 | ENTRY(native_usergs_sysret32) | |
34 | swapgs | |
35 | sysretl | |
36 | ENDPROC(native_usergs_sysret32) | |
2be29982 JF |
37 | #endif |
38 | ||
1da177e4 LT |
39 | /* |
40 | * 32bit SYSENTER instruction entry. | |
41 | * | |
b87cf63e DV |
42 | * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs. |
43 | * IF and VM in rflags are cleared (IOW: interrupts are off). | |
44 | * SYSENTER does not save anything on the stack, | |
45 | * and does not save old rip (!!!) and rflags. | |
46 | * | |
1da177e4 | 47 | * Arguments: |
b87cf63e DV |
48 | * eax system call number |
49 | * ebx arg1 | |
50 | * ecx arg2 | |
51 | * edx arg3 | |
52 | * esi arg4 | |
53 | * edi arg5 | |
54 | * ebp user stack | |
55 | * 0(%ebp) arg6 | |
56 | * | |
1da177e4 | 57 | * This is purely a fast path. For anything complicated we use the int 0x80 |
b87cf63e | 58 | * path below. We set up a complete hardware stack frame to share code |
1da177e4 | 59 | * with the int 0x80 path. |
b87cf63e | 60 | */ |
1da177e4 | 61 | ENTRY(ia32_sysenter_target) |
2601e64d | 62 | /* |
a232e3d5 DV |
63 | * Interrupts are off on entry. |
64 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, | |
65 | * it is too small to ever cause noticeable irq latency. | |
2601e64d | 66 | */ |
a232e3d5 | 67 | SWAPGS_UNSAFE_STACK |
3a23208e | 68 | movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp |
66804154 | 69 | ENABLE_INTERRUPTS(CLBR_NONE) |
a232e3d5 | 70 | |
4ee8ec17 DV |
71 | /* Zero-extending 32-bit regs, do not remove */ |
72 | movl %ebp, %ebp | |
73 | movl %eax, %eax | |
74 | ||
4c9c0e91 | 75 | movl ASM_THREAD_INFO(TI_sysenter_return, %rsp, 0), %r10d |
4c9c0e91 DV |
76 | |
77 | /* Construct struct pt_regs on stack */ | |
131484c8 IM |
78 | pushq $__USER32_DS /* pt_regs->ss */ |
79 | pushq %rbp /* pt_regs->sp */ | |
80 | pushfq /* pt_regs->flags */ | |
81 | pushq $__USER32_CS /* pt_regs->cs */ | |
82 | pushq %r10 /* pt_regs->ip = thread_info->sysenter_return */ | |
83 | pushq %rax /* pt_regs->orig_ax */ | |
84 | pushq %rdi /* pt_regs->di */ | |
85 | pushq %rsi /* pt_regs->si */ | |
86 | pushq %rdx /* pt_regs->dx */ | |
87 | pushq %rcx /* pt_regs->cx */ | |
88 | pushq $-ENOSYS /* pt_regs->ax */ | |
1da177e4 | 89 | cld |
4c9c0e91 | 90 | sub $(10*8),%rsp /* pt_regs->r8-11,bp,bx,r12-15 not saved */ |
4c9c0e91 | 91 | |
b87cf63e DV |
92 | /* |
93 | * no need to do an access_ok check here because rbp has been | |
94 | * 32bit zero extended | |
95 | */ | |
63bcff2a | 96 | ASM_STAC |
295286a8 | 97 | 1: movl (%rbp),%ebp |
1ce6f868 | 98 | _ASM_EXTABLE(1b,ia32_badarg) |
63bcff2a | 99 | ASM_CLAC |
8c7aa698 AL |
100 | |
101 | /* | |
102 | * Sysenter doesn't filter flags, so we need to clear NT | |
103 | * ourselves. To save a few cycles, we can check whether | |
104 | * NT was set instead of doing an unconditional popfq. | |
105 | */ | |
f2db9382 | 106 | testl $X86_EFLAGS_NT,EFLAGS(%rsp) |
8c7aa698 AL |
107 | jnz sysenter_fix_flags |
108 | sysenter_flags_fixed: | |
109 | ||
dca5b52a IM |
110 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
111 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) | |
1da177e4 | 112 | jnz sysenter_tracesys |
131484c8 | 113 | |
d4d67150 | 114 | sysenter_do_call: |
14f6e953 DV |
115 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
116 | movl %edi,%r8d /* arg5 */ | |
117 | movl %ebp,%r9d /* arg6 */ | |
118 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ | |
119 | movl %ebx,%edi /* arg1 */ | |
120 | movl %edx,%edx /* arg3 (zero extension) */ | |
5cbf1565 | 121 | sysenter_dispatch: |
3f5159a9 DV |
122 | cmpq $(IA32_NR_syscalls-1),%rax |
123 | ja 1f | |
1da177e4 | 124 | call *ia32_sys_call_table(,%rax,8) |
f2db9382 | 125 | movq %rax,RAX(%rsp) |
3f5159a9 | 126 | 1: |
66804154 | 127 | DISABLE_INTERRUPTS(CLBR_NONE) |
2601e64d | 128 | TRACE_IRQS_OFF |
dca5b52a | 129 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
5cbf1565 RM |
130 | jnz sysexit_audit |
131 | sysexit_from_sys_call: | |
4214a16b AL |
132 | /* |
133 | * NB: SYSEXIT is not obviously safe for 64-bit kernels -- an | |
134 | * NMI between STI and SYSEXIT has poorly specified behavior, | |
135 | * and and NMI followed by an IRQ with usergs is fatal. So | |
136 | * we just pretend we're using SYSEXIT but we really use | |
137 | * SYSRETL instead. | |
138 | * | |
139 | * This code path is still called 'sysexit' because it pairs | |
140 | * with 'sysenter' and it uses the SYSENTER calling convention. | |
141 | */ | |
dca5b52a | 142 | andl $~TS_COMPAT,ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
4214a16b | 143 | movl RIP(%rsp),%ecx /* User %eip */ |
76f5df43 | 144 | RESTORE_RSI_RDI |
4214a16b | 145 | xorl %edx,%edx /* avoid info leaks */ |
24e35800 JB |
146 | xorq %r8,%r8 |
147 | xorq %r9,%r9 | |
148 | xorq %r10,%r10 | |
4214a16b | 149 | movl EFLAGS(%rsp),%r11d /* User eflags */ |
2601e64d | 150 | TRACE_IRQS_ON |
4214a16b AL |
151 | |
152 | /* | |
153 | * SYSRETL works even on Intel CPUs. Use it in preference to SYSEXIT, | |
154 | * since it avoids a dicey window with interrupts enabled. | |
155 | */ | |
156 | movl RSP(%rsp),%esp | |
157 | ||
b87cf63e | 158 | /* |
4214a16b AL |
159 | * USERGS_SYSRET32 does: |
160 | * gsbase = user's gs base | |
161 | * eip = ecx | |
162 | * rflags = r11 | |
163 | * cs = __USER32_CS | |
164 | * ss = __USER_DS | |
165 | * | |
166 | * The prologue set RIP(%rsp) to VDSO32_SYSENTER_RETURN, which does: | |
167 | * | |
168 | * pop %ebp | |
169 | * pop %edx | |
170 | * pop %ecx | |
171 | * | |
172 | * Therefore, we invoke SYSRETL with EDX and R8-R10 zeroed to | |
173 | * avoid info leaks. R11 ends up with VDSO32_SYSENTER_RETURN's | |
174 | * address (already known to user code), and R12-R15 are | |
175 | * callee-saved and therefore don't contain any interesting | |
176 | * kernel data. | |
b87cf63e | 177 | */ |
4214a16b | 178 | USERGS_SYSRET32 |
1da177e4 | 179 | |
5cbf1565 RM |
180 | #ifdef CONFIG_AUDITSYSCALL |
181 | .macro auditsys_entry_common | |
b4f0d375 RGB |
182 | movl %esi,%r8d /* 5th arg: 4th syscall arg */ |
183 | movl %ecx,%r9d /*swap with edx*/ | |
184 | movl %edx,%ecx /* 4th arg: 3rd syscall arg */ | |
185 | movl %r9d,%edx /* 3rd arg: 2nd syscall arg */ | |
186 | movl %ebx,%esi /* 2nd arg: 1st syscall arg */ | |
187 | movl %eax,%edi /* 1st arg: syscall number */ | |
b05d8447 | 188 | call __audit_syscall_entry |
3f5159a9 | 189 | movl ORIG_RAX(%rsp),%eax /* reload syscall number */ |
5cbf1565 | 190 | movl %ebx,%edi /* reload 1st syscall arg */ |
f2db9382 DV |
191 | movl RCX(%rsp),%esi /* reload 2nd syscall arg */ |
192 | movl RDX(%rsp),%edx /* reload 3rd syscall arg */ | |
193 | movl RSI(%rsp),%ecx /* reload 4th syscall arg */ | |
194 | movl RDI(%rsp),%r8d /* reload 5th syscall arg */ | |
5cbf1565 RM |
195 | .endm |
196 | ||
81766741 | 197 | .macro auditsys_exit exit |
dca5b52a | 198 | testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
24e35800 | 199 | jnz ia32_ret_from_sys_call |
5cbf1565 | 200 | TRACE_IRQS_ON |
40a1ef95 | 201 | ENABLE_INTERRUPTS(CLBR_NONE) |
5cbf1565 | 202 | movl %eax,%esi /* second arg, syscall return value */ |
d7e7528b | 203 | cmpl $-MAX_ERRNO,%eax /* is it an error ? */ |
f031cd25 EP |
204 | jbe 1f |
205 | movslq %eax, %rsi /* if error sign extend to 64 bits */ | |
206 | 1: setbe %al /* 1 if error, 0 if not */ | |
5cbf1565 | 207 | movzbl %al,%edi /* zero-extend that into %edi */ |
d7e7528b | 208 | call __audit_syscall_exit |
f2db9382 | 209 | movq RAX(%rsp),%rax /* reload syscall return value */ |
5cbf1565 | 210 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi |
40a1ef95 | 211 | DISABLE_INTERRUPTS(CLBR_NONE) |
5cbf1565 | 212 | TRACE_IRQS_OFF |
dca5b52a | 213 | testl %edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
24e35800 | 214 | jz \exit |
ef0cd5dc DV |
215 | xorl %eax, %eax /* do not leak kernel information */ |
216 | movq %rax, R11(%rsp) | |
217 | movq %rax, R10(%rsp) | |
218 | movq %rax, R9(%rsp) | |
219 | movq %rax, R8(%rsp) | |
24e35800 | 220 | jmp int_with_check |
5cbf1565 RM |
221 | .endm |
222 | ||
223 | sysenter_auditsys: | |
5cbf1565 RM |
224 | auditsys_entry_common |
225 | movl %ebp,%r9d /* reload 6th syscall arg */ | |
226 | jmp sysenter_dispatch | |
227 | ||
228 | sysexit_audit: | |
229 | auditsys_exit sysexit_from_sys_call | |
230 | #endif | |
231 | ||
8c7aa698 | 232 | sysenter_fix_flags: |
131484c8 IM |
233 | pushq $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) |
234 | popfq | |
8c7aa698 AL |
235 | jmp sysenter_flags_fixed |
236 | ||
5cbf1565 | 237 | sysenter_tracesys: |
5cbf1565 | 238 | #ifdef CONFIG_AUDITSYSCALL |
dca5b52a | 239 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
5cbf1565 RM |
240 | jz sysenter_auditsys |
241 | #endif | |
76f5df43 | 242 | SAVE_EXTRA_REGS |
ef0cd5dc DV |
243 | xorl %eax, %eax /* do not leak kernel information */ |
244 | movq %rax, R11(%rsp) | |
245 | movq %rax, R10(%rsp) | |
246 | movq %rax, R9(%rsp) | |
247 | movq %rax, R8(%rsp) | |
1da177e4 LT |
248 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
249 | call syscall_trace_enter | |
73cbf687 DV |
250 | |
251 | /* Reload arg registers from stack. (see sysenter_tracesys) */ | |
252 | movl RCX(%rsp), %ecx | |
253 | movl RDX(%rsp), %edx | |
254 | movl RSI(%rsp), %esi | |
255 | movl RDI(%rsp), %edi | |
256 | movl %eax, %eax /* zero extension */ | |
257 | ||
76f5df43 | 258 | RESTORE_EXTRA_REGS |
1da177e4 | 259 | jmp sysenter_do_call |
4b787e0b | 260 | ENDPROC(ia32_sysenter_target) |
1da177e4 LT |
261 | |
262 | /* | |
263 | * 32bit SYSCALL instruction entry. | |
264 | * | |
b87cf63e DV |
265 | * 32bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11, |
266 | * then loads new ss, cs, and rip from previously programmed MSRs. | |
267 | * rflags gets masked by a value from another MSR (so CLD and CLAC | |
268 | * are not needed). SYSCALL does not save anything on the stack | |
269 | * and does not change rsp. | |
270 | * | |
271 | * Note: rflags saving+masking-with-MSR happens only in Long mode | |
272 | * (in legacy 32bit mode, IF, RF and VM bits are cleared and that's it). | |
273 | * Don't get confused: rflags saving+masking depends on Long Mode Active bit | |
274 | * (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes | |
275 | * or target CS descriptor's L bit (SYSCALL does not read segment descriptors). | |
276 | * | |
1da177e4 | 277 | * Arguments: |
b87cf63e DV |
278 | * eax system call number |
279 | * ecx return address | |
280 | * ebx arg1 | |
281 | * ebp arg2 (note: not saved in the stack frame, should not be touched) | |
282 | * edx arg3 | |
283 | * esi arg4 | |
284 | * edi arg5 | |
285 | * esp user stack | |
286 | * 0(%esp) arg6 | |
287 | * | |
1da177e4 | 288 | * This is purely a fast path. For anything complicated we use the int 0x80 |
b87cf63e DV |
289 | * path below. We set up a complete hardware stack frame to share code |
290 | * with the int 0x80 path. | |
291 | */ | |
1da177e4 | 292 | ENTRY(ia32_cstar_target) |
a232e3d5 DV |
293 | /* |
294 | * Interrupts are off on entry. | |
295 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, | |
296 | * it is too small to ever cause noticeable irq latency. | |
297 | */ | |
457da70e | 298 | SWAPGS_UNSAFE_STACK |
1da177e4 | 299 | movl %esp,%r8d |
3a23208e | 300 | movq PER_CPU_VAR(cpu_current_top_of_stack),%rsp |
66804154 | 301 | ENABLE_INTERRUPTS(CLBR_NONE) |
a232e3d5 | 302 | |
4ee8ec17 DV |
303 | /* Zero-extending 32-bit regs, do not remove */ |
304 | movl %eax,%eax | |
305 | ||
4c9c0e91 | 306 | /* Construct struct pt_regs on stack */ |
131484c8 IM |
307 | pushq $__USER32_DS /* pt_regs->ss */ |
308 | pushq %r8 /* pt_regs->sp */ | |
309 | pushq %r11 /* pt_regs->flags */ | |
310 | pushq $__USER32_CS /* pt_regs->cs */ | |
311 | pushq %rcx /* pt_regs->ip */ | |
312 | pushq %rax /* pt_regs->orig_ax */ | |
313 | pushq %rdi /* pt_regs->di */ | |
314 | pushq %rsi /* pt_regs->si */ | |
315 | pushq %rdx /* pt_regs->dx */ | |
316 | pushq %rbp /* pt_regs->cx */ | |
1da177e4 | 317 | movl %ebp,%ecx |
131484c8 | 318 | pushq $-ENOSYS /* pt_regs->ax */ |
4c9c0e91 | 319 | sub $(10*8),%rsp /* pt_regs->r8-11,bp,bx,r12-15 not saved */ |
4c9c0e91 | 320 | |
b87cf63e DV |
321 | /* |
322 | * no need to do an access_ok check here because r8 has been | |
323 | * 32bit zero extended | |
324 | */ | |
63bcff2a | 325 | ASM_STAC |
53e9accf | 326 | 1: movl (%r8),%ebp |
a3e859fe | 327 | _ASM_EXTABLE(1b,ia32_badarg) |
63bcff2a | 328 | ASM_CLAC |
dca5b52a IM |
329 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
330 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) | |
1da177e4 | 331 | jnz cstar_tracesys |
131484c8 | 332 | |
295286a8 | 333 | cstar_do_call: |
14f6e953 DV |
334 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
335 | movl %edi,%r8d /* arg5 */ | |
53e9accf | 336 | movl %ebp,%r9d /* arg6 */ |
14f6e953 DV |
337 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
338 | movl %ebx,%edi /* arg1 */ | |
339 | movl %edx,%edx /* arg3 (zero extension) */ | |
5cbf1565 | 340 | cstar_dispatch: |
3f5159a9 DV |
341 | cmpq $(IA32_NR_syscalls-1),%rax |
342 | ja 1f | |
1da177e4 | 343 | call *ia32_sys_call_table(,%rax,8) |
f2db9382 | 344 | movq %rax,RAX(%rsp) |
3f5159a9 | 345 | 1: |
66804154 | 346 | DISABLE_INTERRUPTS(CLBR_NONE) |
2601e64d | 347 | TRACE_IRQS_OFF |
dca5b52a | 348 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
5cbf1565 RM |
349 | jnz sysretl_audit |
350 | sysretl_from_sys_call: | |
dca5b52a | 351 | andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
53e9accf | 352 | movl RCX(%rsp), %ebp |
76f5df43 | 353 | RESTORE_RSI_RDI_RDX |
f2db9382 | 354 | movl RIP(%rsp),%ecx |
f2db9382 | 355 | movl EFLAGS(%rsp),%r11d |
24e35800 JB |
356 | xorq %r10,%r10 |
357 | xorq %r9,%r9 | |
358 | xorq %r8,%r8 | |
2601e64d | 359 | TRACE_IRQS_ON |
f2db9382 | 360 | movl RSP(%rsp),%esp |
b87cf63e DV |
361 | /* |
362 | * 64bit->32bit SYSRET restores eip from ecx, | |
363 | * eflags from r11 (but RF and VM bits are forced to 0), | |
364 | * cs and ss are loaded from MSRs. | |
365 | * (Note: 32bit->32bit SYSRET is different: since r11 | |
366 | * does not exist, it merely sets eflags.IF=1). | |
61f01dd9 AL |
367 | * |
368 | * NB: On AMD CPUs with the X86_BUG_SYSRET_SS_ATTRS bug, the ss | |
369 | * descriptor is not reinitialized. This means that we must | |
370 | * avoid SYSRET with SS == NULL, which could happen if we schedule, | |
371 | * exit the kernel, and re-enter using an interrupt vector. (All | |
372 | * interrupt entries on x86_64 set SS to NULL.) We prevent that | |
373 | * from happening by reloading SS in __switch_to. | |
b87cf63e | 374 | */ |
2be29982 | 375 | USERGS_SYSRET32 |
b87cf63e | 376 | |
5cbf1565 RM |
377 | #ifdef CONFIG_AUDITSYSCALL |
378 | cstar_auditsys: | |
5cbf1565 | 379 | auditsys_entry_common |
53e9accf | 380 | movl %ebp, %r9d /* reload 6th syscall arg */ |
5cbf1565 RM |
381 | jmp cstar_dispatch |
382 | ||
383 | sysretl_audit: | |
81766741 | 384 | auditsys_exit sysretl_from_sys_call |
5cbf1565 RM |
385 | #endif |
386 | ||
387 | cstar_tracesys: | |
388 | #ifdef CONFIG_AUDITSYSCALL | |
dca5b52a | 389 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
5cbf1565 RM |
390 | jz cstar_auditsys |
391 | #endif | |
76f5df43 | 392 | SAVE_EXTRA_REGS |
ef0cd5dc DV |
393 | xorl %eax, %eax /* do not leak kernel information */ |
394 | movq %rax, R11(%rsp) | |
395 | movq %rax, R10(%rsp) | |
53e9accf | 396 | movq %rax, R9(%rsp) |
ef0cd5dc | 397 | movq %rax, R8(%rsp) |
53e9accf DV |
398 | movq %rsp, %rdi /* &pt_regs -> arg1 */ |
399 | call syscall_trace_enter | |
73cbf687 DV |
400 | |
401 | /* Reload arg registers from stack. (see sysenter_tracesys) */ | |
402 | movl RCX(%rsp), %ecx | |
403 | movl RDX(%rsp), %edx | |
404 | movl RSI(%rsp), %esi | |
405 | movl RDI(%rsp), %edi | |
406 | movl %eax, %eax /* zero extension */ | |
407 | ||
76f5df43 | 408 | RESTORE_EXTRA_REGS |
53e9accf | 409 | jmp cstar_do_call |
4b787e0b | 410 | END(ia32_cstar_target) |
1da177e4 LT |
411 | |
412 | ia32_badarg: | |
63bcff2a | 413 | ASM_CLAC |
1da177e4 LT |
414 | movq $-EFAULT,%rax |
415 | jmp ia32_sysret | |
1da177e4 | 416 | |
61b1e3e7 | 417 | ia32_ret_from_sys_call: |
ef0cd5dc DV |
418 | xorl %eax, %eax /* do not leak kernel information */ |
419 | movq %rax, R11(%rsp) | |
420 | movq %rax, R10(%rsp) | |
421 | movq %rax, R9(%rsp) | |
422 | movq %rax, R8(%rsp) | |
61b1e3e7 DV |
423 | jmp int_ret_from_sys_call |
424 | ||
b87cf63e DV |
425 | /* |
426 | * Emulated IA32 system calls via int 0x80. | |
1da177e4 | 427 | * |
b87cf63e DV |
428 | * Arguments: |
429 | * eax system call number | |
430 | * ebx arg1 | |
431 | * ecx arg2 | |
432 | * edx arg3 | |
433 | * esi arg4 | |
434 | * edi arg5 | |
435 | * ebp arg6 (note: not saved in the stack frame, should not be touched) | |
1da177e4 LT |
436 | * |
437 | * Notes: | |
b87cf63e DV |
438 | * Uses the same stack frame as the x86-64 version. |
439 | * All registers except eax must be saved (but ptrace may violate that). | |
1da177e4 LT |
440 | * Arguments are zero extended. For system calls that want sign extension and |
441 | * take long arguments a wrapper is needed. Most calls can just be called | |
442 | * directly. | |
b87cf63e DV |
443 | * Assumes it is only called from user space and entered with interrupts off. |
444 | */ | |
1da177e4 LT |
445 | |
446 | ENTRY(ia32_syscall) | |
2601e64d | 447 | /* |
a232e3d5 DV |
448 | * Interrupts are off on entry. |
449 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, | |
450 | * it is too small to ever cause noticeable irq latency. | |
2601e64d | 451 | */ |
a232e3d5 DV |
452 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
453 | SWAPGS | |
66804154 | 454 | ENABLE_INTERRUPTS(CLBR_NONE) |
a232e3d5 | 455 | |
4ee8ec17 DV |
456 | /* Zero-extending 32-bit regs, do not remove */ |
457 | movl %eax,%eax | |
458 | ||
4c9c0e91 | 459 | /* Construct struct pt_regs on stack (iret frame is already on stack) */ |
131484c8 IM |
460 | pushq %rax /* pt_regs->orig_ax */ |
461 | pushq %rdi /* pt_regs->di */ | |
462 | pushq %rsi /* pt_regs->si */ | |
463 | pushq %rdx /* pt_regs->dx */ | |
464 | pushq %rcx /* pt_regs->cx */ | |
465 | pushq $-ENOSYS /* pt_regs->ax */ | |
61b1e3e7 DV |
466 | pushq $0 /* pt_regs->r8 */ |
467 | pushq $0 /* pt_regs->r9 */ | |
468 | pushq $0 /* pt_regs->r10 */ | |
469 | pushq $0 /* pt_regs->r11 */ | |
1da177e4 | 470 | cld |
61b1e3e7 | 471 | sub $(6*8),%rsp /* pt_regs->bp,bx,r12-15 not saved */ |
4c9c0e91 | 472 | |
dca5b52a IM |
473 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
474 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) | |
1da177e4 | 475 | jnz ia32_tracesys |
c09249f8 | 476 | ia32_do_call: |
14f6e953 DV |
477 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
478 | movl %edi,%r8d /* arg5 */ | |
479 | movl %ebp,%r9d /* arg6 */ | |
480 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ | |
481 | movl %ebx,%edi /* arg1 */ | |
482 | movl %edx,%edx /* arg3 (zero extension) */ | |
3f5159a9 DV |
483 | cmpq $(IA32_NR_syscalls-1),%rax |
484 | ja 1f | |
1da177e4 LT |
485 | call *ia32_sys_call_table(,%rax,8) # xxx: rip relative |
486 | ia32_sysret: | |
f2db9382 | 487 | movq %rax,RAX(%rsp) |
3f5159a9 | 488 | 1: |
76f5df43 | 489 | jmp int_ret_from_sys_call |
1da177e4 | 490 | |
76f5df43 DV |
491 | ia32_tracesys: |
492 | SAVE_EXTRA_REGS | |
1da177e4 LT |
493 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
494 | call syscall_trace_enter | |
73cbf687 DV |
495 | /* |
496 | * Reload arg registers from stack in case ptrace changed them. | |
497 | * Don't reload %eax because syscall_trace_enter() returned | |
498 | * the %rax value we should see. But do truncate it to 32 bits. | |
499 | * If it's -1 to make us punt the syscall, then (u32)-1 is still | |
500 | * an appropriately invalid value. | |
501 | */ | |
502 | movl RCX(%rsp), %ecx | |
503 | movl RDX(%rsp), %edx | |
504 | movl RSI(%rsp), %esi | |
505 | movl RDI(%rsp), %edi | |
506 | movl %eax, %eax /* zero extension */ | |
76f5df43 | 507 | RESTORE_EXTRA_REGS |
c09249f8 | 508 | jmp ia32_do_call |
4b787e0b | 509 | END(ia32_syscall) |
1da177e4 | 510 | |
d2475b8f | 511 | .macro PTREGSCALL label, func |
f6b2bc84 JB |
512 | ALIGN |
513 | GLOBAL(\label) | |
1da177e4 | 514 | leaq \func(%rip),%rax |
1da177e4 LT |
515 | jmp ia32_ptregs_common |
516 | .endm | |
517 | ||
3fe26fa3 AV |
518 | PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn |
519 | PTREGSCALL stub32_sigreturn, sys32_sigreturn | |
3fe26fa3 AV |
520 | PTREGSCALL stub32_fork, sys_fork |
521 | PTREGSCALL stub32_vfork, sys_vfork | |
1da177e4 | 522 | |
1d4b4b29 AV |
523 | ALIGN |
524 | GLOBAL(stub32_clone) | |
525 | leaq sys_clone(%rip),%rax | |
526 | mov %r8, %rcx | |
527 | jmp ia32_ptregs_common | |
528 | ||
f6b2bc84 JB |
529 | ALIGN |
530 | ia32_ptregs_common: | |
76f5df43 | 531 | SAVE_EXTRA_REGS 8 |
1da177e4 | 532 | call *%rax |
76f5df43 DV |
533 | RESTORE_EXTRA_REGS 8 |
534 | ret | |
4b787e0b | 535 | END(ia32_ptregs_common) |