1*5a0015d6SChris Zankel /* 2*5a0015d6SChris Zankel * arch/xtensa/kernel/traps.c 3*5a0015d6SChris Zankel * 4*5a0015d6SChris Zankel * Exception handling. 5*5a0015d6SChris Zankel * 6*5a0015d6SChris Zankel * Derived from code with the following copyrights: 7*5a0015d6SChris Zankel * Copyright (C) 1994 - 1999 by Ralf Baechle 8*5a0015d6SChris Zankel * Modified for R3000 by Paul M. Antoine, 1995, 1996 9*5a0015d6SChris Zankel * Complete output from die() by Ulf Carlsson, 1998 10*5a0015d6SChris Zankel * Copyright (C) 1999 Silicon Graphics, Inc. 11*5a0015d6SChris Zankel * 12*5a0015d6SChris Zankel * Essentially rewritten for the Xtensa architecture port. 13*5a0015d6SChris Zankel * 14*5a0015d6SChris Zankel * Copyright (C) 2001 - 2005 Tensilica Inc. 15*5a0015d6SChris Zankel * 16*5a0015d6SChris Zankel * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com> 17*5a0015d6SChris Zankel * Chris Zankel <chris@zankel.net> 18*5a0015d6SChris Zankel * Marc Gauthier<marc@tensilica.com, marc@alumni.uwaterloo.ca> 19*5a0015d6SChris Zankel * Kevin Chea 20*5a0015d6SChris Zankel * 21*5a0015d6SChris Zankel * This file is subject to the terms and conditions of the GNU General Public 22*5a0015d6SChris Zankel * License. See the file "COPYING" in the main directory of this archive 23*5a0015d6SChris Zankel * for more details. 24*5a0015d6SChris Zankel */ 25*5a0015d6SChris Zankel 26*5a0015d6SChris Zankel #include <linux/kernel.h> 27*5a0015d6SChris Zankel #include <linux/sched.h> 28*5a0015d6SChris Zankel #include <linux/init.h> 29*5a0015d6SChris Zankel #include <linux/module.h> 30*5a0015d6SChris Zankel #include <linux/stringify.h> 31*5a0015d6SChris Zankel #include <linux/kallsyms.h> 32*5a0015d6SChris Zankel 33*5a0015d6SChris Zankel #include <asm/ptrace.h> 34*5a0015d6SChris Zankel #include <asm/timex.h> 35*5a0015d6SChris Zankel #include <asm/uaccess.h> 36*5a0015d6SChris Zankel #include <asm/pgtable.h> 37*5a0015d6SChris Zankel #include <asm/processor.h> 38*5a0015d6SChris Zankel 39*5a0015d6SChris Zankel #ifdef CONFIG_KGDB 40*5a0015d6SChris Zankel extern int gdb_enter; 41*5a0015d6SChris Zankel extern int return_from_debug_flag; 42*5a0015d6SChris Zankel #endif 43*5a0015d6SChris Zankel 44*5a0015d6SChris Zankel /* 45*5a0015d6SChris Zankel * Machine specific interrupt handlers 46*5a0015d6SChris Zankel */ 47*5a0015d6SChris Zankel 48*5a0015d6SChris Zankel extern void kernel_exception(void); 49*5a0015d6SChris Zankel extern void user_exception(void); 50*5a0015d6SChris Zankel 51*5a0015d6SChris Zankel extern void fast_syscall_kernel(void); 52*5a0015d6SChris Zankel extern void fast_syscall_user(void); 53*5a0015d6SChris Zankel extern void fast_alloca(void); 54*5a0015d6SChris Zankel extern void fast_unaligned(void); 55*5a0015d6SChris Zankel extern void fast_second_level_miss(void); 56*5a0015d6SChris Zankel extern void fast_store_prohibited(void); 57*5a0015d6SChris Zankel extern void fast_coprocessor(void); 58*5a0015d6SChris Zankel 59*5a0015d6SChris Zankel extern void do_illegal_instruction (struct pt_regs*); 60*5a0015d6SChris Zankel extern void do_interrupt (struct pt_regs*); 61*5a0015d6SChris Zankel extern void do_unaligned_user (struct pt_regs*); 62*5a0015d6SChris Zankel extern void do_multihit (struct pt_regs*, unsigned long); 63*5a0015d6SChris Zankel extern void do_page_fault (struct pt_regs*, unsigned long); 64*5a0015d6SChris Zankel extern void do_debug (struct pt_regs*); 65*5a0015d6SChris Zankel extern void system_call (struct pt_regs*); 66*5a0015d6SChris Zankel 67*5a0015d6SChris Zankel /* 68*5a0015d6SChris Zankel * The vector table must be preceded by a save area (which 69*5a0015d6SChris Zankel * implies it must be in RAM, unless one places RAM immediately 70*5a0015d6SChris Zankel * before a ROM and puts the vector at the start of the ROM (!)) 71*5a0015d6SChris Zankel */ 72*5a0015d6SChris Zankel 73*5a0015d6SChris Zankel #define KRNL 0x01 74*5a0015d6SChris Zankel #define USER 0x02 75*5a0015d6SChris Zankel 76*5a0015d6SChris Zankel #define COPROCESSOR(x) \ 77*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_COPROCESSOR ## x ## _DISABLED, USER, fast_coprocessor } 78*5a0015d6SChris Zankel 79*5a0015d6SChris Zankel typedef struct { 80*5a0015d6SChris Zankel int cause; 81*5a0015d6SChris Zankel int fast; 82*5a0015d6SChris Zankel void* handler; 83*5a0015d6SChris Zankel } dispatch_init_table_t; 84*5a0015d6SChris Zankel 85*5a0015d6SChris Zankel dispatch_init_table_t __init dispatch_init_table[] = { 86*5a0015d6SChris Zankel 87*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_ILLEGAL_INSTRUCTION, 0, do_illegal_instruction}, 88*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_SYSTEM_CALL, KRNL, fast_syscall_kernel }, 89*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_SYSTEM_CALL, USER, fast_syscall_user }, 90*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_SYSTEM_CALL, 0, system_call }, 91*5a0015d6SChris Zankel /* XCHAL_EXCCAUSE_INSTRUCTION_FETCH unhandled */ 92*5a0015d6SChris Zankel /* XCHAL_EXCCAUSE_LOAD_STORE_ERROR unhandled*/ 93*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_LEVEL1_INTERRUPT, 0, do_interrupt }, 94*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_ALLOCA, USER|KRNL, fast_alloca }, 95*5a0015d6SChris Zankel /* XCHAL_EXCCAUSE_INTEGER_DIVIDE_BY_ZERO unhandled */ 96*5a0015d6SChris Zankel /* XCHAL_EXCCAUSE_PRIVILEGED unhandled */ 97*5a0015d6SChris Zankel #if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION 98*5a0015d6SChris Zankel #ifdef CONFIG_UNALIGNED_USER 99*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_UNALIGNED, USER, fast_unaligned }, 100*5a0015d6SChris Zankel #else 101*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_UNALIGNED, 0, do_unaligned_user }, 102*5a0015d6SChris Zankel #endif 103*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_UNALIGNED, KRNL, fast_unaligned }, 104*5a0015d6SChris Zankel #endif 105*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_ITLB_MISS, 0, do_page_fault }, 106*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_ITLB_MISS, USER|KRNL, fast_second_level_miss}, 107*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_ITLB_MULTIHIT, 0, do_multihit }, 108*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_ITLB_PRIVILEGE, 0, do_page_fault }, 109*5a0015d6SChris Zankel /* XCHAL_EXCCAUSE_SIZE_RESTRICTION unhandled */ 110*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_FETCH_CACHE_ATTRIBUTE, 0, do_page_fault }, 111*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_DTLB_MISS, USER|KRNL, fast_second_level_miss}, 112*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_DTLB_MISS, 0, do_page_fault }, 113*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_DTLB_MULTIHIT, 0, do_multihit }, 114*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_DTLB_PRIVILEGE, 0, do_page_fault }, 115*5a0015d6SChris Zankel /* XCHAL_EXCCAUSE_DTLB_SIZE_RESTRICTION unhandled */ 116*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_STORE_CACHE_ATTRIBUTE, USER|KRNL, fast_store_prohibited }, 117*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_STORE_CACHE_ATTRIBUTE, 0, do_page_fault }, 118*5a0015d6SChris Zankel { XCHAL_EXCCAUSE_LOAD_CACHE_ATTRIBUTE, 0, do_page_fault }, 119*5a0015d6SChris Zankel /* XCCHAL_EXCCAUSE_FLOATING_POINT unhandled */ 120*5a0015d6SChris Zankel #if (XCHAL_CP_MASK & 1) 121*5a0015d6SChris Zankel COPROCESSOR(0), 122*5a0015d6SChris Zankel #endif 123*5a0015d6SChris Zankel #if (XCHAL_CP_MASK & 2) 124*5a0015d6SChris Zankel COPROCESSOR(1), 125*5a0015d6SChris Zankel #endif 126*5a0015d6SChris Zankel #if (XCHAL_CP_MASK & 4) 127*5a0015d6SChris Zankel COPROCESSOR(2), 128*5a0015d6SChris Zankel #endif 129*5a0015d6SChris Zankel #if (XCHAL_CP_MASK & 8) 130*5a0015d6SChris Zankel COPROCESSOR(3), 131*5a0015d6SChris Zankel #endif 132*5a0015d6SChris Zankel #if (XCHAL_CP_MASK & 16) 133*5a0015d6SChris Zankel COPROCESSOR(4), 134*5a0015d6SChris Zankel #endif 135*5a0015d6SChris Zankel #if (XCHAL_CP_MASK & 32) 136*5a0015d6SChris Zankel COPROCESSOR(5), 137*5a0015d6SChris Zankel #endif 138*5a0015d6SChris Zankel #if (XCHAL_CP_MASK & 64) 139*5a0015d6SChris Zankel COPROCESSOR(6), 140*5a0015d6SChris Zankel #endif 141*5a0015d6SChris Zankel #if (XCHAL_CP_MASK & 128) 142*5a0015d6SChris Zankel COPROCESSOR(7), 143*5a0015d6SChris Zankel #endif 144*5a0015d6SChris Zankel { EXCCAUSE_MAPPED_DEBUG, 0, do_debug }, 145*5a0015d6SChris Zankel { -1, -1, 0 } 146*5a0015d6SChris Zankel 147*5a0015d6SChris Zankel }; 148*5a0015d6SChris Zankel 149*5a0015d6SChris Zankel /* The exception table <exc_table> serves two functions: 150*5a0015d6SChris Zankel * 1. it contains three dispatch tables (fast_user, fast_kernel, default-c) 151*5a0015d6SChris Zankel * 2. it is a temporary memory buffer for the exception handlers. 152*5a0015d6SChris Zankel */ 153*5a0015d6SChris Zankel 154*5a0015d6SChris Zankel unsigned long exc_table[EXC_TABLE_SIZE/4]; 155*5a0015d6SChris Zankel 156*5a0015d6SChris Zankel void die(const char*, struct pt_regs*, long); 157*5a0015d6SChris Zankel 158*5a0015d6SChris Zankel static inline void 159*5a0015d6SChris Zankel __die_if_kernel(const char *str, struct pt_regs *regs, long err) 160*5a0015d6SChris Zankel { 161*5a0015d6SChris Zankel if (!user_mode(regs)) 162*5a0015d6SChris Zankel die(str, regs, err); 163*5a0015d6SChris Zankel } 164*5a0015d6SChris Zankel 165*5a0015d6SChris Zankel /* 166*5a0015d6SChris Zankel * Unhandled Exceptions. Kill user task or panic if in kernel space. 167*5a0015d6SChris Zankel */ 168*5a0015d6SChris Zankel 169*5a0015d6SChris Zankel void do_unhandled(struct pt_regs *regs, unsigned long exccause) 170*5a0015d6SChris Zankel { 171*5a0015d6SChris Zankel __die_if_kernel("Caught unhandled exception - should not happen", 172*5a0015d6SChris Zankel regs, SIGKILL); 173*5a0015d6SChris Zankel 174*5a0015d6SChris Zankel /* If in user mode, send SIGILL signal to current process */ 175*5a0015d6SChris Zankel printk("Caught unhandled exception in '%s' " 176*5a0015d6SChris Zankel "(pid = %d, pc = %#010lx) - should not happen\n" 177*5a0015d6SChris Zankel "\tEXCCAUSE is %ld\n", 178*5a0015d6SChris Zankel current->comm, current->pid, regs->pc, exccause); 179*5a0015d6SChris Zankel force_sig(SIGILL, current); 180*5a0015d6SChris Zankel } 181*5a0015d6SChris Zankel 182*5a0015d6SChris Zankel /* 183*5a0015d6SChris Zankel * Multi-hit exception. This if fatal! 184*5a0015d6SChris Zankel */ 185*5a0015d6SChris Zankel 186*5a0015d6SChris Zankel void do_multihit(struct pt_regs *regs, unsigned long exccause) 187*5a0015d6SChris Zankel { 188*5a0015d6SChris Zankel die("Caught multihit exception", regs, SIGKILL); 189*5a0015d6SChris Zankel } 190*5a0015d6SChris Zankel 191*5a0015d6SChris Zankel /* 192*5a0015d6SChris Zankel * Level-1 interrupt. 193*5a0015d6SChris Zankel * We currently have no priority encoding. 194*5a0015d6SChris Zankel */ 195*5a0015d6SChris Zankel 196*5a0015d6SChris Zankel unsigned long ignored_level1_interrupts; 197*5a0015d6SChris Zankel extern void do_IRQ(int, struct pt_regs *); 198*5a0015d6SChris Zankel 199*5a0015d6SChris Zankel void do_interrupt (struct pt_regs *regs) 200*5a0015d6SChris Zankel { 201*5a0015d6SChris Zankel unsigned long intread = get_sr (INTREAD); 202*5a0015d6SChris Zankel unsigned long intenable = get_sr (INTENABLE); 203*5a0015d6SChris Zankel int i, mask; 204*5a0015d6SChris Zankel 205*5a0015d6SChris Zankel /* Handle all interrupts (no priorities). 206*5a0015d6SChris Zankel * (Clear the interrupt before processing, in case it's 207*5a0015d6SChris Zankel * edge-triggered or software-generated) 208*5a0015d6SChris Zankel */ 209*5a0015d6SChris Zankel 210*5a0015d6SChris Zankel for (i=0, mask = 1; i < XCHAL_NUM_INTERRUPTS; i++, mask <<= 1) { 211*5a0015d6SChris Zankel if (mask & (intread & intenable)) { 212*5a0015d6SChris Zankel set_sr (mask, INTCLEAR); 213*5a0015d6SChris Zankel do_IRQ (i,regs); 214*5a0015d6SChris Zankel } 215*5a0015d6SChris Zankel } 216*5a0015d6SChris Zankel } 217*5a0015d6SChris Zankel 218*5a0015d6SChris Zankel /* 219*5a0015d6SChris Zankel * Illegal instruction. Fatal if in kernel space. 220*5a0015d6SChris Zankel */ 221*5a0015d6SChris Zankel 222*5a0015d6SChris Zankel void 223*5a0015d6SChris Zankel do_illegal_instruction(struct pt_regs *regs) 224*5a0015d6SChris Zankel { 225*5a0015d6SChris Zankel __die_if_kernel("Illegal instruction in kernel", regs, SIGKILL); 226*5a0015d6SChris Zankel 227*5a0015d6SChris Zankel /* If in user mode, send SIGILL signal to current process. */ 228*5a0015d6SChris Zankel 229*5a0015d6SChris Zankel printk("Illegal Instruction in '%s' (pid = %d, pc = %#010lx)\n", 230*5a0015d6SChris Zankel current->comm, current->pid, regs->pc); 231*5a0015d6SChris Zankel force_sig(SIGILL, current); 232*5a0015d6SChris Zankel } 233*5a0015d6SChris Zankel 234*5a0015d6SChris Zankel 235*5a0015d6SChris Zankel /* 236*5a0015d6SChris Zankel * Handle unaligned memory accesses from user space. Kill task. 237*5a0015d6SChris Zankel * 238*5a0015d6SChris Zankel * If CONFIG_UNALIGNED_USER is not set, we don't allow unaligned memory 239*5a0015d6SChris Zankel * accesses causes from user space. 240*5a0015d6SChris Zankel */ 241*5a0015d6SChris Zankel 242*5a0015d6SChris Zankel #if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION 243*5a0015d6SChris Zankel #ifndef CONFIG_UNALIGNED_USER 244*5a0015d6SChris Zankel void 245*5a0015d6SChris Zankel do_unaligned_user (struct pt_regs *regs) 246*5a0015d6SChris Zankel { 247*5a0015d6SChris Zankel siginfo_t info; 248*5a0015d6SChris Zankel 249*5a0015d6SChris Zankel __die_if_kernel("Unhandled unaligned exception in kernel", 250*5a0015d6SChris Zankel regs, SIGKILL); 251*5a0015d6SChris Zankel 252*5a0015d6SChris Zankel current->thread.bad_vaddr = regs->excvaddr; 253*5a0015d6SChris Zankel current->thread.error_code = -3; 254*5a0015d6SChris Zankel printk("Unaligned memory access to %08lx in '%s' " 255*5a0015d6SChris Zankel "(pid = %d, pc = %#010lx)\n", 256*5a0015d6SChris Zankel regs->excvaddr, current->comm, current->pid, regs->pc); 257*5a0015d6SChris Zankel info.si_signo = SIGBUS; 258*5a0015d6SChris Zankel info.si_errno = 0; 259*5a0015d6SChris Zankel info.si_code = BUS_ADRALN; 260*5a0015d6SChris Zankel info.si_addr = (void *) regs->excvaddr; 261*5a0015d6SChris Zankel force_sig_info(SIGSEGV, &info, current); 262*5a0015d6SChris Zankel 263*5a0015d6SChris Zankel } 264*5a0015d6SChris Zankel #endif 265*5a0015d6SChris Zankel #endif 266*5a0015d6SChris Zankel 267*5a0015d6SChris Zankel void 268*5a0015d6SChris Zankel do_debug(struct pt_regs *regs) 269*5a0015d6SChris Zankel { 270*5a0015d6SChris Zankel #ifdef CONFIG_KGDB 271*5a0015d6SChris Zankel /* If remote debugging is configured AND enabled, we give control to 272*5a0015d6SChris Zankel * kgdb. Otherwise, we fall through, perhaps giving control to the 273*5a0015d6SChris Zankel * native debugger. 274*5a0015d6SChris Zankel */ 275*5a0015d6SChris Zankel 276*5a0015d6SChris Zankel if (gdb_enter) { 277*5a0015d6SChris Zankel extern void gdb_handle_exception(struct pt_regs *); 278*5a0015d6SChris Zankel gdb_handle_exception(regs); 279*5a0015d6SChris Zankel return_from_debug_flag = 1; 280*5a0015d6SChris Zankel return; 281*5a0015d6SChris Zankel } 282*5a0015d6SChris Zankel #endif 283*5a0015d6SChris Zankel 284*5a0015d6SChris Zankel __die_if_kernel("Breakpoint in kernel", regs, SIGKILL); 285*5a0015d6SChris Zankel 286*5a0015d6SChris Zankel /* If in user mode, send SIGTRAP signal to current process */ 287*5a0015d6SChris Zankel 288*5a0015d6SChris Zankel force_sig(SIGTRAP, current); 289*5a0015d6SChris Zankel } 290*5a0015d6SChris Zankel 291*5a0015d6SChris Zankel 292*5a0015d6SChris Zankel /* 293*5a0015d6SChris Zankel * Initialize dispatch tables. 294*5a0015d6SChris Zankel * 295*5a0015d6SChris Zankel * The exception vectors are stored compressed the __init section in the 296*5a0015d6SChris Zankel * dispatch_init_table. This function initializes the following three tables 297*5a0015d6SChris Zankel * from that compressed table: 298*5a0015d6SChris Zankel * - fast user first dispatch table for user exceptions 299*5a0015d6SChris Zankel * - fast kernel first dispatch table for kernel exceptions 300*5a0015d6SChris Zankel * - default C-handler C-handler called by the default fast handler. 301*5a0015d6SChris Zankel * 302*5a0015d6SChris Zankel * See vectors.S for more details. 303*5a0015d6SChris Zankel */ 304*5a0015d6SChris Zankel 305*5a0015d6SChris Zankel #define set_handler(idx,handler) (exc_table[idx] = (unsigned long) (handler)) 306*5a0015d6SChris Zankel 307*5a0015d6SChris Zankel void trap_init(void) 308*5a0015d6SChris Zankel { 309*5a0015d6SChris Zankel int i; 310*5a0015d6SChris Zankel 311*5a0015d6SChris Zankel /* Setup default vectors. */ 312*5a0015d6SChris Zankel 313*5a0015d6SChris Zankel for(i = 0; i < 64; i++) { 314*5a0015d6SChris Zankel set_handler(EXC_TABLE_FAST_USER/4 + i, user_exception); 315*5a0015d6SChris Zankel set_handler(EXC_TABLE_FAST_KERNEL/4 + i, kernel_exception); 316*5a0015d6SChris Zankel set_handler(EXC_TABLE_DEFAULT/4 + i, do_unhandled); 317*5a0015d6SChris Zankel } 318*5a0015d6SChris Zankel 319*5a0015d6SChris Zankel /* Setup specific handlers. */ 320*5a0015d6SChris Zankel 321*5a0015d6SChris Zankel for(i = 0; dispatch_init_table[i].cause >= 0; i++) { 322*5a0015d6SChris Zankel 323*5a0015d6SChris Zankel int fast = dispatch_init_table[i].fast; 324*5a0015d6SChris Zankel int cause = dispatch_init_table[i].cause; 325*5a0015d6SChris Zankel void *handler = dispatch_init_table[i].handler; 326*5a0015d6SChris Zankel 327*5a0015d6SChris Zankel if (fast == 0) 328*5a0015d6SChris Zankel set_handler (EXC_TABLE_DEFAULT/4 + cause, handler); 329*5a0015d6SChris Zankel if (fast && fast & USER) 330*5a0015d6SChris Zankel set_handler (EXC_TABLE_FAST_USER/4 + cause, handler); 331*5a0015d6SChris Zankel if (fast && fast & KRNL) 332*5a0015d6SChris Zankel set_handler (EXC_TABLE_FAST_KERNEL/4 + cause, handler); 333*5a0015d6SChris Zankel } 334*5a0015d6SChris Zankel 335*5a0015d6SChris Zankel /* Initialize EXCSAVE_1 to hold the address of the exception table. */ 336*5a0015d6SChris Zankel 337*5a0015d6SChris Zankel i = (unsigned long)exc_table; 338*5a0015d6SChris Zankel __asm__ __volatile__("wsr %0, "__stringify(EXCSAVE_1)"\n" : : "a" (i)); 339*5a0015d6SChris Zankel } 340*5a0015d6SChris Zankel 341*5a0015d6SChris Zankel /* 342*5a0015d6SChris Zankel * This function dumps the current valid window frame and other base registers. 343*5a0015d6SChris Zankel */ 344*5a0015d6SChris Zankel 345*5a0015d6SChris Zankel void show_regs(struct pt_regs * regs) 346*5a0015d6SChris Zankel { 347*5a0015d6SChris Zankel int i, wmask; 348*5a0015d6SChris Zankel 349*5a0015d6SChris Zankel wmask = regs->wmask & ~1; 350*5a0015d6SChris Zankel 351*5a0015d6SChris Zankel for (i = 0; i < 32; i++) { 352*5a0015d6SChris Zankel if (wmask & (1 << (i / 4))) 353*5a0015d6SChris Zankel break; 354*5a0015d6SChris Zankel if ((i % 8) == 0) 355*5a0015d6SChris Zankel printk ("\n" KERN_INFO "a%02d: ", i); 356*5a0015d6SChris Zankel printk("%08lx ", regs->areg[i]); 357*5a0015d6SChris Zankel } 358*5a0015d6SChris Zankel printk("\n"); 359*5a0015d6SChris Zankel 360*5a0015d6SChris Zankel printk("pc: %08lx, ps: %08lx, depc: %08lx, excvaddr: %08lx\n", 361*5a0015d6SChris Zankel regs->pc, regs->ps, regs->depc, regs->excvaddr); 362*5a0015d6SChris Zankel printk("lbeg: %08lx, lend: %08lx lcount: %08lx, sar: %08lx\n", 363*5a0015d6SChris Zankel regs->lbeg, regs->lend, regs->lcount, regs->sar); 364*5a0015d6SChris Zankel if (user_mode(regs)) 365*5a0015d6SChris Zankel printk("wb: %08lx, ws: %08lx, wmask: %08lx, syscall: %ld\n", 366*5a0015d6SChris Zankel regs->windowbase, regs->windowstart, regs->wmask, 367*5a0015d6SChris Zankel regs->syscall); 368*5a0015d6SChris Zankel } 369*5a0015d6SChris Zankel 370*5a0015d6SChris Zankel void show_trace(struct task_struct *task, unsigned long *sp) 371*5a0015d6SChris Zankel { 372*5a0015d6SChris Zankel unsigned long a0, a1, pc; 373*5a0015d6SChris Zankel unsigned long sp_start, sp_end; 374*5a0015d6SChris Zankel 375*5a0015d6SChris Zankel a1 = (unsigned long)sp; 376*5a0015d6SChris Zankel 377*5a0015d6SChris Zankel if (a1 == 0) 378*5a0015d6SChris Zankel __asm__ __volatile__ ("mov %0, a1\n" : "=a"(a1)); 379*5a0015d6SChris Zankel 380*5a0015d6SChris Zankel 381*5a0015d6SChris Zankel sp_start = a1 & ~(THREAD_SIZE-1); 382*5a0015d6SChris Zankel sp_end = sp_start + THREAD_SIZE; 383*5a0015d6SChris Zankel 384*5a0015d6SChris Zankel printk("Call Trace:"); 385*5a0015d6SChris Zankel #ifdef CONFIG_KALLSYMS 386*5a0015d6SChris Zankel printk("\n"); 387*5a0015d6SChris Zankel #endif 388*5a0015d6SChris Zankel spill_registers(); 389*5a0015d6SChris Zankel 390*5a0015d6SChris Zankel while (a1 > sp_start && a1 < sp_end) { 391*5a0015d6SChris Zankel sp = (unsigned long*)a1; 392*5a0015d6SChris Zankel 393*5a0015d6SChris Zankel a0 = *(sp - 4); 394*5a0015d6SChris Zankel a1 = *(sp - 3); 395*5a0015d6SChris Zankel 396*5a0015d6SChris Zankel if (a1 <= (unsigned long) sp) 397*5a0015d6SChris Zankel break; 398*5a0015d6SChris Zankel 399*5a0015d6SChris Zankel pc = MAKE_PC_FROM_RA(a0, a1); 400*5a0015d6SChris Zankel 401*5a0015d6SChris Zankel if (kernel_text_address(pc)) { 402*5a0015d6SChris Zankel printk(" [<%08lx>] ", pc); 403*5a0015d6SChris Zankel print_symbol("%s\n", pc); 404*5a0015d6SChris Zankel } 405*5a0015d6SChris Zankel } 406*5a0015d6SChris Zankel printk("\n"); 407*5a0015d6SChris Zankel } 408*5a0015d6SChris Zankel 409*5a0015d6SChris Zankel /* 410*5a0015d6SChris Zankel * This routine abuses get_user()/put_user() to reference pointers 411*5a0015d6SChris Zankel * with at least a bit of error checking ... 412*5a0015d6SChris Zankel */ 413*5a0015d6SChris Zankel 414*5a0015d6SChris Zankel static int kstack_depth_to_print = 24; 415*5a0015d6SChris Zankel 416*5a0015d6SChris Zankel void show_stack(struct task_struct *task, unsigned long *sp) 417*5a0015d6SChris Zankel { 418*5a0015d6SChris Zankel int i = 0; 419*5a0015d6SChris Zankel unsigned long *stack; 420*5a0015d6SChris Zankel 421*5a0015d6SChris Zankel if (sp == 0) 422*5a0015d6SChris Zankel __asm__ __volatile__ ("mov %0, a1\n" : "=a"(sp)); 423*5a0015d6SChris Zankel 424*5a0015d6SChris Zankel stack = sp; 425*5a0015d6SChris Zankel 426*5a0015d6SChris Zankel printk("\nStack: "); 427*5a0015d6SChris Zankel 428*5a0015d6SChris Zankel for (i = 0; i < kstack_depth_to_print; i++) { 429*5a0015d6SChris Zankel if (kstack_end(sp)) 430*5a0015d6SChris Zankel break; 431*5a0015d6SChris Zankel if (i && ((i % 8) == 0)) 432*5a0015d6SChris Zankel printk("\n "); 433*5a0015d6SChris Zankel printk("%08lx ", *sp++); 434*5a0015d6SChris Zankel } 435*5a0015d6SChris Zankel printk("\n"); 436*5a0015d6SChris Zankel show_trace(task, stack); 437*5a0015d6SChris Zankel } 438*5a0015d6SChris Zankel 439*5a0015d6SChris Zankel void dump_stack(void) 440*5a0015d6SChris Zankel { 441*5a0015d6SChris Zankel show_stack(current, NULL); 442*5a0015d6SChris Zankel } 443*5a0015d6SChris Zankel 444*5a0015d6SChris Zankel EXPORT_SYMBOL(dump_stack); 445*5a0015d6SChris Zankel 446*5a0015d6SChris Zankel 447*5a0015d6SChris Zankel void show_code(unsigned int *pc) 448*5a0015d6SChris Zankel { 449*5a0015d6SChris Zankel long i; 450*5a0015d6SChris Zankel 451*5a0015d6SChris Zankel printk("\nCode:"); 452*5a0015d6SChris Zankel 453*5a0015d6SChris Zankel for(i = -3 ; i < 6 ; i++) { 454*5a0015d6SChris Zankel unsigned long insn; 455*5a0015d6SChris Zankel if (__get_user(insn, pc + i)) { 456*5a0015d6SChris Zankel printk(" (Bad address in pc)\n"); 457*5a0015d6SChris Zankel break; 458*5a0015d6SChris Zankel } 459*5a0015d6SChris Zankel printk("%c%08lx%c",(i?' ':'<'),insn,(i?' ':'>')); 460*5a0015d6SChris Zankel } 461*5a0015d6SChris Zankel } 462*5a0015d6SChris Zankel 463*5a0015d6SChris Zankel spinlock_t die_lock = SPIN_LOCK_UNLOCKED; 464*5a0015d6SChris Zankel 465*5a0015d6SChris Zankel void die(const char * str, struct pt_regs * regs, long err) 466*5a0015d6SChris Zankel { 467*5a0015d6SChris Zankel static int die_counter; 468*5a0015d6SChris Zankel int nl = 0; 469*5a0015d6SChris Zankel 470*5a0015d6SChris Zankel console_verbose(); 471*5a0015d6SChris Zankel spin_lock_irq(&die_lock); 472*5a0015d6SChris Zankel 473*5a0015d6SChris Zankel printk("%s: sig: %ld [#%d]\n", str, err, ++die_counter); 474*5a0015d6SChris Zankel #ifdef CONFIG_PREEMPT 475*5a0015d6SChris Zankel printk("PREEMPT "); 476*5a0015d6SChris Zankel nl = 1; 477*5a0015d6SChris Zankel #endif 478*5a0015d6SChris Zankel if (nl) 479*5a0015d6SChris Zankel printk("\n"); 480*5a0015d6SChris Zankel show_regs(regs); 481*5a0015d6SChris Zankel if (!user_mode(regs)) 482*5a0015d6SChris Zankel show_stack(NULL, (unsigned long*)regs->areg[1]); 483*5a0015d6SChris Zankel 484*5a0015d6SChris Zankel spin_unlock_irq(&die_lock); 485*5a0015d6SChris Zankel 486*5a0015d6SChris Zankel if (in_interrupt()) 487*5a0015d6SChris Zankel panic("Fatal exception in interrupt"); 488*5a0015d6SChris Zankel 489*5a0015d6SChris Zankel if (panic_on_oops) { 490*5a0015d6SChris Zankel printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n"); 491*5a0015d6SChris Zankel set_current_state(TASK_UNINTERRUPTIBLE); 492*5a0015d6SChris Zankel schedule_timeout(5 * HZ); 493*5a0015d6SChris Zankel panic("Fatal exception"); 494*5a0015d6SChris Zankel } 495*5a0015d6SChris Zankel do_exit(err); 496*5a0015d6SChris Zankel } 497*5a0015d6SChris Zankel 498*5a0015d6SChris Zankel 499