Revert "misc cleanup"
[rpi-open-firmware.git] / arm_chainloader / trap.cc
1 /*
2 * trap.cc
3 * Copyright (c) 2017 Kristina Brooks
4 *
5 * ARM trap handling code.
6 */
7
8 #include <lib/runtime.h>
9
10 struct arm_saved_state {
11 uint32_t r[13]; /* General purpose register r0-r12 */
12 uint32_t sp; /* Stack pointer r13 */
13 uint32_t lr; /* Link register r14 */
14 uint32_t pc; /* Program counter r15 */
15 uint32_t cpsr; /* Current program status register */
16 uint32_t fsr; /* Fault status */
17 uint32_t far; /* Virtual Fault Address */
18 uint32_t exception; /* exception number */
19 };
20 typedef struct arm_saved_state arm_saved_state_t;
21
22 #define REGISTER_FORMAT_STRING(prefix) \
23 prefix " r0: 0x%08x r1: 0x%08x r2: 0x%08x r3: 0x%08x\n" \
24 prefix " r4: 0x%08x r5: 0x%08x r6: 0x%08x r7: 0x%08x\n" \
25 prefix " r8: 0x%08x r9: 0x%08x r10: 0x%08x r11: 0x%08x\n" \
26 prefix " r12: 0x%08x sp: 0x%08x lr: 0x%08x pc: 0x%08x\n" \
27 prefix "cpsr: 0x%08x\n"
28
29 #define REGISTER_PRINTF_LIST(regs) regs->r[0], regs->r[1], regs->r[2], regs->r[3],\
30 regs->r[4], regs->r[5], regs->r[6], regs->r[7], \
31 regs->r[8], regs->r[9], regs->r[10], regs->r[11], \
32 regs->r[12], regs->sp, regs->lr, regs->pc, regs->cpsr
33
34 extern "C" void fatal_exception(arm_saved_state_t* regs, const char* fmt, ...)
35 {
36 va_list va;
37
38 printf("Fatal Exception: ");
39 va_start(va, fmt);
40 vprintf(fmt, va);
41 va_end(va);
42 printf("\n");
43
44 printf("ARM registers: \n");
45 printf(REGISTER_FORMAT_STRING(" "), REGISTER_PRINTF_LIST(regs));
46
47 panic("Fatal CPU exception!");
48 }
49
50 extern "C" void sleh_undef(arm_saved_state_t* regs) {
51 fatal_exception(regs, "Undefined instruction");
52 }
53
54 extern "C" void sleh_prefabt(arm_saved_state_t* regs) {
55 fatal_exception(regs, "Prefetch abort");
56 }
57
58 extern "C" void sleh_dataabt(arm_saved_state_t* regs) {
59 fatal_exception(regs, "Data abort");
60 }
61 extern "C" void sleh_addrexc(arm_saved_state_t* regs) {
62 fatal_exception(regs, "Address exception");
63 }
64
65 extern "C" void sleh_irq(arm_saved_state_t* regs) {
66 fatal_exception(regs, "IRQ");
67 }
68
69 extern "C" void sleh_fiq(arm_saved_state_t* regs) {
70 fatal_exception(regs, "FIQ");
71 }
This page took 0.074711 seconds and 4 git commands to generate.