Reorganized file structure
This commit is contained in:
@ -1,14 +0,0 @@
|
||||
package x64
|
||||
|
||||
// Call places the return address on the top of the stack and continues
|
||||
// program flow at the new address. The address is relative to the next instruction.
|
||||
func Call(code []byte, address uint32) []byte {
|
||||
return append(
|
||||
code,
|
||||
0xe8,
|
||||
byte(address),
|
||||
byte(address>>8),
|
||||
byte(address>>16),
|
||||
byte(address>>24),
|
||||
)
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package x64
|
||||
|
||||
// MoveRegNum32 moves a 32 bit integer into the given register.
|
||||
func MoveRegNum32(code []byte, register uint8, number uint32) []byte {
|
||||
return append(
|
||||
code,
|
||||
0xb8+register,
|
||||
byte(number),
|
||||
byte(number>>8),
|
||||
byte(number>>16),
|
||||
byte(number>>24),
|
||||
)
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package x64
|
||||
|
||||
// Return transfers program control to a return address located on the top of the stack.
|
||||
// The address is usually placed on the stack by a Call instruction.
|
||||
func Return(code []byte) []byte {
|
||||
return append(code, 0xc3)
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package x64
|
||||
|
||||
import "git.akyoto.dev/cli/q/src/register"
|
||||
|
||||
const (
|
||||
SyscallNumber = register.R0 // rax
|
||||
SyscallReturn = register.R0 // rax
|
||||
)
|
||||
|
||||
var SyscallArgs = []register.ID{
|
||||
register.R7, // rdi
|
||||
register.R6, // rsi
|
||||
register.R2, // rdx
|
||||
register.R10,
|
||||
register.R8,
|
||||
register.R9,
|
||||
}
|
||||
|
||||
// Syscall is the primary way to communicate with the OS kernel.
|
||||
func Syscall(code []byte) []byte {
|
||||
return append(code, 0x0f, 0x05)
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package x64_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/arch/x64"
|
||||
"git.akyoto.dev/go/assert"
|
||||
)
|
||||
|
||||
func TestX64(t *testing.T) {
|
||||
assert.DeepEqual(t, x64.Call([]byte{}, 1), []byte{0xe8, 0x01, 0x00, 0x00, 0x00})
|
||||
assert.DeepEqual(t, x64.MoveRegNum32([]byte{}, 0, 1), []byte{0xb8, 0x01, 0x00, 0x00, 0x00})
|
||||
assert.DeepEqual(t, x64.MoveRegNum32([]byte{}, 1, 1), []byte{0xb9, 0x01, 0x00, 0x00, 0x00})
|
||||
assert.DeepEqual(t, x64.Return([]byte{}), []byte{0xc3})
|
||||
assert.DeepEqual(t, x64.Syscall([]byte{}), []byte{0x0f, 0x05})
|
||||
}
|
Reference in New Issue
Block a user