[PATCH 1/2] firmware: Clear scratch->trap_context on warm boot

Nia Su nia.su at sifive.com
Fri Sep 4 01:16:43 PDT 2026


sbi_trap_handler() links tcntx->prev_context on entry and restores
scratch->trap_context on exit, forming a stack that unwinds through
the same path it was pushed from.

Non-retentive suspend/resume breaks that unwind: the SBI call
requesting suspend jumps straight to warm boot (jump_warmboot())
instead of returning through the normal exit path, leaving
scratch->trap_context stale. Since each hart's scratch space sits at
a fixed address, the next trap taken after warm boot resume reads
that same stale scratch->trap_context as its prev_context.

Clear trap_context in the scratch space on warm boot entry,
mirroring what cold boot's _scratch_init already does.

Signed-off-by: Nia Su <nia.su at sifive.com>
---
 firmware/fw_base.S | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/firmware/fw_base.S b/firmware/fw_base.S
index 0c5c65c10e5cf38d1cc6d0b3a66ffac661e7bacf..8ccca5e91c09f9c4cfcbab9c31c7e77afe7a96ab 100644
--- a/firmware/fw_base.S
+++ b/firmware/fw_base.S
@@ -364,6 +364,9 @@ _start_warm:
 	/* update the mscratch */
 	csrw	CSR_MSCRATCH, tp
 
+	/* Clear trap_context in scratch space */
+	REG_S	zero, SBI_SCRATCH_TRAP_CONTEXT_OFFSET(tp)
+
 	/* Setup stack */
 	add	sp, tp, zero
 

-- 
2.43.7




More information about the opensbi mailing list