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

📄 traps.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  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@samba.org) *//* * 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/ptrace.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 <linux/prctl.h>#include <linux/delay.h>#include <linux/kprobes.h>#include <asm/kdebug.h>#include <asm/pgtable.h>#include <asm/uaccess.h>#include <asm/system.h>#include <asm/io.h>#include <asm/machdep.h>#include <asm/rtas.h>#include <asm/pmc.h>#ifdef CONFIG_PPC32#include <asm/reg.h>#endif#ifdef CONFIG_PMAC_BACKLIGHT#include <asm/backlight.h>#endif#ifdef CONFIG_PPC64#include <asm/firmware.h>#include <asm/processor.h>#endif#ifdef CONFIG_PPC64	/* XXX */#define _IO_BASE	pci_io_base#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);#endifstruct notifier_block *powerpc_die_chain;static DEFINE_SPINLOCK(die_notifier_lock);int register_die_notifier(struct notifier_block *nb){	int err = 0;	unsigned long flags;	spin_lock_irqsave(&die_notifier_lock, flags);	err = notifier_chain_register(&powerpc_die_chain, nb);	spin_unlock_irqrestore(&die_notifier_lock, flags);	return err;}/* * Trap & Exception support */static DEFINE_SPINLOCK(die_lock);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);#ifdef CONFIG_PMAC_BACKLIGHT	if (_machine == _MACH_Pmac) {		set_backlight_enable(1);		set_backlight_level(BACKLIGHT_MAX);	}#endif	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#ifdef CONFIG_PPC64	switch (_machine) {	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;	case PLATFORM_CELL:		printk("CELL ");		nl = 1;		break;	}#endif	if (nl)		printk("\n");	print_modules();	show_regs(regs);	bust_spinlocks(0);	spin_unlock_irq(&die_lock);	if (in_interrupt())		panic("Fatal exception in interrupt");	if (panic_on_oops) {#ifdef CONFIG_PPC64		printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");		ssleep(5);#endif		panic("Fatal exception");	}	do_exit(err);	return 0;}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);	/*	 * Init gets no signals that it doesn't have a handler for.	 * That's all very well, but if it has caused a synchronous	 * exception and we ignore the resulting signal, it will just	 * generate the same exception over and over again and we get	 * nowhere.  Better to kill it and let the kernel panic.	 */	if (current->pid == 1) {		__sighandler_t handler;		spin_lock_irq(&current->sighand->siglock);		handler = current->sighand->action[signr-1].sa.sa_handler;		spin_unlock_irq(&current->sighand->siglock);		if (handler == SIG_DFL) {			/* init has generated a synchronous exception			   and it doesn't have a handler for the signal */			printk(KERN_CRIT "init has generated signal %d "			       "but has no handler for it\n", signr);			do_exit(signr);		}	}}#ifdef CONFIG_PPC64void system_reset_exception(struct pt_regs *regs){	/* See if any machine dependent calls */	if (ppc_md.system_reset_exception)		ppc_md.system_reset_exception(regs);	die("System Reset", regs, SIGABRT);	/* 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. */}#endif/* * I/O accesses can cause machine checks on powermacs. * Check if the NIP corresponds to the address of a sync * instruction for which there is an entry in the exception * table. * Note that the 601 only takes a machine check on TEA * (transfer error ack) signal assertion, and does not * set any of the top 16 bits of SRR1. *  -- paulus. */static inline int check_io_access(struct pt_regs *regs){#ifdef CONFIG_PPC_PMAC	unsigned long msr = regs->msr;	const struct exception_table_entry *entry;	unsigned int *nip = (unsigned int *)regs->nip;	if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))	    && (entry = search_exception_tables(regs->nip)) != NULL) {		/*		 * Check that it's a sync instruction, or somewhere		 * in the twi; isync; nop sequence that inb/inw/inl uses.		 * As the address is in the exception table		 * we should be able to read the instr there.		 * For the debug message, we look at the preceding		 * load or store.		 */		if (*nip == 0x60000000)		/* nop */			nip -= 2;		else if (*nip == 0x4c00012c)	/* isync */			--nip;		if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {			/* sync or twi */			unsigned int rb;			--nip;			rb = (*nip >> 11) & 0x1f;			printk(KERN_DEBUG "%s bad port %lx at %p\n",			       (*nip & 0x100)? "OUT to": "IN from",			       regs->gpr[rb] - _IO_BASE, nip);			regs->msr |= MSR_RI;			regs->nip = entry->fixup;			return 1;		}	}#endif /* CONFIG_PPC_PMAC */	return 0;}#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)/* On 4xx, the reason for the machine check or program exception   is in the ESR. */#define get_reason(regs)	((regs)->dsisr)#ifndef CONFIG_FSL_BOOKE#define get_mc_reason(regs)	((regs)->dsisr)#else#define get_mc_reason(regs)	(mfspr(SPRN_MCSR))#endif#define REASON_FP		ESR_FP#define REASON_ILLEGAL		(ESR_PIL | ESR_PUO)#define REASON_PRIVILEGED	ESR_PPR#define REASON_TRAP		ESR_PTR/* single-step stuff */#define single_stepping(regs)	(current->thread.dbcr0 & DBCR0_IC)#define clear_single_step(regs)	(current->thread.dbcr0 &= ~DBCR0_IC)#else/* On non-4xx, the reason for the machine check or program   exception is in the MSR. */#define get_reason(regs)	((regs)->msr)#define get_mc_reason(regs)	((regs)->msr)#define REASON_FP		0x100000#define REASON_ILLEGAL		0x80000#define REASON_PRIVILEGED	0x40000#define REASON_TRAP		0x20000#define single_stepping(regs)	((regs)->msr & MSR_SE)#define clear_single_step(regs)	((regs)->msr &= ~MSR_SE)#endif/* * This is "fall-back" implementation for configurations * which don't provide platform-specific machine check info */void __attribute__ ((weak))platform_machine_check(struct pt_regs *regs){}void machine_check_exception(struct pt_regs *regs){#ifdef CONFIG_PPC64	int recover = 0;	/* See if any machine dependent calls */	if (ppc_md.machine_check_exception)		recover = ppc_md.machine_check_exception(regs);	if (recover)		return;#else	unsigned long reason = get_mc_reason(regs);	if (user_mode(regs)) {		regs->msr |= MSR_RI;		_exception(SIGBUS, regs, BUS_ADRERR, regs->nip);		return;	}#if defined(CONFIG_8xx) && defined(CONFIG_PCI)	/* the qspan pci read routines can cause machine checks -- Cort */	bad_page_fault(regs, regs->dar, SIGBUS);	return;#endif	if (debugger_fault_handler(regs)) {		regs->msr |= MSR_RI;		return;	}	if (check_io_access(regs))		return;#if defined(CONFIG_4xx) && !defined(CONFIG_440A)	if (reason & ESR_IMCP) {		printk("Instruction");		mtspr(SPRN_ESR, reason & ~ESR_IMCP);	} else		printk("Data");	printk(" machine check in kernel mode.\n");#elif defined(CONFIG_440A)	printk("Machine check in kernel mode.\n");	if (reason & ESR_IMCP){		printk("Instruction Synchronous Machine Check exception\n");		mtspr(SPRN_ESR, reason & ~ESR_IMCP);	}	else {		u32 mcsr = mfspr(SPRN_MCSR);		if (mcsr & MCSR_IB)			printk("Instruction Read PLB Error\n");		if (mcsr & MCSR_DRB)			printk("Data Read PLB Error\n");		if (mcsr & MCSR_DWB)			printk("Data Write PLB Error\n");		if (mcsr & MCSR_TLBP)			printk("TLB Parity Error\n");		if (mcsr & MCSR_ICP){			flush_instruction_cache();			printk("I-Cache Parity Error\n");		}		if (mcsr & MCSR_DCSP)			printk("D-Cache Search Parity Error\n");		if (mcsr & MCSR_DCFP)			printk("D-Cache Flush Parity Error\n");		if (mcsr & MCSR_IMPE)			printk("Machine Check exception is imprecise\n");		/* Clear MCSR */		mtspr(SPRN_MCSR, mcsr);	}#elif defined (CONFIG_E500)	printk("Machine check in kernel mode.\n");	printk("Caused by (from MCSR=%lx): ", reason);	if (reason & MCSR_MCP)		printk("Machine Check Signal\n");	if (reason & MCSR_ICPERR)		printk("Instruction Cache Parity Error\n");	if (reason & MCSR_DCP_PERR)		printk("Data Cache Push Parity Error\n");	if (reason & MCSR_DCPERR)		printk("Data Cache Parity Error\n");	if (reason & MCSR_GL_CI)		printk("Guarded Load or Cache-Inhibited stwcx.\n");	if (reason & MCSR_BUS_IAERR)		printk("Bus - Instruction Address Error\n");	if (reason & MCSR_BUS_RAERR)		printk("Bus - Read Address Error\n");	if (reason & MCSR_BUS_WAERR)		printk("Bus - Write Address Error\n");	if (reason & MCSR_BUS_IBERR)		printk("Bus - Instruction Data Error\n");	if (reason & MCSR_BUS_RBERR)		printk("Bus - Read Data Bus Error\n");	if (reason & MCSR_BUS_WBERR)		printk("Bus - Read Data Bus Error\n");	if (reason & MCSR_BUS_IPERR)		printk("Bus - Instruction Parity Error\n");	if (reason & MCSR_BUS_RPERR)		printk("Bus - Read Parity Error\n");#elif defined (CONFIG_E200)	printk("Machine check in kernel mode.\n");	printk("Caused by (from MCSR=%lx): ", reason);	if (reason & MCSR_MCP)		printk("Machine Check Signal\n");	if (reason & MCSR_CP_PERR)		printk("Cache Push Parity Error\n");	if (reason & MCSR_CPERR)		printk("Cache Parity Error\n");	if (reason & MCSR_EXCP_ERR)		printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");	if (reason & MCSR_BUS_IRERR)		printk("Bus - Read Bus Error on instruction fetch\n");	if (reason & MCSR_BUS_DRERR)		printk("Bus - Read Bus Error on data load\n");	if (reason & MCSR_BUS_WRERR)		printk("Bus - Write Bus Error on buffered store or cache line push\n");#else /* !CONFIG_4xx && !CONFIG_E500 && !CONFIG_E200 */	printk("Machine check in kernel mode.\n");	printk("Caused by (from SRR1=%lx): ", reason);	switch (reason & 0x601F0000) {	case 0x80000:		printk("Machine check signal\n");		break;	case 0:		/* for 601 */	case 0x40000:	case 0x140000:	/* 7450 MSS error and TEA */		printk("Transfer error ack signal\n");		break;	case 0x20000:		printk("Data parity error signal\n");		break;	case 0x10000:		printk("Address parity error signal\n");		break;	case 0x20000000:		printk("L1 Data Cache error\n");		break;	case 0x40000000:		printk("L1 Instruction Cache error\n");		break;	case 0x00100000:		printk("L2 data cache parity error\n");		break;	default:		printk("Unknown values in msr\n");	}#endif /* CONFIG_4xx */	/*	 * Optional platform-provided routine to print out	 * additional info, e.g. bus error registers.	 */	platform_machine_check(regs);#endif /* CONFIG_PPC64 */	if (debugger_fault_handler(regs))		return;	die("Machine check", regs, SIGBUS);	/* Must die if the interrupt is not recoverable */	if (!(regs->msr & MSR_RI))		panic("Unrecoverable Machine check");}void SMIException(struct pt_regs *regs){	die("System Management Interrupt", regs, SIGABRT);}void unknown_exception(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);}void instruction_breakpoint_exception(struct pt_regs *regs){	if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5,					5, SIGTRAP) == NOTIFY_STOP)		return;	if (debugger_iabr_match(regs))		return;	_exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);}void RunModeException(struct pt_regs *regs){	_exception(SIGTRAP, regs, 0, 0);}void __kprobes single_step_exception(struct pt_regs *regs){	regs->msr &= ~(MSR_SE | MSR_BE);  /* Turn off 'trace' bits */	if (notify_die(DIE_SSTEP, "single_step", regs, 5,					5, SIGTRAP) == NOTIFY_STOP)		return;	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 void emulate_single_step(struct pt_regs *regs){	if (single_stepping(regs)) {		clear_single_step(regs);		_exception(SIGTRAP, regs, TRAP_TRACE, 0);	}}static void parse_fpe(struct pt_regs *regs)

⌨️ 快捷键说明

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