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 */
41 * Reload arg registers from stack in case ptrace changed them.
42 * We don't reload %eax because syscall_trace_enter() returned
43 * the value it wants us to use in the table lookup.
45 .macro LOAD_ARGS32 offset
46 movl \offset(%rsp),%r11d
47 movl \offset+8(%rsp),%r10d
48 movl \offset+16(%rsp),%r9d
49 movl \offset+24(%rsp),%r8d
50 movl \offset+40(%rsp),%ecx
51 movl \offset+48(%rsp),%edx
52 movl \offset+56(%rsp),%esi
53 movl \offset+64(%rsp),%edi
56 .macro CFI_STARTPROC32 simple
68 #ifdef CONFIG_PARAVIRT
69 ENTRY(native_usergs_sysret32)
72 ENDPROC(native_usergs_sysret32)
74 ENTRY(native_irq_enable_sysexit)
78 ENDPROC(native_irq_enable_sysexit)
82 * 32bit SYSENTER instruction entry.
85 * %eax System call number.
96 * This is purely a fast path. For anything complicated we use the int 0x80
97 * path below. Set up a complete hardware stack frame to share code
98 * with the int 0x80 path.
100 ENTRY(ia32_sysenter_target)
101 CFI_STARTPROC32 simple
106 movq %gs:pda_kernelstack, %rsp
107 addq $(PDA_STACKOFFSET),%rsp
109 * No need to follow this irqs on/off section: the syscall
110 * disabled irqs, here we enable it straight after entry:
112 ENABLE_INTERRUPTS(CLBR_NONE)
113 movl %ebp,%ebp /* zero extension */
115 CFI_ADJUST_CFA_OFFSET 8
116 /*CFI_REL_OFFSET ss,0*/
118 CFI_ADJUST_CFA_OFFSET 8
121 CFI_ADJUST_CFA_OFFSET 8
122 /*CFI_REL_OFFSET rflags,0*/
123 movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
126 CFI_ADJUST_CFA_OFFSET 8
127 /*CFI_REL_OFFSET cs,0*/
130 CFI_ADJUST_CFA_OFFSET 8
133 CFI_ADJUST_CFA_OFFSET 8
136 /* no need to do an access_ok check here because rbp has been
137 32bit zero extended */
139 .section __ex_table,"a"
142 GET_THREAD_INFO(%r10)
143 orl $TS_COMPAT,TI_status(%r10)
144 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
146 jnz sysenter_tracesys
147 cmpl $(IA32_NR_syscalls-1),%eax
151 call *ia32_sys_call_table(,%rax,8)
152 movq %rax,RAX-ARGOFFSET(%rsp)
153 GET_THREAD_INFO(%r10)
154 DISABLE_INTERRUPTS(CLBR_NONE)
156 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
157 jnz int_ret_from_sys_call
158 andl $~TS_COMPAT,TI_status(%r10)
159 /* clear IF, that popfq doesn't enable interrupts early */
160 andl $~0x200,EFLAGS-R11(%rsp)
161 movl RIP-R11(%rsp),%edx /* User %eip */
163 RESTORE_ARGS 1,24,1,1,1,1
165 CFI_ADJUST_CFA_OFFSET -8
166 /*CFI_RESTORE rflags*/
167 popq %rcx /* User %esp */
168 CFI_ADJUST_CFA_OFFSET -8
171 ENABLE_INTERRUPTS_SYSEXIT32
179 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
180 movq %rsp,%rdi /* &pt_regs -> arg1 */
181 call syscall_trace_enter
182 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
185 cmpl $(IA32_NR_syscalls-1),%eax
186 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
189 ENDPROC(ia32_sysenter_target)
192 * 32bit SYSCALL instruction entry.
195 * %eax System call number.
201 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
207 * This is purely a fast path. For anything complicated we use the int 0x80
208 * path below. Set up a complete hardware stack frame to share code
209 * with the int 0x80 path.
211 ENTRY(ia32_cstar_target)
212 CFI_STARTPROC32 simple
214 CFI_DEF_CFA rsp,PDA_STACKOFFSET
216 /*CFI_REGISTER rflags,r11*/
220 movq %gs:pda_kernelstack,%rsp
222 * No need to follow this irqs on/off section: the syscall
223 * disabled irqs and here we enable it straight after entry:
225 ENABLE_INTERRUPTS(CLBR_NONE)
227 movl %eax,%eax /* zero extension */
228 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
229 movq %rcx,RIP-ARGOFFSET(%rsp)
230 CFI_REL_OFFSET rip,RIP-ARGOFFSET
231 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
233 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
234 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
235 movq %r11,EFLAGS-ARGOFFSET(%rsp)
236 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
237 movq %r8,RSP-ARGOFFSET(%rsp)
238 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
239 /* no need to do an access_ok check here because r8 has been
240 32bit zero extended */
241 /* hardware stack frame is complete now */
243 .section __ex_table,"a"
246 GET_THREAD_INFO(%r10)
247 orl $TS_COMPAT,TI_status(%r10)
248 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
252 cmpl $IA32_NR_syscalls-1,%eax
255 call *ia32_sys_call_table(,%rax,8)
256 movq %rax,RAX-ARGOFFSET(%rsp)
257 GET_THREAD_INFO(%r10)
258 DISABLE_INTERRUPTS(CLBR_NONE)
260 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
261 jnz int_ret_from_sys_call
262 andl $~TS_COMPAT,TI_status(%r10)
263 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
264 movl RIP-ARGOFFSET(%rsp),%ecx
266 movl EFLAGS-ARGOFFSET(%rsp),%r11d
267 /*CFI_REGISTER rflags,r11*/
269 movl RSP-ARGOFFSET(%rsp),%esp
279 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
280 movq %rsp,%rdi /* &pt_regs -> arg1 */
281 call syscall_trace_enter
282 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
285 movl RSP-ARGOFFSET(%rsp), %r8d
286 cmpl $(IA32_NR_syscalls-1),%eax
287 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
289 END(ia32_cstar_target)
297 * Emulated IA32 system calls via int 0x80.
300 * %eax System call number.
306 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
309 * Uses the same stack frame as the x86-64 version.
310 * All registers except %eax must be saved (but ptrace may violate that)
311 * Arguments are zero extended. For system calls that want sign extension and
312 * take long arguments a wrapper is needed. Most calls can just be called
314 * Assumes it is only called from user space and entered with interrupts off.
318 CFI_STARTPROC32 simple
320 CFI_DEF_CFA rsp,SS+8-RIP
321 /*CFI_REL_OFFSET ss,SS-RIP*/
322 CFI_REL_OFFSET rsp,RSP-RIP
323 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
324 /*CFI_REL_OFFSET cs,CS-RIP*/
325 CFI_REL_OFFSET rip,RIP-RIP
326 PARAVIRT_ADJUST_EXCEPTION_FRAME
329 * No need to follow this irqs on/off section: the syscall
330 * disabled irqs and here we enable it straight after entry:
332 ENABLE_INTERRUPTS(CLBR_NONE)
335 CFI_ADJUST_CFA_OFFSET 8
337 /* note the registers are not zero extended to the sf.
338 this could be a problem. */
340 GET_THREAD_INFO(%r10)
341 orl $TS_COMPAT,TI_status(%r10)
342 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
345 cmpl $(IA32_NR_syscalls-1),%eax
346 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
348 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
350 movq %rax,RAX-ARGOFFSET(%rsp)
351 jmp int_ret_from_sys_call
356 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
357 movq %rsp,%rdi /* &pt_regs -> arg1 */
358 call syscall_trace_enter
359 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
365 movq $0,ORIG_RAX-ARGOFFSET(%rsp)
366 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
367 jmp int_ret_from_sys_call
374 .macro PTREGSCALL label, func, arg
377 leaq \func(%rip),%rax
378 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
379 jmp ia32_ptregs_common
384 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
385 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
386 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
387 PTREGSCALL stub32_execve, sys32_execve, %rcx
388 PTREGSCALL stub32_fork, sys_fork, %rdi
389 PTREGSCALL stub32_clone, sys32_clone, %rdx
390 PTREGSCALL stub32_vfork, sys_vfork, %rdi
391 PTREGSCALL stub32_iopl, sys_iopl, %rsi
393 ENTRY(ia32_ptregs_common)
396 CFI_STARTPROC32 simple
398 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
399 CFI_REL_OFFSET rax,RAX-ARGOFFSET
400 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
401 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
402 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
403 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
404 CFI_REL_OFFSET rip,RIP-ARGOFFSET
405 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
406 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
407 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
408 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
412 jmp ia32_sysret /* misbalances the return cache */
414 END(ia32_ptregs_common)
419 .quad sys_restart_syscall
424 .quad compat_sys_open /* 5 */
429 .quad sys_unlink /* 10 */
432 .quad compat_sys_time
434 .quad sys_chmod /* 15 */
436 .quad quiet_ni_syscall /* old break syscall holder */
439 .quad sys_getpid /* 20 */
440 .quad compat_sys_mount /* mount */
441 .quad sys_oldumount /* old_umount */
444 .quad compat_sys_stime /* stime */ /* 25 */
445 .quad compat_sys_ptrace /* ptrace */
447 .quad sys_fstat /* (old)fstat */
449 .quad compat_sys_utime /* 30 */
450 .quad quiet_ni_syscall /* old stty syscall holder */
451 .quad quiet_ni_syscall /* old gtty syscall holder */
454 .quad quiet_ni_syscall /* 35 */ /* old ftime syscall holder */
459 .quad sys_rmdir /* 40 */
462 .quad compat_sys_times
463 .quad quiet_ni_syscall /* old prof syscall holder */
464 .quad sys_brk /* 45 */
469 .quad sys_getegid16 /* 50 */
471 .quad sys_umount /* new_umount */
472 .quad quiet_ni_syscall /* old lock syscall holder */
473 .quad compat_sys_ioctl
474 .quad compat_sys_fcntl64 /* 55 */
475 .quad quiet_ni_syscall /* old mpx syscall holder */
477 .quad quiet_ni_syscall /* old ulimit syscall holder */
479 .quad sys_umask /* 60 */
484 .quad sys_getpgrp /* 65 */
486 .quad sys32_sigaction
489 .quad sys_setreuid16 /* 70 */
491 .quad sys32_sigsuspend
492 .quad compat_sys_sigpending
493 .quad sys_sethostname
494 .quad compat_sys_setrlimit /* 75 */
495 .quad compat_sys_old_getrlimit /* old_getrlimit */
496 .quad compat_sys_getrusage
497 .quad sys32_gettimeofday
498 .quad sys32_settimeofday
499 .quad sys_getgroups16 /* 80 */
500 .quad sys_setgroups16
501 .quad sys32_old_select
504 .quad sys_readlink /* 85 */
508 .quad compat_sys_old_readdir
509 .quad sys32_mmap /* 90 */
514 .quad sys_fchown16 /* 95 */
515 .quad sys_getpriority
516 .quad sys_setpriority
517 .quad quiet_ni_syscall /* old profil syscall holder */
518 .quad compat_sys_statfs
519 .quad compat_sys_fstatfs /* 100 */
521 .quad compat_sys_socketcall
523 .quad compat_sys_setitimer
524 .quad compat_sys_getitimer /* 105 */
525 .quad compat_sys_newstat
526 .quad compat_sys_newlstat
527 .quad compat_sys_newfstat
529 .quad stub32_iopl /* 110 */
531 .quad quiet_ni_syscall /* old "idle" system call */
532 .quad sys32_vm86_warning /* vm86old */
533 .quad compat_sys_wait4
534 .quad sys_swapoff /* 115 */
535 .quad compat_sys_sysinfo
538 .quad stub32_sigreturn
539 .quad stub32_clone /* 120 */
540 .quad sys_setdomainname
543 .quad compat_sys_adjtimex
544 .quad sys32_mprotect /* 125 */
545 .quad compat_sys_sigprocmask
546 .quad quiet_ni_syscall /* create_module */
547 .quad sys_init_module
548 .quad sys_delete_module
549 .quad quiet_ni_syscall /* 130 get_kernel_syms */
553 .quad quiet_ni_syscall /* bdflush */
554 .quad sys_sysfs /* 135 */
555 .quad sys_personality
556 .quad quiet_ni_syscall /* for afs_syscall */
559 .quad sys_llseek /* 140 */
560 .quad compat_sys_getdents
561 .quad compat_sys_select
564 .quad compat_sys_readv /* 145 */
565 .quad compat_sys_writev
568 .quad sys32_sysctl /* sysctl */
569 .quad sys_mlock /* 150 */
573 .quad sys_sched_setparam
574 .quad sys_sched_getparam /* 155 */
575 .quad sys_sched_setscheduler
576 .quad sys_sched_getscheduler
577 .quad sys_sched_yield
578 .quad sys_sched_get_priority_max
579 .quad sys_sched_get_priority_min /* 160 */
580 .quad sys32_sched_rr_get_interval
581 .quad compat_sys_nanosleep
583 .quad sys_setresuid16
584 .quad sys_getresuid16 /* 165 */
585 .quad sys32_vm86_warning /* vm86 */
586 .quad quiet_ni_syscall /* query_module */
588 .quad compat_sys_nfsservctl
589 .quad sys_setresgid16 /* 170 */
590 .quad sys_getresgid16
592 .quad stub32_rt_sigreturn
593 .quad sys32_rt_sigaction
594 .quad sys32_rt_sigprocmask /* 175 */
595 .quad sys32_rt_sigpending
596 .quad compat_sys_rt_sigtimedwait
597 .quad sys32_rt_sigqueueinfo
598 .quad sys_rt_sigsuspend
599 .quad sys32_pread /* 180 */
605 .quad stub32_sigaltstack
607 .quad quiet_ni_syscall /* streams1 */
608 .quad quiet_ni_syscall /* streams2 */
609 .quad stub32_vfork /* 190 */
610 .quad compat_sys_getrlimit
612 .quad sys32_truncate64
613 .quad sys32_ftruncate64
614 .quad sys32_stat64 /* 195 */
619 .quad sys_getgid /* 200 */
624 .quad sys_getgroups /* 205 */
629 .quad sys_setresgid /* 210 */
634 .quad sys_setfsuid /* 215 */
639 .quad compat_sys_getdents64 /* 220 getdents64 */
640 .quad compat_sys_fcntl64
641 .quad quiet_ni_syscall /* tux */
642 .quad quiet_ni_syscall /* security */
644 .quad sys32_readahead /* 225 */
649 .quad sys_lgetxattr /* 230 */
654 .quad sys_removexattr /* 235 */
655 .quad sys_lremovexattr
656 .quad sys_fremovexattr
659 .quad compat_sys_futex /* 240 */
660 .quad compat_sys_sched_setaffinity
661 .quad compat_sys_sched_getaffinity
662 .quad sys_set_thread_area
663 .quad sys_get_thread_area
664 .quad compat_sys_io_setup /* 245 */
666 .quad compat_sys_io_getevents
667 .quad compat_sys_io_submit
669 .quad sys32_fadvise64 /* 250 */
670 .quad quiet_ni_syscall /* free_huge_pages */
672 .quad sys32_lookup_dcookie
673 .quad sys_epoll_create
674 .quad sys_epoll_ctl /* 255 */
676 .quad sys_remap_file_pages
677 .quad sys_set_tid_address
678 .quad compat_sys_timer_create
679 .quad compat_sys_timer_settime /* 260 */
680 .quad compat_sys_timer_gettime
681 .quad sys_timer_getoverrun
682 .quad sys_timer_delete
683 .quad compat_sys_clock_settime
684 .quad compat_sys_clock_gettime /* 265 */
685 .quad compat_sys_clock_getres
686 .quad compat_sys_clock_nanosleep
687 .quad compat_sys_statfs64
688 .quad compat_sys_fstatfs64
689 .quad sys_tgkill /* 270 */
690 .quad compat_sys_utimes
691 .quad sys32_fadvise64_64
692 .quad quiet_ni_syscall /* sys_vserver */
694 .quad compat_sys_get_mempolicy /* 275 */
695 .quad sys_set_mempolicy
696 .quad compat_sys_mq_open
698 .quad compat_sys_mq_timedsend
699 .quad compat_sys_mq_timedreceive /* 280 */
700 .quad compat_sys_mq_notify
701 .quad compat_sys_mq_getsetattr
702 .quad compat_sys_kexec_load /* reserved for kexec */
703 .quad compat_sys_waitid
704 .quad quiet_ni_syscall /* 285: sys_altroot */
706 .quad sys_request_key
709 .quad sys_ioprio_get /* 290 */
710 .quad sys_inotify_init
711 .quad sys_inotify_add_watch
712 .quad sys_inotify_rm_watch
713 .quad sys_migrate_pages
714 .quad compat_sys_openat /* 295 */
718 .quad compat_sys_futimesat
719 .quad sys32_fstatat /* 300 */
724 .quad sys_readlinkat /* 305 */
727 .quad compat_sys_pselect6
728 .quad compat_sys_ppoll
729 .quad sys_unshare /* 310 */
730 .quad compat_sys_set_robust_list
731 .quad compat_sys_get_robust_list
733 .quad sys32_sync_file_range
734 .quad sys_tee /* 315 */
735 .quad compat_sys_vmsplice
736 .quad compat_sys_move_pages
738 .quad sys_epoll_pwait
739 .quad compat_sys_utimensat /* 320 */
740 .quad compat_sys_signalfd
741 .quad sys_timerfd_create
743 .quad sys32_fallocate
744 .quad compat_sys_timerfd_settime /* 325 */
745 .quad compat_sys_timerfd_gettime