entry.s
来自「优龙2410linux2.6.8内核源代码」· S 代码 · 共 891 行 · 第 1/2 页
S
891 行
/* * linux/arch/i386/entry.S * * Copyright (C) 1991, 1992 Linus Torvalds *//* * entry.S contains the system-call and fault low-level handling routines. * This also contains the timer-interrupt handler, as well as all interrupts * and faults that can result in a task-switch. * * NOTE: This code handles signal-recognition, which happens every time * after a timer-interrupt and after each system call. * * I changed all the .align's to 4 (16 byte alignment), as that's faster * on a 486. * * Stack layout in 'ret_from_system_call': * ptrace needs to have all regs on the stack. * if the order here is changed, it needs to be * updated in fork.c:copy_process, signal.c:do_signal, * ptrace.c and ptrace.h * * 0(%esp) - %ebx * 4(%esp) - %ecx * 8(%esp) - %edx * C(%esp) - %esi * 10(%esp) - %edi * 14(%esp) - %ebp * 18(%esp) - %eax * 1C(%esp) - %ds * 20(%esp) - %es * 24(%esp) - orig_eax * 28(%esp) - %eip * 2C(%esp) - %cs * 30(%esp) - %eflags * 34(%esp) - %oldesp * 38(%esp) - %oldss * * "current" is in register %ebx during any slow entries. */#include <linux/config.h>#include <linux/linkage.h>#include <asm/thread_info.h>#include <asm/errno.h>#include <asm/segment.h>#include <asm/smp.h>#include <asm/page.h>#include "irq_vectors.h"#define nr_syscalls ((syscall_table_size)/4)EBX = 0x00ECX = 0x04EDX = 0x08ESI = 0x0CEDI = 0x10EBP = 0x14EAX = 0x18DS = 0x1CES = 0x20ORIG_EAX = 0x24EIP = 0x28CS = 0x2CEFLAGS = 0x30OLDESP = 0x34OLDSS = 0x38CF_MASK = 0x00000001TF_MASK = 0x00000100IF_MASK = 0x00000200DF_MASK = 0x00000400 NT_MASK = 0x00004000VM_MASK = 0x00020000#ifdef CONFIG_PREEMPT#define preempt_stop cli#else#define preempt_stop#define resume_kernel restore_all#endif#define SAVE_ALL \ cld; \ pushl %es; \ pushl %ds; \ pushl %eax; \ pushl %ebp; \ pushl %edi; \ pushl %esi; \ pushl %edx; \ pushl %ecx; \ pushl %ebx; \ movl $(__USER_DS), %edx; \ movl %edx, %ds; \ movl %edx, %es;#define RESTORE_INT_REGS \ popl %ebx; \ popl %ecx; \ popl %edx; \ popl %esi; \ popl %edi; \ popl %ebp; \ popl %eax#define RESTORE_REGS \ RESTORE_INT_REGS; \1: popl %ds; \2: popl %es; \.section .fixup,"ax"; \3: movl $0,(%esp); \ jmp 1b; \4: movl $0,(%esp); \ jmp 2b; \.previous; \.section __ex_table,"a";\ .align 4; \ .long 1b,3b; \ .long 2b,4b; \.previous#define RESTORE_ALL \ RESTORE_REGS \ addl $4, %esp; \1: iret; \.section .fixup,"ax"; \2: sti; \ movl $(__USER_DS), %edx; \ movl %edx, %ds; \ movl %edx, %es; \ pushl $11; \ call do_exit; \.previous; \.section __ex_table,"a";\ .align 4; \ .long 1b,2b; \.previousENTRY(lcall7) pushfl # We get a different stack layout with call # gates, which has to be cleaned up later.. pushl %eax SAVE_ALL movl %esp, %ebp pushl %ebp pushl $0x7do_lcall: movl EIP(%ebp), %eax # due to call gates, this is eflags, not eip.. movl CS(%ebp), %edx # this is eip.. movl EFLAGS(%ebp), %ecx # and this is cs.. movl %eax,EFLAGS(%ebp) # movl %edx,EIP(%ebp) # Now we move them to their "normal" places movl %ecx,CS(%ebp) # GET_THREAD_INFO_WITH_ESP(%ebp) # GET_THREAD_INFO movl TI_exec_domain(%ebp), %edx # Get the execution domain call *EXEC_DOMAIN_handler(%edx) # Call the handler for the domain addl $4, %esp popl %eax jmp resume_userspaceENTRY(lcall27) pushfl # We get a different stack layout with call # gates, which has to be cleaned up later.. pushl %eax SAVE_ALL movl %esp, %ebp pushl %ebp pushl $0x27 jmp do_lcallENTRY(ret_from_fork) pushl %eax call schedule_tail GET_THREAD_INFO(%ebp) popl %eax jmp syscall_exit/* * Return to user mode is not as complex as all this looks, * but we want the default path for a system call return to * go as quickly as possible which is why some of this is * less clear than it otherwise should be. */ # userspace resumption stub bypassing syscall exit tracing ALIGNret_from_exception: preempt_stopret_from_intr: GET_THREAD_INFO(%ebp) movl EFLAGS(%esp), %eax # mix EFLAGS and CS movb CS(%esp), %al testl $(VM_MASK | 3), %eax jz resume_kernel # returning to kernel or vm86-spaceENTRY(resume_userspace) cli # make sure we don't miss an interrupt # setting need_resched or sigpending # between sampling and the iret movl TI_flags(%ebp), %ecx andl $_TIF_WORK_MASK, %ecx # is there any work to be done on # int/exception return? jne work_pending jmp restore_all#ifdef CONFIG_PREEMPTENTRY(resume_kernel) cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ? jnz restore_allneed_resched: movl TI_flags(%ebp), %ecx # need_resched set ? testb $_TIF_NEED_RESCHED, %cl jz restore_all testl $IF_MASK,EFLAGS(%esp) # interrupts off (exception path) ? jz restore_all movl $PREEMPT_ACTIVE,TI_preempt_count(%ebp) sti call schedule movl $0,TI_preempt_count(%ebp) cli jmp need_resched#endif/* SYSENTER_RETURN points to after the "sysenter" instruction in the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */ # sysenter call handler stubENTRY(sysenter_entry) movl TSS_sysenter_esp0(%esp),%espsysenter_past_esp: sti pushl $(__USER_DS) pushl %ebp pushfl pushl $(__USER_CS) pushl $SYSENTER_RETURN/* * Load the potential sixth argument from user stack. * Careful about security. */ cmpl $__PAGE_OFFSET-3,%ebp jae syscall_fault1: movl (%ebp),%ebp.section __ex_table,"a" .align 4 .long 1b,syscall_fault.previous pushl %eax SAVE_ALL GET_THREAD_INFO(%ebp) cmpl $(nr_syscalls), %eax jae syscall_badsys testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%ebp) jnz syscall_trace_entry call *sys_call_table(,%eax,4) movl %eax,EAX(%esp) cli movl TI_flags(%ebp), %ecx testw $_TIF_ALLWORK_MASK, %cx jne syscall_exit_work/* if something modifies registers it must also disable sysexit */ movl EIP(%esp), %edx movl OLDESP(%esp), %ecx sti sysexit # system call handler stubENTRY(system_call) pushl %eax # save orig_eax SAVE_ALL GET_THREAD_INFO(%ebp) cmpl $(nr_syscalls), %eax jae syscall_badsys # system call tracing in operation testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%ebp) jnz syscall_trace_entrysyscall_call: call *sys_call_table(,%eax,4) movl %eax,EAX(%esp) # store the return valuesyscall_exit: cli # make sure we don't miss an interrupt # setting need_resched or sigpending # between sampling and the iret movl TI_flags(%ebp), %ecx testw $_TIF_ALLWORK_MASK, %cx # current->work jne syscall_exit_workrestore_all: RESTORE_ALL # perform work that needs to be done immediately before resumption ALIGNwork_pending: testb $_TIF_NEED_RESCHED, %cl jz work_notifysigwork_resched: call schedule cli # make sure we don't miss an interrupt # setting need_resched or sigpending # between sampling and the iret movl TI_flags(%ebp), %ecx andl $_TIF_WORK_MASK, %ecx # is there any work to be done other # than syscall tracing? jz restore_all testb $_TIF_NEED_RESCHED, %cl jnz work_reschedwork_notifysig: # deal with pending signals and # notify-resume requests testl $VM_MASK, EFLAGS(%esp) movl %esp, %eax jne work_notifysig_v86 # returning to kernel-space or # vm86-space xorl %edx, %edx call do_notify_resume jmp restore_all ALIGNwork_notifysig_v86: pushl %ecx call save_v86_state popl %ecx movl %eax, %esp xorl %edx, %edx call do_notify_resume jmp restore_all # perform syscall exit tracing ALIGNsyscall_trace_entry: movl $-ENOSYS,EAX(%esp) movl %esp, %eax xorl %edx,%edx call do_syscall_trace movl ORIG_EAX(%esp), %eax cmpl $(nr_syscalls), %eax jnae syscall_call jmp syscall_exit # perform syscall exit tracing ALIGNsyscall_exit_work: testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT), %cl jz work_pending sti # could let do_syscall_trace() call # schedule() instead movl %esp, %eax movl $1, %edx call do_syscall_trace jmp resume_userspace ALIGNsyscall_fault: pushl %eax # save orig_eax SAVE_ALL GET_THREAD_INFO(%ebp) movl $-EFAULT,EAX(%esp) jmp resume_userspace ALIGNsyscall_badsys: movl $-ENOSYS,EAX(%esp) jmp resume_userspace/* * Build the entry stubs and pointer table with * some assembler magic. */.dataENTRY(interrupt).textvector=0ENTRY(irq_entries_start).rept NR_IRQS ALIGN1: pushl $vector-256 jmp common_interrupt.data .long 1b.textvector=vector+1.endr ALIGNcommon_interrupt: SAVE_ALL call do_IRQ jmp ret_from_intr#define BUILD_INTERRUPT(name, nr) \ENTRY(name) \ pushl $nr-256; \ SAVE_ALL \ call smp_/**/name; \ jmp ret_from_intr;/* The include is where all of the SMP etc. interrupts come from */#include "entry_arch.h"ENTRY(divide_error) pushl $0 # no error code pushl $do_divide_error ALIGNerror_code: pushl %ds pushl %eax xorl %eax, %eax pushl %ebp pushl %edi pushl %esi pushl %edx decl %eax # eax = -1 pushl %ecx pushl %ebx cld movl %es, %ecx movl ORIG_EAX(%esp), %esi # get the error code movl ES(%esp), %edi # get the function address movl %eax, ORIG_EAX(%esp) movl %ecx, ES(%esp) movl %esp, %edx pushl %esi # push the error code pushl %edx # push the pt_regs pointer movl $(__USER_DS), %edx movl %edx, %ds movl %edx, %es call *%edi addl $8, %esp jmp ret_from_exceptionENTRY(coprocessor_error) pushl $0 pushl $do_coprocessor_error jmp error_codeENTRY(simd_coprocessor_error) pushl $0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?