compiler: work around AVR atomics bugs

The AVR backend has several critical atomics bugs.
This change invokes libcalls for all atomic operations on AVR.
Now `testdata/atomic.go` compiles and runs correctly.
This commit is contained in:
Nia Waldvogel
2022-01-13 14:02:34 -05:00
committed by Ron Evans
parent b2ef7299b7
commit e2178ce682
3 changed files with 53 additions and 1 deletions
+19
View File
@@ -1,7 +1,10 @@
//go:build avr
// +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).
@@ -16,3 +19,19 @@ func align(ptr uintptr) uintptr {
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)
}