mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 02:57:46 +00:00
avr: convert initialization from asm to Go
This increases code size by 1 instruction (2 bytes) because LLVM isn't yet smart enough to recognize that it doesn't need to clear a register to use 0: it can just use r1 which is always 0 according to the convention. It makes initialization a lot easier to read, however.
This commit is contained in:
@@ -22,9 +22,15 @@ var hasScheduler bool
|
||||
// Entry point for Go. Initialize all packages and call main.main().
|
||||
//go:export main
|
||||
func main() int {
|
||||
// Initialize memory etc.
|
||||
preinit()
|
||||
|
||||
// Run initializers of all packages.
|
||||
initAll()
|
||||
|
||||
// Enable interrupts etc.
|
||||
postinit()
|
||||
|
||||
// This branch must be optimized away. Only one of the targets must remain,
|
||||
// or there will be link errors.
|
||||
if hasScheduler {
|
||||
|
||||
@@ -4,6 +4,7 @@ package runtime
|
||||
|
||||
import (
|
||||
"device/avr"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const BOARD = "arduino"
|
||||
@@ -28,6 +29,25 @@ const (
|
||||
WDT_PERIOD_2S
|
||||
)
|
||||
|
||||
var (
|
||||
_extern__sbss unsafe.Pointer // defined by the linker
|
||||
_extern__ebss unsafe.Pointer // defined by the linker
|
||||
)
|
||||
|
||||
func preinit() {
|
||||
// Initialize .bss: zero-initialized global variables.
|
||||
ptr := uintptr(unsafe.Pointer(&_extern__sbss))
|
||||
for ptr != uintptr(unsafe.Pointer(&_extern__ebss)) {
|
||||
*(*uint8)(unsafe.Pointer(ptr)) = 0
|
||||
ptr += 1
|
||||
}
|
||||
}
|
||||
|
||||
func postinit() {
|
||||
// Enable interrupts after initialization.
|
||||
avr.Asm("sei")
|
||||
}
|
||||
|
||||
func init() {
|
||||
initUART()
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ func _start() {
|
||||
main()
|
||||
}
|
||||
|
||||
func preinit() {
|
||||
}
|
||||
|
||||
func postinit() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
initUART()
|
||||
initLFCLK()
|
||||
|
||||
@@ -24,6 +24,12 @@ type timespec struct {
|
||||
|
||||
const CLOCK_MONOTONIC_RAW = 4
|
||||
|
||||
func preinit() {
|
||||
}
|
||||
|
||||
func postinit() {
|
||||
}
|
||||
|
||||
func putchar(c byte) {
|
||||
_Cfunc_putchar(int(c))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user