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
65 * 32bit SYSENTER instruction entry.
68 * %eax System call number.
79 * This is purely a fast path. For anything complicated we use the int 0x80
80 * path below. Set up a complete hardware stack frame to share code
81 * with the int 0x80 path.
83 ENTRY(ia32_sysenter_target)
84 CFI_STARTPROC32 simple
89 movq %gs:pda_kernelstack, %rsp
90 addq $(PDA_STACKOFFSET),%rsp
92 * No need to follow this irqs on/off section: the syscall
93 * disabled irqs, here we enable it straight after entry:
96 movl %ebp,%ebp /* zero extension */
98 CFI_ADJUST_CFA_OFFSET 8
99 /*CFI_REL_OFFSET ss,0*/
101 CFI_ADJUST_CFA_OFFSET 8
104 CFI_ADJUST_CFA_OFFSET 8
105 /*CFI_REL_OFFSET rflags,0*/
106 movl 8*3-THREAD_SIZE+threadinfo_sysenter_return(%rsp), %r10d
109 CFI_ADJUST_CFA_OFFSET 8
110 /*CFI_REL_OFFSET cs,0*/
113 CFI_ADJUST_CFA_OFFSET 8
116 CFI_ADJUST_CFA_OFFSET 8
119 /* no need to do an access_ok check here because rbp has been
120 32bit zero extended */
122 .section __ex_table,"a"
125 GET_THREAD_INFO(%r10)
126 orl $TS_COMPAT,threadinfo_status(%r10)
127 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
129 jnz sysenter_tracesys
131 cmpl $(IA32_NR_syscalls-1),%eax
134 call *ia32_sys_call_table(,%rax,8)
135 movq %rax,RAX-ARGOFFSET(%rsp)
136 GET_THREAD_INFO(%r10)
139 testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
140 jnz int_ret_from_sys_call
141 andl $~TS_COMPAT,threadinfo_status(%r10)
142 /* clear IF, that popfq doesn't enable interrupts early */
143 andl $~0x200,EFLAGS-R11(%rsp)
144 movl RIP-R11(%rsp),%edx /* User %eip */
146 RESTORE_ARGS 1,24,1,1,1,1
148 CFI_ADJUST_CFA_OFFSET -8
149 /*CFI_RESTORE rflags*/
150 popq %rcx /* User %esp */
151 CFI_ADJUST_CFA_OFFSET -8
155 sti /* sti only takes effect after the next instruction */
165 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
166 movq %rsp,%rdi /* &pt_regs -> arg1 */
167 call syscall_trace_enter
168 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
171 cmpl $(IA32_NR_syscalls-1),%eax
172 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
175 ENDPROC(ia32_sysenter_target)
178 * 32bit SYSCALL instruction entry.
181 * %eax System call number.
187 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
193 * This is purely a fast path. For anything complicated we use the int 0x80
194 * path below. Set up a complete hardware stack frame to share code
195 * with the int 0x80 path.
197 ENTRY(ia32_cstar_target)
198 CFI_STARTPROC32 simple
200 CFI_DEF_CFA rsp,PDA_STACKOFFSET
202 /*CFI_REGISTER rflags,r11*/
206 movq %gs:pda_kernelstack,%rsp
208 * No need to follow this irqs on/off section: the syscall
209 * disabled irqs and here we enable it straight after entry:
213 movl %eax,%eax /* zero extension */
214 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
215 movq %rcx,RIP-ARGOFFSET(%rsp)
216 CFI_REL_OFFSET rip,RIP-ARGOFFSET
217 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
219 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
220 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
221 movq %r11,EFLAGS-ARGOFFSET(%rsp)
222 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
223 movq %r8,RSP-ARGOFFSET(%rsp)
224 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
225 /* no need to do an access_ok check here because r8 has been
226 32bit zero extended */
227 /* hardware stack frame is complete now */
229 .section __ex_table,"a"
232 GET_THREAD_INFO(%r10)
233 orl $TS_COMPAT,threadinfo_status(%r10)
234 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
238 cmpl $IA32_NR_syscalls-1,%eax
241 call *ia32_sys_call_table(,%rax,8)
242 movq %rax,RAX-ARGOFFSET(%rsp)
243 GET_THREAD_INFO(%r10)
246 testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
247 jnz int_ret_from_sys_call
248 andl $~TS_COMPAT,threadinfo_status(%r10)
249 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
250 movl RIP-ARGOFFSET(%rsp),%ecx
252 movl EFLAGS-ARGOFFSET(%rsp),%r11d
253 /*CFI_REGISTER rflags,r11*/
255 movl RSP-ARGOFFSET(%rsp),%esp
266 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
267 movq %rsp,%rdi /* &pt_regs -> arg1 */
268 call syscall_trace_enter
269 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
272 movl RSP-ARGOFFSET(%rsp), %r8d
273 cmpl $(IA32_NR_syscalls-1),%eax
274 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
276 END(ia32_cstar_target)
284 * Emulated IA32 system calls via int 0x80.
287 * %eax System call number.
293 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
296 * Uses the same stack frame as the x86-64 version.
297 * All registers except %eax must be saved (but ptrace may violate that)
298 * Arguments are zero extended. For system calls that want sign extension and
299 * take long arguments a wrapper is needed. Most calls can just be called
301 * Assumes it is only called from user space and entered with interrupts off.
305 CFI_STARTPROC32 simple
307 CFI_DEF_CFA rsp,SS+8-RIP
308 /*CFI_REL_OFFSET ss,SS-RIP*/
309 CFI_REL_OFFSET rsp,RSP-RIP
310 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
311 /*CFI_REL_OFFSET cs,CS-RIP*/
312 CFI_REL_OFFSET rip,RIP-RIP
315 * No need to follow this irqs on/off section: the syscall
316 * disabled irqs and here we enable it straight after entry:
321 CFI_ADJUST_CFA_OFFSET 8
323 /* note the registers are not zero extended to the sf.
324 this could be a problem. */
326 GET_THREAD_INFO(%r10)
327 orl $TS_COMPAT,threadinfo_status(%r10)
328 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
331 cmpl $(IA32_NR_syscalls-1),%eax
332 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
334 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
336 movq %rax,RAX-ARGOFFSET(%rsp)
337 jmp int_ret_from_sys_call
342 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
343 movq %rsp,%rdi /* &pt_regs -> arg1 */
344 call syscall_trace_enter
345 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
351 movq $0,ORIG_RAX-ARGOFFSET(%rsp)
352 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
353 jmp int_ret_from_sys_call
360 .macro PTREGSCALL label, func, arg
363 leaq \func(%rip),%rax
364 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
365 jmp ia32_ptregs_common
370 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
371 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
372 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
373 PTREGSCALL stub32_sigsuspend, sys32_sigsuspend, %rcx
374 PTREGSCALL stub32_execve, sys32_execve, %rcx
375 PTREGSCALL stub32_fork, sys_fork, %rdi
376 PTREGSCALL stub32_clone, sys32_clone, %rdx
377 PTREGSCALL stub32_vfork, sys_vfork, %rdi
378 PTREGSCALL stub32_iopl, sys_iopl, %rsi
379 PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdx
381 ENTRY(ia32_ptregs_common)
384 CFI_STARTPROC32 simple
386 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
387 CFI_REL_OFFSET rax,RAX-ARGOFFSET
388 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
389 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
390 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
391 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
392 CFI_REL_OFFSET rip,RIP-ARGOFFSET
393 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
394 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
395 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
396 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
400 jmp ia32_sysret /* misbalances the return cache */
402 END(ia32_ptregs_common)
407 .quad sys_restart_syscall
412 .quad compat_sys_open /* 5 */
417 .quad sys_unlink /* 10 */
420 .quad compat_sys_time
422 .quad sys_chmod /* 15 */
424 .quad quiet_ni_syscall /* old break syscall holder */
427 .quad sys_getpid /* 20 */
428 .quad compat_sys_mount /* mount */
429 .quad sys_oldumount /* old_umount */
432 .quad compat_sys_stime /* stime */ /* 25 */
433 .quad sys32_ptrace /* ptrace */
435 .quad sys_fstat /* (old)fstat */
437 .quad compat_sys_utime /* 30 */
438 .quad quiet_ni_syscall /* old stty syscall holder */
439 .quad quiet_ni_syscall /* old gtty syscall holder */
442 .quad quiet_ni_syscall /* 35 */ /* old ftime syscall holder */
447 .quad sys_rmdir /* 40 */
450 .quad compat_sys_times
451 .quad quiet_ni_syscall /* old prof syscall holder */
452 .quad sys_brk /* 45 */
457 .quad sys_getegid16 /* 50 */
459 .quad sys_umount /* new_umount */
460 .quad quiet_ni_syscall /* old lock syscall holder */
461 .quad compat_sys_ioctl
462 .quad compat_sys_fcntl64 /* 55 */
463 .quad quiet_ni_syscall /* old mpx syscall holder */
465 .quad quiet_ni_syscall /* old ulimit syscall holder */
467 .quad sys_umask /* 60 */
472 .quad sys_getpgrp /* 65 */
474 .quad sys32_sigaction
477 .quad sys_setreuid16 /* 70 */
479 .quad stub32_sigsuspend
480 .quad compat_sys_sigpending
481 .quad sys_sethostname
482 .quad compat_sys_setrlimit /* 75 */
483 .quad compat_sys_old_getrlimit /* old_getrlimit */
484 .quad compat_sys_getrusage
485 .quad sys32_gettimeofday
486 .quad sys32_settimeofday
487 .quad sys_getgroups16 /* 80 */
488 .quad sys_setgroups16
489 .quad sys32_old_select
492 .quad sys_readlink /* 85 */
496 .quad compat_sys_old_readdir
497 .quad sys32_mmap /* 90 */
502 .quad sys_fchown16 /* 95 */
503 .quad sys_getpriority
504 .quad sys_setpriority
505 .quad quiet_ni_syscall /* old profil syscall holder */
506 .quad compat_sys_statfs
507 .quad compat_sys_fstatfs /* 100 */
509 .quad compat_sys_socketcall
511 .quad compat_sys_setitimer
512 .quad compat_sys_getitimer /* 105 */
513 .quad compat_sys_newstat
514 .quad compat_sys_newlstat
515 .quad compat_sys_newfstat
517 .quad stub32_iopl /* 110 */
519 .quad quiet_ni_syscall /* old "idle" system call */
520 .quad sys32_vm86_warning /* vm86old */
521 .quad compat_sys_wait4
522 .quad sys_swapoff /* 115 */
523 .quad compat_sys_sysinfo
526 .quad stub32_sigreturn
527 .quad stub32_clone /* 120 */
528 .quad sys_setdomainname
531 .quad compat_sys_adjtimex
532 .quad sys32_mprotect /* 125 */
533 .quad compat_sys_sigprocmask
534 .quad quiet_ni_syscall /* create_module */
535 .quad sys_init_module
536 .quad sys_delete_module
537 .quad quiet_ni_syscall /* 130 get_kernel_syms */
541 .quad quiet_ni_syscall /* bdflush */
542 .quad sys_sysfs /* 135 */
543 .quad sys_personality
544 .quad quiet_ni_syscall /* for afs_syscall */
547 .quad sys_llseek /* 140 */
548 .quad compat_sys_getdents
549 .quad compat_sys_select
552 .quad compat_sys_readv /* 145 */
553 .quad compat_sys_writev
556 .quad sys32_sysctl /* sysctl */
557 .quad sys_mlock /* 150 */
561 .quad sys_sched_setparam
562 .quad sys_sched_getparam /* 155 */
563 .quad sys_sched_setscheduler
564 .quad sys_sched_getscheduler
565 .quad sys_sched_yield
566 .quad sys_sched_get_priority_max
567 .quad sys_sched_get_priority_min /* 160 */
568 .quad sys32_sched_rr_get_interval
569 .quad compat_sys_nanosleep
571 .quad sys_setresuid16
572 .quad sys_getresuid16 /* 165 */
573 .quad sys32_vm86_warning /* vm86 */
574 .quad quiet_ni_syscall /* query_module */
576 .quad compat_sys_nfsservctl
577 .quad sys_setresgid16 /* 170 */
578 .quad sys_getresgid16
580 .quad stub32_rt_sigreturn
581 .quad sys32_rt_sigaction
582 .quad sys32_rt_sigprocmask /* 175 */
583 .quad sys32_rt_sigpending
584 .quad compat_sys_rt_sigtimedwait
585 .quad sys32_rt_sigqueueinfo
586 .quad stub32_rt_sigsuspend
587 .quad sys32_pread /* 180 */
593 .quad stub32_sigaltstack
595 .quad quiet_ni_syscall /* streams1 */
596 .quad quiet_ni_syscall /* streams2 */
597 .quad stub32_vfork /* 190 */
598 .quad compat_sys_getrlimit
600 .quad sys32_truncate64
601 .quad sys32_ftruncate64
602 .quad sys32_stat64 /* 195 */
607 .quad sys_getgid /* 200 */
612 .quad sys_getgroups /* 205 */
617 .quad sys_setresgid /* 210 */
622 .quad sys_setfsuid /* 215 */
627 .quad compat_sys_getdents64 /* 220 getdents64 */
628 .quad compat_sys_fcntl64
629 .quad quiet_ni_syscall /* tux */
630 .quad quiet_ni_syscall /* security */
632 .quad sys32_readahead /* 225 */
637 .quad sys_lgetxattr /* 230 */
642 .quad sys_removexattr /* 235 */
643 .quad sys_lremovexattr
644 .quad sys_fremovexattr
647 .quad compat_sys_futex /* 240 */
648 .quad compat_sys_sched_setaffinity
649 .quad compat_sys_sched_getaffinity
650 .quad sys_set_thread_area
651 .quad sys_get_thread_area
652 .quad compat_sys_io_setup /* 245 */
654 .quad compat_sys_io_getevents
655 .quad compat_sys_io_submit
657 .quad sys32_fadvise64 /* 250 */
658 .quad quiet_ni_syscall /* free_huge_pages */
660 .quad sys32_lookup_dcookie
661 .quad sys_epoll_create
662 .quad sys_epoll_ctl /* 255 */
664 .quad sys_remap_file_pages
665 .quad sys_set_tid_address
666 .quad compat_sys_timer_create
667 .quad compat_sys_timer_settime /* 260 */
668 .quad compat_sys_timer_gettime
669 .quad sys_timer_getoverrun
670 .quad sys_timer_delete
671 .quad compat_sys_clock_settime
672 .quad compat_sys_clock_gettime /* 265 */
673 .quad compat_sys_clock_getres
674 .quad compat_sys_clock_nanosleep
675 .quad compat_sys_statfs64
676 .quad compat_sys_fstatfs64
677 .quad sys_tgkill /* 270 */
678 .quad compat_sys_utimes
679 .quad sys32_fadvise64_64
680 .quad quiet_ni_syscall /* sys_vserver */
682 .quad compat_sys_get_mempolicy /* 275 */
683 .quad sys_set_mempolicy
684 .quad compat_sys_mq_open
686 .quad compat_sys_mq_timedsend
687 .quad compat_sys_mq_timedreceive /* 280 */
688 .quad compat_sys_mq_notify
689 .quad compat_sys_mq_getsetattr
690 .quad compat_sys_kexec_load /* reserved for kexec */
691 .quad compat_sys_waitid
692 .quad quiet_ni_syscall /* 285: sys_altroot */
694 .quad sys_request_key
697 .quad sys_ioprio_get /* 290 */
698 .quad sys_inotify_init
699 .quad sys_inotify_add_watch
700 .quad sys_inotify_rm_watch
701 .quad sys_migrate_pages
702 .quad compat_sys_openat /* 295 */
706 .quad compat_sys_futimesat
707 .quad sys32_fstatat /* 300 */
712 .quad sys_readlinkat /* 305 */
715 .quad compat_sys_pselect6
716 .quad compat_sys_ppoll
717 .quad sys_unshare /* 310 */
718 .quad compat_sys_set_robust_list
719 .quad compat_sys_get_robust_list
721 .quad sys32_sync_file_range
722 .quad sys_tee /* 315 */
723 .quad compat_sys_vmsplice
724 .quad compat_sys_move_pages
726 .quad sys_epoll_pwait
727 .quad compat_sys_utimensat /* 320 */
728 .quad compat_sys_signalfd
729 .quad sys_timerfd_create
731 .quad sys32_fallocate
732 .quad compat_sys_timerfd_settime /* 325 */
733 .quad compat_sys_timerfd_gettime