Skip to content

Commit cbd25e1

Browse files
[nrf fromlist] soc: nordic: s2ram: Align s2ram marking procedures
Rework Nordic specific S2RAM marking procedures. The S2RAM marking procedures must not disrupt the stack due to the TLS pointer not yet being initialized during their execution. Upstream PR: zephyrproject-rtos/zephyr#80039 Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent b8c2ddb commit cbd25e1

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

soc/nordic/nrf54h/pm_s2ram.c

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,48 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
127127
return ret;
128128
}
129129

130-
void pm_s2ram_mark_set(void)
130+
void __attribute__((naked)) pm_s2ram_mark_set(void)
131131
{
132132
/* empty */
133+
__asm__ volatile("bx lr\n");
133134
}
134135

135-
bool pm_s2ram_mark_check_and_clear(void)
136+
bool __attribute__((naked)) pm_s2ram_mark_check_and_clear(void)
136137
{
137-
bool unretained_wake;
138-
bool restore_valid;
139-
uint32_t reset_reason = nrf_resetinfo_resetreas_local_get(NRF_RESETINFO);
138+
__asm__ volatile(
139+
/* Set return value to 0 */
140+
"mov r0, #0\n"
140141

141-
if (reset_reason != NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK) {
142-
return false;
143-
}
144-
unretained_wake = reset_reason & NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK;
145-
nrf_resetinfo_resetreas_local_set(NRF_RESETINFO, 0);
142+
/* Load and check RESETREAS register */
143+
"ldr r3, [%[resetinfo_addr], %[resetreas_offs]]\n"
144+
"cmp r3, %[resetreas_unretained_mask]\n"
145+
146+
"bne exit\n"
147+
148+
/* Clear RESETREAS register */
149+
"str r0, [%[resetinfo_addr], %[resetreas_offs]]\n"
150+
151+
/* Load RESTOREVALID register */
152+
"ldr r3, [%[resetinfo_addr], %[restorevalid_offs]]\n"
153+
154+
/* Clear RESTOREVALID */
155+
"str r0, [%[resetinfo_addr], %[restorevalid_offs]]\n"
156+
157+
/* Check RESTOREVALID register */
158+
"cmp r3, %[restorevalid_present_mask]\n"
159+
"bne exit\n"
160+
161+
/* Set return value to 1 */
162+
"mov r0, #1\n"
146163

147-
restore_valid = nrf_resetinfo_restore_valid_check(NRF_RESETINFO);
148-
nrf_resetinfo_restore_valid_set(NRF_RESETINFO, false);
164+
"exit:\n"
165+
"bx lr\n"
166+
:
167+
: [resetinfo_addr] "r"(NRF_RESETINFO),
168+
[resetreas_offs] "r"(offsetof(NRF_RESETINFO_Type, RESETREAS.LOCAL)),
169+
[resetreas_unretained_mask] "r"(NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK),
170+
[restorevalid_offs] "r"(offsetof(NRF_RESETINFO_Type, RESTOREVALID)),
171+
[restorevalid_present_mask] "r"(RESETINFO_RESTOREVALID_RESTOREVALID_Msk)
149172

150-
return (unretained_wake & restore_valid) ? true : false;
173+
: "r0", "r1", "r3", "r4", "memory");
151174
}

0 commit comments

Comments
 (0)