From: Keith Packard Date: Wed, 1 May 2013 02:04:26 +0000 (-0700) Subject: altos: Use separate exception stack on STM32L X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=38d7a68d9edf1e8ea6e7ed72b41705a2a5882435;p=fw%2Faltos altos: Use separate exception stack on STM32L This reserves 512 bytes of memory for a stack, then makes sure that exceptions continue to use that stack while processes use the per-task stack. Signed-off-by: Keith Packard --- diff --git a/src/core/ao_task.c b/src/core/ao_task.c index e1d35d67..0aad6508 100644 --- a/src/core/ao_task.c +++ b/src/core/ao_task.c @@ -538,5 +538,8 @@ ao_start_scheduler(void) ao_cur_task_index = AO_NO_TASK_INDEX; #endif ao_cur_task = NULL; +#if HAS_ARCH_START_SCHEDULER + ao_arch_start_scheduler(); +#endif ao_yield(); } diff --git a/src/stm/altos.ld b/src/stm/altos.ld index 6affc376..3106cc3b 100644 --- a/src/stm/altos.ld +++ b/src/stm/altos.ld @@ -17,7 +17,8 @@ MEMORY { rom (rx) : ORIGIN = 0x08001000, LENGTH = 124K - ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K + ram (!w) : ORIGIN = 0x20000000, LENGTH = 15872 + stack (!w) : ORIGIN = 0x20003e00, LENGTH = 512 } INCLUDE registers.ld @@ -86,8 +87,9 @@ SECTIONS { __bss_end__ = .; } >ram - PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram)); PROVIDE(end = .); + + PROVIDE(__stack__ = ORIGIN(stack) + LENGTH(stack)); } ENTRY(start); diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h index e152440a..0d63b396 100644 --- a/src/stm/ao_arch_funcs.h +++ b/src/stm/ao_arch_funcs.h @@ -334,6 +334,20 @@ static inline void ao_arch_restore_stack(void) { /* Return to calling function */ asm("bx lr"); } + +#define HAS_ARCH_START_SCHEDULER 1 + +static inline void ao_arch_start_scheduler(void) { + uint32_t sp; + uint32_t control; + + asm("mrs %0,msp" : "=&r" (sp)); + asm("msr psp,%0" : : "r" (sp)); + asm("mrs %0,control" : "=&r" (control)); + control |= (1 << 1); + asm("msr control,%0" : : "r" (control)); +} + #endif #define ao_arch_isr_stack()