mirror of https://github.com/tinygo-org/tinygo.git
Ayke van Laethem
6 years ago
8 changed files with 242 additions and 15 deletions
@ -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 |
@ -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) |
|||
} |
@ -0,0 +1,61 @@ |
|||
// Generic Cortex-M interrupt vector. |
|||
// This vector is used by the QEMU target. |
|||
|
|||
.syntax unified |
|||
|
|||
// This is a convenience function for QEMU semihosting support. |
|||
// At some point, this should be replaced by inline assembly. |
|||
.section .text.SemihostingCall |
|||
.global SemihostingCall |
|||
.type SemihostingCall, %function |
|||
SemihostingCall: |
|||
bkpt 0xab |
|||
bx lr |
|||
|
|||
// This is the default handler for interrupts, if triggered but not defined. |
|||
.section .text.Default_Handler |
|||
.global Default_Handler |
|||
.type Default_Handler, %function |
|||
Default_Handler: |
|||
wfe |
|||
b Default_Handler |
|||
|
|||
// Avoid the need for repeated .weak and .set instructions. |
|||
.macro IRQ handler |
|||
.weak \handler |
|||
.set \handler, Default_Handler |
|||
.endm |
|||
|
|||
.section .isr_vector |
|||
.global __isr_vector |
|||
// Interrupt vector as defined by Cortex-M, starting with the stack top. |
|||
// On reset, SP is initialized with *0x0 and PC is loaded with *0x4, loading |
|||
// _stack_top and Reset_Handler. |
|||
.long _stack_top |
|||
.long Reset_Handler |
|||
.long NMI_Handler |
|||
.long HardFault_Handler |
|||
.long MemoryManagement_Handler |
|||
.long BusFault_Handler |
|||
.long UsageFault_Handler |
|||
.long 0 |
|||
.long 0 |
|||
.long 0 |
|||
.long 0 |
|||
.long SVC_Handler |
|||
.long DebugMon_Handler |
|||
.long 0 |
|||
.long PendSV_Handler |
|||
.long SysTick_Handler |
|||
|
|||
// Define default implementations for interrupts, redirecting to |
|||
// Default_Handler when not implemented. |
|||
IRQ NMI_Handler |
|||
IRQ HardFault_Handler |
|||
IRQ MemoryManagement_Handler |
|||
IRQ BusFault_Handler |
|||
IRQ UsageFault_Handler |
|||
IRQ SVC_Handler |
|||
IRQ DebugMon_Handler |
|||
IRQ PendSV_Handler |
|||
IRQ SysTick_Handler |
@ -0,0 +1,10 @@ |
|||
|
|||
MEMORY |
|||
{ |
|||
FLASH_TEXT (rw) : ORIGIN = 0x00000000, LENGTH = 256K |
|||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K |
|||
} |
|||
|
|||
_stack_size = 4K; |
|||
|
|||
INCLUDE "targets/arm.ld" |
@ -0,0 +1,20 @@ |
|||
{ |
|||
"llvm-target": "armv7m-none-eabi", |
|||
"build-tags": ["qemu", "lm3s6965", "arm", "js", "wasm"], |
|||
"linker": "arm-none-eabi-gcc", |
|||
"compiler-rt": true, |
|||
"pre-link-args": [ |
|||
"-nostdlib", |
|||
"-nostartfiles", |
|||
"-mcpu=cortex-m0", |
|||
"-mthumb", |
|||
"-T", "targets/lm3s6965.ld", |
|||
"-Wl,--gc-sections", |
|||
"-fno-exceptions", "-fno-unwind-tables", |
|||
"-ffunction-sections", "-fdata-sections", |
|||
"-Os", |
|||
"targets/cortex-m.s" |
|||
], |
|||
"objcopy": "arm-none-eabi-objcopy", |
|||
"emulator": ["qemu-system-arm", "-machine", "lm3s6965evb", "-semihosting", "-nographic", "-kernel"] |
|||
} |
Loading…
Reference in new issue