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

📄 traps.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
			case INST_LSWI:				if (get_user(val, (u8 __user *)EA))					return -EFAULT;				/* first time updating this reg,				 * zero it out */				if (pos == 0)					regs->gpr[rT] = 0;				regs->gpr[rT] |= val << shift;				break;			case INST_STSWI:			case INST_STSWX:				val = regs->gpr[rT] >> shift;				if (put_user(val, (u8 __user *)EA))					return -EFAULT;				break;		}		/* move EA to next address */		EA += 1;		num_bytes--;		/* manage our position within the register */		if (++pos == 4) {			pos = 0;			if (++rT == 32)				rT = 0;		}	}	return 0;}static int emulate_instruction(struct pt_regs *regs){	u32 instword;	u32 rd;	if (!user_mode(regs))		return -EINVAL;	CHECK_FULL_REGS(regs);	if (get_user(instword, (u32 __user *)(regs->nip)))		return -EFAULT;	/* Emulate the mfspr rD, PVR.	 */	if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {		rd = (instword >> 21) & 0x1f;		regs->gpr[rd] = mfspr(SPRN_PVR);		return 0;	}	/* Emulating the dcba insn is just a no-op.  */	if ((instword & INST_DCBA_MASK) == INST_DCBA)		return 0;	/* Emulate the mcrxr insn.  */	if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {		int shift = (instword >> 21) & 0x1c;		unsigned long msk = 0xf0000000UL >> shift;		regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);		regs->xer &= ~0xf0000000UL;		return 0;	}	/* Emulate load/store string insn. */	if ((instword & INST_STRING_GEN_MASK) == INST_STRING)		return emulate_string_inst(regs, instword);	return -EINVAL;}/* * After we have successfully emulated an instruction, we have to * check if the instruction was being single-stepped, and if so, * pretend we got a single-step exception.  This was pointed out * by Kumar Gala.  -- paulus */static void emulate_single_step(struct pt_regs *regs){	if (single_stepping(regs)) {		clear_single_step(regs);		_exception(SIGTRAP, regs, TRAP_TRACE, 0);	}}/* * Look through the list of trap instructions that are used for BUG(), * BUG_ON() and WARN_ON() and see if we hit one.  At this point we know * that the exception was caused by a trap instruction of some kind. * Returns 1 if we should continue (i.e. it was a WARN_ON) or 0 * otherwise. */extern struct bug_entry __start___bug_table[], __stop___bug_table[];#ifndef CONFIG_MODULES#define module_find_bug(x)	NULL#endifstruct bug_entry *find_bug(unsigned long bugaddr){	struct bug_entry *bug;	for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)		if (bugaddr == bug->bug_addr)			return bug;	return module_find_bug(bugaddr);}int check_bug_trap(struct pt_regs *regs){	struct bug_entry *bug;	unsigned long addr;	if (regs->msr & MSR_PR)		return 0;	/* not in kernel */	addr = regs->nip;	/* address of trap instruction */	if (addr < PAGE_OFFSET)		return 0;	bug = find_bug(regs->nip);	if (bug == NULL)		return 0;	if (bug->line & BUG_WARNING_TRAP) {		/* this is a WARN_ON rather than BUG/BUG_ON */#ifdef CONFIG_XMON		xmon_printf(KERN_ERR "Badness in %s at %s:%ld\n",		       bug->function, bug->file,		       bug->line & ~BUG_WARNING_TRAP);#endif /* CONFIG_XMON */				printk(KERN_ERR "Badness in %s at %s:%ld\n",		       bug->function, bug->file,		       bug->line & ~BUG_WARNING_TRAP);		dump_stack();		return 1;	}#ifdef CONFIG_XMON	xmon_printf(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",	       bug->function, bug->file, bug->line);	xmon(regs);#endif /* CONFIG_XMON */	printk(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",	       bug->function, bug->file, bug->line);	return 0;}void program_check_exception(struct pt_regs *regs){	unsigned int reason = get_reason(regs);	extern int do_mathemu(struct pt_regs *regs);#ifdef CONFIG_MATH_EMULATION	/* (reason & REASON_ILLEGAL) would be the obvious thing here,	 * but there seems to be a hardware bug on the 405GP (RevD)	 * that means ESR is sometimes set incorrectly - either to	 * ESR_DST (!?) or 0.  In the process of chasing this with the	 * hardware people - not sure if it can happen on any illegal	 * instruction or only on FP instructions, whether there is a	 * pattern to occurences etc. -dgibson 31/Mar/2003 */	if (!(reason & REASON_TRAP) && do_mathemu(regs) == 0) {		emulate_single_step(regs);		return;	}#endif /* CONFIG_MATH_EMULATION */	if (reason & REASON_FP) {		/* IEEE FP exception */		int code = 0;		u32 fpscr;		/* We must make sure the FP state is consistent with		 * our MSR_FP in regs		 */		preempt_disable();		if (regs->msr & MSR_FP)			giveup_fpu(current);		preempt_enable();		fpscr = current->thread.fpscr.val;		fpscr &= fpscr << 22;	/* mask summary bits with enables */		if (fpscr & FPSCR_VX)			code = FPE_FLTINV;		else if (fpscr & FPSCR_OX)			code = FPE_FLTOVF;		else if (fpscr & FPSCR_UX)			code = FPE_FLTUND;		else if (fpscr & FPSCR_ZX)			code = FPE_FLTDIV;		else if (fpscr & FPSCR_XX)			code = FPE_FLTRES;		_exception(SIGFPE, regs, code, regs->nip);		return;	}	if (reason & REASON_TRAP) {		/* trap exception */		if (debugger_bpt(regs))			return;		if (check_bug_trap(regs)) {			regs->nip += 4;			return;		}		_exception(SIGTRAP, regs, TRAP_BRKPT, 0);		return;	}	/* Try to emulate it if we should. */	if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {		switch (emulate_instruction(regs)) {		case 0:			regs->nip += 4;			emulate_single_step(regs);			return;		case -EFAULT:			_exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);			return;		}	}	if (reason & REASON_PRIVILEGED)		_exception(SIGILL, regs, ILL_PRVOPC, regs->nip);	else		_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);}void single_step_exception(struct pt_regs *regs){	regs->msr &= ~(MSR_SE | MSR_BE);  /* Turn off 'trace' bits */	if (debugger_sstep(regs))		return;	_exception(SIGTRAP, regs, TRAP_TRACE, 0);}void alignment_exception(struct pt_regs *regs){	int fixed;	fixed = fix_alignment(regs);	if (fixed == 1) {		regs->nip += 4;	/* skip over emulated instruction */		emulate_single_step(regs);		return;	}	if (fixed == -EFAULT) {		/* fixed == -EFAULT means the operand address was bad */		if (user_mode(regs))			_exception(SIGSEGV, regs, SEGV_ACCERR, regs->dar);		else			bad_page_fault(regs, regs->dar, SIGSEGV);		return;	}	_exception(SIGBUS, regs, BUS_ADRALN, regs->dar);}void StackOverflow(struct pt_regs *regs){	printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",	       current, regs->gpr[1]);	debugger(regs);	show_regs(regs);	panic("kernel stack overflow");}void nonrecoverable_exception(struct pt_regs *regs){	printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",	       regs->nip, regs->msr);	debugger(regs);	die("nonrecoverable exception", regs, SIGKILL);}void trace_syscall(struct pt_regs *regs){	printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",	       current, current->pid, regs->nip, regs->link, regs->gpr[0],	       regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());}#ifdef CONFIG_8xxvoid SoftwareEmulation(struct pt_regs *regs){	extern int do_mathemu(struct pt_regs *);	extern int Soft_emulate_8xx(struct pt_regs *);	int errcode;	CHECK_FULL_REGS(regs);	if (!user_mode(regs)) {		debugger(regs);		die("Kernel Mode Software FPU Emulation", regs, SIGFPE);	}#ifdef CONFIG_MATH_EMULATION	errcode = do_mathemu(regs);#else	errcode = Soft_emulate_8xx(regs);#endif	if (errcode) {		if (errcode > 0)			_exception(SIGFPE, regs, 0, 0);		else if (errcode == -EFAULT)			_exception(SIGSEGV, regs, 0, 0);		else			_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);	} else		emulate_single_step(regs);}#endif /* CONFIG_8xx */#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)void DebugException(struct pt_regs *regs, unsigned long debug_status){	if (debug_status & DBSR_IC) {	/* instruction completion */		regs->msr &= ~MSR_DE;		if (user_mode(regs)) {			current->thread.dbcr0 &= ~DBCR0_IC;		} else {			/* Disable instruction completion */			mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);			/* Clear the instruction completion event */			mtspr(SPRN_DBSR, DBSR_IC);			if (debugger_sstep(regs))				return;		}		_exception(SIGTRAP, regs, TRAP_TRACE, 0);	}}#endif /* CONFIG_4xx || CONFIG_BOOKE */#if !defined(CONFIG_TAU_INT)void TAUException(struct pt_regs *regs){	printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx    %s\n",	       regs->nip, regs->msr, regs->trap, print_tainted());}#endif /* CONFIG_INT_TAU *//* * FP unavailable trap from kernel - print a message, but let * the task use FP in the kernel until it returns to user mode. */void kernel_fp_unavailable_exception(struct pt_regs *regs){	regs->msr |= MSR_FP;	printk(KERN_ERR "floating point used in kernel (task=%p, pc=%lx)\n",	       current, regs->nip);}void altivec_unavailable_exception(struct pt_regs *regs){	static int kernel_altivec_count;#ifndef CONFIG_ALTIVEC	if (user_mode(regs)) {		/* A user program has executed an altivec instruction,		   but this kernel doesn't support altivec. */		_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);		return;	}#endif	/* The kernel has executed an altivec instruction without	   first enabling altivec.  Whinge but let it do it. */	if (++kernel_altivec_count < 10)		printk(KERN_ERR "AltiVec used in kernel (task=%p, pc=%lx)\n",		       current, regs->nip);	regs->msr |= MSR_VEC;}#ifdef CONFIG_ALTIVECvoid altivec_assist_exception(struct pt_regs *regs){	int err;	preempt_disable();	if (regs->msr & MSR_VEC)		giveup_altivec(current);	preempt_enable();	if (!user_mode(regs)) {		printk(KERN_ERR "altivec assist exception in kernel mode"		       " at %lx\n", regs->nip);		debugger(regs);		die("altivec assist exception", regs, SIGFPE);		return;	}	err = emulate_altivec(regs);	if (err == 0) {		regs->nip += 4;		/* skip emulated instruction */		emulate_single_step(regs);		return;	}	if (err == -EFAULT) {		/* got an error reading the instruction */		_exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);	} else {		/* didn't recognize the instruction */		/* XXX quick hack for now: set the non-Java bit in the VSCR */		printk(KERN_ERR "unrecognized altivec instruction "		       "in %s at %lx\n", current->comm, regs->nip);		current->thread.vscr.u[3] |= 0x10000;	}}#endif /* CONFIG_ALTIVEC */#ifdef CONFIG_E500void performance_monitor_exception(struct pt_regs *regs){	perf_irq(regs);}#endif#ifdef CONFIG_FSL_BOOKEvoid CacheLockingException(struct pt_regs *regs, unsigned long address,			   unsigned long error_code){	/* We treat cache locking instructions from the user	 * as priv ops, in the future we could try to do	 * something smarter	 */	if (error_code & (ESR_DLK|ESR_ILK))		_exception(SIGILL, regs, ILL_PRVOPC, regs->nip);	return;}#endif /* CONFIG_FSL_BOOKE */#ifdef CONFIG_SPEvoid SPEFloatingPointException(struct pt_regs *regs){	unsigned long spefscr;	int fpexc_mode;	int code = 0;	spefscr = current->thread.spefscr;	fpexc_mode = current->thread.fpexc_mode;	/* Hardware does not neccessarily set sticky	 * underflow/overflow/invalid flags */	if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {		code = FPE_FLTOVF;		spefscr |= SPEFSCR_FOVFS;	}	else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {		code = FPE_FLTUND;		spefscr |= SPEFSCR_FUNFS;	}	else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))		code = FPE_FLTDIV;	else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {		code = FPE_FLTINV;		spefscr |= SPEFSCR_FINVS;	}	else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))		code = FPE_FLTRES;	current->thread.spefscr = spefscr;	_exception(SIGFPE, regs, code, regs->nip);	return;}#endif#ifdef CONFIG_BOOKE_WDT/* * Default handler for a Watchdog exception, * spins until a reboot occurs */void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs){	/* Generic WatchdogHandler, implement your own */	mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));	return;}void WatchdogException(struct pt_regs *regs){	printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");	WatchdogHandler(regs);}#endifvoid __init trap_init(void){}

⌨️ 快捷键说明

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