all: add emulation support for Cortex-M3 with QEMU

This commit is contained in:
Ayke van Laethem
2018-10-08 17:07:19 +02:00
parent 8982b8df83
commit a63af97e86
8 changed files with 243 additions and 16 deletions
+63
View File
@@ -0,0 +1,63 @@
package arm
// Semihosting commands.
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471c/Bgbjhiea.html
const (
// Regular semihosting calls
SemihostingClock = 0x10
SemihostingClose = 0x02
SemihostingElapsed = 0x30
SemihostingErrno = 0x13
SemihostingFileLen = 0x0C
SemihostingGetCmdline = 0x15
SemihostingHeapInfo = 0x16
SemihostingIsError = 0x08
SemihostingIsTTY = 0x09
SemihostingOpen = 0x01
SemihostingRead = 0x06
SemihostingReadByte = 0x07
SemihostingRemove = 0x0E
SemihostingRename = 0x0F
SemihostingSeek = 0x0A
SemihostingSystem = 0x12
SemihostingTickFreq = 0x31
SemihostingTime = 0x11
SemihostingTmpName = 0x0D
SemihostingWrite = 0x05
SemihostingWrite0 = 0x04
SemihostingWriteByte = 0x03
// Angel semihosting calls
SemihostingEnterSVC = 0x17
SemihostingReportException = 0x18
)
// Special codes for the Angel Semihosting interface.
const (
// Hardware vector reason codes
SemihostingBranchThroughZero = 20000
SemihostingUndefinedInstr = 20001
SemihostingSoftwareInterrupt = 20002
SemihostingPrefetchAbort = 20003
SemihostingDataAbort = 20004
SemihostingAddressException = 20005
SemihostingIRQ = 20006
SemihostingFIQ = 20007
// Software reason codes
SemihostingBreakPoint = 20020
SemihostingWatchPoint = 20021
SemihostingStepComplete = 20022
SemihostingRunTimeErrorUnknown = 20023
SemihostingInternalError = 20024
SemihostingUserInterruption = 20025
SemihostingApplicationExit = 20026
SemihostingStackOverflow = 20027
SemihostingDivisionByZero = 20028
SemihostingOSSpecific = 20029
)
// Call a semihosting function.
// TODO: implement it here using inline assembly.
//go:linkname SemihostingCall SemihostingCall
func SemihostingCall(num int, arg uintptr) int
+45
View File
@@ -0,0 +1,45 @@
// +build qemu
package runtime
// This file implements the Stellaris LM3S6965 Cortex-M3 chip as implemented by
// QEMU.
import (
"device/arm"
"unsafe"
)
type timeUnit int64
const tickMicros = 1
var timestamp timeUnit
//go:export Reset_Handler
func main() {
preinit()
initAll()
mainWrapper()
arm.SemihostingCall(arm.SemihostingReportException, arm.SemihostingApplicationExit)
abort()
}
func sleepTicks(d timeUnit) {
// TODO: actually sleep here for the given time.
timestamp += d
}
func ticks() timeUnit {
return timestamp
}
//go:volatile
type regValue uint32
// UART0 output register.
var stdoutWrite *regValue = (*regValue)(unsafe.Pointer(uintptr(0x4000c000)))
func putchar(c byte) {
*stdoutWrite = regValue(c)
}