summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-03-20 18:56:46 +1100
committerDamien George <damien.p.george@gmail.com>2017-03-20 18:56:46 +1100
commitebbaf7ee57a7c70067b8d1cc1d148cbdaf14762f (patch)
tree3decc01bc287bdfd32da021d98debe76cdd633aa
parent1a5c8d1053b391ea0ce260b882a1f1026ee7a6e0 (diff)
stmhal/pendsv: Disable interrupts during a thread switch.
We can actually handle interrupts during a thread switch (because we always have a valid stack), but only if those interrupts don't access any of the thread state (because the state may not correspond to the stack pointer). So to be on the safe side we disable interrupts during the very short period of the thread state+stack switch.
-rw-r--r--stmhal/pendsv.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/stmhal/pendsv.c b/stmhal/pendsv.c
index 4c2a14de1..200d13a5a 100644
--- a/stmhal/pendsv.c
+++ b/stmhal/pendsv.c
@@ -106,11 +106,14 @@ void pendsv_isr_handler(void) {
".no_obj:\n" // pendsv_object==NULL
"push {r4-r11, lr}\n"
"vpush {s16-s31}\n"
+ "mrs r5, primask\n" // save PRIMASK in r5
+ "cpsid i\n" // disable interrupts while we change stacks
"mov r0, sp\n" // pass sp to save
"mov r4, lr\n" // save lr because we are making a call
"bl pyb_thread_next\n" // get next thread to execute
"mov lr, r4\n" // restore lr
"mov sp, r0\n" // switch stacks
+ "msr primask, r5\n" // reenable interrupts
"vpop {s16-s31}\n"
"pop {r4-r11, lr}\n"
"bx lr\n" // return from interrupt; will return to new thread