1 /* SPDX-License-Identifier: BSD-3-Clause */
4 #include <arch/cache.h>
5 #include <arch/exception.h>
6 #include <console/console.h>
8 uint8_t exception_stack
[0x100] __aligned(8);
9 extern void *exception_stack_end
;
11 void exception_undefined_instruction(uint32_t *regs
);
12 void exception_software_interrupt(uint32_t *regs
);
13 void exception_prefetch_abort(uint32_t *regs
);
14 void exception_data_abort(uint32_t *regs
);
15 void exception_not_used(uint32_t *regs
);
16 void exception_irq(uint32_t *regs
);
17 void exception_fiq(uint32_t *regs
);
19 static void dump_stack(uintptr_t addr
, size_t bytes
)
23 uint32_t *ptr
= (uint32_t *)(addr
& ~(line
* sizeof(*ptr
) - 1));
25 printk(BIOS_ERR
, "Dumping stack:\n");
26 for (i
= bytes
/ sizeof(*ptr
); i
>= 0; i
-= line
) {
27 printk(BIOS_ERR
, "%p: ", ptr
+ i
);
28 for (j
= i
; j
< i
+ line
; j
++)
29 printk(BIOS_ERR
, "%08x ", *(ptr
+ j
));
30 printk(BIOS_ERR
, "\n");
34 static void print_regs(uint32_t *regs
)
38 for (i
= 0; i
< 16; i
++) {
40 printk(BIOS_ERR
, "PC");
42 printk(BIOS_ERR
, "LR");
44 printk(BIOS_ERR
, "SP");
46 printk(BIOS_ERR
, "IP");
48 printk(BIOS_ERR
, "R%d", i
);
49 printk(BIOS_ERR
, " = 0x%08x\n", regs
[i
]);
53 void exception_undefined_instruction(uint32_t *regs
)
55 printk(BIOS_ERR
, "exception _undefined_instruction\n");
56 regs
[15] -= 2; /* CAREFUL: specific to thumb mode (otherwise 4)! */
58 dump_stack(regs
[13], 512);
62 void exception_software_interrupt(uint32_t *regs
)
64 printk(BIOS_ERR
, "exception _software_interrupt\n");
66 dump_stack(regs
[13], 512);
70 void exception_prefetch_abort(uint32_t *regs
)
72 printk(BIOS_ERR
, "exception _prefetch_abort\n");
75 printk(BIOS_ERR
, "IFAR = %#.8x\n", read_ifar());
76 printk(BIOS_ERR
, "IFSR = %#.8x\n", read_ifsr());
77 printk(BIOS_ERR
, "AIFSR = %#.8x\n", read_aifsr());
78 dump_stack(regs
[13], 512);
82 void exception_data_abort(uint32_t *regs
)
84 printk(BIOS_ERR
, "exception _data_abort\n");
87 printk(BIOS_ERR
, "DFAR = %#.8x\n", read_dfar());
88 printk(BIOS_ERR
, "DFSR = %#.8x\n", read_dfsr());
89 printk(BIOS_ERR
, "ADFSR = %#.8x\n", read_adfsr());
90 dump_stack(regs
[13], 512);
94 void exception_not_used(uint32_t *regs
)
96 printk(BIOS_ERR
, "exception _not_used\n");
98 dump_stack(regs
[13], 512);
102 void exception_irq(uint32_t *regs
)
104 printk(BIOS_ERR
, "exception _irq\n");
107 dump_stack(regs
[13], 512);
111 void exception_fiq(uint32_t *regs
)
113 printk(BIOS_ERR
, "exception _fiq\n");
116 dump_stack(regs
[13], 512);
120 void exception_init(void)
122 uint32_t sctlr
= read_sctlr();
123 /* Handle exceptions in ARM mode. */
125 /* Set V=0 in SCTLR so VBAR points to the exception vector table. */
127 /* Enforce alignment temporarily. */
130 extern uint32_t exception_table
[];
131 set_vbar((uintptr_t)exception_table
);
132 exception_stack_end
= exception_stack
+ sizeof(exception_stack
);
134 printk(BIOS_DEBUG
, "Exception handlers installed.\n");