traps.c
来自「linux 内核源代码」· C语言 代码 · 共 832 行 · 第 1/2 页
C
832 行
/* * File: arch/blackfin/kernel/traps.c * Based on: * Author: Hamish Macdonald * * Created: * Description: uses S/W interrupt 15 for the system calls * * Modified: * Copyright 2004-2006 Analog Devices Inc. * * Bugs: Enter bugs at http://blackfin.uclinux.org/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see the file COPYING, or write * to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */#include <linux/uaccess.h>#include <linux/interrupt.h>#include <linux/module.h>#include <linux/kallsyms.h>#include <linux/fs.h>#include <asm/traps.h>#include <asm/cacheflush.h>#include <asm/blackfin.h>#include <asm/irq_handler.h>#include <asm/trace.h>#include <asm/fixed_code.h>#ifdef CONFIG_KGDB# include <linux/debugger.h># include <linux/kgdb.h># define CHK_DEBUGGER_TRAP() \ do { \ CHK_DEBUGGER(trapnr, sig, info.si_code, fp, ); \ } while (0)# define CHK_DEBUGGER_TRAP_MAYBE() \ do { \ if (kgdb_connected) \ CHK_DEBUGGER_TRAP(); \ } while (0)#else# define CHK_DEBUGGER_TRAP() do { } while (0)# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)#endif/* Initiate the event table handler */void __init trap_init(void){ CSYNC(); bfin_write_EVT3(trap); CSYNC();}int kstack_depth_to_print = 48;static void decode_address(char *buf, unsigned long address){ struct vm_list_struct *vml; struct task_struct *p; struct mm_struct *mm; unsigned long flags, offset; unsigned int in_exception = bfin_read_IPEND() & 0x10;#ifdef CONFIG_KALLSYMS unsigned long symsize; const char *symname; char *modname; char *delim = ":"; char namebuf[128]; /* look up the address and see if we are in kernel space */ symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf); if (symname) { /* yeah! kernel space! */ if (!modname) modname = delim = ""; sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }", (void *)address, delim, modname, delim, symname, (unsigned long)offset); return; }#endif /* Problem in fixed code section? */ if (address >= FIXED_CODE_START && address < FIXED_CODE_END) { sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address); return; } /* Problem somewhere before the kernel start address */ if (address < CONFIG_BOOT_LOAD) { sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address); return; } /* looks like we're off in user-land, so let's walk all the * mappings of all our processes and see if we can't be a whee * bit more specific */ write_lock_irqsave(&tasklist_lock, flags); for_each_process(p) { mm = (in_exception ? p->mm : get_task_mm(p)); if (!mm) continue; vml = mm->context.vmlist; while (vml) { struct vm_area_struct *vma = vml->vma; if (address >= vma->vm_start && address < vma->vm_end) { char *name = p->comm; struct file *file = vma->vm_file; if (file) { char _tmpbuf[256]; name = d_path(file->f_dentry, file->f_vfsmnt, _tmpbuf, sizeof(_tmpbuf)); } /* FLAT does not have its text aligned to the start of * the map while FDPIC ELF does ... */ if (current->mm && (address > current->mm->start_code) && (address < current->mm->end_code)) offset = address - current->mm->start_code; else offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT); sprintf(buf, "<0x%p> [ %s + 0x%lx ]", (void *)address, name, offset); if (!in_exception) mmput(mm); goto done; } vml = vml->next; } if (!in_exception) mmput(mm); } /* we were unable to find this address anywhere */ sprintf(buf, "<0x%p> /* unknown address */", (void *)address);done: write_unlock_irqrestore(&tasklist_lock, flags);}asmlinkage void double_fault_c(struct pt_regs *fp){ console_verbose(); oops_in_progress = 1; printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n"); dump_bfin_process(fp); dump_bfin_mem((void *)fp->retx); show_regs(fp); panic("Double Fault - unrecoverable event\n");}asmlinkage void trap_c(struct pt_regs *fp){#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON int j;#endif int sig = 0; siginfo_t info; unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE; trace_buffer_save(j); /* Important - be very careful dereferncing pointers - will lead to * double faults if the stack has become corrupt */ /* If the fault was caused by a kernel thread, or interrupt handler * we will kernel panic, so the system reboots. * If KGDB is enabled, don't set this for kernel breakpoints */ if ((bfin_read_IPEND() & 0xFFC0)#ifdef CONFIG_KGDB && trapnr != VEC_EXCPT02#endif ){ console_verbose(); oops_in_progress = 1; } else if (current) { if (current->mm == NULL) { console_verbose(); oops_in_progress = 1; } } /* trap_c() will be called for exceptions. During exceptions * processing, the pc value should be set with retx value. * With this change we can cleanup some code in signal.c- TODO */ fp->orig_pc = fp->retx; /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n", trapnr, fp->ipend, fp->pc, fp->retx); */ /* send the appropriate signal to the user program */ switch (trapnr) { /* This table works in conjuction with the one in ./mach-common/entry.S * Some exceptions are handled there (in assembly, in exception space) * Some are handled here, (in C, in interrupt space) * Some, like CPLB, are handled in both, where the normal path is * handled in assembly/exception space, and the error path is handled * here */ /* 0x00 - Linux Syscall, getting here is an error */ /* 0x01 - userspace gdb breakpoint, handled here */ case VEC_EXCPT01: info.si_code = TRAP_ILLTRAP; sig = SIGTRAP; CHK_DEBUGGER_TRAP_MAYBE(); /* Check if this is a breakpoint in kernel space */ if (fp->ipend & 0xffc0) return; else break;#ifdef CONFIG_KGDB case VEC_EXCPT02 : /* gdb connection */ info.si_code = TRAP_ILLTRAP; sig = SIGTRAP; CHK_DEBUGGER_TRAP(); return;#else /* 0x02 - User Defined, Caught by default */#endif /* 0x03 - User Defined, userspace stack overflow */ case VEC_EXCPT03: info.si_code = SEGV_STACKFLOW; sig = SIGSEGV; printk(KERN_NOTICE EXC_0x03(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x04 - User Defined, Caught by default */ /* 0x05 - User Defined, Caught by default */ /* 0x06 - User Defined, Caught by default */ /* 0x07 - User Defined, Caught by default */ /* 0x08 - User Defined, Caught by default */ /* 0x09 - User Defined, Caught by default */ /* 0x0A - User Defined, Caught by default */ /* 0x0B - User Defined, Caught by default */ /* 0x0C - User Defined, Caught by default */ /* 0x0D - User Defined, Caught by default */ /* 0x0E - User Defined, Caught by default */ /* 0x0F - User Defined, Caught by default */ /* 0x10 HW Single step, handled here */ case VEC_STEP: info.si_code = TRAP_STEP; sig = SIGTRAP; CHK_DEBUGGER_TRAP_MAYBE(); /* Check if this is a single step in kernel space */ if (fp->ipend & 0xffc0) return; else break; /* 0x11 - Trace Buffer Full, handled here */ case VEC_OVFLOW: info.si_code = TRAP_TRACEFLOW; sig = SIGTRAP; printk(KERN_NOTICE EXC_0x11(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x12 - Reserved, Caught by default */ /* 0x13 - Reserved, Caught by default */ /* 0x14 - Reserved, Caught by default */ /* 0x15 - Reserved, Caught by default */ /* 0x16 - Reserved, Caught by default */ /* 0x17 - Reserved, Caught by default */ /* 0x18 - Reserved, Caught by default */ /* 0x19 - Reserved, Caught by default */ /* 0x1A - Reserved, Caught by default */ /* 0x1B - Reserved, Caught by default */ /* 0x1C - Reserved, Caught by default */ /* 0x1D - Reserved, Caught by default */ /* 0x1E - Reserved, Caught by default */ /* 0x1F - Reserved, Caught by default */ /* 0x20 - Reserved, Caught by default */ /* 0x21 - Undefined Instruction, handled here */ case VEC_UNDEF_I: info.si_code = ILL_ILLOPC; sig = SIGILL; printk(KERN_NOTICE EXC_0x21(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x22 - Illegal Instruction Combination, handled here */ case VEC_ILGAL_I: info.si_code = ILL_ILLPARAOP; sig = SIGILL; printk(KERN_NOTICE EXC_0x22(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x23 - Data CPLB protection violation, handled here */ case VEC_CPLB_VL: info.si_code = ILL_CPLB_VI; sig = SIGBUS; printk(KERN_NOTICE EXC_0x23(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x24 - Data access misaligned, handled here */ case VEC_MISALI_D: info.si_code = BUS_ADRALN; sig = SIGBUS; printk(KERN_NOTICE EXC_0x24(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x25 - Unrecoverable Event, handled here */ case VEC_UNCOV: info.si_code = ILL_ILLEXCPT; sig = SIGILL; printk(KERN_NOTICE EXC_0x25(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr, error case is handled here */ case VEC_CPLB_M: info.si_code = BUS_ADRALN; sig = SIGBUS; printk(KERN_NOTICE EXC_0x26(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */ case VEC_CPLB_MHIT: info.si_code = ILL_CPLB_MULHIT;#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO sig = SIGSEGV; printk(KERN_NOTICE "NULL pointer access (probably)\n");#else sig = SIGILL; printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));#endif CHK_DEBUGGER_TRAP(); break; /* 0x28 - Emulation Watchpoint, handled here */ case VEC_WATCH: info.si_code = TRAP_WATCHPT; sig = SIGTRAP; pr_debug(EXC_0x28(KERN_DEBUG)); CHK_DEBUGGER_TRAP_MAYBE(); /* Check if this is a watchpoint in kernel space */ if (fp->ipend & 0xffc0) return; else break;#ifdef CONFIG_BF535 /* 0x29 - Instruction fetch access error (535 only) */ case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */ info.si_code = BUS_OPFETCH; sig = SIGBUS; printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n"); CHK_DEBUGGER_TRAP(); break;#else /* 0x29 - Reserved, Caught by default */#endif /* 0x2A - Instruction fetch misaligned, handled here */ case VEC_MISALI_I: info.si_code = BUS_ADRALN; sig = SIGBUS; printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x2B - Instruction CPLB protection violation, handled here */ case VEC_CPLB_I_VL: info.si_code = ILL_CPLB_VI; sig = SIGBUS; printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */ case VEC_CPLB_I_M: info.si_code = ILL_CPLB_MISS; sig = SIGBUS; printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE)); CHK_DEBUGGER_TRAP(); break; /* 0x2D - Instruction CPLB Multiple Hits, handled here */ case VEC_CPLB_I_MHIT: info.si_code = ILL_CPLB_MULHIT;#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO sig = SIGSEGV; printk(KERN_NOTICE "Jump to address 0 - 0x0fff\n");#else sig = SIGILL; printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));#endif CHK_DEBUGGER_TRAP(); break; /* 0x2E - Illegal use of Supervisor Resource, handled here */ case VEC_ILL_RES: info.si_code = ILL_PRVOPC; sig = SIGILL; printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?