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_execve, sys32_execve, %rcx
374 PTREGSCALL stub32_fork, sys_fork, %rdi
375 PTREGSCALL stub32_clone, sys32_clone, %rdx
376 PTREGSCALL stub32_vfork, sys_vfork, %rdi
377 PTREGSCALL stub32_iopl, sys_iopl, %rsi
379 ENTRY(ia32_ptregs_common)
382 CFI_STARTPROC32 simple
384 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
385 CFI_REL_OFFSET rax,RAX-ARGOFFSET
386 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
387 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
388 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
389 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
390 CFI_REL_OFFSET rip,RIP-ARGOFFSET
391 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
392 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
393 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
394 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
398 jmp ia32_sysret /* misbalances the return cache */
400 END(ia32_ptregs_common)
405 .quad sys_restart_syscall
410 .quad compat_sys_open /* 5 */
415 .quad sys_unlink /* 10 */
418 .quad compat_sys_time
420 .quad sys_chmod /* 15 */
422 .quad quiet_ni_syscall /* old break syscall holder */
425 .quad sys_getpid /* 20 */
426 .quad compat_sys_mount /* mount */
427 .quad sys_oldumount /* old_umount */
430 .quad compat_sys_stime /* stime */ /* 25 */
431 .quad compat_sys_ptrace /* ptrace */
433 .quad sys_fstat /* (old)fstat */
435 .quad compat_sys_utime /* 30 */
436 .quad quiet_ni_syscall /* old stty syscall holder */
437 .quad quiet_ni_syscall /* old gtty syscall holder */
440 .quad quiet_ni_syscall /* 35 */ /* old ftime syscall holder */
445 .quad sys_rmdir /* 40 */
448 .quad compat_sys_times
449 .quad quiet_ni_syscall /* old prof syscall holder */
450 .quad sys_brk /* 45 */
455 .quad sys_getegid16 /* 50 */
457 .quad sys_umount /* new_umount */
458 .quad quiet_ni_syscall /* old lock syscall holder */
459 .quad compat_sys_ioctl
460 .quad compat_sys_fcntl64 /* 55 */
461 .quad quiet_ni_syscall /* old mpx syscall holder */
463 .quad quiet_ni_syscall /* old ulimit syscall holder */
465 .quad sys_umask /* 60 */
470 .quad sys_getpgrp /* 65 */
472 .quad sys32_sigaction
475 .quad sys_setreuid16 /* 70 */
477 .quad sys32_sigsuspend
478 .quad compat_sys_sigpending
479 .quad sys_sethostname
480 .quad compat_sys_setrlimit /* 75 */
481 .quad compat_sys_old_getrlimit /* old_getrlimit */
482 .quad compat_sys_getrusage
483 .quad sys32_gettimeofday
484 .quad sys32_settimeofday
485 .quad sys_getgroups16 /* 80 */
486 .quad sys_setgroups16
487 .quad sys32_old_select
490 .quad sys_readlink /* 85 */
494 .quad compat_sys_old_readdir
495 .quad sys32_mmap /* 90 */
500 .quad sys_fchown16 /* 95 */
501 .quad sys_getpriority
502 .quad sys_setpriority
503 .quad quiet_ni_syscall /* old profil syscall holder */
504 .quad compat_sys_statfs
505 .quad compat_sys_fstatfs /* 100 */
507 .quad compat_sys_socketcall
509 .quad compat_sys_setitimer
510 .quad compat_sys_getitimer /* 105 */
511 .quad compat_sys_newstat
512 .quad compat_sys_newlstat
513 .quad compat_sys_newfstat
515 .quad stub32_iopl /* 110 */
517 .quad quiet_ni_syscall /* old "idle" system call */
518 .quad sys32_vm86_warning /* vm86old */
519 .quad compat_sys_wait4
520 .quad sys_swapoff /* 115 */
521 .quad compat_sys_sysinfo
524 .quad stub32_sigreturn
525 .quad stub32_clone /* 120 */
526 .quad sys_setdomainname
529 .quad compat_sys_adjtimex
530 .quad sys32_mprotect /* 125 */
531 .quad compat_sys_sigprocmask
532 .quad quiet_ni_syscall /* create_module */
533 .quad sys_init_module
534 .quad sys_delete_module
535 .quad quiet_ni_syscall /* 130 get_kernel_syms */
539 .quad quiet_ni_syscall /* bdflush */
540 .quad sys_sysfs /* 135 */
541 .quad sys_personality
542 .quad quiet_ni_syscall /* for afs_syscall */
545 .quad sys_llseek /* 140 */
546 .quad compat_sys_getdents
547 .quad compat_sys_select
550 .quad compat_sys_readv /* 145 */
551 .quad compat_sys_writev
554 .quad sys32_sysctl /* sysctl */
555 .quad sys_mlock /* 150 */
559 .quad sys_sched_setparam
560 .quad sys_sched_getparam /* 155 */
561 .quad sys_sched_setscheduler
562 .quad sys_sched_getscheduler
563 .quad sys_sched_yield
564 .quad sys_sched_get_priority_max
565 .quad sys_sched_get_priority_min /* 160 */
566 .quad sys32_sched_rr_get_interval
567 .quad compat_sys_nanosleep
569 .quad sys_setresuid16
570 .quad sys_getresuid16 /* 165 */
571 .quad sys32_vm86_warning /* vm86 */
572 .quad quiet_ni_syscall /* query_module */
574 .quad compat_sys_nfsservctl
575 .quad sys_setresgid16 /* 170 */
576 .quad sys_getresgid16
578 .quad stub32_rt_sigreturn
579 .quad sys32_rt_sigaction
580 .quad sys32_rt_sigprocmask /* 175 */
581 .quad sys32_rt_sigpending
582 .quad compat_sys_rt_sigtimedwait
583 .quad sys32_rt_sigqueueinfo
584 .quad sys_rt_sigsuspend
585 .quad sys32_pread /* 180 */
591 .quad stub32_sigaltstack
593 .quad quiet_ni_syscall /* streams1 */
594 .quad quiet_ni_syscall /* streams2 */
595 .quad stub32_vfork /* 190 */
596 .quad compat_sys_getrlimit
598 .quad sys32_truncate64
599 .quad sys32_ftruncate64
600 .quad sys32_stat64 /* 195 */
605 .quad sys_getgid /* 200 */
610 .quad sys_getgroups /* 205 */
615 .quad sys_setresgid /* 210 */
620 .quad sys_setfsuid /* 215 */
625 .quad compat_sys_getdents64 /* 220 getdents64 */
626 .quad compat_sys_fcntl64
627 .quad quiet_ni_syscall /* tux */
628 .quad quiet_ni_syscall /* security */
630 .quad sys32_readahead /* 225 */
635 .quad sys_lgetxattr /* 230 */
640 .quad sys_removexattr /* 235 */
641 .quad sys_lremovexattr
642 .quad sys_fremovexattr
645 .quad compat_sys_futex /* 240 */
646 .quad compat_sys_sched_setaffinity
647 .quad compat_sys_sched_getaffinity
648 .quad sys_set_thread_area
649 .quad sys_get_thread_area
650 .quad compat_sys_io_setup /* 245 */
652 .quad compat_sys_io_getevents
653 .quad compat_sys_io_submit
655 .quad sys32_fadvise64 /* 250 */
656 .quad quiet_ni_syscall /* free_huge_pages */
658 .quad sys32_lookup_dcookie
659 .quad sys_epoll_create
660 .quad sys_epoll_ctl /* 255 */
662 .quad sys_remap_file_pages
663 .quad sys_set_tid_address
664 .quad compat_sys_timer_create
665 .quad compat_sys_timer_settime /* 260 */
666 .quad compat_sys_timer_gettime
667 .quad sys_timer_getoverrun
668 .quad sys_timer_delete
669 .quad compat_sys_clock_settime
670 .quad compat_sys_clock_gettime /* 265 */
671 .quad compat_sys_clock_getres
672 .quad compat_sys_clock_nanosleep
673 .quad compat_sys_statfs64
674 .quad compat_sys_fstatfs64
675 .quad sys_tgkill /* 270 */
676 .quad compat_sys_utimes
677 .quad sys32_fadvise64_64
678 .quad quiet_ni_syscall /* sys_vserver */
680 .quad compat_sys_get_mempolicy /* 275 */
681 .quad sys_set_mempolicy
682 .quad compat_sys_mq_open
684 .quad compat_sys_mq_timedsend
685 .quad compat_sys_mq_timedreceive /* 280 */
686 .quad compat_sys_mq_notify
687 .quad compat_sys_mq_getsetattr
688 .quad compat_sys_kexec_load /* reserved for kexec */
689 .quad compat_sys_waitid
690 .quad quiet_ni_syscall /* 285: sys_altroot */
692 .quad sys_request_key
695 .quad sys_ioprio_get /* 290 */
696 .quad sys_inotify_init
697 .quad sys_inotify_add_watch
698 .quad sys_inotify_rm_watch
699 .quad sys_migrate_pages
700 .quad compat_sys_openat /* 295 */
704 .quad compat_sys_futimesat
705 .quad sys32_fstatat /* 300 */
710 .quad sys_readlinkat /* 305 */
713 .quad compat_sys_pselect6
714 .quad compat_sys_ppoll
715 .quad sys_unshare /* 310 */
716 .quad compat_sys_set_robust_list
717 .quad compat_sys_get_robust_list
719 .quad sys32_sync_file_range
720 .quad sys_tee /* 315 */
721 .quad compat_sys_vmsplice
722 .quad compat_sys_move_pages
724 .quad sys_epoll_pwait
725 .quad compat_sys_utimensat /* 320 */
726 .quad compat_sys_signalfd
727 .quad sys_timerfd_create
729 .quad sys32_fallocate
730 .quad compat_sys_timerfd_settime /* 325 */
731 .quad compat_sys_timerfd_gettime