amd64

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RAX asm.Variable = iota
	RBX
	RCX
	RDX
	RSI
	RDI
	RSP
	RBP
	R8
	R9
	R10
	R11
	R12
	R13
	R14
	R15
)

Variables

This section is empty.

Functions

func AddRegImm

func AddRegImm(reg Reg, value int32) asm.Fragment

func AddRegReg

func AddRegReg(dst, src Reg) asm.Fragment

func AndRegImm

func AndRegImm(reg Reg, value int32) asm.Fragment

func AndRegReg

func AndRegReg(dst, src Reg) asm.Fragment

func Call

func Call(label asm.Label) asm.Fragment

func CallReg

func CallReg(target Reg) asm.Fragment

func Cli

func Cli() asm.Fragment

func CmpRegImm

func CmpRegImm(reg Reg, value int32) asm.Fragment

func CmpRegReg

func CmpRegReg(dst, src Reg) asm.Fragment

func EmitBytes

func EmitBytes(fragment asm.Fragment) ([]byte, error)

func EmitProgram

func EmitProgram(fragment asm.Fragment) (asm.Program, error)

func EmitStandaloneELF

func EmitStandaloneELF(f asm.Fragment) ([]byte, error)

EmitStandaloneELF emits the provided fragment as a standalone ELF binary using the default configuration.

func EmitStandaloneELFWithConfig

func EmitStandaloneELFWithConfig(f asm.Fragment, cfg StandaloneELFConfig) ([]byte, error)

EmitStandaloneELFWithConfig emits the provided fragment as a standalone ELF binary using the supplied configuration.

func Hlt

func Hlt() asm.Fragment

func IRet

func IRet() asm.Fragment

func ImulRegImm

func ImulRegImm(dst, src Reg, value int32) asm.Fragment

func Jump

func Jump(label asm.Label) asm.Fragment

func JumpIfAbove

func JumpIfAbove(label asm.Label) asm.Fragment

func JumpIfAboveOrEqual

func JumpIfAboveOrEqual(label asm.Label) asm.Fragment

func JumpIfBelowOrEqual

func JumpIfBelowOrEqual(label asm.Label) asm.Fragment

func JumpIfEqual

func JumpIfEqual(label asm.Label) asm.Fragment

func JumpIfGreater

func JumpIfGreater(label asm.Label) asm.Fragment

func JumpIfLess

func JumpIfLess(label asm.Label) asm.Fragment

func JumpIfNegative

func JumpIfNegative(label asm.Label) asm.Fragment

func JumpIfNotEqual

func JumpIfNotEqual(label asm.Label) asm.Fragment

func JumpIfNotZero

func JumpIfNotZero(label asm.Label) asm.Fragment

func JumpIfZero

func JumpIfZero(label asm.Label) asm.Fragment

func JumpRaw

func JumpRaw(value asm.Variable) asm.Fragment

func LeaRelative

func LeaRelative(dst Reg, offset int32) asm.Fragment

func Lgdt

func Lgdt(mem Memory) asm.Fragment

func Lidt

func Lidt(mem Memory) asm.Fragment

func LoadAddress

func LoadAddress(dst Reg, variable asm.Variable) asm.Fragment

func LoadConstantBytes

func LoadConstantBytes(target asm.Variable, data []byte) asm.Fragment

func LoadConstantString

func LoadConstantString(target asm.Variable, s string) asm.Fragment

func LoadPointerArray

func LoadPointerArray(target asm.Variable, values []asm.Variable) asm.Fragment

func MovFromCR

func MovFromCR(dst Reg, ctrl ControlReg) asm.Fragment

func MovFromMemory

func MovFromMemory(dst Reg, mem Memory) asm.Fragment

func MovImmediate

func MovImmediate(dst Reg, value int64) asm.Fragment

func MovReg

func MovReg(dst, src Reg) asm.Fragment

func MovStoreImm8

func MovStoreImm8(mem Memory, value byte) asm.Fragment

func MovStoreImm32

func MovStoreImm32(mem Memory, value uint32) asm.Fragment

func MovToCR

func MovToCR(ctrl ControlReg, src Reg) asm.Fragment

func MovToMemory

func MovToMemory(mem Memory, src Reg) asm.Fragment

func MovZX8

func MovZX8(dst Reg, mem Memory) asm.Fragment

func MovZX16

func MovZX16(dst Reg, mem Memory) asm.Fragment

func Move

func Move(dst, src asm.Variable) asm.Fragment

func MustCompileErrno0

func MustCompileErrno0(f asm.Fragment) func() gosyscall.Errno

MustCompileErrno0 compiles the fragment into a no-argument function that returns a syscall.Errno. The fragment is expected to return zero on success, or a negative errno value on failure.

func MustCompileUnaryInt

func MustCompileUnaryInt(f asm.Fragment) func(int) int

MustCompileUnaryInt compiles the fragment into a function that takes and returns Go ints.

func MustCompileUnaryInt32

func MustCompileUnaryInt32(f asm.Fragment) func(int32) int32

MustCompileUnaryInt32 compiles the fragment into a function operating on int32 values.

func MustCompileUnaryInt64

func MustCompileUnaryInt64(f asm.Fragment) func(int64) int64

MustCompileUnaryInt64 compiles the fragment into a function operating on int64 values.

func OrRegImm

func OrRegImm(reg Reg, value int32) asm.Fragment

func OrRegReg

func OrRegReg(dst, src Reg) asm.Fragment

func OutDXAL

func OutDXAL() asm.Fragment

func PopReg

func PopReg(reg Reg) asm.Fragment

func PrepareAssembly

func PrepareAssembly(code []byte, relocations []int, bssSize ...int) (func(), func(), error)

func Print

func Print(s string) asm.Fragment

func Printf

func Printf(format string, args ...asm.Value) asm.Fragment

Printf writes a formatted string to stdout. Format only supports %x for hexadecimal output.

func PushReg

func PushReg(reg Reg) asm.Fragment

func Rdmsr

func Rdmsr() asm.Fragment

func ReserveZero

func ReserveZero(target asm.Variable, size int) asm.Fragment

func Ret

func Ret() asm.Fragment

func ShlRegImm

func ShlRegImm(reg Reg, count uint8) asm.Fragment

func ShrRegImm

func ShrRegImm(reg Reg, count uint8) asm.Fragment

func StandaloneELF

func StandaloneELF(prog asm.Program) ([]byte, error)

StandaloneELF emits the program as a standalone ELF binary using the default configuration.

func StandaloneELFWithConfig

func StandaloneELFWithConfig(prog asm.Program, cfg StandaloneELFConfig) ([]byte, error)

StandaloneELFWithConfig emits the program as a standalone ELF binary using the provided configuration. Zero-valued configuration fields are replaced with sensible defaults.

func Sti

func Sti() asm.Fragment

func SubRegReg

func SubRegReg(dst, src Reg) asm.Fragment

func Syscall

func Syscall(number defs.Syscall, args ...asm.Value) asm.Fragment

func SyscallWrite

func SyscallWrite(fd asm.Value, buf asm.Value, count asm.Value) asm.Fragment

func SyscallWriteString

func SyscallWriteString(fd asm.Value, s string) asm.Fragment

func TestZero

func TestZero(reg asm.Variable) asm.Fragment

func UseRegister

func UseRegister(v asm.Variable) asm.Value

func Wrmsr

func Wrmsr() asm.Fragment

func XorRegReg

func XorRegReg(dst, src Reg) asm.Fragment

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) AddConstant

func (c *Context) AddConstant(target asm.Variable, data []byte)

func (*Context) AddZeroConstant

func (c *Context) AddZeroConstant(target asm.Variable, size int)

func (*Context) ConstantLocation

func (c *Context) ConstantLocation(v asm.Variable) (constantLocation, bool)

func (*Context) EmitBytes

func (c *Context) EmitBytes(code []byte)

func (*Context) GetLabel

func (c *Context) GetLabel(label asm.Label) (int, bool)

func (*Context) SetLabel

func (c *Context) SetLabel(label asm.Label)

type ControlReg

type ControlReg uint8

ControlReg identifies an x86_64 control register (e.g. CR0, CR3, CR4).

const (
	CR0 ControlReg = 0
	CR2 ControlReg = 2
	CR3 ControlReg = 3
	CR4 ControlReg = 4
	CR8 ControlReg = 8
)

type Func

type Func struct {
	// contains filtered or unexported fields
}

func Compile

func Compile(f asm.Fragment) (Func, func(), error)

func MustCompile

func MustCompile(f asm.Fragment) Func

func PrepareAssemblyWithArgs

func PrepareAssemblyWithArgs(code []byte, relocations []int, bssSize ...int) (Func, func(), error)

PrepareAssemblyWithArgs is like PrepareAssembly, but allows calling the assembled code with up to six integer or pointer arguments (passed in the System V calling convention registers). It also accepts an optional bssSize parameter to allocate space for BSS (globals).

func (Func) Call

func (fn Func) Call(args ...any) uintptr

Call executes the compiled assembly with the provided arguments.

func (Func) Entry

func (fn Func) Entry() uintptr

Entry returns the entrypoint address of the compiled fragment.

func (Func) Program

func (fn Func) Program() asm.Program

Program returns a deep copy of the Program backing the compiled function.

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

Memory describes an effective address used by memory operands.

func Mem

func Mem(base Reg) Memory

Mem constructs a memory operand referencing [base].

func MemIndex

func MemIndex(base Reg, index Reg, scale uint8) Memory

MemIndex constructs a memory operand referencing [base + index*scale].

func (Memory) WithDisp

func (m Memory) WithDisp(disp int32) Memory

WithDisp returns a copy of the memory operand with the supplied displacement added.

type Reg

type Reg struct {
	// contains filtered or unexported fields
}

Reg represents a general-purpose register with an explicit operand size.

func Reg8

func Reg8(id asm.Variable) Reg

Reg8 constructs an 8-bit register operand backed by the provided register id.

func Reg16

func Reg16(id asm.Variable) Reg

Reg16 constructs a 16-bit register operand backed by the provided register id.

func Reg32

func Reg32(id asm.Variable) Reg

Reg32 constructs a 32-bit register operand backed by the provided register id.

func Reg64

func Reg64(id asm.Variable) Reg

Reg64 constructs a 64-bit register operand backed by the provided register id.

type StandaloneELFConfig

type StandaloneELFConfig struct {
	// BaseAddress is the virtual address where the first byte of the emitted
	// program will be loaded. The relocation entries in Program are resolved
	// against this address.
	BaseAddress uint64
	// SegmentOffset is the file offset where the loadable segment begins. This
	// must be aligned to SegmentAlignment and large enough to fit the ELF and
	// program headers placed before the segment.
	SegmentOffset uint64
	// SegmentAlignment is the alignment requirement for the loadable segment.
	SegmentAlignment uint64
	// SegmentFlags controls the permission bits on the loadable segment. The
	// default marks the segment readable, writable, and executable so embedded
	// data can be modified by the program.
	SegmentFlags elf.ProgFlag
}

StandaloneELFConfig controls how Program.StandaloneELF emits the final executable.

func DefaultStandaloneELFConfig

func DefaultStandaloneELFConfig() StandaloneELFConfig

DefaultStandaloneELFConfig returns the configuration used by StandaloneELF when no overrides are provided.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL