-
Notifications
You must be signed in to change notification settings - Fork 942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance HardFault debugging #1232
base: dev
Are you sure you want to change the base?
Enhance HardFault debugging #1232
Conversation
2f75daf
to
cd521eb
Compare
8 bytes of the change are due to <Default_Handler>:
bf20 wfe
e7fd b.n <Default_Handler>
d4d4 bmi.n <tinygo_getSystemStackPointer+0x2>
+d4d4 bmi.n <tinygo_getSystemStackPointer+0x4>
+d4d4 bmi.n <tinygo_switchToScheduler>
+d4d4 bmi.n <tinygo_switchToScheduler+0x2>
+d4d4 bmi.n <tinygo_switchToScheduler+0x4> |
8db28ce
to
f6217b8
Compare
@firelizzard18 please make sure you rebase against the |
Define targets for Cortex-M0, -M0+, and -M3, in addition to the existing Cortex-M4 target to allow targeting specific architectures.
f6217b8
to
83a501f
Compare
@deadprogram Rebased |
On interrupt, the link register is filled with an tst lr, #(1<<2)
itete eq
mrseq r0, PSP
mrsne r0, MSP
moveq r1, #0 ; system == false
movne r1, #1 ; system == true I have no idea why this does not work but the Go implementation does. I thought maybe I misunderstood the conditionals, so I switched them, but that didn't help. I triggered a stack overflow (via dumb recursive fibonacci) in the scheduler and in main (separately). The Go implementation correctly reports PSP vs MSP; the assembly implementation does not. |
The following works as expected, but fails to compile for the Feather M0: //go:export HardFault_Handler
func hardFaultEntry() {
pspStacked := arm.AsmFull("ands.w {}, lr, #(1<<2)", nil)
sp := (*interruptStack)(unsafe.Pointer(arm.AsmFull(`
ite ne
mrsne {}, PSP
mrseq {}, MSP
`, nil)))
arm.AsmFull(`
movs r3, #0
ldr r3, [r3]
mov sp, r3
`, nil)
handleHardFault(sp, pspStacked)
}
func handleHardFault(sp *interruptStack, pspStacked uintptr) {
// ...
} The error:
|
Yes, the Cortex-M0 has implemented far fewer instructions. Many wide instructions (such as This is what the error says:
Cortex-M0 implements thumb, not thumb2. |
@@ -56,195 +19,3 @@ func Asm(asm string) | |||
// You can use {} in the asm string (which expands to a register) to set the | |||
// return value. | |||
func AsmFull(asm string, regs map[string]interface{}) uintptr | |||
|
|||
// Run the following system call (SVCall) with 0 arguments. | |||
func SVCall0(num uintptr) uintptr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you move all these to arm_cortex.go? At least the svc
instruction should be implemented on basically all ARM chips. Why did you split this file in arm.go and arm_cortex.go?
This MR updates the HardFault handler, allowing improved debugging for Cortex-M3 and Cortex-M4 based boards, using the fault status registers defined by those cores.
Changes
cortex-m0.json
,cortex-m0p.json
, andcortex-m3.json
totargets/
, and update Cortex-M targets to inherit from these, to allow targeting of M0/M0+/M3/M4 (targets/cortex-m4.json
already exists).arm.go
to core-specific files (arm_cortex_mX.go
) to allow for core-specific registers.PSP
andMSP
instead of justSP
, in order to log the correct stack pointer (becauseSP
in the ISR always refers toMSP
)stackTop-stackSize
instead of a hardcoded value (0x20000000
) to detect stack overflow (on the Teensy 3.6, RAM starts at0x1fff0000
)Executable size does not increase greatly for M3/M4 cores, unless
const hardFaultDebug bool
is set totrue
. As of cd521eb, sizes forsrc/examples/blinky1
are: