2 * Compatibility mode system call entry point for x86-64.
4 * Copyright 2000-2002 Andi Kleen, SuSE Labs.
7 #include <asm/dwarf2.h>
8 #include <asm/calling.h>
9 #include <asm/asm-offsets.h>
10 #include <asm/current.h>
11 #include <asm/errno.h>
12 #include <asm/ia32_unistd.h>
13 #include <asm/thread_info.h>
14 #include <asm/segment.h>
15 #include <asm/irqflags.h>
16 #include <linux/linkage.h>
17 #include <linux/err.h>
19 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
20 #include <linux/elf-em.h>
21 #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
22 #define __AUDIT_ARCH_LE 0x40000000
24 #ifndef CONFIG_AUDITSYSCALL
25 #define sysexit_audit ia32_ret_from_sys_call
26 #define sysretl_audit ia32_ret_from_sys_call
29 .section .entry.text, "ax"
31 .macro IA32_ARG_FIXUP noebp=0
39 movl %edx,%edx /* zero extension */
43 .macro CLEAR_RREGS offset=0, _r9=rax
45 movq %rax,\offset+R11(%rsp)
46 movq %rax,\offset+R10(%rsp)
47 movq %\_r9,\offset+R9(%rsp)
48 movq %rax,\offset+R8(%rsp)
52 * Reload arg registers from stack in case ptrace changed them.
53 * We don't reload %eax because syscall_trace_enter() returned
54 * the %rax value we should see. Instead, we just truncate that
55 * value to 32 bits again as we did on entry from user mode.
56 * If it's a new value set by user_regset during entry tracing,
57 * this matches the normal truncation of the user-mode value.
58 * If it's -1 to make us punt the syscall, then (u32)-1 is still
59 * an appropriately invalid value.
61 .macro LOAD_ARGS32 offset, _r9=0
63 movl \offset+16(%rsp),%r9d
65 movl \offset+40(%rsp),%ecx
66 movl \offset+48(%rsp),%edx
67 movl \offset+56(%rsp),%esi
68 movl \offset+64(%rsp),%edi
69 movl %eax,%eax /* zero extension */
72 .macro CFI_STARTPROC32 simple
84 #ifdef CONFIG_PARAVIRT
85 ENTRY(native_usergs_sysret32)
88 ENDPROC(native_usergs_sysret32)
90 ENTRY(native_irq_enable_sysexit)
94 ENDPROC(native_irq_enable_sysexit)
98 * 32bit SYSENTER instruction entry.
101 * %eax System call number.
112 * This is purely a fast path. For anything complicated we use the int 0x80
113 * path below. Set up a complete hardware stack frame to share code
114 * with the int 0x80 path.
116 ENTRY(ia32_sysenter_target)
117 CFI_STARTPROC32 simple
122 movq PER_CPU_VAR(kernel_stack), %rsp
123 addq $(KERNEL_STACK_OFFSET),%rsp
125 * No need to follow this irqs on/off section: the syscall
126 * disabled irqs, here we enable it straight after entry:
128 ENABLE_INTERRUPTS(CLBR_NONE)
129 movl %ebp,%ebp /* zero extension */
130 pushq_cfi $__USER32_DS
131 /*CFI_REL_OFFSET ss,0*/
135 /*CFI_REL_OFFSET rflags,0*/
136 movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
138 pushq_cfi $__USER32_CS
139 /*CFI_REL_OFFSET cs,0*/
146 /* no need to do an access_ok check here because rbp has been
147 32bit zero extended */
149 .section __ex_table,"a"
152 orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
153 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
155 jnz sysenter_tracesys
156 cmpq $(IA32_NR_syscalls-1),%rax
161 call *ia32_sys_call_table(,%rax,8)
162 movq %rax,RAX-ARGOFFSET(%rsp)
163 DISABLE_INTERRUPTS(CLBR_NONE)
165 testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
167 sysexit_from_sys_call:
168 andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
169 /* clear IF, that popfq doesn't enable interrupts early */
170 andl $~0x200,EFLAGS-R11(%rsp)
171 movl RIP-R11(%rsp),%edx /* User %eip */
173 RESTORE_ARGS 0,24,0,0,0,0
179 /*CFI_RESTORE rflags*/
180 popq_cfi %rcx /* User %esp */
183 ENABLE_INTERRUPTS_SYSEXIT32
185 #ifdef CONFIG_AUDITSYSCALL
186 .macro auditsys_entry_common
187 movl %esi,%r9d /* 6th arg: 4th syscall arg */
188 movl %edx,%r8d /* 5th arg: 3rd syscall arg */
189 /* (already in %ecx) 4th arg: 2nd syscall arg */
190 movl %ebx,%edx /* 3rd arg: 1st syscall arg */
191 movl %eax,%esi /* 2nd arg: syscall number */
192 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
193 call __audit_syscall_entry
194 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
195 cmpq $(IA32_NR_syscalls-1),%rax
197 movl %ebx,%edi /* reload 1st syscall arg */
198 movl RCX-ARGOFFSET(%rsp),%esi /* reload 2nd syscall arg */
199 movl RDX-ARGOFFSET(%rsp),%edx /* reload 3rd syscall arg */
200 movl RSI-ARGOFFSET(%rsp),%ecx /* reload 4th syscall arg */
201 movl RDI-ARGOFFSET(%rsp),%r8d /* reload 5th syscall arg */
204 .macro auditsys_exit exit
205 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
206 jnz ia32_ret_from_sys_call
209 movl %eax,%esi /* second arg, syscall return value */
210 cmpl $-MAX_ERRNO,%eax /* is it an error ? */
212 movslq %eax, %rsi /* if error sign extend to 64 bits */
213 1: setbe %al /* 1 if error, 0 if not */
214 movzbl %al,%edi /* zero-extend that into %edi */
215 call __audit_syscall_exit
216 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
217 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
220 testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
222 CLEAR_RREGS -ARGOFFSET
228 auditsys_entry_common
229 movl %ebp,%r9d /* reload 6th syscall arg */
230 jmp sysenter_dispatch
233 auditsys_exit sysexit_from_sys_call
237 #ifdef CONFIG_AUDITSYSCALL
238 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
243 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
244 movq %rsp,%rdi /* &pt_regs -> arg1 */
245 call syscall_trace_enter
246 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
248 cmpq $(IA32_NR_syscalls-1),%rax
249 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
252 ENDPROC(ia32_sysenter_target)
255 * 32bit SYSCALL instruction entry.
258 * %eax System call number.
264 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
270 * This is purely a fast path. For anything complicated we use the int 0x80
271 * path below. Set up a complete hardware stack frame to share code
272 * with the int 0x80 path.
274 ENTRY(ia32_cstar_target)
275 CFI_STARTPROC32 simple
277 CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
279 /*CFI_REGISTER rflags,r11*/
283 movq PER_CPU_VAR(kernel_stack),%rsp
285 * No need to follow this irqs on/off section: the syscall
286 * disabled irqs and here we enable it straight after entry:
288 ENABLE_INTERRUPTS(CLBR_NONE)
290 movl %eax,%eax /* zero extension */
291 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
292 movq %rcx,RIP-ARGOFFSET(%rsp)
293 CFI_REL_OFFSET rip,RIP-ARGOFFSET
294 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
296 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
297 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
298 movq %r11,EFLAGS-ARGOFFSET(%rsp)
299 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
300 movq %r8,RSP-ARGOFFSET(%rsp)
301 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
302 /* no need to do an access_ok check here because r8 has been
303 32bit zero extended */
304 /* hardware stack frame is complete now */
306 .section __ex_table,"a"
309 orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
310 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
313 cmpq $IA32_NR_syscalls-1,%rax
318 call *ia32_sys_call_table(,%rax,8)
319 movq %rax,RAX-ARGOFFSET(%rsp)
320 DISABLE_INTERRUPTS(CLBR_NONE)
322 testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
324 sysretl_from_sys_call:
325 andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
326 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
327 movl RIP-ARGOFFSET(%rsp),%ecx
329 movl EFLAGS-ARGOFFSET(%rsp),%r11d
330 /*CFI_REGISTER rflags,r11*/
335 movl RSP-ARGOFFSET(%rsp),%esp
339 #ifdef CONFIG_AUDITSYSCALL
342 movl %r9d,R9-ARGOFFSET(%rsp) /* register to be clobbered by call */
343 auditsys_entry_common
344 movl R9-ARGOFFSET(%rsp),%r9d /* reload 6th syscall arg */
348 auditsys_exit sysretl_from_sys_call
352 #ifdef CONFIG_AUDITSYSCALL
353 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
359 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
360 movq %rsp,%rdi /* &pt_regs -> arg1 */
361 call syscall_trace_enter
362 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
365 cmpq $(IA32_NR_syscalls-1),%rax
366 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
368 END(ia32_cstar_target)
376 * Emulated IA32 system calls via int 0x80.
379 * %eax System call number.
385 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
388 * Uses the same stack frame as the x86-64 version.
389 * All registers except %eax must be saved (but ptrace may violate that)
390 * Arguments are zero extended. For system calls that want sign extension and
391 * take long arguments a wrapper is needed. Most calls can just be called
393 * Assumes it is only called from user space and entered with interrupts off.
397 CFI_STARTPROC32 simple
399 CFI_DEF_CFA rsp,SS+8-RIP
400 /*CFI_REL_OFFSET ss,SS-RIP*/
401 CFI_REL_OFFSET rsp,RSP-RIP
402 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
403 /*CFI_REL_OFFSET cs,CS-RIP*/
404 CFI_REL_OFFSET rip,RIP-RIP
405 PARAVIRT_ADJUST_EXCEPTION_FRAME
408 * No need to follow this irqs on/off section: the syscall
409 * disabled irqs and here we enable it straight after entry:
411 ENABLE_INTERRUPTS(CLBR_NONE)
415 /* note the registers are not zero extended to the sf.
416 this could be a problem. */
418 orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
419 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
421 cmpq $(IA32_NR_syscalls-1),%rax
425 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
427 movq %rax,RAX-ARGOFFSET(%rsp)
428 ia32_ret_from_sys_call:
429 CLEAR_RREGS -ARGOFFSET
430 jmp int_ret_from_sys_call
435 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
436 movq %rsp,%rdi /* &pt_regs -> arg1 */
437 call syscall_trace_enter
438 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
440 cmpq $(IA32_NR_syscalls-1),%rax
441 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
446 movq $0,ORIG_RAX-ARGOFFSET(%rsp)
452 .macro PTREGSCALL label, func, arg
455 leaq \func(%rip),%rax
456 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
457 jmp ia32_ptregs_common
462 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
463 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
464 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
465 PTREGSCALL stub32_execve, sys32_execve, %rcx
466 PTREGSCALL stub32_fork, sys_fork, %rdi
467 PTREGSCALL stub32_clone, sys32_clone, %rdx
468 PTREGSCALL stub32_vfork, sys_vfork, %rdi
469 PTREGSCALL stub32_iopl, sys_iopl, %rsi
475 CFI_STARTPROC32 simple
477 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
478 CFI_REL_OFFSET rax,RAX-ARGOFFSET
479 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
480 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
481 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
482 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
483 CFI_REL_OFFSET rip,RIP-ARGOFFSET
484 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
485 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
486 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
487 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
491 jmp ia32_sysret /* misbalances the return cache */
493 END(ia32_ptregs_common)