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