diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-01-04 23:53:44 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-01-04 23:53:44 +0100 |
commit | ec96951943921b57ef9c1e9dacb63e34716fe5b7 (patch) | |
tree | c85d1c0a063712459ad12144900eb522b39ef7a0 /playground | |
parent | baedda497d16c5096971eee83a0c467fe663fe6d (diff) | |
download | stm32f103-playground-ec96951943921b57ef9c1e9dacb63e34716fe5b7.tar.gz stm32f103-playground-ec96951943921b57ef9c1e9dacb63e34716fe5b7.tar.bz2 stm32f103-playground-ec96951943921b57ef9c1e9dacb63e34716fe5b7.tar.xz stm32f103-playground-ec96951943921b57ef9c1e9dacb63e34716fe5b7.zip |
o Actually working implementation of context switching.
It is important to remember to update the stack to the task descriptor on every switch!
Diffstat (limited to 'playground')
-rw-r--r-- | playground/include/init_high.h | 7 | ||||
-rw-r--r-- | playground/include/playground.h | 14 | ||||
-rw-r--r-- | playground/src/init_high.cpp | 52 | ||||
-rw-r--r-- | playground/src/init_low.s | 5 |
4 files changed, 59 insertions, 19 deletions
diff --git a/playground/include/init_high.h b/playground/include/init_high.h index c6da514..7b1d555 100644 --- a/playground/include/init_high.h +++ b/playground/include/init_high.h @@ -3,13 +3,6 @@ extern "C" { -void init_high(); - -/** - * Declare all the interrupt/event handlers as weak symbols and make them aliases of the default handler. - */ -extern void Default_Handler() __attribute__((weak)); - extern void _Reset_Handler(); extern void NMI_Handler(); diff --git a/playground/include/playground.h b/playground/include/playground.h index c224908..3ccfeeb 100644 --- a/playground/include/playground.h +++ b/playground/include/playground.h @@ -1,10 +1,20 @@ #ifndef PLAYGROUND_H #define PLAYGROUND_H -extern "C" void halt(); +extern "C" +void halt(); + +extern "C" +void init_high(); + +extern "C" +int main(); + +extern "C" +void Default_Handler(); template<typename T, size_t N> -static inline +static inline constexpr size_t SizeOfArray(const T(&)[N]) { return N; } diff --git a/playground/src/init_high.cpp b/playground/src/init_high.cpp index 700d17a..b877b7d 100644 --- a/playground/src/init_high.cpp +++ b/playground/src/init_high.cpp @@ -8,26 +8,60 @@ /** * Symbols that are defined by the linker */ +extern "C" +{ extern uint32_t _copy_data_load, _copy_data_store, _copy_data_store_end; extern uint32_t _bss_start, _bss_end; -extern int main(); +typedef void(*constructor_t)(); +extern constructor_t _init_array_start[], _init_array_end[]; +} + +extern "C" +void *memset(void *dst, int i, size_t n) { + if (n) { + char *d = (char *) dst; + char c = (char) i; + + do { + *d = c; + d++; + } while (--n); + } + return dst; +} + +extern "C" +void *memcpy(void *destination, void *source, size_t num) { + char *d = (char *) destination; + char *s = (char *) source; + for (size_t i = 0; i < num; i++) { + d[i] = s[i]; + } + return destination; +} +__attribute__((used)) void init_high() { // Copy data from flash to ram uint32_t *src = &_copy_data_load; - uint32_t *dest = &_copy_data_store; + uint32_t *dst = &_copy_data_store; uint32_t *end = &_copy_data_store_end; - while (dest <= end) { - *dest++ = *src++; + while (dst <= end) { + *dst++ = *src++; } // Clear the BSS segment - dest = &_bss_start; + dst = &_bss_start; end = &_bss_end; - while (dest <= end) { - *dest++ = 0; + while (dst <= end) { + *dst++ = 0; + } + + // Initialize c++ constructors + for (constructor_t *fn = _init_array_start; fn < _init_array_end; fn++) { + (*fn)(); } main(); @@ -43,6 +77,7 @@ struct { uint32_t BFAR; } Default_Handler_Info; +extern "C" __attribute__((used)) void Default_Handler() { Default_Handler_Info = { @@ -97,9 +132,6 @@ void Default_Handler() { if (Default_Handler_Info.CFSR & SCB_CFSR_IMPRECISERR) { dbg_printf(" BFSR.IMPRECISERR\n"); } - if (Default_Handler_Info.CFSR & SCB_CFSR_IMPRECISERR) { - dbg_printf(" BFSR.IMPRECISERR\n"); - } if (Default_Handler_Info.CFSR & SCB_CFSR_PRECISERR) { dbg_printf(" BFSR.PRECISERR\n"); } diff --git a/playground/src/init_low.s b/playground/src/init_low.s index bc12b5b..b666ed4 100644 --- a/playground/src/init_low.s +++ b/playground/src/init_low.s @@ -16,10 +16,12 @@ halt: b . .thumb_func +.global NMI_Handler NMI_Handler: b halt .thumb_func +.global HardFault_Handler HardFault_Handler: tst lr, #4 ite eq @@ -28,14 +30,17 @@ HardFault_Handler: b HardFault_Handler_C .thumb_func +.global MemManage_Handler MemManage_Handler: b halt .thumb_func +.global BusFault_Handler BusFault_Handler: b halt .thumb_func +.global UsageFault_Handler UsageFault_Handler: b halt |