mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
3392827c3e
This is not very useful in itself, but makes it possible to detect this address in the output. See the next commit. This adds around 50 bytes to each binary (except for AVR and wasm). This is unfortunate, but I think this feature is quite useful still. A future enhancement might be to create a build tag for extended panic information that's not set by default.
79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
//go:build avr
|
|
|
|
package runtime
|
|
|
|
import "runtime/interrupt"
|
|
|
|
const GOARCH = "arm" // avr pretends to be arm
|
|
|
|
// The bitness of the CPU (e.g. 8, 32, 64).
|
|
const TargetBits = 8
|
|
|
|
const deferExtraRegs = 1 // the frame pointer (Y register) also needs to be stored
|
|
|
|
const callInstSize = 2 // "call" is 4 bytes, "rcall" is 2 bytes
|
|
|
|
// Align on a word boundary.
|
|
func align(ptr uintptr) uintptr {
|
|
// No alignment necessary on the AVR.
|
|
return ptr
|
|
}
|
|
|
|
func getCurrentStackPointer() uintptr {
|
|
return uintptr(stacksave())
|
|
}
|
|
|
|
// The safest thing to do here would just be to disable interrupts for
|
|
// procPin/procUnpin. Note that a global variable is safe in this case, as any
|
|
// access to procPinnedMask will happen with interrupts disabled.
|
|
|
|
var procPinnedMask interrupt.State
|
|
|
|
//go:linkname procPin sync/atomic.runtime_procPin
|
|
func procPin() {
|
|
procPinnedMask = interrupt.Disable()
|
|
}
|
|
|
|
//go:linkname procUnpin sync/atomic.runtime_procUnpin
|
|
func procUnpin() {
|
|
interrupt.Restore(procPinnedMask)
|
|
}
|
|
|
|
// The following functions are workarounds for things missing in compiler-rt.
|
|
// They will likely need special assembly implementations.
|
|
// They are treated specially: they're added to @llvm.compiler.used so that the
|
|
// linker won't eliminate them.
|
|
|
|
//export __mulsi3
|
|
func __mulsi3(a, b uint32) uint32 {
|
|
var r uint32
|
|
for a != 0 {
|
|
if a&1 != 0 {
|
|
r += b
|
|
}
|
|
a >>= 1
|
|
b <<= 1
|
|
}
|
|
return r
|
|
}
|
|
|
|
//export __divsi3
|
|
func __divsi3(a, b int32) int32
|
|
|
|
//export __udivsi3
|
|
func __udivsi3(a, b uint32) uint32
|
|
|
|
//export __divmodsi4
|
|
func __divmodsi4(a, b int32) uint64 {
|
|
d := __divsi3(a, b)
|
|
rem := a - (d * b)
|
|
return uint64(uint32(d)) | uint64(uint32(rem))<<32
|
|
}
|
|
|
|
//export __udivmodsi4
|
|
func __udivmodsi4(a, b uint32) uint64 {
|
|
d := __udivsi3(a, b)
|
|
rem := a - (d * b)
|
|
return uint64(d) | uint64(rem)<<32
|
|
}
|