From 310df7acb59ff135376b221dea482e01ca93067a Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 17 Sep 2025 10:14:17 -0400 Subject: [PATCH] fix(rp2): reset spinlocks at startup --- src/runtime/runtime_rp2.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/runtime/runtime_rp2.go b/src/runtime/runtime_rp2.go index f2e81ff27..08ae86569 100644 --- a/src/runtime/runtime_rp2.go +++ b/src/runtime/runtime_rp2.go @@ -14,6 +14,7 @@ import ( ) const numCPU = 2 +const numSpinlocks = 32 // machineTicks is provided by package machine. func machineTicks() uint64 @@ -297,6 +298,13 @@ var ( futexLock = spinLock{id: 23} ) +func resetSpinLocks() { + for i := uint8(0); i < numSpinlocks; i++ { + l := &spinLock{id: i} + l.spinlock().Set(0) + } +} + // A hardware spinlock, one of the 32 spinlocks defined in the SIO peripheral. type spinLock struct { id uint8 @@ -357,9 +365,16 @@ func init() { machine.InitSerial() } +func prerun() { + // Reset spinlocks before the full machineInit() so the scheduler doesn't + // hang waiting for schedulerLock after a soft reset. + resetSpinLocks() +} + //export Reset_Handler func main() { preinit() + prerun() run() exit(0) }