Skip to content

Commit 77378a8

Browse files
Mathieu Choplainkartben
authored andcommitted
arch: arm: pm_s2ram: fix compatibility with ARMv6-M again
The original 'arch_pm_s2ram_resume' implementation saved lr on the stack using 'push {lr}' and restored it using 'pop {lr}'. However, the Thumb-1 'pop' does not support lr as a target register, so this code would not compile for ARMv6-M or ARMv8-M Baseline. r0 was added to these push/pop later in 2590c48. In 474d4c3, arch_pm_s2ram* functions were modified to no longer use the stack, which incidentally "fixed" this issue. b4fb5d3 reverted this commit and brought back 'pop {r0, lr}' as-is, without taking compatibility into account. Modify the sequence to use "pop {r0, pc}" which is supported on all ARM M-profile implementations (v6/v7/v8 Baseline/v8 Mainline), and add comments to (hopefully) prevent this issue from re-appearing. Signed-off-by: Mathieu Choplain <[email protected]>
1 parent 0e24841 commit 77378a8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

arch/arm/core/cortex_m/pm_s2ram.S

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,17 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_resume)
219219
push {r0, lr}
220220
bl pm_s2ram_mark_check_and_clear
221221
cmp r0, #0x1
222-
pop {r0, lr}
223222
beq .L_resume
224-
bx lr
223+
pop {r0, pc}
225224

226225
.L_resume:
227226
/*
228-
* Restore the CPU context
227+
* Switch to the stack used to execute "arch_pm_s2ram_suspend"
228+
* and restore CPU context backed up by that function, then
229+
* return to the call site of "arch_pm_s2ram_suspend".
230+
*
231+
* Note: the "push {r0, lr}" performed earlier doesn't
232+
* need to be balanced out since we are switching stacks.
229233
*/
230234
ldr r0, =_cpu_context
231235

0 commit comments

Comments
 (0)