33package runtime
44
55import (
6- "device/arm"
76 "unsafe"
87)
98
@@ -40,16 +39,6 @@ func preinit() {
4039 }
4140}
4241
43- func abort () {
44- // disable all interrupts
45- arm .DisableInterrupts ()
46-
47- // lock up forever
48- for {
49- arm .Asm ("wfi" )
50- }
51- }
52-
5342// The stack layout at the moment an interrupt occurs.
5443// Registers can be accessed if the stack pointer is cast to a pointer to this
5544// struct.
@@ -63,35 +52,3 @@ type interruptStack struct {
6352 PC uintptr
6453 PSR uintptr
6554}
66-
67- // This function is called at HardFault.
68- // Before this function is called, the stack pointer is reset to the initial
69- // stack pointer (loaded from addres 0x0) and the previous stack pointer is
70- // passed as an argument to this function. This allows for easy inspection of
71- // the stack the moment a HardFault occurs, but it means that the stack will be
72- // corrupted by this function and thus this handler must not attempt to recover.
73- //
74- // For details, see:
75- // https://community.arm.com/developer/ip-products/system/f/embedded-forum/3257/debugging-a-cortex-m0-hard-fault
76- // https://blog.feabhas.com/2013/02/developing-a-generic-hard-fault-handler-for-arm-cortex-m3cortex-m4/
77- //export handleHardFault
78- func handleHardFault (sp * interruptStack ) {
79- print ("fatal error: " )
80- if uintptr (unsafe .Pointer (sp )) < 0x20000000 {
81- print ("stack overflow" )
82- } else {
83- // TODO: try to find the cause of the hard fault. Especially on
84- // Cortex-M3 and higher it is possible to find more detailed information
85- // in special status registers.
86- print ("HardFault" )
87- }
88- print (" with sp=" , sp )
89- if uintptr (unsafe .Pointer (& sp .PC )) >= 0x20000000 {
90- // Only print the PC if it points into memory.
91- // It may not point into memory during a stack overflow, so check that
92- // first before accessing the stack.
93- print (" pc=" , sp .PC )
94- }
95- println ()
96- abort ()
97- }
0 commit comments