traps.c
来自「linux 内核源代码」· C语言 代码 · 共 1,198 行 · 第 1/3 页
C
1,198 行
return; }create_atc_entry: /* setup an ATC entry for the access about to be retried */ asm volatile ("ploadr #2,%0@" : /* no outputs */ : "a" (addr));}#endif /* CPU_M68020_OR_M68030 */#endif /* !CONFIG_SUN3 */asmlinkage void buserr_c(struct frame *fp){ /* Only set esp0 if coming from user mode */ if (user_mode(&fp->ptregs)) current->thread.esp0 = (unsigned long) fp;#ifdef DEBUG printk ("*** Bus Error *** Format is %x\n", fp->ptregs.format);#endif switch (fp->ptregs.format) {#if defined (CONFIG_M68060) case 4: /* 68060 access error */ access_error060 (fp); break;#endif#if defined (CONFIG_M68040) case 0x7: /* 68040 access error */ access_error040 (fp); break;#endif#if defined (CPU_M68020_OR_M68030) case 0xa: case 0xb: bus_error030 (fp); break;#endif default: die_if_kernel("bad frame format",&fp->ptregs,0);#ifdef DEBUG printk("Unknown SIGSEGV - 4\n");#endif force_sig(SIGSEGV, current); }}static int kstack_depth_to_print = 48;void show_trace(unsigned long *stack){ unsigned long *endstack; unsigned long addr; int i; printk("Call Trace:"); addr = (unsigned long)stack + THREAD_SIZE - 1; endstack = (unsigned long *)(addr & -THREAD_SIZE); i = 0; while (stack + 1 <= endstack) { addr = *stack++; /* * 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 (__kernel_text_address(addr)) {#ifndef CONFIG_KALLSYMS if (i % 5 == 0) printk("\n ");#endif printk(" [<%08lx>]", addr); print_symbol(" %s\n", addr); i++; } } printk("\n");}void show_registers(struct pt_regs *regs){ struct frame *fp = (struct frame *)regs; mm_segment_t old_fs = get_fs(); u16 c, *cp; unsigned long addr; int i; print_modules(); printk("PC: [<%08lx>]",regs->pc); print_symbol(" %s", regs->pc); printk("\nSR: %04x SP: %p a2: %08lx\n", regs->sr, regs, regs->a2); printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n", regs->d0, regs->d1, regs->d2, regs->d3); printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n", regs->d4, regs->d5, regs->a0, regs->a1); printk("Process %s (pid: %d, task=%p)\n", current->comm, task_pid_nr(current), current); addr = (unsigned long)&fp->un; printk("Frame format=%X ", regs->format); switch (regs->format) { case 0x2: printk("instr addr=%08lx\n", fp->un.fmt2.iaddr); addr += sizeof(fp->un.fmt2); break; case 0x3: printk("eff addr=%08lx\n", fp->un.fmt3.effaddr); addr += sizeof(fp->un.fmt3); break; case 0x4: printk((CPU_IS_060 ? "fault addr=%08lx fslw=%08lx\n" : "eff addr=%08lx pc=%08lx\n"), fp->un.fmt4.effaddr, fp->un.fmt4.pc); addr += sizeof(fp->un.fmt4); break; case 0x7: printk("eff addr=%08lx ssw=%04x faddr=%08lx\n", fp->un.fmt7.effaddr, fp->un.fmt7.ssw, fp->un.fmt7.faddr); printk("wb 1 stat/addr/data: %04x %08lx %08lx\n", fp->un.fmt7.wb1s, fp->un.fmt7.wb1a, fp->un.fmt7.wb1dpd0); printk("wb 2 stat/addr/data: %04x %08lx %08lx\n", fp->un.fmt7.wb2s, fp->un.fmt7.wb2a, fp->un.fmt7.wb2d); printk("wb 3 stat/addr/data: %04x %08lx %08lx\n", fp->un.fmt7.wb3s, fp->un.fmt7.wb3a, fp->un.fmt7.wb3d); printk("push data: %08lx %08lx %08lx %08lx\n", fp->un.fmt7.wb1dpd0, fp->un.fmt7.pd1, fp->un.fmt7.pd2, fp->un.fmt7.pd3); addr += sizeof(fp->un.fmt7); break; case 0x9: printk("instr addr=%08lx\n", fp->un.fmt9.iaddr); addr += sizeof(fp->un.fmt9); break; case 0xa: printk("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n", fp->un.fmta.ssw, fp->un.fmta.isc, fp->un.fmta.isb, fp->un.fmta.daddr, fp->un.fmta.dobuf); addr += sizeof(fp->un.fmta); break; case 0xb: printk("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n", fp->un.fmtb.ssw, fp->un.fmtb.isc, fp->un.fmtb.isb, fp->un.fmtb.daddr, fp->un.fmtb.dobuf); printk("baddr=%08lx dibuf=%08lx ver=%x\n", fp->un.fmtb.baddr, fp->un.fmtb.dibuf, fp->un.fmtb.ver); addr += sizeof(fp->un.fmtb); break; default: printk("\n"); } show_stack(NULL, (unsigned long *)addr); printk("Code:"); set_fs(KERNEL_DS); cp = (u16 *)regs->pc; for (i = -8; i < 16; i++) { if (get_user(c, cp + i) && i >= 0) { printk(" Bad PC value."); break; } printk(i ? " %04x" : " <%04x>", c); } set_fs(old_fs); printk ("\n");}void show_stack(struct task_struct *task, unsigned long *stack){ unsigned long *p; unsigned long *endstack; int i; if (!stack) { if (task) stack = (unsigned long *)task->thread.esp0; else stack = (unsigned long *)&stack; } endstack = (unsigned long *)(((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE); printk("Stack from %08lx:", (unsigned long)stack); p = stack; for (i = 0; i < kstack_depth_to_print; i++) { if (p + 1 > endstack) break; if (i % 8 == 0) printk("\n "); printk(" %08lx", *p++); } printk("\n"); show_trace(stack);}/* * The architecture-independent backtrace generator */void dump_stack(void){ unsigned long stack; show_trace(&stack);}EXPORT_SYMBOL(dump_stack);void bad_super_trap (struct frame *fp){ console_verbose(); if (fp->ptregs.vector < 4 * ARRAY_SIZE(vec_names)) printk ("*** %s *** FORMAT=%X\n", vec_names[(fp->ptregs.vector) >> 2], fp->ptregs.format); else printk ("*** Exception %d *** FORMAT=%X\n", (fp->ptregs.vector) >> 2, fp->ptregs.format); if (fp->ptregs.vector >> 2 == VEC_ADDRERR && CPU_IS_020_OR_030) { unsigned short ssw = fp->un.fmtb.ssw; printk ("SSW=%#06x ", ssw); if (ssw & RC) printk ("Pipe stage C instruction fault at %#010lx\n", (fp->ptregs.format) == 0xA ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2); if (ssw & RB) printk ("Pipe stage B instruction fault at %#010lx\n", (fp->ptregs.format) == 0xA ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr); if (ssw & DF) printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n", ssw & RW ? "read" : "write", fp->un.fmtb.daddr, space_names[ssw & DFC], fp->ptregs.pc); } printk ("Current process id is %d\n", task_pid_nr(current)); die_if_kernel("BAD KERNEL TRAP", &fp->ptregs, 0);}asmlinkage void trap_c(struct frame *fp){ int sig; siginfo_t info; if (fp->ptregs.sr & PS_S) { if ((fp->ptregs.vector >> 2) == VEC_TRACE) { /* traced a trapping instruction */ current->ptrace |= PT_DTRACE; } else bad_super_trap(fp); return; } /* send the appropriate signal to the user program */ switch ((fp->ptregs.vector) >> 2) { case VEC_ADDRERR: info.si_code = BUS_ADRALN; sig = SIGBUS; break; case VEC_ILLEGAL: case VEC_LINE10: case VEC_LINE11: info.si_code = ILL_ILLOPC; sig = SIGILL; break; case VEC_PRIV: info.si_code = ILL_PRVOPC; sig = SIGILL; break; case VEC_COPROC: info.si_code = ILL_COPROC; sig = SIGILL; break; case VEC_TRAP1: case VEC_TRAP2: case VEC_TRAP3: case VEC_TRAP4: case VEC_TRAP5: case VEC_TRAP6: case VEC_TRAP7: case VEC_TRAP8: case VEC_TRAP9: case VEC_TRAP10: case VEC_TRAP11: case VEC_TRAP12: case VEC_TRAP13: case VEC_TRAP14: info.si_code = ILL_ILLTRP; sig = SIGILL; break; case VEC_FPBRUC: case VEC_FPOE: case VEC_FPNAN: info.si_code = FPE_FLTINV; sig = SIGFPE; break; case VEC_FPIR: info.si_code = FPE_FLTRES; sig = SIGFPE; break; case VEC_FPDIVZ: info.si_code = FPE_FLTDIV; sig = SIGFPE; break; case VEC_FPUNDER: info.si_code = FPE_FLTUND; sig = SIGFPE; break; case VEC_FPOVER: info.si_code = FPE_FLTOVF; sig = SIGFPE; break; case VEC_ZERODIV: info.si_code = FPE_INTDIV; sig = SIGFPE; break; case VEC_CHK: case VEC_TRAP: info.si_code = FPE_INTOVF; sig = SIGFPE; break; case VEC_TRACE: /* ptrace single step */ info.si_code = TRAP_TRACE; sig = SIGTRAP; break; case VEC_TRAP15: /* breakpoint */ info.si_code = TRAP_BRKPT; sig = SIGTRAP; break; default: info.si_code = ILL_ILLOPC; sig = SIGILL; break; } info.si_signo = sig; info.si_errno = 0; switch (fp->ptregs.format) { default: info.si_addr = (void *) fp->ptregs.pc; break; case 2: info.si_addr = (void *) fp->un.fmt2.iaddr; break; case 7: info.si_addr = (void *) fp->un.fmt7.effaddr; break; case 9: info.si_addr = (void *) fp->un.fmt9.iaddr; break; case 10: info.si_addr = (void *) fp->un.fmta.daddr; break; case 11: info.si_addr = (void *) fp->un.fmtb.daddr; break; } force_sig_info (sig, &info, current);}void die_if_kernel (char *str, struct pt_regs *fp, int nr){ if (!(fp->sr & PS_S)) return; console_verbose(); printk("%s: %08x\n",str,nr); show_registers(fp); add_taint(TAINT_DIE); do_exit(SIGSEGV);}/* * This function is called if an error occur while accessing * user-space from the fpsp040 code. */asmlinkage void fpsp040_die(void){ do_exit(SIGSEGV);}#ifdef CONFIG_M68KFPU_EMUasmlinkage void fpemu_signal(int signal, int code, void *addr){ siginfo_t info; info.si_signo = signal; info.si_errno = 0; info.si_code = code; info.si_addr = addr; force_sig_info(signal, &info, current);}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?