Implemented position independent addresses for x86

This commit is contained in:
Eduard Urbach 2025-03-07 11:39:13 +01:00
parent 014f161633
commit 0765351891
Signed by: eduard
GPG key ID: 49226B848C78F6C8
3 changed files with 68 additions and 13 deletions

13
src/x86/LoadAddress.go Normal file
View file

@ -0,0 +1,13 @@
package x86
import (
"encoding/binary"
"git.urbach.dev/cli/q/src/cpu"
)
// LoadAddress calculates the address with the RIP-relative offset and writes the result to the destination register.
func LoadAddress(code []byte, destination cpu.Register, offset int) []byte {
code = encode(code, AddressMemory, destination, 0b101, 8, 0x8D)
return binary.LittleEndian.AppendUint32(code, uint32(offset))
}