Renamed x64 store function
This commit is contained in:
parent
169810e3a2
commit
9153a4ba30
3 changed files with 10 additions and 10 deletions
|
@ -1,130 +0,0 @@
|
|||
package x64
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/cpu"
|
||||
)
|
||||
|
||||
// StoreDynamicOffsetNumber stores a number into the memory address at `destination` with a register offset.
|
||||
func StoreDynamicOffsetNumber(code []byte, destination cpu.Register, offset cpu.Register, length byte, number int) []byte {
|
||||
var (
|
||||
w = byte(0)
|
||||
r = byte(0)
|
||||
x = byte(0)
|
||||
b = byte(0)
|
||||
opCode = byte(0xC7)
|
||||
mod = AddressMemory
|
||||
)
|
||||
|
||||
if length == 1 {
|
||||
opCode = 0xC6
|
||||
}
|
||||
|
||||
if offset == RSP {
|
||||
tmp := offset
|
||||
offset = destination
|
||||
destination = tmp
|
||||
}
|
||||
|
||||
if length == 8 {
|
||||
w = 1
|
||||
}
|
||||
|
||||
if offset > 0b111 {
|
||||
x = 1
|
||||
offset &= 0b111
|
||||
}
|
||||
|
||||
if destination > 0b111 {
|
||||
b = 1
|
||||
destination &= 0b111
|
||||
}
|
||||
|
||||
if destination == RBP || destination == R13 {
|
||||
mod = AddressMemoryOffset8
|
||||
}
|
||||
|
||||
if length == 2 {
|
||||
code = append(code, 0x66)
|
||||
}
|
||||
|
||||
code = append(code, REX(w, r, x, b))
|
||||
code = append(code, opCode)
|
||||
code = append(code, ModRM(mod, 0b000, 0b100))
|
||||
code = append(code, SIB(Scale1, byte(offset), byte(destination)))
|
||||
|
||||
if mod == AddressMemoryOffset8 {
|
||||
code = append(code, 0x00)
|
||||
}
|
||||
|
||||
switch length {
|
||||
case 8, 4:
|
||||
return binary.LittleEndian.AppendUint32(code, uint32(number))
|
||||
|
||||
case 2:
|
||||
return binary.LittleEndian.AppendUint16(code, uint16(number))
|
||||
}
|
||||
|
||||
return append(code, byte(number))
|
||||
}
|
||||
|
||||
// StoreDynamicOffsetRegister stores the contents of the `source` register into the memory address at `destination` with a register offset.
|
||||
func StoreDynamicOffsetRegister(code []byte, destination cpu.Register, offset cpu.Register, length byte, source cpu.Register) []byte {
|
||||
var (
|
||||
w = byte(0)
|
||||
r = byte(0)
|
||||
x = byte(0)
|
||||
b = byte(0)
|
||||
opCode = byte(0x89)
|
||||
mod = AddressMemory
|
||||
)
|
||||
|
||||
if length == 1 {
|
||||
opCode = 0x88
|
||||
}
|
||||
|
||||
if offset == RSP {
|
||||
tmp := offset
|
||||
offset = destination
|
||||
destination = tmp
|
||||
}
|
||||
|
||||
if length == 8 {
|
||||
w = 1
|
||||
}
|
||||
|
||||
if source > 0b111 {
|
||||
r = 1
|
||||
source &= 0b111
|
||||
}
|
||||
|
||||
if offset > 0b111 {
|
||||
x = 1
|
||||
offset &= 0b111
|
||||
}
|
||||
|
||||
if destination > 0b111 {
|
||||
b = 1
|
||||
destination &= 0b111
|
||||
}
|
||||
|
||||
if destination == RBP || destination == R13 {
|
||||
mod = AddressMemoryOffset8
|
||||
}
|
||||
|
||||
if length == 2 {
|
||||
code = append(code, 0x66)
|
||||
}
|
||||
|
||||
code = append(code, REX(w, r, x, b))
|
||||
code = append(code, opCode)
|
||||
code = append(code, ModRM(mod, byte(source), 0b100))
|
||||
code = append(code, SIB(Scale1, byte(offset), byte(destination)))
|
||||
|
||||
if mod == AddressMemoryOffset8 {
|
||||
code = append(code, 0x00)
|
||||
}
|
||||
|
||||
return code
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue