QXK: PendSV_Handler uses inconsistent stack frames for saving and restoring...
Real-Time Embedded Frameworks based on active objects & state machines
Brought to you by:
quantum-leaps
The PendSV_Handler coded in qxk_port.s uses inconsistent stack frames for saving and restoring AO for the ARMv6-M architecture (Cortex-M0/M0+/M1). Specifically, in QP 5.9.9, the code for storing the AO context is as follows:
. . . PendSV_save_ao: #if (__CORE__ == __ARM6M__) ; Cortex-M0/M0+/M1 ? PUSH {r4-r7} ; save the low registers MOV r4,r8 ; move the high registers to low registers... MOV r5,r9 MOV r6,r10 MOV r7,r11 PUSH {r4-r7} ; save the high registers #else ; M3/M4/M7 . . .
This code produces the following stack frame:
hi memory sp before-> r7 r6 r5 r4 r11 r10 r9 sp after -> r8 low memory
The code for restoring the AO context is as follows:
PendSV_restore_ao: . . . #if (__CORE__ == __ARM6M__) ; Cortex-M0/M0+/M1 ? MOV r0,sp ; r0 := top of stack MOV r1,r0 ADDS r1,r1,#(4*4) ; point r0 to the 4 high registers r7-r11 LDMIA r1!,{r4-r7} ; pop the 4 high registers into low registers MOV r8,r4 ; move low registers into high registers MOV r9,r5 MOV r10,r6 MOV r11,r7 LDMIA r0!,{r4-r7} ; pop the low registers ADD sp,sp,#(8*4) ; remove 8 registers from the stack . . . #else ; M3/M4/M7 . . .
This code expects the following stack frame:
hi memory sp before-> r11 r10 r9 r8 r7 r6 r5 sp after -> r4 low memory
--MMS
Anonymous
The bug will be fixed in the next QP/C/C++ relese 6.0.0 by adjusting the saving of the AO context. This will produce a stack frame, which will be consistent with all other cases, such as stack frames produced for Cortex-M3/M4/M7 and stack frames produced while saving extended thread contexts.
The fix will use the following code:
This code produces the following stack frame:
--MMS
Fixed in QP/C/C++6.0.0.
--MMS