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

📄 traps.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
			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 += instruction_size(instruction);	return ret;}#endif /* CONFIG_CPU_SH2A */#ifdef CONFIG_CPU_HAS_SR_RB#define lookup_exception_vector(x)	\	__asm__ __volatile__ ("stc r2_bank, %0\n\t" : "=r" ((x)))#else#define lookup_exception_vector(x)	\	__asm__ __volatile__ ("mov r4, %0\n\t" : "=r" ((x)))#endif/* * Handle various address error exceptions: *  - instruction address error: *       misaligned PC *       PC >= 0x80000000 in user mode *  - data address error (read and write) *       misaligned data access *       access to >= 0x80000000 is user mode * Unfortuntaly we can't distinguish between instruction address error * and data address errors caused by read accesses. */asmlinkage void do_address_error(struct pt_regs *regs,				 unsigned long writeaccess,				 unsigned long address){	unsigned long error_code = 0;	mm_segment_t oldfs;	siginfo_t info;#ifndef CONFIG_CPU_SH2A	u16 instruction;	int tmp;#endif	/* Intentional ifdef */#ifdef CONFIG_CPU_HAS_SR_RB	lookup_exception_vector(error_code);#endif	oldfs = get_fs();	if (user_mode(regs)) {		int si_code = BUS_ADRERR;		local_irq_enable();		/* bad PC is not something we can fix */		if (regs->pc & 1) {			si_code = BUS_ADRALN;			goto uspace_segv;		}#ifndef CONFIG_CPU_SH2A		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 */#endifuspace_segv:		printk(KERN_NOTICE "Sending SIGBUS to \"%s\" due to unaligned "		       "access (PC %lx PR %lx)\n", current->comm, regs->pc,		       regs->pr);		info.si_signo = SIGBUS;		info.si_errno = 0;		info.si_code = si_code;		info.si_addr = (void __user *)address;		force_sig_info(SIGBUS, &info, current);	} else {		if (regs->pc & 1)			die("unaligned program counter", regs, error_code);#ifndef CONFIG_CPU_SH2A		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);#else		printk(KERN_NOTICE "Killing process \"%s\" due to unaligned "		       "access\n", current->comm);		force_sig(SIGSEGV, current);#endif	}}#ifdef CONFIG_SH_DSP/* *	SH-DSP support gerg@snapgear.com. */int is_dsp_inst(struct pt_regs *regs){	unsigned short inst = 0;	/*	 * Safe guard if DSP mode is already enabled or we're lacking	 * the DSP altogether.	 */	if (!(current_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 */#ifdef CONFIG_CPU_SH2Aasmlinkage void do_divide_error(unsigned long r4, unsigned long r5,				unsigned long r6, unsigned long r7,				struct pt_regs __regs){	siginfo_t info;	switch (r4) {	case TRAP_DIVZERO_ERROR:		info.si_code = FPE_INTDIV;		break;	case TRAP_DIVOVF_ERROR:		info.si_code = FPE_INTOVF;		break;	}	force_sig_info(SIGFPE, &info, current);}#endif/* arch/sh/kernel/cpu/sh4/fpu.c */extern int do_fpu_inst(unsigned short, struct pt_regs *);extern asmlinkage void do_fpu_state_restore(unsigned long r4, unsigned long r5,		unsigned long r6, unsigned long r7, struct pt_regs __regs);asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5,				unsigned long r6, unsigned long r7,				struct pt_regs __regs){	struct pt_regs *regs = RELOC_HIDE(&__regs, 0);	unsigned long error_code;	struct task_struct *tsk = current;#ifdef CONFIG_SH_FPU_EMU	unsigned short inst = 0;	int err;	get_user(inst, (unsigned short*)regs->pc);	err = do_fpu_inst(inst, regs);	if (!err) {		regs->pc += instruction_size(inst);		return;	}	/* not a FPU inst. */#endif#ifdef CONFIG_SH_DSP	/* Check if it's a DSP instruction */	if (is_dsp_inst(regs)) {		/* Enable DSP mode, and restart instruction. */		regs->sr |= SR_DSP;		return;	}#endif	lookup_exception_vector(error_code);	local_irq_enable();	CHK_REMOTE_DEBUG(regs);	force_sig(SIGILL, tsk);	die_if_no_fixup("reserved instruction", regs, error_code);}#ifdef CONFIG_SH_FPU_EMUstatic int emulate_branch(unsigned short inst, struct pt_regs* regs){	/*	 * bfs: 8fxx: PC+=d*2+4;	 * bts: 8dxx: PC+=d*2+4;	 * bra: axxx: PC+=D*2+4;	 * bsr: bxxx: PC+=D*2+4  after PR=PC+4;	 * braf:0x23: PC+=Rn*2+4;	 * bsrf:0x03: PC+=Rn*2+4 after PR=PC+4;	 * jmp: 4x2b: PC=Rn;	 * jsr: 4x0b: PC=Rn      after PR=PC+4;	 * rts: 000b: PC=PR;	 */	if ((inst & 0xfd00) == 0x8d00) {		regs->pc += SH_PC_8BIT_OFFSET(inst);		return 0;	}	if ((inst & 0xe000) == 0xa000) {		regs->pc += SH_PC_12BIT_OFFSET(inst);		return 0;	}	if ((inst & 0xf0df) == 0x0003) {		regs->pc += regs->regs[(inst & 0x0f00) >> 8] + 4;		return 0;	}	if ((inst & 0xf0df) == 0x400b) {		regs->pc = regs->regs[(inst & 0x0f00) >> 8];		return 0;	}	if ((inst & 0xffff) == 0x000b) {		regs->pc = regs->pr;		return 0;	}	return 1;}#endifasmlinkage void do_illegal_slot_inst(unsigned long r4, unsigned long r5,				unsigned long r6, unsigned long r7,				struct pt_regs __regs){	struct pt_regs *regs = RELOC_HIDE(&__regs, 0);	unsigned long error_code;	struct task_struct *tsk = current;#ifdef CONFIG_SH_FPU_EMU	unsigned short inst = 0;	get_user(inst, (unsigned short *)regs->pc + 1);	if (!do_fpu_inst(inst, regs)) {		get_user(inst, (unsigned short *)regs->pc);		if (!emulate_branch(inst, regs))			return;		/* fault in branch.*/	}	/* not a FPU inst. */#endif	lookup_exception_vector(error_code);	local_irq_enable();	CHK_REMOTE_DEBUG(regs);	force_sig(SIGILL, tsk);	die_if_no_fixup("illegal slot instruction", regs, error_code);}asmlinkage void do_exception_error(unsigned long r4, unsigned long r5,				   unsigned long r6, unsigned long r7,				   struct pt_regs __regs){	struct pt_regs *regs = RELOC_HIDE(&__regs, 0);	long ex;	lookup_exception_vector(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 __cpuinit per_cpu_trap_init(void){	extern void *vbr_base;#ifdef CONFIG_SH_STANDARD_BIOS	if (raw_smp_processor_id() == 0)		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 *set_exception_table_vec(unsigned int vec, void *handler){	extern void *exception_handling_table[];	void *old_handler;	old_handler = exception_handling_table[vec];	exception_handling_table[vec] = handler;	return old_handler;}extern asmlinkage void address_error_handler(unsigned long r4, unsigned long r5,					     unsigned long r6, unsigned long r7,					     struct pt_regs __regs);void __init trap_init(void){	set_exception_table_vec(TRAP_RESERVED_INST, do_reserved_inst);	set_exception_table_vec(TRAP_ILLEGAL_SLOT_INST, do_illegal_slot_inst);#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_FPU) || \    defined(CONFIG_SH_FPU_EMU)	/*	 * For SH-4 lacking an FPU, treat floating point instructions as	 * reserved. They'll be handled in the math-emu case, or faulted on	 * otherwise.	 */	set_exception_table_evt(0x800, do_reserved_inst);	set_exception_table_evt(0x820, do_illegal_slot_inst);#elif defined(CONFIG_SH_FPU)#ifdef CONFIG_CPU_SUBTYPE_SHX3	set_exception_table_evt(0xd80, do_fpu_state_restore);	set_exception_table_evt(0xda0, do_fpu_state_restore);#else	set_exception_table_evt(0x800, do_fpu_state_restore);	set_exception_table_evt(0x820, do_fpu_state_restore);#endif#endif#ifdef CONFIG_CPU_SH2	set_exception_table_vec(TRAP_ADDRESS_ERROR, address_error_handler);#endif#ifdef CONFIG_CPU_SH2A	set_exception_table_vec(TRAP_DIVZERO_ERROR, do_divide_error);	set_exception_table_vec(TRAP_DIVOVF_ERROR, do_divide_error);#endif	/* Setup VBR for boot cpu */	per_cpu_trap_init();}#ifdef CONFIG_BUGvoid handle_BUG(struct pt_regs *regs){	enum bug_trap_type tt;	tt = report_bug(regs->pc, regs);	if (tt == BUG_TRAP_TYPE_WARN) {		regs->pc += 2;		return;	}	die("Kernel BUG", regs, TRAPA_BUG_OPCODE & 0xff);}int is_valid_bugaddr(unsigned long addr){	return addr >= PAGE_OFFSET;}#endifvoid show_trace(struct task_struct *tsk, unsigned long *sp,		struct pt_regs *regs){	unsigned long addr;	if (regs && user_mode(regs))		return;	printk("\nCall trace: ");#ifdef CONFIG_KALLSYMS	printk("\n");#endif	while (!kstack_end(sp)) {		addr = *sp++;		if (kernel_text_address(addr))			print_ip_sym(addr);	}	printk("\n");	if (!tsk)		tsk = current;	debug_show_held_locks(tsk);}void show_stack(struct task_struct *tsk, unsigned long *sp){	unsigned long stack;	if (!tsk)		tsk = current;	if (tsk == current)		sp = (unsigned long *)current_stack_pointer;	else		sp = (unsigned long *)tsk->thread.sp;	stack = (unsigned long)sp;	dump_mem("Stack: ", stack, THREAD_SIZE +		 (unsigned long)task_stack_page(tsk));	show_trace(tsk, sp, NULL);}void dump_stack(void){	show_stack(NULL, NULL);}EXPORT_SYMBOL(dump_stack);

⌨️ 快捷键说明

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