altos: Use separate exception stack on STM32L
authorKeith Packard <keithp@keithp.com>
Wed, 1 May 2013 02:04:26 +0000 (19:04 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 8 May 2013 03:08:00 +0000 (20:08 -0700)
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 <keithp@keithp.com>
src/core/ao_task.c
src/stm/altos.ld
src/stm/ao_arch_funcs.h

index 9cb074b5220a2c6279353d1b4ab5371be2dd5385..c24c992927782438e35cba1871e2d643be656760 100644 (file)
@@ -536,5 +536,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();
 }
index f78a45d677e335570a735097c621903939b792b6..d218e992ad8aa5e835c951d94bd8b97e93e6cac1 100644 (file)
@@ -17,7 +17,8 @@
 
 MEMORY {
        rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
-       ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K
+       ram (!w) : ORIGIN = 0x20000000, LENGTH = 15872
+       stack (!w) : ORIGIN = 0x20003e00, LENGTH = 512
 }
 
 INCLUDE registers.ld
@@ -63,8 +64,9 @@ SECTIONS {
                __bss_end__ = .;
        } >ram
 
-       PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram));
        PROVIDE(end = .);
+
+       PROVIDE(__stack__ = ORIGIN(stack) + LENGTH(stack));
 }
 
 ENTRY(start);
index d17793076f38ca177e60f66082288c607044d1b5..f3d68202303a1844e180b7b846873999275aa417 100644 (file)
@@ -317,6 +317,19 @@ static inline void ao_arch_restore_stack(void) {
        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));
+}
+
 #define ao_arch_isr_stack()
 
 #define ao_arch_wait_interrupt() do {                  \