traps.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 640 行 · 第 1/2 页
C
640 行
/* * linux/arch/ppc64/kernel/traps.c * * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Modified by Cort Dougan (cort@cs.nmt.edu) * and Paul Mackerras (paulus@cs.anu.edu.au) *//* * This file handles the architecture-dependent parts of hardware exceptions */#include <linux/config.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/kernel.h>#include <linux/mm.h>#include <linux/stddef.h>#include <linux/unistd.h>#include <linux/slab.h>#include <linux/user.h>#include <linux/a.out.h>#include <linux/interrupt.h>#include <linux/init.h>#include <linux/module.h>#include <asm/pgtable.h>#include <asm/uaccess.h>#include <asm/system.h>#include <asm/io.h>#include <asm/processor.h>#include <asm/ppcdebug.h>#include <asm/rtas.h>#ifdef CONFIG_PPC_PSERIES/* This is true if we are using the firmware NMI handler (typically LPAR) */extern int fwnmi_active;#endif#ifdef CONFIG_DEBUGGERint (*__debugger)(struct pt_regs *regs);int (*__debugger_ipi)(struct pt_regs *regs);int (*__debugger_bpt)(struct pt_regs *regs);int (*__debugger_sstep)(struct pt_regs *regs);int (*__debugger_iabr_match)(struct pt_regs *regs);int (*__debugger_dabr_match)(struct pt_regs *regs);int (*__debugger_fault_handler)(struct pt_regs *regs);EXPORT_SYMBOL(__debugger);EXPORT_SYMBOL(__debugger_ipi);EXPORT_SYMBOL(__debugger_bpt);EXPORT_SYMBOL(__debugger_sstep);EXPORT_SYMBOL(__debugger_iabr_match);EXPORT_SYMBOL(__debugger_dabr_match);EXPORT_SYMBOL(__debugger_fault_handler);#endif/* * Trap & Exception support */static spinlock_t die_lock = SPIN_LOCK_UNLOCKED;int die(const char *str, struct pt_regs *regs, long err){ static int die_counter; int nl = 0; if (debugger(regs)) return 1; console_verbose(); spin_lock_irq(&die_lock); bust_spinlocks(1); printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);#ifdef CONFIG_PREEMPT printk("PREEMPT "); nl = 1;#endif#ifdef CONFIG_SMP printk("SMP NR_CPUS=%d ", NR_CPUS); nl = 1;#endif#ifdef CONFIG_DEBUG_PAGEALLOC printk("DEBUG_PAGEALLOC "); nl = 1;#endif#ifdef CONFIG_NUMA printk("NUMA "); nl = 1;#endif switch(systemcfg->platform) { case PLATFORM_PSERIES: printk("PSERIES "); nl = 1; break; case PLATFORM_PSERIES_LPAR: printk("PSERIES LPAR "); nl = 1; break; case PLATFORM_ISERIES_LPAR: printk("ISERIES LPAR "); nl = 1; break; case PLATFORM_POWERMAC: printk("POWERMAC "); nl = 1; break; } if (nl) printk("\n"); show_regs(regs); bust_spinlocks(0); spin_unlock_irq(&die_lock); if (in_interrupt()) panic("Fatal exception in interrupt"); if (panic_on_oops) { printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n"); set_current_state(TASK_UNINTERRUPTIBLE); schedule_timeout(5 * HZ); panic("Fatal exception"); } do_exit(SIGSEGV); return 0;}static void_exception(int signr, struct pt_regs *regs, int code, unsigned long addr){ siginfo_t info; if (!user_mode(regs)) { if (die("Exception in kernel mode", regs, signr)) return; } memset(&info, 0, sizeof(info)); info.si_signo = signr; info.si_code = code; info.si_addr = (void __user *) addr; force_sig_info(signr, &info, current);}#ifdef CONFIG_PPC_PSERIES/* Get the error information for errors coming through the * FWNMI vectors. The pt_regs' r3 will be updated to reflect * the actual r3 if possible, and a ptr to the error log entry * will be returned if found. */static struct rtas_error_log *FWNMI_get_errinfo(struct pt_regs *regs){ unsigned long errdata = regs->gpr[3]; struct rtas_error_log *errhdr = NULL; unsigned long *savep; if ((errdata >= 0x7000 && errdata < 0x7fff0) || (errdata >= rtas.base && errdata < rtas.base + rtas.size - 16)) { savep = __va(errdata); regs->gpr[3] = savep[0]; /* restore original r3 */ errhdr = (struct rtas_error_log *)(savep + 1); } else { printk("FWNMI: corrupt r3\n"); } return errhdr;}/* Call this when done with the data returned by FWNMI_get_errinfo. * It will release the saved data area for other CPUs in the * partition to receive FWNMI errors. */static void FWNMI_release_errinfo(void){ int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL); if (ret != 0) printk("FWNMI: nmi-interlock failed: %d\n", ret);}#endifvoidSystemResetException(struct pt_regs *regs){#ifdef CONFIG_PPC_PSERIES if (fwnmi_active) { struct rtas_error_log *errhdr = FWNMI_get_errinfo(regs); if (errhdr) { /* XXX Should look at FWNMI information */ } FWNMI_release_errinfo(); }#endif die("System Reset", regs, 0); /* Must die if the interrupt is not recoverable */ if (!(regs->msr & MSR_RI)) panic("Unrecoverable System Reset"); /* What should we do here? We could issue a shutdown or hard reset. */}#ifdef CONFIG_PPC_PSERIES/* * See if we can recover from a machine check exception. * This is only called on power4 (or above) and only via * the Firmware Non-Maskable Interrupts (fwnmi) handler * which provides the error analysis for us. * * Return 1 if corrected (or delivered a signal). * Return 0 if there is nothing we can do. */static int recover_mce(struct pt_regs *regs, struct rtas_error_log err){ if (err.disposition == RTAS_DISP_FULLY_RECOVERED) { /* Platform corrected itself */ return 1; } else if ((regs->msr & MSR_RI) && user_mode(regs) && err.severity == RTAS_SEVERITY_ERROR_SYNC && err.disposition == RTAS_DISP_NOT_RECOVERED && err.target == RTAS_TARGET_MEMORY && err.type == RTAS_TYPE_ECC_UNCORR && !(current->pid == 0 || current->pid == 1)) { /* Kill off a user process with an ECC error */ printk(KERN_ERR "MCE: uncorrectable ecc error for pid %d\n", current->pid); /* XXX something better for ECC error? */ _exception(SIGBUS, regs, BUS_ADRERR, regs->nip); return 1; } return 0;}#endif/* * Handle a machine check. * * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi) * should be present. If so the handler which called us tells us if the * error was recovered (never true if RI=0). * * On hardware prior to Power 4 these exceptions were asynchronous which * means we can't tell exactly where it occurred and so we can't recover. */voidMachineCheckException(struct pt_regs *regs){#ifdef CONFIG_PPC_PSERIES struct rtas_error_log err, *errp; if (fwnmi_active) { errp = FWNMI_get_errinfo(regs); if (errp) err = *errp; FWNMI_release_errinfo(); /* frees errp */ if (errp && recover_mce(regs, err)) return; }#endif if (debugger_fault_handler(regs)) return; die("Machine check", regs, 0); /* Must die if the interrupt is not recoverable */ if (!(regs->msr & MSR_RI)) panic("Unrecoverable Machine check");}voidUnknownException(struct pt_regs *regs){ printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", regs->nip, regs->msr, regs->trap); _exception(SIGTRAP, regs, 0, 0);}voidInstructionBreakpointException(struct pt_regs *regs){ if (debugger_iabr_match(regs)) return; _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);}voidSingleStepException(struct pt_regs *regs){ regs->msr &= ~MSR_SE; /* Turn off 'trace' bit */ if (debugger_sstep(regs)) return; _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);}/* * 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 inline void emulate_single_step(struct pt_regs *regs){ if (regs->msr & MSR_SE) SingleStepException(regs);}static void parse_fpe(struct pt_regs *regs){ int code = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?