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

📄 entry.s

📁 LINUX 2.6.17.4的源码
💻 S
📖 第 1 页 / 共 3 页
字号:
   (via the function `switch_thread'), so callers will save any   call-clobbered registers themselves.  We do need to save the CT regs, as   they're normally not saved during kernel entry (the kernel doesn't use   them).  We save PSW so that interrupt-status state will correctly follow   each thread (mostly NMI vs. normal-IRQ/trap), though for the most part   it doesn't matter since threads are always in almost exactly the same   processor state during a context switch.  The stack pointer and return   value are handled by switch_thread itself.  */#define SWITCH_STATE_SAVER						      \	SAVE_CALL_SAVED_REGS;						      \	SAVE_PSW(PSW);							      \	SAVE_CT_REGS#define SWITCH_STATE_RESTORER						      \	RESTORE_CALL_SAVED_REGS;					      \	RESTORE_PSW(PSW);						      \	RESTORE_CT_REGS/* Restore register state from the state-save-frame on the stack, switch back   to the user stack if necessary, and return from the trap/interrupt.   EXTRA_STATE_RESTORER is a sequence of assembly language statements to   restore anything not restored by this macro.  Only registers not saved by   the C compiler are restored (that is, R3(sp), R4(gp), R31(lp), and   anything restored by EXTRA_STATE_RESTORER).  */#define RETURN(type)							      \	ld.b	PTO+PT_KERNEL_MODE[sp], r19;				      \	di;				/* Disable interrupts */	      \	cmp	r19, r0;		/* See if returning to kernel mode, */\	bne	2f;			/* ... if so, skip resched &c.  */    \									      \	/* We're returning to user mode, so check for various conditions that \	   trigger rescheduling. */					      \	GET_CURRENT_THREAD(r18);					      \	ld.w	TI_FLAGS[r18], r19;					      \	andi	_TIF_NEED_RESCHED, r19, r0;				      \	bnz	3f;			/* Call the scheduler.  */	      \5:	andi	_TIF_SIGPENDING, r19, r18;				      \	ld.w	TASK_PTRACE[CURRENT_TASK], r19; /* ptrace flags */	      \	or	r18, r19;		/* see if either is non-zero */	      \	bnz	4f;			/* if so, handle them */	      \									      \/* Return to user state.  */						      \1:	st.b	r0, KM;			/* Now officially in user state. */   \									      \/* Final return.  The stack-pointer fiddling is not needed when returning     \   to kernel-mode, but they don't hurt, and this way we can share the	      \   (sometimes rather lengthy) POP_STATE macro.  */			      \2:	POP_STATE(type);						      \	st.w	sp, KSP;		/* Save the kernel stack pointer. */  \	ld.w	PT_GPR(GPR_SP)-PT_SIZE[sp], sp; /* Restore stack pointer. */  \	type ## _RET;			/* Return from the trap/interrupt. */ \									      \/* Call the scheduler before returning from a syscall/trap. */		      \3:	SAVE_EXTRA_STATE_FOR_SCHEDULE(type); /* Prepare to call scheduler. */ \	jarl	call_scheduler, lp;	/* Call scheduler */		      \	di;				/* The scheduler enables interrupts */\	RESTORE_EXTRA_STATE_FOR_SCHEDULE(type);				      \	GET_CURRENT_THREAD(r18);					      \	ld.w	TI_FLAGS[r18], r19;					      \	br	5b;			/* Continue with return path. */      \									      \/* Handle a signal or ptraced process return.				      \   r18 should be non-zero if there are pending signals.  */		      \4:	/* Not all registers are saved by the normal trap/interrupt entry     \	   points (for instance, call-saved registers (because the normal     \	   C-compiler calling sequence in the kernel makes sure they're	      \	   preserved), and call-clobbered registers in the case of	      \	   traps), but signal handlers may want to examine or change the      \	   complete register state.  Here we save anything not saved by	      \	   the normal entry sequence, so that it may be safely restored	      \	   (in a possibly modified form) after do_signal returns.  */	      \	SAVE_EXTRA_STATE(type);		/* Save state not saved by entry. */  \	jarl	handle_signal_or_ptrace_return, lp;			      \	RESTORE_EXTRA_STATE(type);	/* Restore extra regs.  */	      \	br	1b/* Jump to the appropriate function for the system call number in r12   (r12 is not preserved), or return an error if r12 is not valid.  The   LP register should point to the location where the called function   should return.  [note that MAKE_SYS_CALL uses label 1]  */#define MAKE_SYS_CALL							      \	/* Figure out which function to use for this system call.  */	      \	shl	2, r12;							      \	/* See if the system call number is valid.  */			      \	addi	lo(CSYM(sys_call_table) - sys_call_table_end), r12, r0;	      \	bnh	1f;							      \	mov	hilo(CSYM(sys_call_table)), r19;			      \	add	r19, r12;						      \	ld.w	0[r12], r12;						      \	/* Make the system call.  */					      \	jmp	[r12];							      \	/* The syscall number is invalid, return an error.  */		      \1:	addi	-ENOSYS, r0, r10;					      \	jmp	[lp]	.text/* * User trap. * * Trap 0 system calls are also handled here. * * The stack-pointer (r3) should have already been saved to the memory * location ENTRY_SP (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). * * Syscall protocol: *   Syscall number in r12, args in r6-r9 *   Return value in r10 */G_ENTRY(trap):	SAVE_STATE (TRAP, r12, ENTRY_SP) // Save registers.	stsr	SR_ECR, r19		// Find out which trap it was.	ei				// Enable interrupts.	mov	hilo(ret_from_trap), lp	// where the trap should return	// The following two shifts (1) clear out extraneous NMI data in the	// upper 16-bits, (2) convert the 0x40 - 0x5f range of trap ECR	// numbers into the (0-31) << 2 range we want, (3) set the flags.	shl	27, r19			// chop off all high bits	shr	25, r19			// scale back down and then << 2	bnz	2f			// See if not trap 0.	// Trap 0 is a `short' system call, skip general trap table.	MAKE_SYS_CALL			// Jump to the syscall function.2:	// For other traps, use a table lookup.	mov	hilo(CSYM(trap_table)), r18	add	r19, r18	ld.w	0[r18], r18	jmp	[r18]			// Jump to the trap handler.END(trap)/* This is just like ret_from_trap, but first restores extra registers   saved by some wrappers.  */L_ENTRY(restore_extra_regs_and_ret_from_trap):	RESTORE_EXTRA_STATE(TRAP)	// fall throughEND(restore_extra_regs_and_ret_from_trap)/* Entry point used to return from a syscall/trap.  */L_ENTRY(ret_from_trap):	RETURN(TRAP)END(ret_from_trap)/* This the initial entry point for a new child thread, with an appropriate   stack in place that makes it look the the child is in the middle of an   syscall.  This function is actually `returned to' from switch_thread   (copy_thread makes ret_from_fork the return address in each new thread's   saved context).  */C_ENTRY(ret_from_fork):	mov	r10, r6			// switch_thread returns the prev task.	jarl	CSYM(schedule_tail), lp	// ...which is schedule_tail's arg	mov	r0, r10			// Child's fork call should return 0.	br	ret_from_trap		// Do normal trap return.C_END(ret_from_fork)/* * Trap 1: `long' system calls * `Long' syscall protocol: *   Syscall number in r12, args in r6-r9, r13-r14 *   Return value in r10 */L_ENTRY(syscall_long):	// Push extra arguments on the stack.  Note that by default, the trap	// handler reserves enough stack space for 6 arguments, so we don't	// have to make any additional room.	st.w	r13, 16[sp]		// arg 5	st.w	r14, 20[sp]		// arg 6	// Make sure r13 and r14 are preserved, in case we have to restart a	// system call because of a signal (ep has already been set by caller).	st.w	r13, PTO+PT_GPR(13)[sp]	st.w	r14, PTO+PT_GPR(13)[sp]	mov	hilo(ret_from_long_syscall), lp	MAKE_SYS_CALL			// Jump to the syscall function.END(syscall_long)/* Entry point used to return from a long syscall.  Only needed to restore   r13/r14 if the general trap mechanism doesnt' do so.  */L_ENTRY(ret_from_long_syscall):	ld.w	PTO+PT_GPR(13)[sp], r13 // Restore the extra registers	ld.w	PTO+PT_GPR(13)[sp], r14	br	ret_from_trap		// The rest is the same as other trapsEND(ret_from_long_syscall)/* These syscalls need access to the struct pt_regs on the stack, so we   implement them in assembly (they're basically all wrappers anyway).  */L_ENTRY(sys_fork_wrapper):#ifdef CONFIG_MMU	addi	SIGCHLD, r0, r6		   // Arg 0: flags	ld.w	PTO+PT_GPR(GPR_SP)[sp], r7 // Arg 1: child SP (use parent's)	movea	PTO, sp, r8		   // Arg 2: parent context	mov	r0, r9			   // Arg 3/4/5: 0	st.w	r0, 16[sp]	st.w	r0, 20[sp]	mov	hilo(CSYM(do_fork)), r18   // Where the real work gets done	br	save_extra_state_tramp	   // Save state and go there#else	// fork almost works, enough to trick you into looking elsewhere :-(	addi	-EINVAL, r0, r10	jmp	[lp]#endifEND(sys_fork_wrapper)L_ENTRY(sys_vfork_wrapper):	addi	CLONE_VFORK | CLONE_VM | SIGCHLD, r0, r6 // Arg 0: flags	ld.w	PTO+PT_GPR(GPR_SP)[sp], r7 // Arg 1: child SP (use parent's)	movea	PTO, sp, r8		   // Arg 2: parent context	mov	r0, r9			   // Arg 3/4/5: 0	st.w	r0, 16[sp]	st.w	r0, 20[sp]	mov	hilo(CSYM(do_fork)), r18   // Where the real work gets done	br	save_extra_state_tramp	   // Save state and go thereEND(sys_vfork_wrapper)L_ENTRY(sys_clone_wrapper):	ld.w	PTO+PT_GPR(GPR_SP)[sp], r19// parent's stack pointer	cmp	r7, r0			   // See if child SP arg (arg 1) is 0.	cmov	z, r19, r7, r7		   // ... and use the parent's if so.	movea	PTO, sp, r8		   // Arg 2: parent context	mov	r0, r9			   // Arg 3/4/5: 0	st.w	r0, 16[sp]	st.w	r0, 20[sp]	mov	hilo(CSYM(do_fork)), r18   // Where the real work gets done	br	save_extra_state_tramp	   // Save state and go thereEND(sys_clone_wrapper)L_ENTRY(sys_execve_wrapper):	movea	PTO, sp, r9		// add user context as 4th arg	jr	CSYM(sys_execve)	// Do real work (tail-call).END(sys_execve_wrapper)L_ENTRY(sys_sigsuspend_wrapper):	movea	PTO, sp, r7		// add user context as 2nd arg	mov	hilo(CSYM(sys_sigsuspend)), r18	// syscall function	jarl	save_extra_state_tramp, lp	// Save state and do it	br	restore_extra_regs_and_ret_from_trapEND(sys_sigsuspend_wrapper)L_ENTRY(sys_rt_sigsuspend_wrapper):	movea	PTO, sp, r8		// add user context as 3rd arg	mov	hilo(CSYM(sys_rt_sigsuspend)), r18 // syscall function	jarl	save_extra_state_tramp, lp	   // Save state and do it	br	restore_extra_regs_and_ret_from_trapEND(sys_rt_sigsuspend_wrapper)L_ENTRY(sys_sigreturn_wrapper):	movea	PTO, sp, r6		// add user context as 1st arg	mov	hilo(CSYM(sys_sigreturn)), r18	// syscall function	jarl	save_extra_state_tramp, lp	// Save state and do it	br	restore_extra_regs_and_ret_from_trapEND(sys_sigreturn_wrapper)L_ENTRY(sys_rt_sigreturn_wrapper):	movea	PTO, sp, r6		// add user context as 1st arg	mov	hilo(CSYM(sys_rt_sigreturn)), r18// syscall function	jarl	save_extra_state_tramp, lp	 // Save state and do it	br	restore_extra_regs_and_ret_from_trapEND(sys_rt_sigreturn_wrapper)/* Save any state not saved by SAVE_STATE(TRAP), and jump to r18.   It's main purpose is to share the rather lengthy code sequence that   SAVE_STATE expands into among the above wrapper functions.  */L_ENTRY(save_extra_state_tramp):	SAVE_EXTRA_STATE(TRAP)		// Save state not saved by entry.	jmp	[r18]			// Do the work the caller wantsEND(save_extra_state_tramp)/* * Hardware maskable interrupts. * * The stack-pointer (r3) should have already been saved to the memory * location ENTRY_SP (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). */G_ENTRY(irq):	SAVE_STATE (IRQ, r0, ENTRY_SP)	// Save registers.	stsr	SR_ECR, r6		// Find out which interrupt it was.	movea	PTO, sp, r7		// User regs are arg2	// All v850 implementations I know about encode their interrupts as	// multiples of 0x10, starting at 0x80 (after NMIs and software	// interrupts).  Convert this number into a simple IRQ index for the	// rest of the kernel.  We also clear the upper 16 bits, which hold	// NMI info, and don't appear to be cleared when a NMI returns.	shl	16, r6			// clear upper 16 bits	shr	20, r6			// shift back, and remove lower nibble	add	-8, r6			// remove bias for irqs	// Call the high-level interrupt handling code.	jarl	CSYM(handle_irq), lp	RETURN(IRQ)END(irq)/* * Debug trap / illegal-instruction exception * * The stack-pointer (r3) should have already been saved to the memory * location ENTRY_SP (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). */G_ENTRY(dbtrap):	SAVE_STATE (DBTRAP, r0, ENTRY_SP)// Save registers.	/* First see if we came from kernel mode; if so, the dbtrap	   instruction has a special meaning, to set the DIR (`debug	   information register') register.  This is because the DIR register	   can _only_ be manipulated/read while in `debug mode,' and debug	   mode is only active while we're inside the dbtrap handler.  The	   exact functionality is:  { DIR = (DIR | r6) & ~r7; return DIR; }. */	ld.b	PTO+PT_KERNEL_MODE[sp], r19	cmp	r19, r0	bz	1f	stsr	SR_DIR, r10	or	r6, r10	not	r7, r7	and	r7, r10	ldsr	r10, SR_DIR	stsr	SR_DIR, r10		// Confirm the value we set	st.w	r10, PTO+PT_GPR(10)[sp]	// return it	br	3f1:	ei				// Enable interrupts.	/* The default signal type we raise.  */	mov	SIGTRAP, r6	/* See if it's a single-step trap.  */	stsr	SR_DBPSW, r19	andi	0x0800, r19, r19	bnz	2f	/* Look to see if the preceding instruction was is a dbtrap or not,	   to decide which signal we should use.  */	stsr	SR_DBPC, r19		// PC following trapping insn	ld.hu	-2[r19], r19	ori	0xf840, r0, r20		// DBTRAP insn	cmp	r19, r20		// Was this trap caused by DBTRAP?	cmov	ne, SIGILL, r6, r6	// Choose signal appropriately	/* Raise the desired signal.  */2:	mov	CURRENT_TASK, r7	// Arg 1: task	jarl	CSYM(send_sig), lp	// tail call3:	RETURN(DBTRAP)END(dbtrap)/* * Hardware non-maskable interrupts. * * The stack-pointer (r3) should have already been saved to the memory * location ENTRY_SP (the reason for this is that the interrupt vectors may be * beyond a 22-bit signed offset jump from the actual interrupt handler, and

⌨️ 快捷键说明

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