avr: fix time.Sleep() in init code

In the early days of TinyGo, the idea of `postinit` was to enable
interrupts only after initializers have run. Which kind of makes
sense... except that `time.Sleep` is allowed in init code and
`time.Sleep` requires interrupts to be enabled. Therefore, interrupts
must be enabled while initializers are being run.

This commit simply moves the enabling of interrupts to a point right
before running package initializers. It also removes `runtime.postinit`,
which is not necessary anymore (and was only used on AVR).
Этот коммит содержится в:
Ayke van Laethem 2022-01-01 22:54:29 +01:00 коммит произвёл Ayke
родитель e536676a67
коммит fcd88356db
22 изменённых файлов: 5 добавлений и 47 удалений

Просмотреть файл

@ -171,9 +171,6 @@ func TestCompiler(t *testing.T) {
case "float.go", "math.go", "print.go":
// Stuck in runtime.printfloat64.
case "goroutines.go":
// The main() never runs.
case "interface.go":
// Several comparison tests fail.

Просмотреть файл

@ -28,8 +28,6 @@ var _sidata [0]byte
//go:extern _edata
var _edata [0]byte
func postinit() {}
// Entry point for Go. Initialize all packages and call main.main().
//export main
func main() {

Просмотреть файл

@ -13,8 +13,6 @@ import (
type timeUnit int64
func postinit() {}
//export Reset_Handler
func main() {
preinit()

Просмотреть файл

@ -12,8 +12,6 @@ import (
type timeUnit int64
func postinit() {}
//export Reset_Handler
func main() {
arm.SCB.CPACR.Set(0) // disable FPU if it is enabled

Просмотреть файл

@ -42,6 +42,7 @@ var _ebss [0]byte
//export main
func main() {
preinit()
initHardware()
run()
exit(0)
}
@ -55,15 +56,13 @@ func preinit() {
}
}
func postinit() {
// Enable interrupts after initialization.
avr.Asm("sei")
}
func init() {
func initHardware() {
initUART()
machine.InitMonotonicTimer()
nextTimerRecalibrate = ticks() + timerRecalibrateInterval
// Enable interrupts after initialization.
avr.Asm("sei")
}
func ticksToNanoseconds(ticks timeUnit) int64 {

Просмотреть файл

@ -15,8 +15,6 @@ type timeUnit int64
var timestamp timeUnit
func postinit() {}
//export Reset_Handler
func main() {
preinit()

Просмотреть файл

@ -14,8 +14,6 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}
func postinit() {}
// Initialize .bss: zero-initialized global variables.
// The .data section has already been loaded by the ROM bootloader.
func clearbss() {

Просмотреть файл

@ -23,8 +23,6 @@ func putchar(c byte) {
//export rom_i2c_writeReg
func rom_i2c_writeReg(block, host_id, reg_add, data uint8)
func postinit() {}
//export main
func main() {
// Clear .bss section. .data has already been loaded by the ROM bootloader.

Просмотреть файл

@ -16,8 +16,6 @@ import (
type timeUnit int64
func postinit() {}
//export main
func main() {
// Zero the PLIC enable bits on startup: they are not zeroed at reset.

Просмотреть файл

@ -15,8 +15,6 @@ import (
type timeUnit int64
func postinit() {}
//export main
func main() {

Просмотреть файл

@ -16,8 +16,6 @@ var _svectors [0]byte
//go:extern _flexram_cfg
var _flexram_cfg [0]byte
func postinit() {}
//export Reset_Handler
func main() {

Просмотреть файл

@ -43,8 +43,6 @@ var (
totalHeap = uint64(0)
)
func postinit() {}
func preinit() {
// Unsafe to use heap here
setupEnv()

Просмотреть файл

@ -15,8 +15,6 @@ type timeUnit int64
//go:linkname systemInit SystemInit
func systemInit()
func postinit() {}
//export Reset_Handler
func main() {
if nrf.FPUPresent {

Просмотреть файл

@ -226,8 +226,6 @@ func initInternal() {
// analog_init();
}
func postinit() {}
func putchar(c byte) {
machine.PutcharUART(machine.UART0, c)
}

Просмотреть файл

@ -53,8 +53,6 @@ func init() {
machine.Serial.Configure(machine.UARTConfig{})
}
func postinit() {}
//export Reset_Handler
func main() {
preinit()

Просмотреть файл

@ -6,8 +6,6 @@ import "device/arm"
type timeUnit int64
func postinit() {}
//export Reset_Handler
func main() {
preinit()

Просмотреть файл

@ -15,8 +15,6 @@ type timeUnit int64
var timestamp timeUnit
func postinit() {}
//export main
func main() {
preinit()

Просмотреть файл

@ -22,8 +22,6 @@ func fd_write(id uint32, iovs *__wasi_iovec_t, iovs_len uint, nwritten *uint) (e
//export proc_exit
func proc_exit(exitcode uint32)
func postinit() {}
const (
putcharBufferSize = 120
stdout = 1

Просмотреть файл

@ -65,8 +65,6 @@ type timespec struct {
var stackTop uintptr
func postinit() {}
// Entry point for Go. Initialize all packages and call main.main().
//export main
func main(argc int32, argv *unsafe.Pointer) int {

Просмотреть файл

@ -41,8 +41,6 @@ func __p___argc() *int32
//export __p___argv
func __p___argv() **unsafe.Pointer
func postinit() {}
//export mainCRTStartup
func mainCRTStartup() int {
preinit()

Просмотреть файл

@ -22,7 +22,6 @@ func run() {
initHeap()
go func() {
initAll()
postinit()
callMain()
schedulerDone = true
}()

Просмотреть файл

@ -23,7 +23,6 @@ func getSystemStackPointer() uintptr {
func run() {
initHeap()
initAll()
postinit()
callMain()
}