1 /*
2 * Copyright (c) 2015 Stefan Kristiansson
3 *
4 * Use of this source code is governed by a MIT-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/MIT
7 */
8 #include <lk/debug.h>
9 #include <arch/or1k.h>
10 #include <kernel/thread.h>
11 #include <platform.h>
12
dump_fault_frame(struct or1k_iframe * frame)13 static void dump_fault_frame(struct or1k_iframe *frame) {
14 addr_t stack = (addr_t)((char *)frame + 128 + sizeof(frame));
15
16 dprintf(CRITICAL, "r0: 0x%08x r1: 0x%08x: r2: 0x%08x r3: 0x%08x\n",
17 0, (uint32_t)stack, frame->r2, frame->r3);
18 dprintf(CRITICAL, "r4: 0x%08x r5: 0x%08x: r6: 0x%08x r7: 0x%08x\n",
19 frame->r4, frame->r5, frame->r6, frame->r7);
20 dprintf(CRITICAL, "r8: 0x%08x r9: 0x%08x: r10: 0x%08x r11: 0x%08x\n",
21 frame->r8, frame->r9, frame->r10, frame->r11);
22 dprintf(CRITICAL, "r12: 0x%08x r13: 0x%08x: r14: 0x%08x r15: 0x%08x\n",
23 frame->r12, frame->r13, frame->r14, frame->r15);
24 dprintf(CRITICAL, "r16: 0x%08x r17: 0x%08x: r18: 0x%08x r19: 0x%08x\n",
25 frame->r16, frame->r17, frame->r18, frame->r19);
26 dprintf(CRITICAL, "r20: 0x%08x r21: 0x%08x: r22: 0x%08x r23: 0x%08x\n",
27 frame->r20, frame->r21, frame->r22, frame->r23);
28 dprintf(CRITICAL, "r24: 0x%08x r25: 0x%08x: r26: 0x%08x r27: 0x%08x\n",
29 frame->r24, frame->r25, frame->r26, frame->r27);
30 dprintf(CRITICAL, "r28: 0x%08x r29: 0x%08x: r30: 0x%08x r31: 0x%08x\n",
31 frame->r28, frame->r29, frame->r30, frame->r31);
32 dprintf(CRITICAL, "PC: 0x%08x SR: 0x%08x\n",
33 frame->pc, frame->sr);
34
35 dprintf(CRITICAL, "bottom of stack at 0x%08x:\n", (unsigned int)stack);
36 hexdump((void *)stack, 128);
37
38 }
39
exception_die(struct or1k_iframe * frame,const char * msg)40 static void exception_die(struct or1k_iframe *frame, const char *msg) {
41 dprintf(CRITICAL, msg);
42 dump_fault_frame(frame);
43
44 platform_halt(HALT_ACTION_HALT, HALT_REASON_SW_PANIC);
45 for (;;);
46 }
47
or1k_busfault_handler(struct or1k_iframe * frame,uint32_t addr)48 void or1k_busfault_handler(struct or1k_iframe *frame, uint32_t addr) {
49 dprintf(CRITICAL, "unhandled busfault (EEAR: 0x%08x)", addr);
50 exception_die(frame, ", halting\n");
51 }
52
or1k_data_pagefault_handler(struct or1k_iframe * frame,uint32_t addr)53 void or1k_data_pagefault_handler(struct or1k_iframe *frame, uint32_t addr) {
54 dprintf(CRITICAL, "unhandled data pagefault (EEAR: 0x%08x)", addr);
55 exception_die(frame, ", halting\n");
56 }
57
or1k_instruction_pagefault_handler(struct or1k_iframe * frame,uint32_t addr)58 void or1k_instruction_pagefault_handler(struct or1k_iframe *frame, uint32_t addr) {
59 dprintf(CRITICAL, "unhandled instruction pagefault (EEAR: 0x%08x)", addr);
60 exception_die(frame, ", halting\n");
61 }
62
or1k_alignment_handler(struct or1k_iframe * frame,uint32_t addr)63 void or1k_alignment_handler(struct or1k_iframe *frame, uint32_t addr) {
64 dprintf(CRITICAL, "unhandled unaligned access (EEAR: 0x%08x)", addr);
65 exception_die(frame, ", halting\n");
66 }
67
or1k_illegal_instruction_handler(struct or1k_iframe * frame,uint32_t addr)68 void or1k_illegal_instruction_handler(struct or1k_iframe *frame, uint32_t addr) {
69 dprintf(CRITICAL, "unhandled illegal instruction (EEAR: 0x%08x)", addr);
70 exception_die(frame, ", halting\n");
71 }
72
or1k_syscall_handler(struct or1k_iframe * frame)73 void or1k_syscall_handler(struct or1k_iframe *frame) {
74 exception_die(frame, "unhandled syscall, halting\n");
75 }
76
or1k_unhandled_exception(struct or1k_iframe * frame,uint32_t vector)77 void or1k_unhandled_exception(struct or1k_iframe *frame, uint32_t vector) {
78 dprintf(CRITICAL, "unhandled exception (vector: 0x%08x)", vector);
79 exception_die(frame, ", halting\n");
80 }
81