Enhance HardFault debugging #1232
Conversation
2f75daf
to
cd521eb
|
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
|
@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
|
@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 == trueI 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 | |||
aykevl
Jul 23, 2020
Member
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?
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?

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

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.jsontotargets/, and update Cortex-M targets to inherit from these, to allow targeting of M0/M0+/M3/M4 (targets/cortex-m4.jsonalready exists).arm.goto core-specific files (arm_cortex_mX.go) to allow for core-specific registers.PSPandMSPinstead of justSP, in order to log the correct stack pointer (becauseSPin the ISR always refers toMSP)stackTop-stackSizeinstead 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 boolis set totrue. As of cd521eb, sizes forsrc/examples/blinky1are: