runtime: improve hardfault handler and stack reporting on Cortex-M

- Add reference to the current goroutine stack (PSP) when showing the hardfault info on Cortex-M.
This commit is contained in:
Konstantin Sharlaimov
2026-05-10 19:57:18 +02:00
committed by Ron Evans
parent 7cbbfd6fc5
commit 8e36d2758b
5 changed files with 39 additions and 1 deletions
@@ -4,6 +4,7 @@ package runtime
import (
"device/arm"
"internal/task"
"unsafe"
)
@@ -106,6 +107,20 @@ func HardFault_Handler() {
print(" pc=", sp.PC)
}
}
// PSP holds the actual exception frame when the fault occurred in a
// goroutine (thread mode, PSP active). The MSP-based sp above is the
// scheduler's stack and its PC is garbage in that case.
pspVal := task.GoroutineStack()
// heapEndSymbol is defined in baremetal.go; we also ensure that the goroutine exception frame is within addressable memory.
if pspVal >= 0x20000000 && pspVal < (uintptr(unsafe.Pointer(&heapEndSymbol))-uintptr(unsafe.Sizeof(interruptStack{}))) {
pspFrame := (*interruptStack)(unsafe.Pointer(pspVal))
print(" psp=", pspFrame)
print(" psp_pc=", pspFrame.PC)
print(" psp_lr=", pspFrame.LR)
}
println()
abort()
}