Skip to content

Commit df9e04a

Browse files
wearyzennordicjm
authored andcommitted
[nrf fromtree] Revert "arch: arm: cortex_m: pm_s2ram: Rework S2RAM mark functions"
What is the change? - This reverts commit 474d4c3 Why do we need this change? - This commit was added because Cortex-M didn't have a valid stack to make required functionality work however, the previous commit fixes this and makes interrupt stack available for use. This removes Arm specific limitation from these generic APIs so revert the commit to reflect the same. Signed-off-by: Sudan Landge <[email protected]> (cherry picked from commit b4fb5d3)
1 parent a6f6964 commit df9e04a

File tree

3 files changed

+19
-54
lines changed

3 files changed

+19
-54
lines changed

Diff for: arch/arm/core/cortex_m/pm_s2ram.S

+11-12
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_suspend)
178178
/*
179179
* Mark entering suspend to RAM.
180180
*/
181-
mov r1, lr
182-
bl pm_s2ram_mark_set
183-
mov lr, r1
181+
bl pm_s2ram_mark_set
184182

185183
/*
186184
* Call the system_off function passed as parameter. This should never
@@ -199,9 +197,7 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_suspend)
199197
/*
200198
* Reset the marking of suspend to RAM, return is ignored.
201199
*/
202-
mov r1, lr
203-
bl pm_s2ram_mark_check_and_clear
204-
mov lr, r1
200+
bl pm_s2ram_mark_check_and_clear
205201

206202
/* Move the stored return value of system_off back to r0,
207203
* setting it as return value for this function.
@@ -216,13 +212,16 @@ GTEXT(arch_pm_s2ram_resume)
216212
SECTION_FUNC(TEXT, arch_pm_s2ram_resume)
217213
/*
218214
* Check if reset occurred after suspending to RAM.
215+
* Store LR to ensure we can continue boot when we are not suspended
216+
* to RAM. In addition to LR, R0 is pushed too, to ensure "SP mod 8 = 0",
217+
* as stated by ARM rule 6.2.1.2 for AAPCS32.
219218
*/
220-
mov r1, lr
221-
bl pm_s2ram_mark_check_and_clear
222-
mov lr, r1
223-
cmp r0, #0x1
224-
beq .L_resume
225-
bx lr
219+
push {r0, lr}
220+
bl pm_s2ram_mark_check_and_clear
221+
cmp r0, #0x1
222+
pop {r0, lr}
223+
beq .L_resume
224+
bx lr
226225

227226
.L_resume:
228227
/*

Diff for: arch/arm/core/cortex_m/pm_s2ram.c

+8-32
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,20 @@ __noinit _cpu_context_t _cpu_context;
2222
*/
2323
static __noinit uint32_t marker;
2424

25-
void __attribute__((naked)) pm_s2ram_mark_set(void)
25+
void pm_s2ram_mark_set(void)
2626
{
27-
__asm__ volatile(
28-
/* Set the marker to MAGIC value */
29-
"str %[_magic_val], [%[_marker]]\n"
30-
31-
"bx lr\n"
32-
:
33-
: [_magic_val] "r"(MAGIC), [_marker] "r"(&marker)
34-
: "r1", "r4", "memory");
27+
marker = MAGIC;
3528
}
3629

37-
bool __attribute__((naked)) pm_s2ram_mark_check_and_clear(void)
30+
bool pm_s2ram_mark_check_and_clear(void)
3831
{
39-
__asm__ volatile(
40-
/* Set return value to 0 */
41-
"mov r0, #0\n"
42-
43-
/* Check the marker */
44-
"ldr r3, [%[_marker]]\n"
45-
"cmp r3, %[_magic_val]\n"
46-
"bne exit\n"
47-
48-
/*
49-
* Reset the marker
50-
*/
51-
"str r0, [%[_marker]]\n"
32+
if (marker == MAGIC) {
33+
marker = 0;
5234

53-
/*
54-
* Set return value to 1
55-
*/
56-
"mov r0, #1\n"
35+
return true;
36+
}
5737

58-
"exit:\n"
59-
"bx lr\n"
60-
:
61-
: [_magic_val] "r"(MAGIC), [_marker] "r"(&marker)
62-
: "r0", "r1", "r3", "r4", "memory");
38+
return false;
6339
}
6440

6541
#endif /* CONFIG_PM_S2RAM_CUSTOM_MARKING */

Diff for: include/zephyr/arch/common/pm_s2ram.h

-10
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ int arch_pm_s2ram_suspend(pm_s2ram_system_off_fn_t system_off);
6565
*
6666
* Default implementation is setting a magic word in RAM. CONFIG_PM_S2RAM_CUSTOM_MARKING
6767
* allows custom implementation.
68-
* The following requirements must be fulfilled:
69-
* - the function cannot use stack (asm function or function with 'naked' attribute)
70-
* - the content of the R1 and R4 registers must remain unchanged
71-
* - returning from the function should be performed with the `bx lr` instruction
72-
*
7368
*/
7469
void pm_s2ram_mark_set(void);
7570

@@ -81,11 +76,6 @@ void pm_s2ram_mark_set(void);
8176
*
8277
* Default implementation is checking a magic word in RAM. CONFIG_PM_S2RAM_CUSTOM_MARKING
8378
* allows custom implementation.
84-
* The following requirements must be fulfilled:
85-
* - the function cannot use stack (most likely asm function)
86-
* - the content of the R1 and R4 registers must remain unchanged
87-
* - the function's return value is passed by R0 register
88-
* - returning from the function should be performed with the `bx lr` instruction
8979
*
9080
* @retval true if marking is found which indicates resuming after suspend-to-RAM.
9181
* @retval false if marking is not found which indicates standard boot.

0 commit comments

Comments
 (0)