2 * linux/arch/i386/entry.S
4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * entry.S contains the system-call and fault low-level handling routines.
9 * This also contains the timer-interrupt handler, as well as all interrupts
10 * and faults that can result in a task-switch.
12 * NOTE: This code handles signal-recognition, which happens every time
13 * after a timer-interrupt and after each system call.
15 * I changed all the .align's to 4 (16 byte alignment), as that's faster
18 * Stack layout in 'ret_from_system_call':
19 * ptrace needs to have all regs on the stack.
20 * if the order here is changed, it needs to be
21 * updated in fork.c:copy_process, signal.c:do_signal,
22 * ptrace.c and ptrace.h
40 * "current" is in register %ebx during any slow entries.
43 #include <linux/config.h>
44 #include <linux/linkage.h>
45 #include <asm/thread_info.h>
46 #include <asm/errno.h>
47 #include <asm/segment.h>
50 #include "irq_vectors.h"
52 #define nr_syscalls ((syscall_table_size)/4)
78 #define preempt_stop cli
81 #define resume_kernel restore_all
95 movl $(__USER_DS), %edx; \
99 #define RESTORE_INT_REGS \
108 #define RESTORE_REGS \
112 .section .fixup,"ax"; \
118 .section __ex_table,"a";\
125 #define RESTORE_ALL \
129 .section .fixup,"ax"; \
131 movl $(__USER_DS), %edx; \
137 .section __ex_table,"a";\
146 GET_THREAD_INFO(%ebp)
151 * Return to user mode is not as complex as all this looks,
152 * but we want the default path for a system call return to
153 * go as quickly as possible which is why some of this is
154 * less clear than it otherwise should be.
157 # userspace resumption stub bypassing syscall exit tracing
162 GET_THREAD_INFO(%ebp)
163 movl EFLAGS(%esp), %eax # mix EFLAGS and CS
165 testl $(VM_MASK | 3), %eax
166 jz resume_kernel # returning to kernel or vm86-space
167 ENTRY(resume_userspace)
168 cli # make sure we don't miss an interrupt
169 # setting need_resched or sigpending
170 # between sampling and the iret
171 movl TI_flags(%ebp), %ecx
172 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
173 # int/exception return?
177 #ifdef CONFIG_PREEMPT
180 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
183 movl TI_flags(%ebp), %ecx # need_resched set ?
184 testb $_TIF_NEED_RESCHED, %cl
186 testl $IF_MASK,EFLAGS(%esp) # interrupts off (exception path) ?
188 call preempt_schedule_irq
192 /* SYSENTER_RETURN points to after the "sysenter" instruction in
193 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
195 # sysenter call handler stub
196 ENTRY(sysenter_entry)
197 movl TSS_sysenter_esp0(%esp),%esp
204 pushl $SYSENTER_RETURN
207 * Load the potential sixth argument from user stack.
208 * Careful about security.
210 cmpl $__PAGE_OFFSET-3,%ebp
213 .section __ex_table,"a"
215 .long 1b,syscall_fault
220 GET_THREAD_INFO(%ebp)
222 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
223 jnz syscall_trace_entry
224 cmpl $(nr_syscalls), %eax
226 call *sys_call_table(,%eax,4)
229 movl TI_flags(%ebp), %ecx
230 testw $_TIF_ALLWORK_MASK, %cx
231 jne syscall_exit_work
232 /* if something modifies registers it must also disable sysexit */
234 movl OLDESP(%esp), %ecx
240 # system call handler stub
242 pushl %eax # save orig_eax
244 GET_THREAD_INFO(%ebp)
245 # system call tracing in operation
246 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
247 jnz syscall_trace_entry
248 cmpl $(nr_syscalls), %eax
251 call *sys_call_table(,%eax,4)
252 movl %eax,EAX(%esp) # store the return value
254 cli # make sure we don't miss an interrupt
255 # setting need_resched or sigpending
256 # between sampling and the iret
257 movl TI_flags(%ebp), %ecx
258 testw $_TIF_ALLWORK_MASK, %cx # current->work
259 jne syscall_exit_work
263 # perform work that needs to be done immediately before resumption
266 testb $_TIF_NEED_RESCHED, %cl
270 cli # make sure we don't miss an interrupt
271 # setting need_resched or sigpending
272 # between sampling and the iret
273 movl TI_flags(%ebp), %ecx
274 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
275 # than syscall tracing?
277 testb $_TIF_NEED_RESCHED, %cl
280 work_notifysig: # deal with pending signals and
281 # notify-resume requests
282 testl $VM_MASK, EFLAGS(%esp)
284 jne work_notifysig_v86 # returning to kernel-space or
287 call do_notify_resume
292 pushl %ecx # save ti_flags for do_notify_resume
293 call save_v86_state # %eax contains pt_regs pointer
297 call do_notify_resume
300 # perform syscall exit tracing
303 movl $-ENOSYS,EAX(%esp)
306 call do_syscall_trace
307 movl ORIG_EAX(%esp), %eax
308 cmpl $(nr_syscalls), %eax
312 # perform syscall exit tracing
315 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
317 sti # could let do_syscall_trace() call
321 call do_syscall_trace
326 pushl %eax # save orig_eax
328 GET_THREAD_INFO(%ebp)
329 movl $-EFAULT,EAX(%esp)
334 movl $-ENOSYS,EAX(%esp)
338 * Build the entry stubs and pointer table with
339 * some assembler magic.
346 ENTRY(irq_entries_start)
364 #define BUILD_INTERRUPT(name, nr) \
372 /* The include is where all of the SMP etc. interrupts come from */
373 #include "entry_arch.h"
376 pushl $0 # no error code
377 pushl $do_divide_error
392 movl ES(%esp), %edi # get the function address
393 movl ORIG_EAX(%esp), %edx # get the error code
394 movl %eax, ORIG_EAX(%esp)
396 movl $(__USER_DS), %ecx
399 movl %esp,%eax # pt_regs pointer
401 jmp ret_from_exception
403 ENTRY(coprocessor_error)
405 pushl $do_coprocessor_error
408 ENTRY(simd_coprocessor_error)
410 pushl $do_simd_coprocessor_error
413 ENTRY(device_not_available)
414 pushl $-1 # mark this as an int
417 testl $0x4, %eax # EM (math emulation bit)
418 jne device_not_available_emulate
420 call math_state_restore
421 jmp ret_from_exception
422 device_not_available_emulate:
423 pushl $0 # temporary storage for ORIG_EIP
426 jmp ret_from_exception
429 * Debug traps and NMI can happen at the one SYSENTER instruction
430 * that sets up the real kernel stack. Check here, since we can't
431 * allow the wrong stack to be used.
433 * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
434 * already pushed 3 words if it hits on the sysenter instruction:
435 * eflags, cs and eip.
437 * We just load the right stack, and push the three (known) values
438 * by hand onto the new stack - while updating the return eip past
439 * the instruction that would have done it for sysenter.
441 #define FIX_STACK(offset, ok, label) \
442 cmpw $__KERNEL_CS,4(%esp); \
445 movl TSS_sysenter_esp0+offset(%esp),%esp; \
447 pushl $__KERNEL_CS; \
448 pushl $sysenter_past_esp
451 cmpl $sysenter_entry,(%esp)
452 jne debug_stack_correct
453 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
455 pushl $-1 # mark this as an int
457 xorl %edx,%edx # error code 0
458 movl %esp,%eax # pt_regs pointer
462 jmp ret_from_exception
465 * NMI is doubly nasty. It can happen _while_ we're handling
466 * a debug fault, and the debug fault hasn't yet been able to
467 * clear up the stack. So we first check whether we got an
468 * NMI on the sysenter entry path, but after that we need to
469 * check whether we got an NMI on the debug path where the debug
470 * fault happened on the sysenter path.
473 cmpl $sysenter_entry,(%esp)
477 /* Do not access memory above the end of our stack page,
478 * it might not exist.
480 andl $(THREAD_SIZE-1),%eax
481 cmpl $(THREAD_SIZE-20),%eax
483 jae nmi_stack_correct
484 cmpl $sysenter_entry,12(%esp)
485 je nmi_debug_stack_check
489 xorl %edx,%edx # zero error code
490 movl %esp,%eax # pt_regs pointer
495 FIX_STACK(12,nmi_stack_correct, 1)
496 jmp nmi_stack_correct
497 nmi_debug_stack_check:
498 cmpw $__KERNEL_CS,16(%esp)
499 jne nmi_stack_correct
500 cmpl $debug - 1,(%esp)
501 jle nmi_stack_correct
502 cmpl $debug_esp_fix_insn,(%esp)
503 jle nmi_debug_stack_fixup
504 nmi_debug_stack_fixup:
505 FIX_STACK(24,nmi_stack_correct, 1)
506 jmp nmi_stack_correct
509 pushl $-1 # mark this as an int
511 xorl %edx,%edx # zero error code
512 movl %esp,%eax # pt_regs pointer
516 jmp ret_from_exception
533 ENTRY(coprocessor_segment_overrun)
535 pushl $do_coprocessor_segment_overrun
539 pushl $do_invalid_TSS
542 ENTRY(segment_not_present)
543 pushl $do_segment_not_present
547 pushl $do_stack_segment
550 ENTRY(general_protection)
551 pushl $do_general_protection
554 ENTRY(alignment_check)
555 pushl $do_alignment_check
562 #ifdef CONFIG_X86_MCE
565 pushl machine_check_vector
569 ENTRY(spurious_interrupt_bug)
571 pushl $do_spurious_interrupt_bug
575 ENTRY(sys_call_table)
576 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
581 .long sys_open /* 5 */
586 .long sys_unlink /* 10 */
591 .long sys_chmod /* 15 */
593 .long sys_ni_syscall /* old break syscall holder */
596 .long sys_getpid /* 20 */
601 .long sys_stime /* 25 */
606 .long sys_utime /* 30 */
607 .long sys_ni_syscall /* old stty syscall holder */
608 .long sys_ni_syscall /* old gtty syscall holder */
611 .long sys_ni_syscall /* 35 - old ftime syscall holder */
616 .long sys_rmdir /* 40 */
620 .long sys_ni_syscall /* old prof syscall holder */
621 .long sys_brk /* 45 */
626 .long sys_getegid16 /* 50 */
628 .long sys_umount /* recycled never used phys() */
629 .long sys_ni_syscall /* old lock syscall holder */
631 .long sys_fcntl /* 55 */
632 .long sys_ni_syscall /* old mpx syscall holder */
634 .long sys_ni_syscall /* old ulimit syscall holder */
636 .long sys_umask /* 60 */
641 .long sys_getpgrp /* 65 */
646 .long sys_setreuid16 /* 70 */
650 .long sys_sethostname
651 .long sys_setrlimit /* 75 */
652 .long sys_old_getrlimit
654 .long sys_gettimeofday
655 .long sys_settimeofday
656 .long sys_getgroups16 /* 80 */
657 .long sys_setgroups16
661 .long sys_readlink /* 85 */
666 .long old_mmap /* 90 */
671 .long sys_fchown16 /* 95 */
672 .long sys_getpriority
673 .long sys_setpriority
674 .long sys_ni_syscall /* old profil syscall holder */
676 .long sys_fstatfs /* 100 */
681 .long sys_getitimer /* 105 */
686 .long sys_iopl /* 110 */
688 .long sys_ni_syscall /* old "idle" system call */
691 .long sys_swapoff /* 115 */
696 .long sys_clone /* 120 */
697 .long sys_setdomainname
701 .long sys_mprotect /* 125 */
702 .long sys_sigprocmask
703 .long sys_ni_syscall /* old "create_module" */
704 .long sys_init_module
705 .long sys_delete_module
706 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
711 .long sys_sysfs /* 135 */
712 .long sys_personality
713 .long sys_ni_syscall /* reserved for afs_syscall */
716 .long sys_llseek /* 140 */
721 .long sys_readv /* 145 */
726 .long sys_mlock /* 150 */
730 .long sys_sched_setparam
731 .long sys_sched_getparam /* 155 */
732 .long sys_sched_setscheduler
733 .long sys_sched_getscheduler
734 .long sys_sched_yield
735 .long sys_sched_get_priority_max
736 .long sys_sched_get_priority_min /* 160 */
737 .long sys_sched_rr_get_interval
740 .long sys_setresuid16
741 .long sys_getresuid16 /* 165 */
743 .long sys_ni_syscall /* Old sys_query_module */
746 .long sys_setresgid16 /* 170 */
747 .long sys_getresgid16
749 .long sys_rt_sigreturn
750 .long sys_rt_sigaction
751 .long sys_rt_sigprocmask /* 175 */
752 .long sys_rt_sigpending
753 .long sys_rt_sigtimedwait
754 .long sys_rt_sigqueueinfo
755 .long sys_rt_sigsuspend
756 .long sys_pread64 /* 180 */
761 .long sys_capset /* 185 */
762 .long sys_sigaltstack
764 .long sys_ni_syscall /* reserved for streams1 */
765 .long sys_ni_syscall /* reserved for streams2 */
766 .long sys_vfork /* 190 */
770 .long sys_ftruncate64
771 .long sys_stat64 /* 195 */
776 .long sys_getgid /* 200 */
781 .long sys_getgroups /* 205 */
786 .long sys_setresgid /* 210 */
791 .long sys_setfsuid /* 215 */
796 .long sys_getdents64 /* 220 */
798 .long sys_ni_syscall /* reserved for TUX */
801 .long sys_readahead /* 225 */
806 .long sys_lgetxattr /* 230 */
811 .long sys_removexattr /* 235 */
812 .long sys_lremovexattr
813 .long sys_fremovexattr
816 .long sys_futex /* 240 */
817 .long sys_sched_setaffinity
818 .long sys_sched_getaffinity
819 .long sys_set_thread_area
820 .long sys_get_thread_area
821 .long sys_io_setup /* 245 */
823 .long sys_io_getevents
826 .long sys_fadvise64 /* 250 */
829 .long sys_lookup_dcookie
830 .long sys_epoll_create
831 .long sys_epoll_ctl /* 255 */
833 .long sys_remap_file_pages
834 .long sys_set_tid_address
835 .long sys_timer_create
836 .long sys_timer_settime /* 260 */
837 .long sys_timer_gettime
838 .long sys_timer_getoverrun
839 .long sys_timer_delete
840 .long sys_clock_settime
841 .long sys_clock_gettime /* 265 */
842 .long sys_clock_getres
843 .long sys_clock_nanosleep
846 .long sys_tgkill /* 270 */
848 .long sys_fadvise64_64
851 .long sys_get_mempolicy
852 .long sys_set_mempolicy
855 .long sys_mq_timedsend
856 .long sys_mq_timedreceive /* 280 */
858 .long sys_mq_getsetattr
859 .long sys_ni_syscall /* reserved for kexec */
861 .long sys_ni_syscall /* 285 */ /* available */
863 .long sys_request_key
866 syscall_table_size=(.-sys_call_table)