aboutsummaryrefslogtreecommitdiff
path: root/system-clock/src/isr_vector.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2018-01-15 15:26:48 -0700
committerJosh Rahm <joshuarahm@gmail.com>2018-01-15 15:26:48 -0700
commite8126528825cb1bd01684f5bd6011fc7ae84bfe5 (patch)
treeacdd2a09be1f0950911d23c0502edbbc8b4d2d23 /system-clock/src/isr_vector.c
parent3b7d25e1586082a7c5d0066a56d80f7c55862e38 (diff)
downloadstm32l4-e8126528825cb1bd01684f5bd6011fc7ae84bfe5.tar.gz
stm32l4-e8126528825cb1bd01684f5bd6011fc7ae84bfe5.tar.bz2
stm32l4-e8126528825cb1bd01684f5bd6011fc7ae84bfe5.zip
added init routine that loads the data and bss sections into memory before executing main.
Diffstat (limited to 'system-clock/src/isr_vector.c')
-rw-r--r--system-clock/src/isr_vector.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/system-clock/src/isr_vector.c b/system-clock/src/isr_vector.c
index a56a8dc..b432732 100644
--- a/system-clock/src/isr_vector.c
+++ b/system-clock/src/isr_vector.c
@@ -5,9 +5,46 @@
/* Forward-declare the main function. This is implemented in main.c. */
void main();
+
+/* These are defined in the linker script. */
+extern uint8_t INIT_DATA_VALUES;
+extern uint8_t DATA_SEGMENT_START;
+extern uint8_t DATA_SEGMENT_STOP;
+extern uint8_t BSS_START;
+extern uint8_t BSS_END;
+
+
+/*
+ * Runs before main. Initializes the data and bss segments by loading them
+ * into memory.
+ */
+void init()
+{
+ uint8_t* src;
+ uint8_t* dest;
+
+ src = &INIT_DATA_VALUES;
+ dest = &DATA_SEGMENT_START;
+
+ /* Copy the values from flash into the data segment. */
+ while (dest != &DATA_SEGMENT_STOP) {
+ *(dest ++) = *(src ++);
+ }
+
+ /* Everything in the BSS segment is set to zero. */
+ dest = &BSS_START;
+ while (dest != &BSS_END) {
+ *(dest ++) = 0;
+ }
+
+
+ /* Jump to main. */
+ main();
+}
+
const void* vectors[] __attribute__((section(".vectors"))) = {
(void *) 0x2000c000, /* Top of stack at top of sram1. 48k */
- main, /* Reset handler */
+ init, /* Reset handler */
unhandled_isr, /* NMI */
unhandled_isr, /* Hard Fault */
unhandled_isr, /* MemManage */