Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <debug.h> |
| 24 | #include <arch/arm.h> |
| 25 | #include <kernel/thread.h> |
| 26 | |
| 27 | static void dump_fault_frame(struct arm_fault_frame *frame) |
| 28 | { |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 29 | dprintf(CRITICAL, "r0 0x%08x r1 0x%08x r2 0x%08x r3 0x%08x\n", frame->r[0], frame->r[1], frame->r[2], frame->r[3]); |
| 30 | dprintf(CRITICAL, "r4 0x%08x r5 0x%08x r6 0x%08x r7 0x%08x\n", frame->r[4], frame->r[5], frame->r[6], frame->r[7]); |
| 31 | dprintf(CRITICAL, "r8 0x%08x r9 0x%08x r10 0x%08x r11 0x%08x\n", frame->r[8], frame->r[9], frame->r[10], frame->r[11]); |
| 32 | dprintf(CRITICAL, "r12 0x%08x usp 0x%08x ulr 0x%08x pc 0x%08x\n", frame->r[12], frame->usp, frame->ulr, frame->pc); |
| 33 | dprintf(CRITICAL, "spsr 0x%08x\n", frame->spsr); |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 34 | |
| 35 | struct arm_mode_regs regs; |
| 36 | arm_save_mode_regs(®s); |
| 37 | |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 38 | dprintf(CRITICAL, "%c%s r13 0x%08x r14 0x%08x\n", ((frame->spsr & MODE_MASK) == MODE_FIQ) ? '*' : ' ', "fiq", regs.fiq_r13, regs.fiq_r14); |
| 39 | dprintf(CRITICAL, "%c%s r13 0x%08x r14 0x%08x\n", ((frame->spsr & MODE_MASK) == MODE_IRQ) ? '*' : ' ', "irq", regs.irq_r13, regs.irq_r14); |
| 40 | dprintf(CRITICAL, "%c%s r13 0x%08x r14 0x%08x\n", ((frame->spsr & MODE_MASK) == MODE_SVC) ? '*' : ' ', "svc", regs.svc_r13, regs.svc_r14); |
| 41 | dprintf(CRITICAL, "%c%s r13 0x%08x r14 0x%08x\n", ((frame->spsr & MODE_MASK) == MODE_UND) ? '*' : ' ', "und", regs.und_r13, regs.und_r14); |
| 42 | dprintf(CRITICAL, "%c%s r13 0x%08x r14 0x%08x\n", ((frame->spsr & MODE_MASK) == MODE_SYS) ? '*' : ' ', "sys", regs.sys_r13, regs.sys_r14); |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 43 | |
| 44 | // dump the bottom of the current stack |
| 45 | addr_t stack; |
| 46 | switch (frame->spsr & MODE_MASK) { |
| 47 | case MODE_FIQ: stack = regs.fiq_r13; break; |
| 48 | case MODE_IRQ: stack = regs.irq_r13; break; |
| 49 | case MODE_SVC: stack = regs.svc_r13; break; |
| 50 | case MODE_UND: stack = regs.und_r13; break; |
| 51 | case MODE_SYS: stack = regs.sys_r13; break; |
| 52 | default: |
| 53 | stack = 0; |
| 54 | } |
| 55 | |
| 56 | if (stack != 0) { |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 57 | dprintf(CRITICAL, "bottom of stack at 0x%08x:\n", (unsigned int)stack); |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 58 | hexdump((void *)stack, 128); |
| 59 | } |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static void exception_die(struct arm_fault_frame *frame, int pc_off, const char *msg) |
| 63 | { |
| 64 | inc_critical_section(); |
| 65 | frame->pc += pc_off; |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 66 | dprintf(CRITICAL, msg); |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 67 | dump_fault_frame(frame); |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 68 | |
| 69 | halt(); |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 70 | for(;;); |
| 71 | } |
| 72 | |
| 73 | void arm_syscall_handler(struct arm_fault_frame *frame) |
| 74 | { |
| 75 | exception_die(frame, -4, "unhandled syscall, halting\n"); |
| 76 | } |
| 77 | |
| 78 | void arm_undefined_handler(struct arm_fault_frame *frame) |
| 79 | { |
| 80 | exception_die(frame, -4, "undefined abort, halting\n"); |
| 81 | } |
| 82 | |
| 83 | void arm_data_abort_handler(struct arm_fault_frame *frame) |
| 84 | { |
| 85 | exception_die(frame, -8, "data abort, halting\n"); |
| 86 | } |
| 87 | |
| 88 | void arm_prefetch_abort_handler(struct arm_fault_frame *frame) |
| 89 | { |
| 90 | exception_die(frame, -4, "prefetch abort, halting\n"); |
| 91 | } |