blob: 646af00f3b4e0ae353cd7e1c4d101eea6a58b0cc [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2015 Stefan Kristiansson
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/or1k.h>
25#include <kernel/thread.h>
26#include <platform.h>
27
28static void dump_fault_frame(struct or1k_iframe *frame)
29{
30 addr_t stack = (addr_t)((char *)frame + 128 + sizeof(frame));
31
32 dprintf(CRITICAL, "r0: 0x%08x r1: 0x%08x: r2: 0x%08x r3: 0x%08x\n",
33 0, (uint32_t)stack, frame->r2, frame->r3);
34 dprintf(CRITICAL, "r4: 0x%08x r5: 0x%08x: r6: 0x%08x r7: 0x%08x\n",
35 frame->r4, frame->r5, frame->r6, frame->r7);
36 dprintf(CRITICAL, "r8: 0x%08x r9: 0x%08x: r10: 0x%08x r11: 0x%08x\n",
37 frame->r8, frame->r9, frame->r10, frame->r11);
38 dprintf(CRITICAL, "r12: 0x%08x r13: 0x%08x: r14: 0x%08x r15: 0x%08x\n",
39 frame->r12, frame->r13, frame->r14, frame->r15);
40 dprintf(CRITICAL, "r16: 0x%08x r17: 0x%08x: r18: 0x%08x r19: 0x%08x\n",
41 frame->r16, frame->r17, frame->r18, frame->r19);
42 dprintf(CRITICAL, "r20: 0x%08x r21: 0x%08x: r22: 0x%08x r23: 0x%08x\n",
43 frame->r20, frame->r21, frame->r22, frame->r23);
44 dprintf(CRITICAL, "r24: 0x%08x r25: 0x%08x: r26: 0x%08x r27: 0x%08x\n",
45 frame->r24, frame->r25, frame->r26, frame->r27);
46 dprintf(CRITICAL, "r28: 0x%08x r29: 0x%08x: r30: 0x%08x r31: 0x%08x\n",
47 frame->r28, frame->r29, frame->r30, frame->r31);
48 dprintf(CRITICAL, "PC: 0x%08x SR: 0x%08x\n",
49 frame->pc, frame->sr);
50
51 dprintf(CRITICAL, "bottom of stack at 0x%08x:\n", (unsigned int)stack);
52 hexdump((void *)stack, 128);
53
54}
55
56static void exception_die(struct or1k_iframe *frame, const char *msg)
57{
58 dprintf(CRITICAL, msg);
59 dump_fault_frame(frame);
60
61 platform_halt(HALT_ACTION_HALT, HALT_REASON_SW_PANIC);
62 for (;;);
63}
64
65void or1k_busfault_handler(struct or1k_iframe *frame, uint32_t addr)
66{
67 dprintf(CRITICAL, "unhandled busfault (EEAR: 0x%08x)", addr);
68 exception_die(frame, ", halting\n");
69}
70
71void or1k_data_pagefault_handler(struct or1k_iframe *frame, uint32_t addr)
72{
73 dprintf(CRITICAL, "unhandled data pagefault (EEAR: 0x%08x)", addr);
74 exception_die(frame, ", halting\n");
75}
76
77void or1k_instruction_pagefault_handler(struct or1k_iframe *frame, uint32_t addr)
78{
79 dprintf(CRITICAL, "unhandled instruction pagefault (EEAR: 0x%08x)", addr);
80 exception_die(frame, ", halting\n");
81}
82
83void or1k_alignment_handler(struct or1k_iframe *frame, uint32_t addr)
84{
85 dprintf(CRITICAL, "unhandled unaligned access (EEAR: 0x%08x)", addr);
86 exception_die(frame, ", halting\n");
87}
88
89void or1k_illegal_instruction_handler(struct or1k_iframe *frame, uint32_t addr)
90{
91 dprintf(CRITICAL, "unhandled illegal instruction (EEAR: 0x%08x)", addr);
92 exception_die(frame, ", halting\n");
93}
94
95void or1k_syscall_handler(struct or1k_iframe *frame)
96{
97 exception_die(frame, "unhandled syscall, halting\n");
98}
99
100void or1k_unhandled_exception(struct or1k_iframe *frame, uint32_t vector)
101{
102 dprintf(CRITICAL, "unhandled exception (vector: 0x%08x)", vector);
103 exception_die(frame, ", halting\n");
104}