Commits

Cliff Biffle committed 9568297

Fixed context switch routine so that threads can use either Main or Process stack.

Comments (0)

Files changed (1)

 .global context_switch
 .thumb_func
 context_switch:
-          push {RSP, IDX, LR}
-          str SP, [TCP, #8]   @ Record SP into the user area + 8.
+          tst LR, #4          @ Check which stack is in use.
+          ite eq
+          mrseq r1, MSP       @ Bit clear: using Main Stack.
+          mrsne r1, PSP       @ Bit set: using Process Stack.
+
+          stmfd r1!, {RSP, IDX, LR}
+          str r1, [TCP, #8]   @ Record SP into the user area + 8.
           ldr TCP, [TCP]      @ Switch tasks
-          ldr SP, [TCP, #8]   @ Load SP from user area + 8.
-          pop {RSP, IDX, LR}
+          ldr r1, [TCP, #8]   @ Load SP from user area + 8.
+          ldmfd r1!, {RSP, IDX, LR}
+
+          tst LR, #4          @ Check which stack we're returning into.
+          ite eq
+          msreq MSP, r1       @ Bit clear: set Main Stack pointer.
+          msrne PSP, r1       @ Bit set: set Process Stack pointer.
+
           bx LR