mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 12:33:42 +00:00
all: pretend to be linux/arm in baremetal targets
So far, we've pretended to be js/wasm in baremetal targets to make the
stdlib happy. Unfortunately, this has various problems because
syscall/js (a dependency of many stdlib packages) thinks it can do JS
calls, and emulating them gets quite hard with all changes to the
syscall/js packages in Go 1.12.
This commit does a few things:
* It lets baremetal targets pretend to be linux/arm instead of
js/wasm.
* It lets the loader only select particular packages from the src
overlay, instead of inserting them just before GOROOT. This makes it
possible to pick which packages to overlay for a given target.
* It adds a baremetal-only syscall package that stubs out almost all
syscalls.
This commit is contained in:
committed by
Ron Evans
parent
792274e86f
commit
a2d0f79be3
@@ -0,0 +1,55 @@
|
||||
// +build cortexm
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"device/arm"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//go:extern _sbss
|
||||
var _sbss unsafe.Pointer
|
||||
|
||||
//go:extern _ebss
|
||||
var _ebss unsafe.Pointer
|
||||
|
||||
//go:extern _sdata
|
||||
var _sdata unsafe.Pointer
|
||||
|
||||
//go:extern _sidata
|
||||
var _sidata unsafe.Pointer
|
||||
|
||||
//go:extern _edata
|
||||
var _edata unsafe.Pointer
|
||||
|
||||
func preinit() {
|
||||
// Initialize .bss: zero-initialized global variables.
|
||||
ptr := uintptr(unsafe.Pointer(&_sbss))
|
||||
for ptr != uintptr(unsafe.Pointer(&_ebss)) {
|
||||
*(*uint32)(unsafe.Pointer(ptr)) = 0
|
||||
ptr += 4
|
||||
}
|
||||
|
||||
// Initialize .data: global variables initialized from flash.
|
||||
src := uintptr(unsafe.Pointer(&_sidata))
|
||||
dst := uintptr(unsafe.Pointer(&_sdata))
|
||||
for dst != uintptr(unsafe.Pointer(&_edata)) {
|
||||
*(*uint32)(unsafe.Pointer(dst)) = *(*uint32)(unsafe.Pointer(src))
|
||||
dst += 4
|
||||
src += 4
|
||||
}
|
||||
}
|
||||
|
||||
func abort() {
|
||||
for {
|
||||
arm.Asm("wfi")
|
||||
}
|
||||
}
|
||||
|
||||
// Implement memset for compiler-rt.
|
||||
//go:export memset
|
||||
func memset(ptr unsafe.Pointer, c byte, size uintptr) {
|
||||
for i := uintptr(0); i < size; i++ {
|
||||
*(*byte)(unsafe.Pointer(uintptr(ptr) + i)) = c
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user