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>
18 #define IA32_NR_syscalls ((ia32_syscall_end - ia32_sys_call_table)/8)
20 .macro IA32_ARG_FIXUP noebp=0
28 movl %edx,%edx /* zero extension */
40 .macro LOAD_ARGS32 offset
41 movl \offset(%rsp),%r11d
42 movl \offset+8(%rsp),%r10d
43 movl \offset+16(%rsp),%r9d
44 movl \offset+24(%rsp),%r8d
45 movl \offset+40(%rsp),%ecx
46 movl \offset+48(%rsp),%edx
47 movl \offset+56(%rsp),%esi
48 movl \offset+64(%rsp),%edi
49 movl \offset+72(%rsp),%eax
52 .macro CFI_STARTPROC32 simple
64 #ifdef CONFIG_PARAVIRT
65 ENTRY(native_usergs_sysret32)
68 ENDPROC(native_usergs_sysret32)
70 ENTRY(native_irq_enable_sysexit)
74 ENDPROC(native_irq_enable_sysexit)
78 * 32bit SYSENTER instruction entry.
81 * %eax System call number.
92 * This is purely a fast path. For anything complicated we use the int 0x80
93 * path below. Set up a complete hardware stack frame to share code
94 * with the int 0x80 path.
96 ENTRY(ia32_sysenter_target)
97 CFI_STARTPROC32 simple
102 movq %gs:pda_kernelstack, %rsp
103 addq $(PDA_STACKOFFSET),%rsp
105 * No need to follow this irqs on/off section: the syscall
106 * disabled irqs, here we enable it straight after entry:
108 ENABLE_INTERRUPTS(CLBR_NONE)
109 movl %ebp,%ebp /* zero extension */
111 CFI_ADJUST_CFA_OFFSET 8
112 /*CFI_REL_OFFSET ss,0*/
114 CFI_ADJUST_CFA_OFFSET 8
117 CFI_ADJUST_CFA_OFFSET 8
118 /*CFI_REL_OFFSET rflags,0*/
119 movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
122 CFI_ADJUST_CFA_OFFSET 8
123 /*CFI_REL_OFFSET cs,0*/
126 CFI_ADJUST_CFA_OFFSET 8
129 CFI_ADJUST_CFA_OFFSET 8
132 /* no need to do an access_ok check here because rbp has been
133 32bit zero extended */
135 .section __ex_table,"a"
138 GET_THREAD_INFO(%r10)
139 orl $TS_COMPAT,TI_status(%r10)
140 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP), \
143 jnz sysenter_tracesys
145 cmpl $(IA32_NR_syscalls-1),%eax
148 call *ia32_sys_call_table(,%rax,8)
149 movq %rax,RAX-ARGOFFSET(%rsp)
150 GET_THREAD_INFO(%r10)
151 DISABLE_INTERRUPTS(CLBR_NONE)
153 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
154 jnz int_ret_from_sys_call
155 andl $~TS_COMPAT,TI_status(%r10)
156 /* clear IF, that popfq doesn't enable interrupts early */
157 andl $~0x200,EFLAGS-R11(%rsp)
158 movl RIP-R11(%rsp),%edx /* User %eip */
160 RESTORE_ARGS 1,24,1,1,1,1
162 CFI_ADJUST_CFA_OFFSET -8
163 /*CFI_RESTORE rflags*/
164 popq %rcx /* User %esp */
165 CFI_ADJUST_CFA_OFFSET -8
168 ENABLE_INTERRUPTS_SYSEXIT32
176 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
177 movq %rsp,%rdi /* &pt_regs -> arg1 */
178 call syscall_trace_enter
179 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
182 cmpl $(IA32_NR_syscalls-1),%eax
183 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
186 ENDPROC(ia32_sysenter_target)
189 * 32bit SYSCALL instruction entry.
192 * %eax System call number.
198 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
204 * This is purely a fast path. For anything complicated we use the int 0x80
205 * path below. Set up a complete hardware stack frame to share code
206 * with the int 0x80 path.
208 ENTRY(ia32_cstar_target)
209 CFI_STARTPROC32 simple
211 CFI_DEF_CFA rsp,PDA_STACKOFFSET
213 /*CFI_REGISTER rflags,r11*/
217 movq %gs:pda_kernelstack,%rsp
219 * No need to follow this irqs on/off section: the syscall
220 * disabled irqs and here we enable it straight after entry:
222 ENABLE_INTERRUPTS(CLBR_NONE)
224 movl %eax,%eax /* zero extension */
225 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
226 movq %rcx,RIP-ARGOFFSET(%rsp)
227 CFI_REL_OFFSET rip,RIP-ARGOFFSET
228 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
230 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
231 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
232 movq %r11,EFLAGS-ARGOFFSET(%rsp)
233 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
234 movq %r8,RSP-ARGOFFSET(%rsp)
235 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
236 /* no need to do an access_ok check here because r8 has been
237 32bit zero extended */
238 /* hardware stack frame is complete now */
240 .section __ex_table,"a"
243 GET_THREAD_INFO(%r10)
244 orl $TS_COMPAT,TI_status(%r10)
245 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP), \
250 cmpl $IA32_NR_syscalls-1,%eax
253 call *ia32_sys_call_table(,%rax,8)
254 movq %rax,RAX-ARGOFFSET(%rsp)
255 GET_THREAD_INFO(%r10)
256 DISABLE_INTERRUPTS(CLBR_NONE)
258 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
259 jnz int_ret_from_sys_call
260 andl $~TS_COMPAT,TI_status(%r10)
261 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
262 movl RIP-ARGOFFSET(%rsp),%ecx
264 movl EFLAGS-ARGOFFSET(%rsp),%r11d
265 /*CFI_REGISTER rflags,r11*/
267 movl RSP-ARGOFFSET(%rsp),%esp
277 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
278 movq %rsp,%rdi /* &pt_regs -> arg1 */
279 call syscall_trace_enter
280 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
283 movl RSP-ARGOFFSET(%rsp), %r8d
284 cmpl $(IA32_NR_syscalls-1),%eax
285 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
287 END(ia32_cstar_target)
295 * Emulated IA32 system calls via int 0x80.
298 * %eax System call number.
304 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
307 * Uses the same stack frame as the x86-64 version.
308 * All registers except %eax must be saved (but ptrace may violate that)
309 * Arguments are zero extended. For system calls that want sign extension and
310 * take long arguments a wrapper is needed. Most calls can just be called
312 * Assumes it is only called from user space and entered with interrupts off.
316 CFI_STARTPROC32 simple
318 CFI_DEF_CFA rsp,SS+8-RIP
319 /*CFI_REL_OFFSET ss,SS-RIP*/
320 CFI_REL_OFFSET rsp,RSP-RIP
321 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
322 /*CFI_REL_OFFSET cs,CS-RIP*/
323 CFI_REL_OFFSET rip,RIP-RIP
326 * No need to follow this irqs on/off section: the syscall
327 * disabled irqs and here we enable it straight after entry:
329 ENABLE_INTERRUPTS(CLBR_NONE)
332 CFI_ADJUST_CFA_OFFSET 8
334 /* note the registers are not zero extended to the sf.
335 this could be a problem. */
337 GET_THREAD_INFO(%r10)
338 orl $TS_COMPAT,TI_status(%r10)
339 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP), \
343 cmpl $(IA32_NR_syscalls-1),%eax
344 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
346 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
348 movq %rax,RAX-ARGOFFSET(%rsp)
349 jmp int_ret_from_sys_call
354 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
355 movq %rsp,%rdi /* &pt_regs -> arg1 */
356 call syscall_trace_enter
357 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
363 movq $0,ORIG_RAX-ARGOFFSET(%rsp)
364 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
365 jmp int_ret_from_sys_call
372 .macro PTREGSCALL label, func, arg
375 leaq \func(%rip),%rax
376 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
377 jmp ia32_ptregs_common
382 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
383 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
384 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
385 PTREGSCALL stub32_execve, sys32_execve, %rcx
386 PTREGSCALL stub32_fork, sys_fork, %rdi
387 PTREGSCALL stub32_clone, sys32_clone, %rdx
388 PTREGSCALL stub32_vfork, sys_vfork, %rdi
389 PTREGSCALL stub32_iopl, sys_iopl, %rsi
391 ENTRY(ia32_ptregs_common)
394 CFI_STARTPROC32 simple
396 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
397 CFI_REL_OFFSET rax,RAX-ARGOFFSET
398 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
399 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
400 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
401 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
402 CFI_REL_OFFSET rip,RIP-ARGOFFSET
403 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
404 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
405 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
406 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
410 jmp ia32_sysret /* misbalances the return cache */
412 END(ia32_ptregs_common)
417 .quad sys_restart_syscall
422 .quad compat_sys_open /* 5 */
427 .quad sys_unlink /* 10 */
430 .quad compat_sys_time
432 .quad sys_chmod /* 15 */
434 .quad quiet_ni_syscall /* old break syscall holder */
437 .quad sys_getpid /* 20 */
438 .quad compat_sys_mount /* mount */
439 .quad sys_oldumount /* old_umount */
442 .quad compat_sys_stime /* stime */ /* 25 */
443 .quad compat_sys_ptrace /* ptrace */
445 .quad sys_fstat /* (old)fstat */
447 .quad compat_sys_utime /* 30 */
448 .quad quiet_ni_syscall /* old stty syscall holder */
449 .quad quiet_ni_syscall /* old gtty syscall holder */
452 .quad quiet_ni_syscall /* 35 */ /* old ftime syscall holder */
457 .quad sys_rmdir /* 40 */
460 .quad compat_sys_times
461 .quad quiet_ni_syscall /* old prof syscall holder */
462 .quad sys_brk /* 45 */
467 .quad sys_getegid16 /* 50 */
469 .quad sys_umount /* new_umount */
470 .quad quiet_ni_syscall /* old lock syscall holder */
471 .quad compat_sys_ioctl
472 .quad compat_sys_fcntl64 /* 55 */
473 .quad quiet_ni_syscall /* old mpx syscall holder */
475 .quad quiet_ni_syscall /* old ulimit syscall holder */
477 .quad sys_umask /* 60 */
482 .quad sys_getpgrp /* 65 */
484 .quad sys32_sigaction
487 .quad sys_setreuid16 /* 70 */
489 .quad sys32_sigsuspend
490 .quad compat_sys_sigpending
491 .quad sys_sethostname
492 .quad compat_sys_setrlimit /* 75 */
493 .quad compat_sys_old_getrlimit /* old_getrlimit */
494 .quad compat_sys_getrusage
495 .quad sys32_gettimeofday
496 .quad sys32_settimeofday
497 .quad sys_getgroups16 /* 80 */
498 .quad sys_setgroups16
499 .quad sys32_old_select
502 .quad sys_readlink /* 85 */
506 .quad compat_sys_old_readdir
507 .quad sys32_mmap /* 90 */
512 .quad sys_fchown16 /* 95 */
513 .quad sys_getpriority
514 .quad sys_setpriority
515 .quad quiet_ni_syscall /* old profil syscall holder */
516 .quad compat_sys_statfs
517 .quad compat_sys_fstatfs /* 100 */
519 .quad compat_sys_socketcall
521 .quad compat_sys_setitimer
522 .quad compat_sys_getitimer /* 105 */
523 .quad compat_sys_newstat
524 .quad compat_sys_newlstat
525 .quad compat_sys_newfstat
527 .quad stub32_iopl /* 110 */
529 .quad quiet_ni_syscall /* old "idle" system call */
530 .quad sys32_vm86_warning /* vm86old */
531 .quad compat_sys_wait4
532 .quad sys_swapoff /* 115 */
533 .quad compat_sys_sysinfo
536 .quad stub32_sigreturn
537 .quad stub32_clone /* 120 */
538 .quad sys_setdomainname
541 .quad compat_sys_adjtimex
542 .quad sys32_mprotect /* 125 */
543 .quad compat_sys_sigprocmask
544 .quad quiet_ni_syscall /* create_module */
545 .quad sys_init_module
546 .quad sys_delete_module
547 .quad quiet_ni_syscall /* 130 get_kernel_syms */
551 .quad quiet_ni_syscall /* bdflush */
552 .quad sys_sysfs /* 135 */
553 .quad sys_personality
554 .quad quiet_ni_syscall /* for afs_syscall */
557 .quad sys_llseek /* 140 */
558 .quad compat_sys_getdents
559 .quad compat_sys_select
562 .quad compat_sys_readv /* 145 */
563 .quad compat_sys_writev
566 .quad sys32_sysctl /* sysctl */
567 .quad sys_mlock /* 150 */
571 .quad sys_sched_setparam
572 .quad sys_sched_getparam /* 155 */
573 .quad sys_sched_setscheduler
574 .quad sys_sched_getscheduler
575 .quad sys_sched_yield
576 .quad sys_sched_get_priority_max
577 .quad sys_sched_get_priority_min /* 160 */
578 .quad sys32_sched_rr_get_interval
579 .quad compat_sys_nanosleep
581 .quad sys_setresuid16
582 .quad sys_getresuid16 /* 165 */
583 .quad sys32_vm86_warning /* vm86 */
584 .quad quiet_ni_syscall /* query_module */
586 .quad compat_sys_nfsservctl
587 .quad sys_setresgid16 /* 170 */
588 .quad sys_getresgid16
590 .quad stub32_rt_sigreturn
591 .quad sys32_rt_sigaction
592 .quad sys32_rt_sigprocmask /* 175 */
593 .quad sys32_rt_sigpending
594 .quad compat_sys_rt_sigtimedwait
595 .quad sys32_rt_sigqueueinfo
596 .quad sys_rt_sigsuspend
597 .quad sys32_pread /* 180 */
603 .quad stub32_sigaltstack
605 .quad quiet_ni_syscall /* streams1 */
606 .quad quiet_ni_syscall /* streams2 */
607 .quad stub32_vfork /* 190 */
608 .quad compat_sys_getrlimit
610 .quad sys32_truncate64
611 .quad sys32_ftruncate64
612 .quad sys32_stat64 /* 195 */
617 .quad sys_getgid /* 200 */
622 .quad sys_getgroups /* 205 */
627 .quad sys_setresgid /* 210 */
632 .quad sys_setfsuid /* 215 */
637 .quad compat_sys_getdents64 /* 220 getdents64 */
638 .quad compat_sys_fcntl64
639 .quad quiet_ni_syscall /* tux */
640 .quad quiet_ni_syscall /* security */
642 .quad sys32_readahead /* 225 */
647 .quad sys_lgetxattr /* 230 */
652 .quad sys_removexattr /* 235 */
653 .quad sys_lremovexattr
654 .quad sys_fremovexattr
657 .quad compat_sys_futex /* 240 */
658 .quad compat_sys_sched_setaffinity
659 .quad compat_sys_sched_getaffinity
660 .quad sys_set_thread_area
661 .quad sys_get_thread_area
662 .quad compat_sys_io_setup /* 245 */
664 .quad compat_sys_io_getevents
665 .quad compat_sys_io_submit
667 .quad sys32_fadvise64 /* 250 */
668 .quad quiet_ni_syscall /* free_huge_pages */
670 .quad sys32_lookup_dcookie
671 .quad sys_epoll_create
672 .quad sys_epoll_ctl /* 255 */
674 .quad sys_remap_file_pages
675 .quad sys_set_tid_address
676 .quad compat_sys_timer_create
677 .quad compat_sys_timer_settime /* 260 */
678 .quad compat_sys_timer_gettime
679 .quad sys_timer_getoverrun
680 .quad sys_timer_delete
681 .quad compat_sys_clock_settime
682 .quad compat_sys_clock_gettime /* 265 */
683 .quad compat_sys_clock_getres
684 .quad compat_sys_clock_nanosleep
685 .quad compat_sys_statfs64
686 .quad compat_sys_fstatfs64
687 .quad sys_tgkill /* 270 */
688 .quad compat_sys_utimes
689 .quad sys32_fadvise64_64
690 .quad quiet_ni_syscall /* sys_vserver */
692 .quad compat_sys_get_mempolicy /* 275 */
693 .quad sys_set_mempolicy
694 .quad compat_sys_mq_open
696 .quad compat_sys_mq_timedsend
697 .quad compat_sys_mq_timedreceive /* 280 */
698 .quad compat_sys_mq_notify
699 .quad compat_sys_mq_getsetattr
700 .quad compat_sys_kexec_load /* reserved for kexec */
701 .quad compat_sys_waitid
702 .quad quiet_ni_syscall /* 285: sys_altroot */
704 .quad sys_request_key
707 .quad sys_ioprio_get /* 290 */
708 .quad sys_inotify_init
709 .quad sys_inotify_add_watch
710 .quad sys_inotify_rm_watch
711 .quad sys_migrate_pages
712 .quad compat_sys_openat /* 295 */
716 .quad compat_sys_futimesat
717 .quad sys32_fstatat /* 300 */
722 .quad sys_readlinkat /* 305 */
725 .quad compat_sys_pselect6
726 .quad compat_sys_ppoll
727 .quad sys_unshare /* 310 */
728 .quad compat_sys_set_robust_list
729 .quad compat_sys_get_robust_list
731 .quad sys32_sync_file_range
732 .quad sys_tee /* 315 */
733 .quad compat_sys_vmsplice
734 .quad compat_sys_move_pages
736 .quad sys_epoll_pwait
737 .quad compat_sys_utimensat /* 320 */
738 .quad compat_sys_signalfd
739 .quad sys_timerfd_create
741 .quad sys32_fallocate
742 .quad compat_sys_timerfd_settime /* 325 */
743 .quad compat_sys_timerfd_gettime