⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entry.s

📁 LINUX 2.6.17.4的源码
💻 S
📖 第 1 页 / 共 3 页
字号:
/* * arch/v850/kernel/entry.S -- Low-level system-call handling, trap handlers, *	and context-switching * *  Copyright (C) 2001,02,03  NEC Electronics Corporation *  Copyright (C) 2001,02,03  Miles Bader <miles@gnu.org> * * This file is subject to the terms and conditions of the GNU General * Public License.  See the file COPYING in the main directory of this * archive for more details. * * Written by Miles Bader <miles@gnu.org> */#include <linux/sys.h>#include <asm/entry.h>#include <asm/current.h>#include <asm/thread_info.h>#include <asm/clinkage.h>#include <asm/processor.h>#include <asm/irq.h>#include <asm/errno.h>#include <asm/asm-offsets.h>/* Make a slightly more convenient alias for C_SYMBOL_NAME.  */#define CSYM	C_SYMBOL_NAME/* The offset of the struct pt_regs in a state-save-frame on the stack.  */#define PTO	STATE_SAVE_PT_OFFSET/* Save argument registers to the state-save-frame pointed to by EP.  */#define SAVE_ARG_REGS							      \	sst.w	r6, PTO+PT_GPR(6)[ep];					      \	sst.w	r7, PTO+PT_GPR(7)[ep];					      \	sst.w	r8, PTO+PT_GPR(8)[ep];					      \	sst.w	r9, PTO+PT_GPR(9)[ep]/* Restore argument registers from the state-save-frame pointed to by EP.  */#define RESTORE_ARG_REGS						      \	sld.w	PTO+PT_GPR(6)[ep], r6;					      \	sld.w	PTO+PT_GPR(7)[ep], r7;					      \	sld.w	PTO+PT_GPR(8)[ep], r8;					      \	sld.w	PTO+PT_GPR(9)[ep], r9/* Save value return registers to the state-save-frame pointed to by EP.  */#define SAVE_RVAL_REGS							      \	sst.w	r10, PTO+PT_GPR(10)[ep];				      \	sst.w	r11, PTO+PT_GPR(11)[ep]/* Restore value return registers from the state-save-frame pointed to by EP.  */#define RESTORE_RVAL_REGS						      \	sld.w	PTO+PT_GPR(10)[ep], r10;				      \	sld.w	PTO+PT_GPR(11)[ep], r11#define SAVE_CALL_CLOBBERED_REGS_BEFORE_ARGS				      \	sst.w	r1, PTO+PT_GPR(1)[ep];					      \	sst.w	r5, PTO+PT_GPR(5)[ep]#define SAVE_CALL_CLOBBERED_REGS_AFTER_RVAL				      \	sst.w	r12, PTO+PT_GPR(12)[ep];				      \	sst.w	r13, PTO+PT_GPR(13)[ep];				      \	sst.w	r14, PTO+PT_GPR(14)[ep];				      \	sst.w	r15, PTO+PT_GPR(15)[ep];				      \	sst.w	r16, PTO+PT_GPR(16)[ep];				      \	sst.w	r17, PTO+PT_GPR(17)[ep];				      \	sst.w	r18, PTO+PT_GPR(18)[ep];				      \	sst.w	r19, PTO+PT_GPR(19)[ep]#define RESTORE_CALL_CLOBBERED_REGS_BEFORE_ARGS				      \	sld.w	PTO+PT_GPR(1)[ep], r1;					      \	sld.w	PTO+PT_GPR(5)[ep], r5#define RESTORE_CALL_CLOBBERED_REGS_AFTER_RVAL				      \	sld.w	PTO+PT_GPR(12)[ep], r12;				      \	sld.w	PTO+PT_GPR(13)[ep], r13;				      \	sld.w	PTO+PT_GPR(14)[ep], r14;				      \	sld.w	PTO+PT_GPR(15)[ep], r15;				      \	sld.w	PTO+PT_GPR(16)[ep], r16;				      \	sld.w	PTO+PT_GPR(17)[ep], r17;				      \	sld.w	PTO+PT_GPR(18)[ep], r18;				      \	sld.w	PTO+PT_GPR(19)[ep], r19/* Save `call clobbered' registers to the state-save-frame pointed to by EP.  */#define SAVE_CALL_CLOBBERED_REGS					      \	SAVE_CALL_CLOBBERED_REGS_BEFORE_ARGS;				      \	SAVE_ARG_REGS;							      \	SAVE_RVAL_REGS;							      \	SAVE_CALL_CLOBBERED_REGS_AFTER_RVAL/* Restore `call clobbered' registers from the state-save-frame pointed to   by EP.  */#define RESTORE_CALL_CLOBBERED_REGS					      \	RESTORE_CALL_CLOBBERED_REGS_BEFORE_ARGS;			      \	RESTORE_ARG_REGS;						      \	RESTORE_RVAL_REGS;						      \	RESTORE_CALL_CLOBBERED_REGS_AFTER_RVAL/* Save `call clobbered' registers except for the return-value registers   to the state-save-frame pointed to by EP.  */#define SAVE_CALL_CLOBBERED_REGS_NO_RVAL				      \	SAVE_CALL_CLOBBERED_REGS_BEFORE_ARGS;				      \	SAVE_ARG_REGS;							      \	SAVE_CALL_CLOBBERED_REGS_AFTER_RVAL/* Restore `call clobbered' registers except for the return-value registers   from the state-save-frame pointed to by EP.  */#define RESTORE_CALL_CLOBBERED_REGS_NO_RVAL				      \	RESTORE_CALL_CLOBBERED_REGS_BEFORE_ARGS;			      \	RESTORE_ARG_REGS;						      \	RESTORE_CALL_CLOBBERED_REGS_AFTER_RVAL/* Save `call saved' registers to the state-save-frame pointed to by EP.  */#define SAVE_CALL_SAVED_REGS						      \	sst.w	r2, PTO+PT_GPR(2)[ep];					      \	sst.w	r20, PTO+PT_GPR(20)[ep];				      \	sst.w	r21, PTO+PT_GPR(21)[ep];				      \	sst.w	r22, PTO+PT_GPR(22)[ep];				      \	sst.w	r23, PTO+PT_GPR(23)[ep];				      \	sst.w	r24, PTO+PT_GPR(24)[ep];				      \	sst.w	r25, PTO+PT_GPR(25)[ep];				      \	sst.w	r26, PTO+PT_GPR(26)[ep];				      \	sst.w	r27, PTO+PT_GPR(27)[ep];				      \	sst.w	r28, PTO+PT_GPR(28)[ep];				      \	sst.w	r29, PTO+PT_GPR(29)[ep]/* Restore `call saved' registers from the state-save-frame pointed to by EP.  */#define RESTORE_CALL_SAVED_REGS						      \	sld.w	PTO+PT_GPR(2)[ep], r2;					      \	sld.w	PTO+PT_GPR(20)[ep], r20;				      \	sld.w	PTO+PT_GPR(21)[ep], r21;				      \	sld.w	PTO+PT_GPR(22)[ep], r22;				      \	sld.w	PTO+PT_GPR(23)[ep], r23;				      \	sld.w	PTO+PT_GPR(24)[ep], r24;				      \	sld.w	PTO+PT_GPR(25)[ep], r25;				      \	sld.w	PTO+PT_GPR(26)[ep], r26;				      \	sld.w	PTO+PT_GPR(27)[ep], r27;				      \	sld.w	PTO+PT_GPR(28)[ep], r28;				      \	sld.w	PTO+PT_GPR(29)[ep], r29/* Save the PC stored in the special register SAVEREG to the state-save-frame   pointed to by EP.  r19 is clobbered.  */#define SAVE_PC(savereg)						      \	stsr	SR_ ## savereg, r19;					      \	sst.w	r19, PTO+PT_PC[ep]/* Restore the PC from the state-save-frame pointed to by EP, to the special   register SAVEREG.  LP is clobbered (it is used as a scratch register   because the POP_STATE macro restores it, and this macro is usually used   inside POP_STATE).  */#define RESTORE_PC(savereg)						      \	sld.w	PTO+PT_PC[ep], lp;					      \	ldsr	lp, SR_ ## savereg/* Save the PSW register stored in the special register SAVREG to the   state-save-frame pointed to by EP.  r19 is clobbered.  */#define SAVE_PSW(savereg)						      \	stsr	SR_ ## savereg, r19;					      \	sst.w	r19, PTO+PT_PSW[ep]/* Restore the PSW register from the state-save-frame pointed to by EP, to   the special register SAVEREG.  LP is clobbered (it is used as a scratch   register because the POP_STATE macro restores it, and this macro is   usually used inside POP_STATE).  */#define RESTORE_PSW(savereg)						      \	sld.w	PTO+PT_PSW[ep], lp;					      \	ldsr	lp, SR_ ## savereg/* Save CTPC/CTPSW/CTBP registers to the state-save-frame pointed to by REG.   r19 is clobbered.  */#define SAVE_CT_REGS							      \	stsr	SR_CTPC, r19;						      \	sst.w	r19, PTO+PT_CTPC[ep];					      \	stsr	SR_CTPSW, r19;						      \	sst.w	r19, PTO+PT_CTPSW[ep];					      \	stsr	SR_CTBP, r19;						      \	sst.w	r19, PTO+PT_CTBP[ep]/* Restore CTPC/CTPSW/CTBP registers from the state-save-frame pointed to by EP.   LP is clobbered (it is used as a scratch register because the POP_STATE   macro restores it, and this macro is usually used inside POP_STATE).  */#define RESTORE_CT_REGS							      \	sld.w	PTO+PT_CTPC[ep], lp;					      \	ldsr	lp, SR_CTPC;						      \	sld.w	PTO+PT_CTPSW[ep], lp;					      \	ldsr	lp, SR_CTPSW;						      \	sld.w	PTO+PT_CTBP[ep], lp;					      \	ldsr	lp, SR_CTBP/* Push register state, except for the stack pointer, on the stack in the   form of a state-save-frame (plus some extra padding), in preparation for   a system call.  This macro makes sure that the EP, GP, and LP   registers are saved, and TYPE identifies the set of extra registers to   be saved as well.  Also copies (the new value of) SP to EP.  */#define PUSH_STATE(type)						      \	addi	-STATE_SAVE_SIZE, sp, sp; /* Make room on the stack.  */      \	st.w	ep, PTO+PT_GPR(GPR_EP)[sp];				      \	mov	sp, ep;							      \	sst.w	gp, PTO+PT_GPR(GPR_GP)[ep];				      \	sst.w	lp, PTO+PT_GPR(GPR_LP)[ep];				      \	type ## _STATE_SAVER/* Pop a register state pushed by PUSH_STATE, except for the stack pointer,   from the the stack.  */#define POP_STATE(type)							      \	mov	sp, ep;							      \	type ## _STATE_RESTORER;					      \	sld.w	PTO+PT_GPR(GPR_GP)[ep], gp;				      \	sld.w	PTO+PT_GPR(GPR_LP)[ep], lp;				      \	sld.w	PTO+PT_GPR(GPR_EP)[ep], ep;				      \	addi	STATE_SAVE_SIZE, sp, sp /* Clean up our stack space.  *//* Switch to the kernel stack if necessary, and push register state on the   stack in the form of a state-save-frame.  Also load the current task   pointer if switching from user mode.  The stack-pointer (r3) should have   already been saved to the memory location SP_SAVE_LOC (the reason for   this is that the interrupt vectors may be beyond a 22-bit signed offset   jump from the actual interrupt handler, and this allows them to save the   stack-pointer and use that register to do an indirect jump).  This macro   makes sure that `special' registers, system registers, and the stack   pointer are saved; TYPE identifies the set of extra registers to be   saved as well.  SYSCALL_NUM is the register in which the system-call   number this state is for is stored (r0 if this isn't a system call).   Interrupts should already be disabled when calling this.  */#define SAVE_STATE(type, syscall_num, sp_save_loc)			      \	tst1	0, KM;			/* See if already in kernel mode.  */ \	bz	1f;							      \	ld.w	sp_save_loc, sp;	/* ... yes, use saved SP.  */	      \	br	2f;							      \1:	ld.w	KSP, sp;		/* ... no, switch to kernel stack. */ \2:	PUSH_STATE(type);						      \	ld.b	KM, r19;		/* Remember old kernel-mode.  */      \	sst.w	r19, PTO+PT_KERNEL_MODE[ep];				      \	ld.w	sp_save_loc, r19;	/* Remember old SP.  */		      \	sst.w	r19, PTO+PT_GPR(GPR_SP)[ep];				      \	mov	1, r19;			/* Now definitely in kernel-mode. */  \	st.b	r19, KM;						      \	GET_CURRENT_TASK(CURRENT_TASK);	/* Fetch the current task pointer. */ \	/* Save away the syscall number.  */				      \	sst.w	syscall_num, PTO+PT_CUR_SYSCALL[ep]/* Save register state not normally saved by PUSH_STATE for TYPE, to the   state-save-frame on the stack; also copies SP to EP.  r19 may be trashed. */#define SAVE_EXTRA_STATE(type)						      \	mov	sp, ep;							      \	type ## _EXTRA_STATE_SAVER/* Restore register state not normally restored by POP_STATE for TYPE,   from the state-save-frame on the stack; also copies SP to EP.   r19 may be trashed.  */#define RESTORE_EXTRA_STATE(type)					      \	mov	sp, ep;							      \	type ## _EXTRA_STATE_RESTORER/* Save any call-clobbered registers not normally saved by PUSH_STATE for   TYPE, to the state-save-frame on the stack.   EP may be trashed, but is not guaranteed to contain a copy of SP   (unlike after most SAVE_... macros).  r19 may be trashed.  */#define SAVE_EXTRA_STATE_FOR_SCHEDULE(type)				      \	type ## _SCHEDULE_EXTRA_STATE_SAVER/* Restore any call-clobbered registers not normally restored by   POP_STATE for TYPE, to the state-save-frame on the stack.   EP may be trashed, but is not guaranteed to contain a copy of SP   (unlike after most RESTORE_... macros).  r19 may be trashed.  */#define RESTORE_EXTRA_STATE_FOR_SCHEDULE(type)				      \	type ## _SCHEDULE_EXTRA_STATE_RESTORER/* These are extra_state_saver/restorer values for a user trap.  Note   that we save the argument registers so that restarted syscalls will   function properly (otherwise it wouldn't be necessary), and we must   _not_ restore the return-value registers (so that traps can return a   value!), but call-clobbered registers are not saved at all, as the   caller of the syscall function should have saved them.  */#define TRAP_RET reti/* Traps don't save call-clobbered registers (but do still save arg regs).   We preserve PSw to keep long-term state, namely interrupt status (for traps   from kernel-mode), and the single-step flag (for user traps).  */#define TRAP_STATE_SAVER						      \	SAVE_ARG_REGS;							      \	SAVE_PC(EIPC);							      \	SAVE_PSW(EIPSW)/* When traps return, they just leave call-clobbered registers (except for arg   regs) with whatever value they have from the kernel.  Traps don't preserve   the PSW, but we zero EIPSW to ensure it doesn't contain anything dangerous   (in particular, the single-step flag).  */#define TRAP_STATE_RESTORER						      \	RESTORE_ARG_REGS;						      \	RESTORE_PC(EIPC);						      \	RESTORE_PSW(EIPSW)/* Save registers not normally saved by traps.  We need to save r12, even   though it's nominally call-clobbered, because it's used when restarting   a system call (the signal-handling path uses SAVE_EXTRA_STATE, and   expects r12 to be restored when the trap returns).  */#define TRAP_EXTRA_STATE_SAVER						      \	SAVE_RVAL_REGS;							      \	sst.w	r12, PTO+PT_GPR(12)[ep];				      \	SAVE_CALL_SAVED_REGS;						      \	SAVE_CT_REGS#define TRAP_EXTRA_STATE_RESTORER					      \	RESTORE_RVAL_REGS;						      \	sld.w	PTO+PT_GPR(12)[ep], r12;				      \	RESTORE_CALL_SAVED_REGS;					      \	RESTORE_CT_REGS/* Save registers prior to calling scheduler (just before trap returns).   We have to save the return-value registers to preserve the trap's return   value.  Note that ..._SCHEDULE_EXTRA_STATE_SAVER, unlike most ..._SAVER   macros, is required to setup EP itself if EP is needed (this is because   in many cases, the macro is empty).  */#define TRAP_SCHEDULE_EXTRA_STATE_SAVER					      \	mov sp, ep;							      \	SAVE_RVAL_REGS/* Note that ..._SCHEDULE_EXTRA_STATE_RESTORER, unlike most ..._RESTORER   macros, is required to setup EP itself if EP is needed (this is because   in many cases, the macro is empty).  */#define TRAP_SCHEDULE_EXTRA_STATE_RESTORER				      \	mov sp, ep;							      \	RESTORE_RVAL_REGS/* Register saving/restoring for maskable interrupts.  */#define IRQ_RET reti#define IRQ_STATE_SAVER							      \	SAVE_CALL_CLOBBERED_REGS;					      \	SAVE_PC(EIPC);							      \	SAVE_PSW(EIPSW)#define IRQ_STATE_RESTORER						      \	RESTORE_CALL_CLOBBERED_REGS;					      \	RESTORE_PC(EIPC);						      \	RESTORE_PSW(EIPSW)#define IRQ_EXTRA_STATE_SAVER						      \	SAVE_CALL_SAVED_REGS;						      \	SAVE_CT_REGS#define IRQ_EXTRA_STATE_RESTORER					      \	RESTORE_CALL_SAVED_REGS;					      \	RESTORE_CT_REGS#define IRQ_SCHEDULE_EXTRA_STATE_SAVER	     /* nothing */#define IRQ_SCHEDULE_EXTRA_STATE_RESTORER    /* nothing *//* Register saving/restoring for non-maskable interrupts.  */#define NMI_RET reti#define NMI_STATE_SAVER							      \	SAVE_CALL_CLOBBERED_REGS;					      \	SAVE_PC(FEPC);							      \	SAVE_PSW(FEPSW);#define NMI_STATE_RESTORER						      \	RESTORE_CALL_CLOBBERED_REGS;					      \	RESTORE_PC(FEPC);						      \	RESTORE_PSW(FEPSW);#define NMI_EXTRA_STATE_SAVER						      \	SAVE_CALL_SAVED_REGS;						      \	SAVE_CT_REGS#define NMI_EXTRA_STATE_RESTORER					      \	RESTORE_CALL_SAVED_REGS;					      \	RESTORE_CT_REGS#define NMI_SCHEDULE_EXTRA_STATE_SAVER	     /* nothing */#define NMI_SCHEDULE_EXTRA_STATE_RESTORER    /* nothing *//* Register saving/restoring for debug traps.  */#define DBTRAP_RET .long 0x014607E0 /* `dbret', but gas doesn't support it. */#define DBTRAP_STATE_SAVER						      \	SAVE_CALL_CLOBBERED_REGS;					      \	SAVE_PC(DBPC);							      \	SAVE_PSW(DBPSW)#define DBTRAP_STATE_RESTORER						      \	RESTORE_CALL_CLOBBERED_REGS;					      \	RESTORE_PC(DBPC);						      \	RESTORE_PSW(DBPSW)#define DBTRAP_EXTRA_STATE_SAVER					      \	SAVE_CALL_SAVED_REGS;						      \	SAVE_CT_REGS#define DBTRAP_EXTRA_STATE_RESTORER					      \	RESTORE_CALL_SAVED_REGS;					      \	RESTORE_CT_REGS#define DBTRAP_SCHEDULE_EXTRA_STATE_SAVER	/* nothing */#define DBTRAP_SCHEDULE_EXTRA_STATE_RESTORER	/* nothing *//* Register saving/restoring for a context switch.  We don't need to save   too many registers, because context-switching looks like a function call

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -