From 9d6356e8a9db4d1536ddc8a1e832e1672aff4a04 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 29 Apr 2025 18:12:51 +0200 Subject: [PATCH] Implemented code pointers on arm64 --- src/asmc/armCompiler.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/asmc/armCompiler.go b/src/asmc/armCompiler.go index 0ce0434..e8529a0 100644 --- a/src/asmc/armCompiler.go +++ b/src/asmc/armCompiler.go @@ -80,7 +80,7 @@ func (c *armCompiler) handleMoveInstruction(instruction asm.Instruction) { if operands.Label.Type == asm.DataLabel { c.dataPointers = append(c.dataPointers, c.createDataPointer(operands, position)) } else { - panic("not implemented") + c.codePointers = append(c.codePointers, c.createCodePointer(operands, position)) } } } @@ -398,6 +398,24 @@ func (c *armCompiler) handleNegateInstruction(instruction asm.Instruction) { } } +func (c *armCompiler) createCodePointer(operands asm.RegisterLabel, position Address) *pointer { + return &pointer{ + Position: position, + OpSize: 0, + Size: 4, + Resolve: func() Address { + destination, exists := c.codeLabels[operands.Label.Name] + + if !exists { + panic("unknown label") + } + + distance := destination - position + 8 + return arm.LoadAddress(operands.Register, int(distance)) + }, + } +} + func (c *armCompiler) createDataPointer(operands asm.RegisterLabel, position Address) *pointer { return &pointer{ Position: position,