1 #include <stdint.h>
2
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 extern void _start();
8 extern void* __StackTop;
9
HardFaultHandler()10 static void HardFaultHandler()
11 {
12 uint32_t args[3];
13 args[0] = 2;
14 args[1] = (uint32_t)"HARDFAULT";
15 args[2] = 9;
16
17 asm("mov r0, #5\n"
18 "mov r1, %0\n"
19 "bkpt 0x00ab" : : "r"(args) : "r0", "r1", "memory");
20 asm("mov r12, %0\n" "mov r0, #24\n" "bkpt 0x00ab" : : "r"(0xDEADBEEF) : "r0");
21 while(1);
22 }
23
24 void* const g_vector_table[16] __attribute__((section(".isr_vector"))) = {
25 (void*)&__StackTop,
26 (void*)&_start,
27 (void*)&HardFaultHandler,
28 (void*)&HardFaultHandler,
29 (void*)&HardFaultHandler,
30 (void*)&HardFaultHandler,
31 (void*)&HardFaultHandler,
32 };
33
34
35 void ramboot() __attribute__((noreturn, naked, section(".ramboot")));
ramboot()36 void ramboot()
37 {
38 *(const void**)0xE000ED08 = g_vector_table; // SCB->VTOR
39 __asm__(
40 "msr msp, %0\n\t"
41 "bx %1" : : "r" (g_vector_table[0]),
42 "r" (g_vector_table[1]) : "memory");
43 }
44
45 #ifdef __cplusplus
46 }
47 #endif
48