Skip to content

Commit f79e66a

Browse files
aykevldeadprogram
authored andcommitted
cortexm: disable FPU on Cortex-M4
On some boards the FPU is already enabled on startup, probably as part of the bootloader. On other chips it was enabled as part of the runtime startup code. In all these cases, enabling the FPU is currently unsupported: the automatic stack sizing of goroutines assumes that the processor won't need to reserve space for FPU registers. Enabling the FPU therefore can lead to a stack overflow. This commit either removes the code that enables the FPU, or simply disables it in startup code. A future change should fully enable the FPU so that operations on float32 can be performed by the FPU instead of in software, greatly speeding up such code.
1 parent 4eac212 commit f79e66a

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

src/device/arm/scb.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ type SCB_Type struct {
2626
SHPR2 volatile.Register32 // 0xD1C: System Handler Priority Register 2
2727
SHPR3 volatile.Register32 // 0xD20: System Handler Priority Register 3
2828
// the following are only applicable for Cortex-M3/M33/M4/M7
29-
SHCSR volatile.Register32 // 0xD24: System Handler Control and State Register
30-
CFSR volatile.Register32 // 0xD28: Configurable Fault Status Register
31-
HFSR volatile.Register32 // 0xD2C: HardFault Status Register
32-
DFSR volatile.Register32 // 0xD30: Debug Fault Status Register
33-
MMFAR volatile.Register32 // 0xD34: MemManage Fault Address Register
34-
BFAR volatile.Register32 // 0xD38: BusFault Address Register
29+
SHCSR volatile.Register32 // 0xD24: System Handler Control and State Register
30+
CFSR volatile.Register32 // 0xD28: Configurable Fault Status Register
31+
HFSR volatile.Register32 // 0xD2C: HardFault Status Register
32+
DFSR volatile.Register32 // 0xD30: Debug Fault Status Register
33+
MMFAR volatile.Register32 // 0xD34: MemManage Fault Address Register
34+
BFAR volatile.Register32 // 0xD38: BusFault Address Register
35+
AFSR volatile.Register32 // 0xD3C: Auxiliary Fault Status Register
36+
PFR [2]volatile.Register32 // 0xD40: Processor Feature Register
37+
DFR volatile.Register32 // 0xD48: Debug Feature Register
38+
ADR volatile.Register32 // 0xD4C: Auxiliary Feature Register
39+
MMFR [4]volatile.Register32 // 0xD50: Memory Model Feature Register
40+
ISAR [5]volatile.Register32 // 0xD60: Instruction Set Attributes Register
41+
_ [5]uint32 // reserved
42+
CPACR volatile.Register32 // 0xD88: Coprocessor Access Control Register
43+
3544
}
3645

3746
var SCB = (*SCB_Type)(unsafe.Pointer(uintptr(SCB_BASE)))

src/runtime/runtime_atsamd51.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func postinit() {}
1616

1717
//export Reset_Handler
1818
func main() {
19+
arm.SCB.CPACR.Set(0) // disable FPU if it is enabled
1920
preinit()
2021
run()
2122
abort()

src/runtime/runtime_mimxrt1062.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ func initSystem() {
102102

103103
func initPeripherals() {
104104

105-
// enable FPU - set CP10, CP11 full access
106-
nxp.SystemControl.CPACR.SetBits(
107-
((nxp.SCB_CPACR_CP10_CP10_3 << nxp.SCB_CPACR_CP10_Pos) & nxp.SCB_CPACR_CP10_Msk) |
108-
((nxp.SCB_CPACR_CP11_CP11_3 << nxp.SCB_CPACR_CP11_Pos) & nxp.SCB_CPACR_CP11_Msk))
109-
110105
enableTimerClocks() // activate GPT/PIT clock gates
111106
initSysTick() // enable SysTick
112107
initRTC() // enable real-time clock

src/runtime/runtime_nrf.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package runtime
44

55
import (
6+
"device/arm"
67
"device/nrf"
78
"machine"
89
"runtime/interrupt"
@@ -18,6 +19,9 @@ func postinit() {}
1819

1920
//export Reset_Handler
2021
func main() {
22+
if nrf.FPUPresent {
23+
arm.SCB.CPACR.Set(0) // disable FPU if it is enabled
24+
}
2125
systemInit()
2226
preinit()
2327
run()

src/runtime/runtime_nxpmk66f18.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func initSystem() {
7575
nxp.SIM.SCGC3.Set(nxp.SIM_SCGC3_ADC1 | nxp.SIM_SCGC3_FTM2 | nxp.SIM_SCGC3_FTM3)
7676
nxp.SIM.SCGC5.Set(0x00043F82) // clocks active to all GPIO
7777
nxp.SIM.SCGC6.Set(nxp.SIM_SCGC6_RTC | nxp.SIM_SCGC6_FTM0 | nxp.SIM_SCGC6_FTM1 | nxp.SIM_SCGC6_ADC0 | nxp.SIM_SCGC6_FTF)
78-
nxp.SystemControl.CPACR.Set(0x00F00000)
7978
nxp.LMEM.PCCCR.Set(0x85000003)
8079

8180
// release I/O pins hold, if we woke up from VLLS mode

0 commit comments

Comments
 (0)