From 27fc397e2140577d4f6af5ba60e42f580895f466 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 18 Nov 2018 18:40:36 +0100 Subject: [PATCH] arm: implement arm.ReadRegister This pseudo-function reads the contents of the specified register, for example "sp". --- compiler/compiler.go | 8 ++++++++ src/device/arm/arm.go | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/compiler/compiler.go b/compiler/compiler.go index f31e9481..bb6ffbbf 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -1964,6 +1964,14 @@ func (c *Compiler) parseCall(frame *Frame, instr *ssa.CallCommon, parentHandle l return c.builder.CreateCall(target, nil, ""), nil } + if fn.RelString(nil) == "device/arm.ReadRegister" { + // Magic function: return the given register. + fnType := llvm.FunctionType(c.uintptrType, []llvm.Type{}, false) + regname := constant.StringVal(instr.Args[0].(*ssa.Const).Value) + target := llvm.InlineAsm(fnType, "mov $0, "+regname, "=r", false, false, 0) + return c.builder.CreateCall(target, nil, ""), nil + } + if fn.RelString(nil) == "device/arm.AsmFull" || fn.RelString(nil) == "device/avr.AsmFull" { asmString := constant.StringVal(instr.Args[0].(*ssa.Const).Value) registers := map[string]llvm.Value{} diff --git a/src/device/arm/arm.go b/src/device/arm/arm.go index d351348b..5ff7d074 100644 --- a/src/device/arm/arm.go +++ b/src/device/arm/arm.go @@ -50,6 +50,10 @@ func Asm(asm string) // }) func AsmFull(asm string, regs map[string]interface{}) +// ReadRegister returns the contents of the specified register. The register +// must be a processor register, reachable with the "mov" instruction. +func ReadRegister(name string) uintptr + //go:volatile type RegValue uint32