-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexceptions.c
75 lines (65 loc) · 1.54 KB
/
exceptions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "interrupts.h"
#include "uart.h"
void halt(void)
{
uart_print("System halted.\r\n");
for (;;);
}
#pragma GCC push_options
#pragma GCC optimize "-fno-stack-protector"
static inline void stack_dump(uint32_t *stack)
{
uart_print("Dump from "); uart_print_uint32((uint32_t)stack);
for (int i = 0; i < 16; ++i) {
uart_print("\r\nSP+");uart_print_uint8(i);
uart_print(" [");uart_print_uint32((uint32_t)&stack[i]);
uart_print("] ");
uart_print_uint32(stack[i]);
}
uart_print("\r\n");
}
void __wrap___stack_chk_fail(void)
{
register uint32_t *reg_sp asm("sp");
register uint32_t *reg_lr asm("lr");
uint32_t *saved_sp = reg_sp;
uint32_t *saved_lr = reg_lr;
uart_print("stack check failed\r\n");
uart_print("LR ");
uart_print_uint32((uint32_t)saved_lr);
uart_print("\r\n");
stack_dump(saved_sp);
halt();
}
#pragma GCC pop_options
void __attribute__((interrupt("UNDEF"))) except_undef(void)
{
register uint32_t *reg_sp asm("sp");
uint32_t *saved_sp = reg_sp;
uart_print("undefined instruction");
stack_dump(saved_sp);
halt();
}
void __attribute__((interrupt("SWI"))) except_swi(void)
{
register uint32_t *reg_sp asm("sp");
uint32_t *saved_sp = reg_sp;
uart_print("SWI");
stack_dump(saved_sp);
halt();
}
void __attribute__((interrupt("ABORT"))) except_prefetch_abort(void)
{
uart_print("prefetch abort\r\n");
halt();
}
void __attribute__((interrupt("ABORT"))) except_data_abort(void)
{
asm("cps #0x13; cpsie if");
hook_data_abort();
}
void __attribute__((interrupt("FIQ"))) except_fiq(void)
{
uart_print("FIQ\r\n");
halt();
}