Added basic support for arm64

This commit is contained in:
Eduard Urbach 2025-03-06 13:40:17 +01:00
parent cc1c990dc8
commit dfe807c2e2
Signed by: eduard
GPG key ID: 49226B848C78F6C8
25 changed files with 270 additions and 33 deletions

29
src/arm/Move.go Normal file
View file

@ -0,0 +1,29 @@
package arm
import (
"encoding/binary"
"git.urbach.dev/cli/q/src/cpu"
)
// MoveRegisterNumber moves an integer into the given register.
func MoveRegisterNumber(code []byte, destination cpu.Register, number int) []byte {
return MoveZero(code, destination, 0, uint16(number))
}
// MoveKeep moves a 16-bit integer into the given register and keeps all other bits.
func MoveKeep(code []byte, destination cpu.Register, halfword int, number uint16) []byte {
x := mov(0b11, halfword, number, destination)
return binary.LittleEndian.AppendUint32(code, x)
}
// MoveZero moves a 16-bit integer into the given register and clears all other bits to zero.
func MoveZero(code []byte, destination cpu.Register, halfword int, number uint16) []byte {
x := mov(0b10, halfword, number, destination)
return binary.LittleEndian.AppendUint32(code, x)
}
// mov encodes a generic move instruction.
func mov(opCode uint32, halfword int, number uint16, destination cpu.Register) uint32 {
return (1 << 31) | (opCode << 29) | (0b100101 << 23) | uint32(halfword<<21) | uint32(number<<5) | uint32(destination)
}