arm: implement arm.ReadRegister

This pseudo-function reads the contents of the specified register, for
example "sp".
This commit is contained in:
Ayke van Laethem
2018-11-18 18:40:36 +01:00
parent 8cb7b583d8
commit 27fc397e21
2 changed files with 12 additions and 0 deletions
+8
View File
@@ -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{}
+4
View File
@@ -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