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

📄 traps.c

📁 linux2.6.16版本
💻 C
📖 第 1 页 / 共 2 页
字号:
	rm = regs->regs[index];	/* shout about the first ten userspace fixups */	if (user_mode(regs) && handle_unaligned_notify_count>0) {		handle_unaligned_notify_count--;		printk("Fixing up unaligned userspace access in \"%s\" pid=%d pc=0x%p ins=0x%04hx\n",		       current->comm,current->pid,(u16*)regs->pc,instruction);	}	ret = -EFAULT;	switch (instruction&0xF000) {	case 0x0000:		if (instruction==0x000B) {			/* rts */			ret = handle_unaligned_delayslot(regs);			if (ret==0)				regs->pc = regs->pr;		}		else if ((instruction&0x00FF)==0x0023) {			/* braf @Rm */			ret = handle_unaligned_delayslot(regs);			if (ret==0)				regs->pc += rm + 4;		}		else if ((instruction&0x00FF)==0x0003) {			/* bsrf @Rm */			ret = handle_unaligned_delayslot(regs);			if (ret==0) {				regs->pr = regs->pc + 4;				regs->pc += rm + 4;			}		}		else {			/* mov.[bwl] to/from memory via r0+rn */			goto simple;		}		break;	case 0x1000: /* mov.l Rm,@(disp,Rn) */		goto simple;	case 0x2000: /* mov.[bwl] to memory, possibly with pre-decrement */		goto simple;	case 0x4000:		if ((instruction&0x00FF)==0x002B) {			/* jmp @Rm */			ret = handle_unaligned_delayslot(regs);			if (ret==0)				regs->pc = rm;		}		else if ((instruction&0x00FF)==0x000B) {			/* jsr @Rm */			ret = handle_unaligned_delayslot(regs);			if (ret==0) {				regs->pr = regs->pc + 4;				regs->pc = rm;			}		}		else {			/* mov.[bwl] to/from memory via r0+rn */			goto simple;		}		break;	case 0x5000: /* mov.l @(disp,Rm),Rn */		goto simple;	case 0x6000: /* mov.[bwl] from memory, possibly with post-increment */		goto simple;	case 0x8000: /* bf lab, bf/s lab, bt lab, bt/s lab */		switch (instruction&0x0F00) {		case 0x0100: /* mov.w R0,@(disp,Rm) */			goto simple;		case 0x0500: /* mov.w @(disp,Rm),R0 */			goto simple;		case 0x0B00: /* bf   lab - no delayslot*/			break;		case 0x0F00: /* bf/s lab */			ret = handle_unaligned_delayslot(regs);			if (ret==0) {#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)				if ((regs->sr & 0x00000001) != 0)					regs->pc += 4; /* next after slot */				else#endif					regs->pc += SH_PC_8BIT_OFFSET(instruction);			}			break;		case 0x0900: /* bt   lab - no delayslot */			break;		case 0x0D00: /* bt/s lab */			ret = handle_unaligned_delayslot(regs);			if (ret==0) {#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)				if ((regs->sr & 0x00000001) == 0)					regs->pc += 4; /* next after slot */				else#endif					regs->pc += SH_PC_8BIT_OFFSET(instruction);			}			break;		}		break;	case 0xA000: /* bra label */		ret = handle_unaligned_delayslot(regs);		if (ret==0)			regs->pc += SH_PC_12BIT_OFFSET(instruction);		break;	case 0xB000: /* bsr label */		ret = handle_unaligned_delayslot(regs);		if (ret==0) {			regs->pr = regs->pc + 4;			regs->pc += SH_PC_12BIT_OFFSET(instruction);		}		break;	}	return ret;	/* handle non-delay-slot instruction */ simple:	ret = handle_unaligned_ins(instruction,regs);	if (ret==0)		regs->pc += 2;	return ret;}/* * Handle various address error exceptions */asmlinkage void do_address_error(struct pt_regs *regs, 				 unsigned long writeaccess,				 unsigned long address){	unsigned long error_code;	mm_segment_t oldfs;	u16 instruction;	int tmp;	asm volatile("stc       r2_bank,%0": "=r" (error_code));	oldfs = get_fs();	if (user_mode(regs)) {		local_irq_enable();		current->thread.error_code = error_code;		current->thread.trap_no = (writeaccess) ? 8 : 7;		/* bad PC is not something we can fix */		if (regs->pc & 1)			goto uspace_segv;		set_fs(USER_DS);		if (copy_from_user(&instruction, (u16 *)(regs->pc), 2)) {			/* Argh. Fault on the instruction itself.			   This should never happen non-SMP			*/			set_fs(oldfs);			goto uspace_segv;		}		tmp = handle_unaligned_access(instruction, regs);		set_fs(oldfs);		if (tmp==0)			return; /* sorted */	uspace_segv:		printk(KERN_NOTICE "Killing process \"%s\" due to unaligned access\n", current->comm);		force_sig(SIGSEGV, current);	} else {		if (regs->pc & 1)			die("unaligned program counter", regs, error_code);		set_fs(KERNEL_DS);		if (copy_from_user(&instruction, (u16 *)(regs->pc), 2)) {			/* Argh. Fault on the instruction itself.			   This should never happen non-SMP			*/			set_fs(oldfs);			die("insn faulting in do_address_error", regs, 0);		}		handle_unaligned_access(instruction, regs);		set_fs(oldfs);	}}#ifdef CONFIG_SH_DSP/* *	SH-DSP support gerg@snapgear.com. */int is_dsp_inst(struct pt_regs *regs){	unsigned short inst;	/* 	 * Safe guard if DSP mode is already enabled or we're lacking	 * the DSP altogether.	 */	if (!(cpu_data->flags & CPU_HAS_DSP) || (regs->sr & SR_DSP))		return 0;	get_user(inst, ((unsigned short *) regs->pc));	inst &= 0xf000;	/* Check for any type of DSP or support instruction */	if ((inst == 0xf000) || (inst == 0x4000))		return 1;	return 0;}#else#define is_dsp_inst(regs)	(0)#endif /* CONFIG_SH_DSP */DO_ERROR(TRAP_RESERVED_INST, SIGILL, "reserved instruction", reserved_inst, current)DO_ERROR(TRAP_ILLEGAL_SLOT_INST, SIGILL, "illegal slot instruction", illegal_slot_inst, current)asmlinkage void do_exception_error(unsigned long r4, unsigned long r5,				   unsigned long r6, unsigned long r7,				   struct pt_regs regs){	long ex;	asm volatile("stc	r2_bank, %0" : "=r" (ex));	die_if_kernel("exception", &regs, ex);}#if defined(CONFIG_SH_STANDARD_BIOS)void *gdb_vbr_vector;static inline void __init gdb_vbr_init(void){	register unsigned long vbr;	/*	 * Read the old value of the VBR register to initialise	 * the vector through which debug and BIOS traps are	 * delegated by the Linux trap handler.	 */	asm volatile("stc vbr, %0" : "=r" (vbr));	gdb_vbr_vector = (void *)(vbr + 0x100);	printk("Setting GDB trap vector to 0x%08lx\n",	       (unsigned long)gdb_vbr_vector);}#endifvoid __init per_cpu_trap_init(void){	extern void *vbr_base;#ifdef CONFIG_SH_STANDARD_BIOS	gdb_vbr_init();#endif	/* NOTE: The VBR value should be at P1	   (or P2, virtural "fixed" address space).	   It's definitely should not in physical address.  */	asm volatile("ldc	%0, vbr"		     : /* no output */		     : "r" (&vbr_base)		     : "memory");}void __init trap_init(void){	extern void *exception_handling_table[];	exception_handling_table[TRAP_RESERVED_INST]		= (void *)do_reserved_inst;	exception_handling_table[TRAP_ILLEGAL_SLOT_INST]		= (void *)do_illegal_slot_inst;#ifdef CONFIG_CPU_SH4	if (!(cpu_data->flags & CPU_HAS_FPU)) {		/* For SH-4 lacking an FPU, treat floating point instructions		   as reserved. */		/* entry 64 corresponds to EXPEVT=0x800 */		exception_handling_table[64] = (void *)do_reserved_inst;		exception_handling_table[65] = (void *)do_illegal_slot_inst;	}#endif			/* Setup VBR for boot cpu */	per_cpu_trap_init();}void show_stack(struct task_struct *tsk, unsigned long *sp){	unsigned long *stack, addr;	unsigned long module_start = VMALLOC_START;	unsigned long module_end = VMALLOC_END;	int i = 1;	if (tsk && !sp) {		sp = (unsigned long *)tsk->thread.sp;	}	if (!sp) {		__asm__ __volatile__ (			"mov r15, %0\n\t"			"stc r7_bank, %1\n\t"			: "=r" (module_start),			  "=r" (module_end)		);				sp = (unsigned long *)module_start;	}	stack = sp;	printk("\nCall trace: ");#ifdef CONFIG_KALLSYMS	printk("\n");#endif	while (!kstack_end(stack)) {		addr = *stack++;		if (((addr >= (unsigned long)_text) &&		     (addr <= (unsigned long)_etext)) ||		    ((addr >= module_start) && (addr <= module_end))) {			/*			 * For 80-columns display, 6 entry is maximum.			 * NOTE: '[<8c00abcd>] ' consumes 13 columns .			 */#ifndef CONFIG_KALLSYMS			if (i && ((i % 6) == 0))				printk("\n       ");#endif			printk("[<%08lx>] ", addr);			print_symbol("%s\n", addr);			i++;		}	}	printk("\n");}void show_task(unsigned long *sp){	show_stack(NULL, sp);}void dump_stack(void){	show_stack(NULL, NULL);}EXPORT_SYMBOL(dump_stack);

⌨️ 快捷键说明

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