qemu: signal correct exit code to QEMU
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.
Этот коммит содержится в:
родитель
00c73d62ad
коммит
98f84a497d
23 изменённых файлов: 104 добавлений и 41 удалений
|
@ -33,28 +33,29 @@ const (
|
|||
)
|
||||
|
||||
// Special codes for the Angel Semihosting interface.
|
||||
// https://www.keil.com/support/man/docs/armcc/armcc_pge1358787050566.htm
|
||||
const (
|
||||
// Hardware vector reason codes
|
||||
SemihostingBranchThroughZero = 20000
|
||||
SemihostingUndefinedInstr = 20001
|
||||
SemihostingSoftwareInterrupt = 20002
|
||||
SemihostingPrefetchAbort = 20003
|
||||
SemihostingDataAbort = 20004
|
||||
SemihostingAddressException = 20005
|
||||
SemihostingIRQ = 20006
|
||||
SemihostingFIQ = 20007
|
||||
SemihostingBranchThroughZero = 0x20000
|
||||
SemihostingUndefinedInstr = 0x20001
|
||||
SemihostingSoftwareInterrupt = 0x20002
|
||||
SemihostingPrefetchAbort = 0x20003
|
||||
SemihostingDataAbort = 0x20004
|
||||
SemihostingAddressException = 0x20005
|
||||
SemihostingIRQ = 0x20006
|
||||
SemihostingFIQ = 0x20007
|
||||
|
||||
// Software reason codes
|
||||
SemihostingBreakPoint = 20020
|
||||
SemihostingWatchPoint = 20021
|
||||
SemihostingStepComplete = 20022
|
||||
SemihostingRunTimeErrorUnknown = 20023
|
||||
SemihostingInternalError = 20024
|
||||
SemihostingUserInterruption = 20025
|
||||
SemihostingApplicationExit = 20026
|
||||
SemihostingStackOverflow = 20027
|
||||
SemihostingDivisionByZero = 20028
|
||||
SemihostingOSSpecific = 20029
|
||||
SemihostingBreakPoint = 0x20020
|
||||
SemihostingWatchPoint = 0x20021
|
||||
SemihostingStepComplete = 0x20022
|
||||
SemihostingRunTimeErrorUnknown = 0x20023
|
||||
SemihostingInternalError = 0x20024
|
||||
SemihostingUserInterruption = 0x20025
|
||||
SemihostingApplicationExit = 0x20026
|
||||
SemihostingStackOverflow = 0x20027
|
||||
SemihostingDivisionByZero = 0x20028
|
||||
SemihostingOSSpecific = 0x20029
|
||||
)
|
||||
|
||||
// Call a semihosting function.
|
||||
|
|
|
@ -48,7 +48,7 @@ func libc_free(ptr unsafe.Pointer) {
|
|||
|
||||
//go:linkname syscall_Exit syscall.Exit
|
||||
func syscall_Exit(code int) {
|
||||
abort()
|
||||
exit(code)
|
||||
}
|
||||
|
||||
const baremetal = true
|
||||
|
|
|
@ -75,6 +75,10 @@ func sleepTicks(d timeUnit) {
|
|||
// TODO
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
// TODO
|
||||
for {
|
||||
|
|
|
@ -19,7 +19,7 @@ func postinit() {}
|
|||
func main() {
|
||||
preinit()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -19,7 +19,7 @@ func main() {
|
|||
arm.SCB.CPACR.Set(0) // disable FPU if it is enabled
|
||||
preinit()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -37,7 +37,7 @@ var _ebss [0]byte
|
|||
func main() {
|
||||
preinit()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func preinit() {
|
||||
|
@ -84,6 +84,10 @@ func ticks() timeUnit {
|
|||
return currentTime
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
for {
|
||||
sleepWDT(WDT_PERIOD_2S)
|
||||
|
|
|
@ -6,6 +6,10 @@ import (
|
|||
"device/arm"
|
||||
)
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
// lock up forever
|
||||
for {
|
||||
|
|
|
@ -23,8 +23,7 @@ func main() {
|
|||
run()
|
||||
|
||||
// Signal successful exit.
|
||||
arm.SemihostingCall(arm.SemihostingReportException, arm.SemihostingApplicationExit)
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||
|
@ -56,8 +55,16 @@ func waitForEvents() {
|
|||
}
|
||||
|
||||
func abort() {
|
||||
// Signal an abnormal exit.
|
||||
arm.SemihostingCall(arm.SemihostingReportException, arm.SemihostingRunTimeErrorUnknown)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
// Exit QEMU.
|
||||
if code == 0 {
|
||||
arm.SemihostingCall(arm.SemihostingReportException, arm.SemihostingApplicationExit)
|
||||
} else {
|
||||
arm.SemihostingCall(arm.SemihostingReportException, arm.SemihostingRunTimeErrorUnknown)
|
||||
}
|
||||
|
||||
// Lock up forever (should be unreachable).
|
||||
for {
|
||||
|
|
|
@ -51,7 +51,7 @@ func main() {
|
|||
run()
|
||||
|
||||
// Fallback: if main ever returns, hang the CPU.
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
//go:extern _sbss
|
||||
|
|
|
@ -54,7 +54,7 @@ func main() {
|
|||
run()
|
||||
|
||||
// Fallback: if main ever returns, hang the CPU.
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func abort() {
|
||||
|
|
|
@ -67,3 +67,7 @@ func sleepTicks(d timeUnit) {
|
|||
// TODO: suspend the CPU to not burn power here unnecessarily.
|
||||
}
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func main() {
|
|||
run()
|
||||
|
||||
// Fallback: if main ever returns, hang the CPU.
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
//go:extern _sbss
|
||||
|
@ -106,6 +106,10 @@ func sleepTicks(d timeUnit) {
|
|||
}
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
for {
|
||||
device.Asm("waiti 0")
|
||||
|
|
|
@ -42,7 +42,7 @@ func main() {
|
|||
preinit()
|
||||
initPeripherals()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
//go:extern handleInterruptASM
|
||||
|
|
|
@ -22,6 +22,10 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
|||
return timeUnit(ns * 64 / 1953125)
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
// lock up forever
|
||||
for {
|
||||
|
|
|
@ -21,6 +21,16 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
|||
}
|
||||
|
||||
func abort() {
|
||||
// Signal a successful exit.
|
||||
testExit.Set(0x5555)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
if code == 0 {
|
||||
// Signal a successful exit.
|
||||
testExit.Set(0x5555) // FINISHER_PASS
|
||||
} else {
|
||||
// Signal a failure. The exit code is stored in the upper 16 bits of the
|
||||
// 32 bit value.
|
||||
testExit.Set(uint32(code)<<16 | 0x3333) // FINISHER_FAIL
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func main() {
|
|||
preinit()
|
||||
initPeripherals()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func initPLIC() {
|
||||
|
|
|
@ -20,6 +20,10 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
|||
return timeUnit(ns * 39 / 5000)
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
// lock up forever
|
||||
for {
|
||||
|
|
|
@ -43,7 +43,7 @@ func main() {
|
|||
arm.EnableInterrupts(irq)
|
||||
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func getRamSizeConfig(itcmKB, dtcmKB uint32) uint32 {
|
||||
|
@ -127,6 +127,10 @@ func putchar(c byte) {
|
|||
machine.UART1.WriteByte(c)
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
for {
|
||||
arm.Asm("wfe")
|
||||
|
|
|
@ -25,7 +25,7 @@ func main() {
|
|||
systemInit()
|
||||
preinit()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -58,7 +58,7 @@ func main() {
|
|||
initInternal()
|
||||
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func initSystem() {
|
||||
|
@ -232,6 +232,10 @@ func putchar(c byte) {
|
|||
machine.PutcharUART(machine.UART0, c)
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
println("!!! ABORT !!!")
|
||||
|
||||
|
|
|
@ -59,5 +59,5 @@ func postinit() {}
|
|||
func main() {
|
||||
preinit()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ func postinit() {}
|
|||
func main() {
|
||||
preinit()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
|
|
|
@ -21,7 +21,7 @@ func postinit() {}
|
|||
func main() {
|
||||
preinit()
|
||||
run()
|
||||
abort()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||
|
@ -49,7 +49,7 @@ var (
|
|||
// UART0 output register.
|
||||
stdoutWrite = (*volatile.Register8)(unsafe.Pointer(uintptr(0x10000000)))
|
||||
// SiFive test finisher
|
||||
testFinisher = (*volatile.Register16)(unsafe.Pointer(uintptr(0x100000)))
|
||||
testFinisher = (*volatile.Register32)(unsafe.Pointer(uintptr(0x100000)))
|
||||
)
|
||||
|
||||
func putchar(c byte) {
|
||||
|
@ -57,8 +57,17 @@ func putchar(c byte) {
|
|||
}
|
||||
|
||||
func abort() {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
// Make sure the QEMU process exits.
|
||||
testFinisher.Set(0x5555) // FINISHER_PASS
|
||||
if code == 0 {
|
||||
testFinisher.Set(0x5555) // FINISHER_PASS
|
||||
} else {
|
||||
// Exit code is stored in the upper 16 bits of the 32 bit value.
|
||||
testFinisher.Set(uint32(code)<<16 | 0x3333) // FINISHER_FAIL
|
||||
}
|
||||
|
||||
// Lock up forever (as a fallback).
|
||||
for {
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче