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/sys.h>
45 #include <linux/linkage.h>
46 #include <asm/segment.h>
72 * these are offsets into the task-struct.
97 movl $(__KERNEL_DS),%edx; \
101 #define RESTORE_ALL \
113 .section .fixup,"ax"; \
125 .section __ex_table,"a";\
132 #define GET_CURRENT(reg) \
137 pushfl # We get a different stack layout with call gates,
138 pushl %eax # which has to be cleaned up later..
140 movl EIP(%esp),%eax # due to call gates, this is eflags, not eip..
141 movl CS(%esp),%edx # this is eip..
142 movl EFLAGS(%esp),%ecx # and this is cs..
143 movl %eax,EFLAGS(%esp) #
144 movl %edx,EIP(%esp) # Now we move them to their "normal" places
148 andl $-8192,%ebx # GET_CURRENT
149 movl exec_domain(%ebx),%edx # Get the execution domain
150 movl 4(%edx),%edx # Get the lcall7 handler for the domain
155 jmp ret_from_sys_call
158 pushfl # We get a different stack layout with call gates,
159 pushl %eax # which has to be cleaned up later..
161 movl EIP(%esp),%eax # due to call gates, this is eflags, not eip..
162 movl CS(%esp),%edx # this is eip..
163 movl EFLAGS(%esp),%ecx # and this is cs..
164 movl %eax,EFLAGS(%esp) #
165 movl %edx,EIP(%esp) # Now we move them to their "normal" places
169 andl $-8192,%ebx # GET_CURRENT
170 movl exec_domain(%ebx),%edx # Get the execution domain
171 movl 4(%edx),%edx # Get the lcall7 handler for the domain
176 jmp ret_from_sys_call
181 call SYMBOL_NAME(schedule_tail)
184 testb $0x02,tsk_ptrace(%ebx) # PT_TRACESYS
186 jmp ret_from_sys_call
189 * Return to user mode is not as complex as all this looks,
190 * but we want the default path for a system call return to
191 * go as quickly as possible which is why some of this is
192 * less clear than it otherwise should be.
196 pushl %eax # save orig_eax
199 cmpl $(NR_syscalls),%eax
201 testb $0x02,tsk_ptrace(%ebx) # PT_TRACESYS
203 call *SYMBOL_NAME(sys_call_table)(,%eax,4)
204 movl %eax,EAX(%esp) # save the return value
205 ENTRY(ret_from_sys_call)
207 movl processor(%ebx),%eax
209 movl SYMBOL_NAME(irq_stat)(,%eax),%ecx # softirq_active
210 testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx # softirq_mask
212 movl SYMBOL_NAME(irq_stat),%ecx # softirq_active
213 testl SYMBOL_NAME(irq_stat)+4,%ecx # softirq_mask
218 cmpl $0,need_resched(%ebx)
220 cmpl $0,sigpending(%ebx)
227 sti # we can get here from an interrupt handler
228 testl $(VM_MASK),EFLAGS(%esp)
230 jne v86_signal_return
232 call SYMBOL_NAME(do_signal)
237 call SYMBOL_NAME(save_v86_state)
240 call SYMBOL_NAME(do_signal)
245 movl $-ENOSYS,EAX(%esp)
246 call SYMBOL_NAME(syscall_trace)
247 movl ORIG_EAX(%esp),%eax
248 cmpl $(NR_syscalls),%eax
250 call *SYMBOL_NAME(sys_call_table)(,%eax,4)
251 movl %eax,EAX(%esp) # save the return value
253 call SYMBOL_NAME(syscall_trace)
254 jmp ret_from_sys_call
256 movl $-ENOSYS,EAX(%esp)
257 jmp ret_from_sys_call
263 movl processor(%ebx),%eax
265 movl SYMBOL_NAME(irq_stat)(,%eax),%ecx # softirq_active
266 testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx # softirq_mask
268 movl SYMBOL_NAME(irq_stat),%ecx # softirq_active
269 testl SYMBOL_NAME(irq_stat)+4,%ecx # softirq_mask
275 movl EFLAGS(%esp),%eax # mix EFLAGS and CS
277 testl $(VM_MASK | 3),%eax # return to VM86 mode or non-supervisor?
278 jne ret_with_reschedule
283 call SYMBOL_NAME(do_softirq)
288 call SYMBOL_NAME(schedule) # test
289 jmp ret_from_sys_call
292 pushl $0 # no error code
293 pushl $ SYMBOL_NAME(do_divide_error)
308 movl ORIG_EAX(%esp), %esi # get the error code
309 movl ES(%esp), %edi # get the function address
310 movl %eax, ORIG_EAX(%esp)
313 pushl %esi # push the error code
314 pushl %edx # push the pt_regs pointer
315 movl $(__KERNEL_DS),%edx
321 jmp ret_from_exception
323 ENTRY(coprocessor_error)
325 pushl $ SYMBOL_NAME(do_coprocessor_error)
328 ENTRY(simd_coprocessor_error)
330 pushl $ SYMBOL_NAME(do_simd_coprocessor_error)
333 ENTRY(device_not_available)
334 pushl $-1 # mark this as an int
337 pushl $ret_from_exception
339 testl $0x4,%eax # EM (math emulation bit)
340 je SYMBOL_NAME(math_state_restore)
341 pushl $0 # temporary storage for ORIG_EIP
342 call SYMBOL_NAME(math_emulate)
348 pushl $ SYMBOL_NAME(do_debug)
357 call SYMBOL_NAME(do_nmi)
363 pushl $ SYMBOL_NAME(do_int3)
368 pushl $ SYMBOL_NAME(do_overflow)
373 pushl $ SYMBOL_NAME(do_bounds)
378 pushl $ SYMBOL_NAME(do_invalid_op)
381 ENTRY(coprocessor_segment_overrun)
383 pushl $ SYMBOL_NAME(do_coprocessor_segment_overrun)
388 pushl $ SYMBOL_NAME(do_reserved)
392 pushl $ SYMBOL_NAME(do_double_fault)
396 pushl $ SYMBOL_NAME(do_invalid_TSS)
399 ENTRY(segment_not_present)
400 pushl $ SYMBOL_NAME(do_segment_not_present)
404 pushl $ SYMBOL_NAME(do_stack_segment)
407 ENTRY(general_protection)
408 pushl $ SYMBOL_NAME(do_general_protection)
411 ENTRY(alignment_check)
412 pushl $ SYMBOL_NAME(do_alignment_check)
416 pushl $ SYMBOL_NAME(do_page_fault)
421 pushl $ SYMBOL_NAME(mcheck_fault)
424 ENTRY(spurious_interrupt_bug)
426 pushl $ SYMBOL_NAME(do_spurious_interrupt_bug)
430 ENTRY(sys_call_table)
431 .long SYMBOL_NAME(sys_ni_syscall) /* 0 - old "setup()" system call*/
432 .long SYMBOL_NAME(sys_exit)
433 .long SYMBOL_NAME(sys_fork)
434 .long SYMBOL_NAME(sys_read)
435 .long SYMBOL_NAME(sys_write)
436 .long SYMBOL_NAME(sys_open) /* 5 */
437 .long SYMBOL_NAME(sys_close)
438 .long SYMBOL_NAME(sys_waitpid)
439 .long SYMBOL_NAME(sys_creat)
440 .long SYMBOL_NAME(sys_link)
441 .long SYMBOL_NAME(sys_unlink) /* 10 */
442 .long SYMBOL_NAME(sys_execve)
443 .long SYMBOL_NAME(sys_chdir)
444 .long SYMBOL_NAME(sys_time)
445 .long SYMBOL_NAME(sys_mknod)
446 .long SYMBOL_NAME(sys_chmod) /* 15 */
447 .long SYMBOL_NAME(sys_lchown16)
448 .long SYMBOL_NAME(sys_ni_syscall) /* old break syscall holder */
449 .long SYMBOL_NAME(sys_stat)
450 .long SYMBOL_NAME(sys_lseek)
451 .long SYMBOL_NAME(sys_getpid) /* 20 */
452 .long SYMBOL_NAME(sys_mount)
453 .long SYMBOL_NAME(sys_oldumount)
454 .long SYMBOL_NAME(sys_setuid16)
455 .long SYMBOL_NAME(sys_getuid16)
456 .long SYMBOL_NAME(sys_stime) /* 25 */
457 .long SYMBOL_NAME(sys_ptrace)
458 .long SYMBOL_NAME(sys_alarm)
459 .long SYMBOL_NAME(sys_fstat)
460 .long SYMBOL_NAME(sys_pause)
461 .long SYMBOL_NAME(sys_utime) /* 30 */
462 .long SYMBOL_NAME(sys_ni_syscall) /* old stty syscall holder */
463 .long SYMBOL_NAME(sys_ni_syscall) /* old gtty syscall holder */
464 .long SYMBOL_NAME(sys_access)
465 .long SYMBOL_NAME(sys_nice)
466 .long SYMBOL_NAME(sys_ni_syscall) /* 35 */ /* old ftime syscall holder */
467 .long SYMBOL_NAME(sys_sync)
468 .long SYMBOL_NAME(sys_kill)
469 .long SYMBOL_NAME(sys_rename)
470 .long SYMBOL_NAME(sys_mkdir)
471 .long SYMBOL_NAME(sys_rmdir) /* 40 */
472 .long SYMBOL_NAME(sys_dup)
473 .long SYMBOL_NAME(sys_pipe)
474 .long SYMBOL_NAME(sys_times)
475 .long SYMBOL_NAME(sys_ni_syscall) /* old prof syscall holder */
476 .long SYMBOL_NAME(sys_brk) /* 45 */
477 .long SYMBOL_NAME(sys_setgid16)
478 .long SYMBOL_NAME(sys_getgid16)
479 .long SYMBOL_NAME(sys_signal)
480 .long SYMBOL_NAME(sys_geteuid16)
481 .long SYMBOL_NAME(sys_getegid16) /* 50 */
482 .long SYMBOL_NAME(sys_acct)
483 .long SYMBOL_NAME(sys_umount) /* recycled never used phys() */
484 .long SYMBOL_NAME(sys_ni_syscall) /* old lock syscall holder */
485 .long SYMBOL_NAME(sys_ioctl)
486 .long SYMBOL_NAME(sys_fcntl) /* 55 */
487 .long SYMBOL_NAME(sys_ni_syscall) /* old mpx syscall holder */
488 .long SYMBOL_NAME(sys_setpgid)
489 .long SYMBOL_NAME(sys_ni_syscall) /* old ulimit syscall holder */
490 .long SYMBOL_NAME(sys_olduname)
491 .long SYMBOL_NAME(sys_umask) /* 60 */
492 .long SYMBOL_NAME(sys_chroot)
493 .long SYMBOL_NAME(sys_ustat)
494 .long SYMBOL_NAME(sys_dup2)
495 .long SYMBOL_NAME(sys_getppid)
496 .long SYMBOL_NAME(sys_getpgrp) /* 65 */
497 .long SYMBOL_NAME(sys_setsid)
498 .long SYMBOL_NAME(sys_sigaction)
499 .long SYMBOL_NAME(sys_sgetmask)
500 .long SYMBOL_NAME(sys_ssetmask)
501 .long SYMBOL_NAME(sys_setreuid16) /* 70 */
502 .long SYMBOL_NAME(sys_setregid16)
503 .long SYMBOL_NAME(sys_sigsuspend)
504 .long SYMBOL_NAME(sys_sigpending)
505 .long SYMBOL_NAME(sys_sethostname)
506 .long SYMBOL_NAME(sys_setrlimit) /* 75 */
507 .long SYMBOL_NAME(sys_old_getrlimit)
508 .long SYMBOL_NAME(sys_getrusage)
509 .long SYMBOL_NAME(sys_gettimeofday)
510 .long SYMBOL_NAME(sys_settimeofday)
511 .long SYMBOL_NAME(sys_getgroups16) /* 80 */
512 .long SYMBOL_NAME(sys_setgroups16)
513 .long SYMBOL_NAME(old_select)
514 .long SYMBOL_NAME(sys_symlink)
515 .long SYMBOL_NAME(sys_lstat)
516 .long SYMBOL_NAME(sys_readlink) /* 85 */
517 .long SYMBOL_NAME(sys_uselib)
518 .long SYMBOL_NAME(sys_swapon)
519 .long SYMBOL_NAME(sys_reboot)
520 .long SYMBOL_NAME(old_readdir)
521 .long SYMBOL_NAME(old_mmap) /* 90 */
522 .long SYMBOL_NAME(sys_munmap)
523 .long SYMBOL_NAME(sys_truncate)
524 .long SYMBOL_NAME(sys_ftruncate)
525 .long SYMBOL_NAME(sys_fchmod)
526 .long SYMBOL_NAME(sys_fchown16) /* 95 */
527 .long SYMBOL_NAME(sys_getpriority)
528 .long SYMBOL_NAME(sys_setpriority)
529 .long SYMBOL_NAME(sys_ni_syscall) /* old profil syscall holder */
530 .long SYMBOL_NAME(sys_statfs)
531 .long SYMBOL_NAME(sys_fstatfs) /* 100 */
532 .long SYMBOL_NAME(sys_ioperm)
533 .long SYMBOL_NAME(sys_socketcall)
534 .long SYMBOL_NAME(sys_syslog)
535 .long SYMBOL_NAME(sys_setitimer)
536 .long SYMBOL_NAME(sys_getitimer) /* 105 */
537 .long SYMBOL_NAME(sys_newstat)
538 .long SYMBOL_NAME(sys_newlstat)
539 .long SYMBOL_NAME(sys_newfstat)
540 .long SYMBOL_NAME(sys_uname)
541 .long SYMBOL_NAME(sys_iopl) /* 110 */
542 .long SYMBOL_NAME(sys_vhangup)
543 .long SYMBOL_NAME(sys_ni_syscall) /* old "idle" system call */
544 .long SYMBOL_NAME(sys_vm86old)
545 .long SYMBOL_NAME(sys_wait4)
546 .long SYMBOL_NAME(sys_swapoff) /* 115 */
547 .long SYMBOL_NAME(sys_sysinfo)
548 .long SYMBOL_NAME(sys_ipc)
549 .long SYMBOL_NAME(sys_fsync)
550 .long SYMBOL_NAME(sys_sigreturn)
551 .long SYMBOL_NAME(sys_clone) /* 120 */
552 .long SYMBOL_NAME(sys_setdomainname)
553 .long SYMBOL_NAME(sys_newuname)
554 .long SYMBOL_NAME(sys_modify_ldt)
555 .long SYMBOL_NAME(sys_adjtimex)
556 .long SYMBOL_NAME(sys_mprotect) /* 125 */
557 .long SYMBOL_NAME(sys_sigprocmask)
558 .long SYMBOL_NAME(sys_create_module)
559 .long SYMBOL_NAME(sys_init_module)
560 .long SYMBOL_NAME(sys_delete_module)
561 .long SYMBOL_NAME(sys_get_kernel_syms) /* 130 */
562 .long SYMBOL_NAME(sys_quotactl)
563 .long SYMBOL_NAME(sys_getpgid)
564 .long SYMBOL_NAME(sys_fchdir)
565 .long SYMBOL_NAME(sys_bdflush)
566 .long SYMBOL_NAME(sys_sysfs) /* 135 */
567 .long SYMBOL_NAME(sys_personality)
568 .long SYMBOL_NAME(sys_ni_syscall) /* for afs_syscall */
569 .long SYMBOL_NAME(sys_setfsuid16)
570 .long SYMBOL_NAME(sys_setfsgid16)
571 .long SYMBOL_NAME(sys_llseek) /* 140 */
572 .long SYMBOL_NAME(sys_getdents)
573 .long SYMBOL_NAME(sys_select)
574 .long SYMBOL_NAME(sys_flock)
575 .long SYMBOL_NAME(sys_msync)
576 .long SYMBOL_NAME(sys_readv) /* 145 */
577 .long SYMBOL_NAME(sys_writev)
578 .long SYMBOL_NAME(sys_getsid)
579 .long SYMBOL_NAME(sys_fdatasync)
580 .long SYMBOL_NAME(sys_sysctl)
581 .long SYMBOL_NAME(sys_mlock) /* 150 */
582 .long SYMBOL_NAME(sys_munlock)
583 .long SYMBOL_NAME(sys_mlockall)
584 .long SYMBOL_NAME(sys_munlockall)
585 .long SYMBOL_NAME(sys_sched_setparam)
586 .long SYMBOL_NAME(sys_sched_getparam) /* 155 */
587 .long SYMBOL_NAME(sys_sched_setscheduler)
588 .long SYMBOL_NAME(sys_sched_getscheduler)
589 .long SYMBOL_NAME(sys_sched_yield)
590 .long SYMBOL_NAME(sys_sched_get_priority_max)
591 .long SYMBOL_NAME(sys_sched_get_priority_min) /* 160 */
592 .long SYMBOL_NAME(sys_sched_rr_get_interval)
593 .long SYMBOL_NAME(sys_nanosleep)
594 .long SYMBOL_NAME(sys_mremap)
595 .long SYMBOL_NAME(sys_setresuid16)
596 .long SYMBOL_NAME(sys_getresuid16) /* 165 */
597 .long SYMBOL_NAME(sys_vm86)
598 .long SYMBOL_NAME(sys_query_module)
599 .long SYMBOL_NAME(sys_poll)
600 .long SYMBOL_NAME(sys_nfsservctl)
601 .long SYMBOL_NAME(sys_setresgid16) /* 170 */
602 .long SYMBOL_NAME(sys_getresgid16)
603 .long SYMBOL_NAME(sys_prctl)
604 .long SYMBOL_NAME(sys_rt_sigreturn)
605 .long SYMBOL_NAME(sys_rt_sigaction)
606 .long SYMBOL_NAME(sys_rt_sigprocmask) /* 175 */
607 .long SYMBOL_NAME(sys_rt_sigpending)
608 .long SYMBOL_NAME(sys_rt_sigtimedwait)
609 .long SYMBOL_NAME(sys_rt_sigqueueinfo)
610 .long SYMBOL_NAME(sys_rt_sigsuspend)
611 .long SYMBOL_NAME(sys_pread) /* 180 */
612 .long SYMBOL_NAME(sys_pwrite)
613 .long SYMBOL_NAME(sys_chown16)
614 .long SYMBOL_NAME(sys_getcwd)
615 .long SYMBOL_NAME(sys_capget)
616 .long SYMBOL_NAME(sys_capset) /* 185 */
617 .long SYMBOL_NAME(sys_sigaltstack)
618 .long SYMBOL_NAME(sys_sendfile)
619 .long SYMBOL_NAME(sys_ni_syscall) /* streams1 */
620 .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */
621 .long SYMBOL_NAME(sys_vfork) /* 190 */
622 .long SYMBOL_NAME(sys_getrlimit)
623 .long SYMBOL_NAME(sys_mmap2)
624 .long SYMBOL_NAME(sys_truncate64)
625 .long SYMBOL_NAME(sys_ftruncate64)
626 .long SYMBOL_NAME(sys_stat64) /* 195 */
627 .long SYMBOL_NAME(sys_lstat64)
628 .long SYMBOL_NAME(sys_fstat64)
629 .long SYMBOL_NAME(sys_lchown)
630 .long SYMBOL_NAME(sys_getuid)
631 .long SYMBOL_NAME(sys_getgid) /* 200 */
632 .long SYMBOL_NAME(sys_geteuid)
633 .long SYMBOL_NAME(sys_getegid)
634 .long SYMBOL_NAME(sys_setreuid)
635 .long SYMBOL_NAME(sys_setregid)
636 .long SYMBOL_NAME(sys_getgroups) /* 205 */
637 .long SYMBOL_NAME(sys_setgroups)
638 .long SYMBOL_NAME(sys_fchown)
639 .long SYMBOL_NAME(sys_setresuid)
640 .long SYMBOL_NAME(sys_getresuid)
641 .long SYMBOL_NAME(sys_setresgid) /* 210 */
642 .long SYMBOL_NAME(sys_getresgid)
643 .long SYMBOL_NAME(sys_chown)
644 .long SYMBOL_NAME(sys_setuid)
645 .long SYMBOL_NAME(sys_setgid)
646 .long SYMBOL_NAME(sys_setfsuid) /* 215 */
647 .long SYMBOL_NAME(sys_setfsgid)
648 .long SYMBOL_NAME(sys_pivot_root)
649 .long SYMBOL_NAME(sys_mincore)
650 .long SYMBOL_NAME(sys_madvise)
651 .long SYMBOL_NAME(sys_getdents64) /* 220 */
652 .long SYMBOL_NAME(sys_fcntl64)
653 .long SYMBOL_NAME(sys_ni_syscall) /* reserved for TUX */
656 * NOTE!! This doesn't have to be exact - we just have
657 * to make sure we have _enough_ of the "sys_ni_syscall"
658 * entries. Don't panic if you notice that this hasn't
659 * been shrunk every time we add a new system call.
661 .rept NR_syscalls-221
662 .long SYMBOL_NAME(sys_ni_syscall)