mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-21 21:09:02 +00:00
runtime: refactor initialization code
Let each target handle its own initialization/finalization sequence instead of providing one in the runtime with hooks for memory initialization etc. This is much more flexible although it causes a little bit of code duplication.
This commit is contained in:
@@ -23,25 +23,6 @@ func initAll()
|
|||||||
// scheduler(coroutine)
|
// scheduler(coroutine)
|
||||||
func mainWrapper()
|
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 {
|
func GOMAXPROCS(n int) int {
|
||||||
// Note: setting GOMAXPROCS is ignored.
|
// Note: setting GOMAXPROCS is ignored.
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -40,9 +40,6 @@ func preinit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func postinit() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func abort() {
|
func abort() {
|
||||||
for {
|
for {
|
||||||
arm.Asm("wfi")
|
arm.Asm("wfi")
|
||||||
|
|||||||
@@ -36,6 +36,15 @@ var _sbss unsafe.Pointer
|
|||||||
//go:extern _ebss
|
//go:extern _ebss
|
||||||
var _ebss unsafe.Pointer
|
var _ebss unsafe.Pointer
|
||||||
|
|
||||||
|
//go:export main
|
||||||
|
func main() {
|
||||||
|
preinit()
|
||||||
|
initAll()
|
||||||
|
postinit()
|
||||||
|
mainWrapper()
|
||||||
|
abort()
|
||||||
|
}
|
||||||
|
|
||||||
func preinit() {
|
func preinit() {
|
||||||
// Initialize .bss: zero-initialized global variables.
|
// Initialize .bss: zero-initialized global variables.
|
||||||
ptr := uintptr(unsafe.Pointer(&_sbss))
|
ptr := uintptr(unsafe.Pointer(&_sbss))
|
||||||
@@ -107,7 +116,6 @@ func ticks() timeUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func abort() {
|
func abort() {
|
||||||
avr.Asm("cli")
|
|
||||||
for {
|
for {
|
||||||
sleepWDT(WDT_PERIOD_2S)
|
sleepWDT(WDT_PERIOD_2S)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,12 @@ const tickMicros = 1024 * 32
|
|||||||
func systemInit()
|
func systemInit()
|
||||||
|
|
||||||
//go:export Reset_Handler
|
//go:export Reset_Handler
|
||||||
func handleReset() {
|
func main() {
|
||||||
systemInit()
|
systemInit()
|
||||||
main()
|
preinit()
|
||||||
|
initAll()
|
||||||
|
mainWrapper()
|
||||||
|
abort()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ type timeUnit int64
|
|||||||
const tickMicros = 1 // TODO
|
const tickMicros = 1 // TODO
|
||||||
|
|
||||||
//go:export Reset_Handler
|
//go:export Reset_Handler
|
||||||
func handleReset() {
|
func main() {
|
||||||
main()
|
preinit()
|
||||||
}
|
initAll()
|
||||||
|
mainWrapper()
|
||||||
func init() {
|
abort()
|
||||||
}
|
}
|
||||||
|
|
||||||
func putchar(c byte) {
|
func putchar(c byte) {
|
||||||
|
|||||||
@@ -24,10 +24,17 @@ type timespec struct {
|
|||||||
|
|
||||||
const CLOCK_MONOTONIC_RAW = 4
|
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()
|
||||||
|
|
||||||
func postinit() {
|
// Compiler-generated wrapper to main.main().
|
||||||
|
mainWrapper()
|
||||||
|
|
||||||
|
// For libc compatibility.
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func putchar(c byte) {
|
func putchar(c byte) {
|
||||||
|
|||||||
Reference in New Issue
Block a user