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

📄 traps.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This file is subject to the terms and conditions of the GNU General Public * License.  See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 1994 - 1999 by Ralf Baechle * Modified for R3000 by Paul M. Antoine, 1995, 1996 * Complete output from die() by Ulf Carlsson, 1998 * Copyright (C) 1999 Silicon Graphics, Inc. */#include <linux/config.h>#include <linux/init.h>#include <linux/mm.h>#include <linux/sched.h>#include <linux/smp.h>#include <linux/smp_lock.h>#include <linux/spinlock.h>#include <asm/branch.h>#include <asm/cachectl.h>#include <asm/jazz.h>#include <asm/pgtable.h>#include <asm/io.h>#include <asm/bootinfo.h>#include <asm/watch.h>#include <asm/system.h>#include <asm/uaccess.h>#include <asm/mmu_context.h>/* * Machine specific interrupt handlers */extern asmlinkage void acer_pica_61_handle_int(void);extern asmlinkage void decstation_handle_int(void);extern asmlinkage void deskstation_rpc44_handle_int(void);extern asmlinkage void deskstation_tyne_handle_int(void);extern asmlinkage void mips_magnum_4000_handle_int(void);extern asmlinkage void handle_mod(void);extern asmlinkage void handle_tlbl(void);extern asmlinkage void handle_tlbs(void);extern asmlinkage void handle_adel(void);extern asmlinkage void handle_ades(void);extern asmlinkage void handle_ibe(void);extern asmlinkage void handle_dbe(void);extern asmlinkage void handle_sys(void);extern asmlinkage void handle_bp(void);extern asmlinkage void handle_ri(void);extern asmlinkage void handle_cpu(void);extern asmlinkage void handle_ov(void);extern asmlinkage void handle_tr(void);extern asmlinkage void handle_fpe(void);extern asmlinkage void handle_watch(void);extern asmlinkage void handle_reserved(void);static char *cpu_names[] = CPU_NAMES;char watch_available = 0;char dedicated_iv_available = 0;char vce_available = 0;void (*ibe_board_handler)(struct pt_regs *regs);void (*dbe_board_handler)(struct pt_regs *regs);int kstack_depth_to_print = 24;/* * These constant is for searching for possible module text segments. * MODULE_RANGE is a guess of how much space is likely to be vmalloced. */#define MODULE_RANGE (8*1024*1024)#if !defined(CONFIG_CPU_HAS_LLSC)/* * This stuff is needed for the userland ll-sc emulation for R2300 */void simulate_ll(struct pt_regs *regs, unsigned int opcode);void simulate_sc(struct pt_regs *regs, unsigned int opcode);#define OPCODE 0xfc000000#define BASE   0x03e00000#define RT     0x001f0000#define OFFSET 0x0000ffff#define LL     0xc0000000#define SC     0xd0000000#define DEBUG_LLSC#endif/* * This routine abuses get_user()/put_user() to reference pointers * with at least a bit of error checking ... */void show_stack(unsigned int *sp){	int i;	unsigned int *stack;	stack = sp;	i = 0;	printk("Stack:");	while ((unsigned long) stack & (PAGE_SIZE - 1)) {		unsigned long stackdata;		if (__get_user(stackdata, stack++)) {			printk(" (Bad stack address)");			break;		}		printk(" %08lx", stackdata);		if (++i > 40) {			printk(" ...");			break;		}		if (i % 8 == 0)			printk("\n      ");	}}void show_trace(unsigned int *sp){	int i;	unsigned int *stack;	unsigned long kernel_start, kernel_end;	unsigned long module_start, module_end;	extern char _stext, _etext;	stack = sp;	i = 0;	kernel_start = (unsigned long) &_stext;	kernel_end = (unsigned long) &_etext;	module_start = VMALLOC_START;	module_end = module_start + MODULE_RANGE;	printk("\nCall Trace:");	while ((unsigned long) stack & (PAGE_SIZE -1)) {		unsigned long addr;		if (__get_user(addr, stack++)) {			printk(" (Bad stack address)\n");			break;		}		/*		 * If the address is either in the text segment of the		 * kernel, or in the region which contains vmalloc'ed		 * memory, it *may* be the address of a calling		 * routine; if so, print it so that someone tracing		 * down the cause of the crash will be able to figure		 * out the call path that was taken.		 */		if ((addr >= kernel_start && addr < kernel_end) ||		    (addr >= module_start && addr < module_end)) { 			printk(" [<%08lx>]", addr);			if (++i > 40) {				printk(" ...");				break;			}		}	}}void show_code(unsigned int *pc){	long i;	printk("\nCode:");	for(i = -3 ; i < 6 ; i++) {		unsigned long insn;		if (__get_user(insn, pc + i)) {			printk(" (Bad address in epc)\n");			break;		}		printk("%c%08lx%c",(i?' ':'<'),insn,(i?' ':'>'));	}}spinlock_t die_lock;extern void __die(const char * str, struct pt_regs * regs, const char *where,                  unsigned long line){	console_verbose();	spin_lock_irq(&die_lock);	printk("%s", str);	if (where)		printk(" in %s, line %ld", where, line);	printk(":\n");	show_regs(regs);	printk("Process %s (pid: %d, stackpage=%08lx)\n",		current->comm, current->pid, (unsigned long) current);	show_stack((unsigned int *) regs->regs[29]);	show_trace((unsigned int *) regs->regs[29]);	show_code((unsigned int *) regs->cp0_epc);	printk("\n");while(1);	spin_unlock_irq(&die_lock);	do_exit(SIGSEGV);}void __die_if_kernel(const char * str, struct pt_regs * regs, const char *where,	unsigned long line){	if (!user_mode(regs))		__die(str, regs, where, line);}extern const struct exception_table_entry __start___dbe_table[];extern const struct exception_table_entry __stop___dbe_table[];void __declare_dbe_table(void){	__asm__ __volatile__(	".section\t__dbe_table,\"a\"\n\t"	".previous"	);}static inline unsigned longsearch_one_table(const struct exception_table_entry *first,		 const struct exception_table_entry *last,		 unsigned long value){	const struct exception_table_entry *mid;	long diff;	while (first < last) {		mid = (last - first) / 2 + first;		diff = mid->insn - value;		if (diff < 0)			first = mid + 1;		else			last = mid;	}	return (first == last && first->insn == value) ? first->nextinsn : 0;}#define search_dbe_table(addr)	\	search_one_table(__start___dbe_table, __stop___dbe_table - 1, (addr))static void default_be_board_handler(struct pt_regs *regs){	unsigned long new_epc;	unsigned long fixup = search_dbe_table(regs->cp0_epc);	if (fixup) {		new_epc = fixup_exception(dpf_reg, fixup, regs->cp0_epc);		regs->cp0_epc = new_epc;		return;	}	/*	 * Assume it would be too dangerous to continue ...	 *//* XXX */printk("Got Bus Error at %08x\n", (unsigned int)regs->cp0_epc);show_regs(regs); while(1);	force_sig(SIGBUS, current);}void do_ibe(struct pt_regs *regs){	ibe_board_handler(regs);}void do_dbe(struct pt_regs *regs){	dbe_board_handler(regs);}void do_ov(struct pt_regs *regs){	if (compute_return_epc(regs))		return;	force_sig(SIGFPE, current);}#ifdef CONFIG_MIPS_FPE_MODULEstatic void (*fpe_handler)(struct pt_regs *regs, unsigned int fcr31);/* * Register_fpe/unregister_fpe are for debugging purposes only.  To make * this hack work a bit better there is no error checking. */int register_fpe(void (*handler)(struct pt_regs *regs, unsigned int fcr31)){	fpe_handler = handler;	return 0;}int unregister_fpe(void (*handler)(struct pt_regs *regs, unsigned int fcr31)){	fpe_handler = NULL;	return 0;}#endif/* * XXX Delayed fp exceptions when doing a lazy ctx switch XXX */void do_fpe(struct pt_regs *regs, unsigned long fcr31){	unsigned long pc;	unsigned int insn;	extern void simfp(unsigned int);#ifdef CONFIG_MIPS_FPE_MODULE	if (fpe_handler != NULL) {		fpe_handler(regs, fcr31);		return;	}#endif	if (fcr31 & 0x20000) {		/* Retry instruction with flush to zero ...  */		if (!(fcr31 & (1<<24))) {			printk("Setting flush to zero for %s.\n",			       current->comm);			fcr31 &= ~0x20000;			fcr31 |= (1<<24);			__asm__ __volatile__(				"ctc1\t%0,$31"				: /* No outputs */				: "r" (fcr31));			return;		}		pc = regs->cp0_epc + ((regs->cp0_cause & CAUSEF_BD) ? 4 : 0);		if (get_user(insn, (unsigned int *)pc)) {			/* XXX Can this happen?  */			force_sig(SIGSEGV, current);		}		printk(KERN_DEBUG "Unimplemented exception for insn %08x at 0x%08lx in %s.\n",		       insn, regs->cp0_epc, current->comm);		simfp(insn);	}	if (compute_return_epc(regs))		return;	//force_sig(SIGFPE, current);	printk(KERN_DEBUG "Should send SIGFPE to %s\n", current->comm);}static inline int get_insn_opcode(struct pt_regs *regs, unsigned int *opcode){	unsigned int *epc;	epc = (unsigned int *) (unsigned long) regs->cp0_epc;	if (regs->cp0_cause & CAUSEF_BD)		epc += 4;	if (verify_area(VERIFY_READ, epc, 4)) {		force_sig(SIGSEGV, current);		return 1;	}	*opcode = *epc;	return 0;}void do_bp(struct pt_regs *regs){	unsigned int opcode, bcode;	/*	 * There is the ancient bug in the MIPS assemblers that the break	 * code starts left to bit 16 instead to bit 6 in the opcode.	 * Gas is bug-compatible ...	 */	if (get_insn_opcode(regs, &opcode))		return;	bcode = ((opcode >> 16) & ((1 << 20) - 1));	/*	 * (A short test says that IRIX 5.3 sends SIGTRAP for all break

⌨️ 快捷键说明

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