diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 25da2143..5b77c1aa 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -23,25 +23,6 @@ func initAll() // scheduler(coroutine) func mainWrapper() -// Entry point for Go. Initialize all packages and call main.main(). -//go:export main -func main() int { - // Initialize memory etc. - preinit() - - // Run initializers of all packages. - initAll() - - // Enable interrupts etc. - postinit() - - // Compiler-generated wrapper to main.main(). - mainWrapper() - - // For libc compatibility. - return 0 -} - func GOMAXPROCS(n int) int { // Note: setting GOMAXPROCS is ignored. return 1 diff --git a/src/runtime/runtime_arm.go b/src/runtime/runtime_arm.go index d47d40b8..3debdd67 100644 --- a/src/runtime/runtime_arm.go +++ b/src/runtime/runtime_arm.go @@ -40,9 +40,6 @@ func preinit() { } } -func postinit() { -} - func abort() { for { arm.Asm("wfi") diff --git a/src/runtime/runtime_avr.go b/src/runtime/runtime_avr.go index 070e146d..7dfa15d2 100644 --- a/src/runtime/runtime_avr.go +++ b/src/runtime/runtime_avr.go @@ -36,6 +36,15 @@ var _sbss unsafe.Pointer //go:extern _ebss var _ebss unsafe.Pointer +//go:export main +func main() { + preinit() + initAll() + postinit() + mainWrapper() + abort() +} + func preinit() { // Initialize .bss: zero-initialized global variables. ptr := uintptr(unsafe.Pointer(&_sbss)) @@ -107,7 +116,6 @@ func ticks() timeUnit { } func abort() { - avr.Asm("cli") for { sleepWDT(WDT_PERIOD_2S) } diff --git a/src/runtime/runtime_nrf.go b/src/runtime/runtime_nrf.go index 893a48a0..76978717 100644 --- a/src/runtime/runtime_nrf.go +++ b/src/runtime/runtime_nrf.go @@ -16,9 +16,12 @@ const tickMicros = 1024 * 32 func systemInit() //go:export Reset_Handler -func handleReset() { +func main() { systemInit() - main() + preinit() + initAll() + mainWrapper() + abort() } func init() { diff --git a/src/runtime/runtime_stm32.go b/src/runtime/runtime_stm32.go index c2e6e2b1..e068a4d4 100644 --- a/src/runtime/runtime_stm32.go +++ b/src/runtime/runtime_stm32.go @@ -11,11 +11,11 @@ type timeUnit int64 const tickMicros = 1 // TODO //go:export Reset_Handler -func handleReset() { - main() -} - -func init() { +func main() { + preinit() + initAll() + mainWrapper() + abort() } func putchar(c byte) { diff --git a/src/runtime/runtime_unix.go b/src/runtime/runtime_unix.go index 396d731e..bc5f9803 100644 --- a/src/runtime/runtime_unix.go +++ b/src/runtime/runtime_unix.go @@ -24,10 +24,17 @@ type timespec struct { const CLOCK_MONOTONIC_RAW = 4 -func preinit() { -} +// Entry point for Go. Initialize all packages and call main.main(). +//go:export main +func main() int { + // Run initializers of all packages. + initAll() + + // Compiler-generated wrapper to main.main(). + mainWrapper() -func postinit() { + // For libc compatibility. + return 0 } func putchar(c byte) {