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

📄 traps.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
 *  SH4: *   - PC always points to delayed branch * - return 0 if handled, -EFAULT if failed (may not return if in kernel) *//* Macros to determine offset from current PC for branch instructions *//* Explicit type coercion is used to force sign extension where needed */#define SH_PC_8BIT_OFFSET(instr) ((((signed char)(instr))*2) + 4)#define SH_PC_12BIT_OFFSET(instr) ((((signed short)(instr<<4))>>3) + 4)static int handle_unaligned_access(u16 instruction, struct pt_regs *regs){	u_int rm;	int ret, index;	index = (instruction>>8)&15;	/* 0x0F00 */	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(__SH4__)				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(__SH4__)				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)) {		sti();		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;	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(12, SIGILL,  "reserved instruction", reserved_inst, current)DO_ERROR(13, 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;#endifvoid __init trap_init(void){	extern void *vbr_base;	extern void *exception_handling_table[14];	exception_handling_table[12] = (void *)do_reserved_inst;	exception_handling_table[13] = (void *)do_illegal_slot_inst;#if defined(CONFIG_SH_STANDARD_BIOS)    	/*	 * 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.	 */	{	    register unsigned long vbr;	    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);	}#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 show_task(unsigned long *sp){	unsigned long *stack, addr;	unsigned long module_start = VMALLOC_START;	unsigned long module_end = VMALLOC_END;	extern long _text, _etext;	int i = 1;	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: ");	while (((long)stack & (THREAD_SIZE - 1))) {		if (__get_user(addr, stack)) {			printk("Failing address 0x%lx\n", *stack);			break;		}		stack++;		if (((addr >= (unsigned long)&_text) &&		     (addr <= (unsigned long)&_etext)) ||		    ((addr >= module_start) && (addr <= module_end))) {			if (i && ((i % 8) == 0))				printk("\n       ");			printk("[<%08lx>] ", addr);			i++;		}	}	printk("\n");}void show_trace_task(struct task_struct *tsk){	show_task((unsigned long *)tsk->thread.sp);}

⌨️ 快捷键说明

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