mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
98f84a497d
There were a few issues that were causing qemu-system-arm and
qemu-system-riscv to give the wrong exit codes. They are in fact capable
of exiting with 0 or 1 signalled from the running application, but this
functionality wasn't used. This commit changes this in the following
ways:
* It fixes SemiHosting codes, which were incorrectly written in
decimal while they should have been written in hexadecimal (oops!).
* It modifies all the baremetal main functions (aka reset handlers) to
exit with `exit(0)` instead of `abort()`.
* It changes `syscall.Exit` to call `exit(code)` instead of `abort()`
on baremetal targets.
* It adds these new exit functions where necessary, implemented in a
way that signals the correct exit status if running under QEMU.
All in all, this means that `tinygo test` doesn't have to look at the
output of a test to determine the outcome. It can simply look at the
exit code.
64 lines
917 B
Go
64 lines
917 B
Go
// +build rp2040
|
|
|
|
package runtime
|
|
|
|
import (
|
|
"device/arm"
|
|
|
|
"machine"
|
|
)
|
|
|
|
// machineTicks is provided by package machine.
|
|
func machineTicks() uint64
|
|
|
|
type timeUnit uint64
|
|
|
|
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
|
func ticks() timeUnit {
|
|
t := machineTicks()
|
|
return timeUnit(t)
|
|
}
|
|
|
|
func ticksToNanoseconds(ticks timeUnit) int64 {
|
|
return int64(ticks) * 1000
|
|
}
|
|
|
|
func nanosecondsToTicks(ns int64) timeUnit {
|
|
return timeUnit(ns / 1000)
|
|
}
|
|
|
|
func sleepTicks(d timeUnit) {
|
|
if d == 0 {
|
|
return
|
|
}
|
|
sleepUntil := ticks() + d
|
|
for ticks() < sleepUntil {
|
|
}
|
|
}
|
|
|
|
func waitForEvents() {
|
|
arm.Asm("wfe")
|
|
}
|
|
|
|
func putchar(c byte) {
|
|
machine.Serial.WriteByte(c)
|
|
}
|
|
|
|
// machineInit is provided by package machine.
|
|
func machineInit()
|
|
|
|
func init() {
|
|
machineInit()
|
|
|
|
machine.Serial.Configure(machine.UARTConfig{})
|
|
}
|
|
|
|
func postinit() {}
|
|
|
|
//export Reset_Handler
|
|
func main() {
|
|
preinit()
|
|
run()
|
|
exit(0)
|
|
}
|