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
+5
View File
@@ -42,3 +42,8 @@ func SystemStack() uintptr {
runtimePanic("scheduler is disabled")
return 0 // unreachable
}
func GoroutineStack() uintptr {
// No separate goroutine stack without a scheduler.
return 0
}
+11
View File
@@ -11,3 +11,14 @@ uintptr_t SystemStack() {
);
return sp;
}
uintptr_t GoroutineStack() {
uintptr_t sp;
asm volatile(
"mrs %0, PSP"
: "=r"(sp)
:
: "memory"
);
return sp;
}
+7
View File
@@ -70,3 +70,10 @@ func (s *state) pause() {
//
//export SystemStack
func SystemStack() uintptr
// GoroutineStack returns the PSP (goroutine stack pointer). When a fault
// occurs in goroutine context, the hardware saves the exception frame to PSP;
// reading PSP+0x18 gives the actual faulting PC.
//
//export GoroutineStack
func GoroutineStack() uintptr