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

wirehaze git hosting

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