github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/arch_avr.go (about) 1 //go:build avr 2 3 package runtime 4 5 import "runtime/interrupt" 6 7 const GOARCH = "arm" // avr pretends to be arm 8 9 // The bitness of the CPU (e.g. 8, 32, 64). 10 const TargetBits = 8 11 12 const deferExtraRegs = 1 // the frame pointer (Y register) also needs to be stored 13 14 const callInstSize = 2 // "call" is 4 bytes, "rcall" is 2 bytes 15 16 // Align on a word boundary. 17 func align(ptr uintptr) uintptr { 18 // No alignment necessary on the AVR. 19 return ptr 20 } 21 22 func getCurrentStackPointer() uintptr { 23 return uintptr(stacksave()) 24 } 25 26 // The safest thing to do here would just be to disable interrupts for 27 // procPin/procUnpin. Note that a global variable is safe in this case, as any 28 // access to procPinnedMask will happen with interrupts disabled. 29 30 var procPinnedMask interrupt.State 31 32 //go:linkname procPin sync/atomic.runtime_procPin 33 func procPin() { 34 procPinnedMask = interrupt.Disable() 35 } 36 37 //go:linkname procUnpin sync/atomic.runtime_procUnpin 38 func procUnpin() { 39 interrupt.Restore(procPinnedMask) 40 } 41 42 // The following functions are workarounds for things missing in compiler-rt. 43 // They will likely need special assembly implementations. 44 // They are treated specially: they're added to @llvm.compiler.used so that the 45 // linker won't eliminate them. 46 47 //export __mulsi3 48 func __mulsi3(a, b uint32) uint32 { 49 var r uint32 50 for a != 0 { 51 if a&1 != 0 { 52 r += b 53 } 54 a >>= 1 55 b <<= 1 56 } 57 return r 58 } 59 60 //export __divsi3 61 func __divsi3(a, b int32) int32 62 63 //export __udivsi3 64 func __udivsi3(a, b uint32) uint32 65 66 //export __divmodsi4 67 func __divmodsi4(a, b int32) uint64 { 68 d := __divsi3(a, b) 69 rem := a - (d * b) 70 return uint64(uint32(d)) | uint64(uint32(rem))<<32 71 } 72 73 //export __udivmodsi4 74 func __udivmodsi4(a, b uint32) uint64 { 75 d := __udivsi3(a, b) 76 rem := a - (d * b) 77 return uint64(d) | uint64(rem)<<32 78 }