]> wirehaze git hosting - stm32f411ceu6.git/blob - sys/core/exceptions.c

wirehaze git hosting

panic ()
[stm32f411ceu6.git] / sys / core / exceptions.c
1 #include "sysclk.h"
2 #include <link.h>
3 #include <led.h>
4 #include <uart.h>
5 #include <panic.h>
6
7 /* Initialize just enough to be able to handle a fault. */
8 __attribute__ ((noinline, used)) static void
9 sys_init (void)
10 {
11 unsigned int *src, *dst;
12
13 /* Relocate .data section to SRAM */
14 src = &_data_lma_start;
15 dst = &_data_vma_start;
16
17 while (dst < &_data_vma_end)
18 *(dst++) = *(src++);
19
20 /* Initialize .bss */
21 dst = &_bss_vma_start;
22
23 while (dst < &_bss_vma_end)
24 *(dst++) = 0;
25
26 led_init ();
27 sysclk_init ();
28 uart_init ();
29 }
30
31 /* Startup */
32 __attribute__ ((naked, noreturn)) static void
33 reset_handler (void)
34 {
35 /* Set FAULTMASK */
36 asm ("cpsid f");
37
38 /* This function is the core logic for reset_handler (). We just need it so
39 * that when we jump to kentry the stack is empty. */
40 asm ("bl sys_init");
41
42 /* Clear FAULTMASK */
43 asm ("cpsie f");
44
45 /* Jump to kernel entry code. When reset_handler () is called we are already
46 * running on Thread mode (Privileged), so we can just jump directly. */
47 asm ("b kentry");
48 }
49
50 /* TODO write proper exception handlers, this is just a test */
51 __attribute__ ((noreturn)) static void
52 fault_handler (void)
53 {
54 panic ("Fault");
55 }
56
57 __attribute__ ((section (".vector_table"), used))
58 static unsigned long const vector_table[] = {
59 [0] = (unsigned long) &_sram_end,
60 [1] = (unsigned long) reset_handler,
61 [3] = (unsigned long) fault_handler, /* ??? */
62 [6] = (unsigned long) fault_handler,
63 };