traps.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 782 行 · 第 1/2 页
C
782 行
rd = (instword >> 21) & 0x1f; regs->gpr[rd] = mfspr(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; } 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#endifstatic struct 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:%d\n", bug->function, bug->file, bug->line & ~BUG_WARNING_TRAP);#endif /* CONFIG_XMON */ printk(KERN_ERR "Badness in %s at %s:%d\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:%d!\n", bug->function, bug->file, bug->line); xmon(regs);#endif /* CONFIG_XMON */ printk(KERN_CRIT "kernel BUG in %s at %s:%d!\n", bug->function, bug->file, bug->line); return 0;}void ProgramCheckException(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; 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 SingleStepException(struct pt_regs *regs){ regs->msr &= ~MSR_SE; /* Turn off 'trace' bit */ if (debugger_sstep(regs)) return; _exception(SIGTRAP, regs, TRAP_TRACE, 0);}void AlignmentException(struct pt_regs *regs){ int fixed; fixed = fix_alignment(regs); if (fixed == 1) { regs->nip += 4; /* skip over emulated instruction */ 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_4xx) || defined(CONFIG_BOOKE)void DebugException(struct pt_regs *regs, unsigned long debug_status){#if 0 if (debug_status & DBSR_TIE) { /* trap instruction*/ if (!user_mode(regs) && debugger_bpt(regs)) return; _exception(SIGTRAP, regs, 0, 0); }#endif if (debug_status & DBSR_IC) { /* instruction completion */ if (!user_mode(regs) && debugger_sstep(regs)) return; current->thread.dbcr0 &= ~DBCR0_IC; _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 */void AltivecUnavailException(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 AltivecAssistException(struct pt_regs *regs){ int err; preempt_disable(); if (regs->msr & MSR_VEC) giveup_altivec(current); preempt_enable(); 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_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;}#endifvoid __init trap_init(void){}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?