Documentation
¶
Index ¶
- Constants
- func AddRegImm(reg Reg, value int32) asm.Fragment
- func AddRegReg(dst, src Reg) asm.Fragment
- func AndRegImm(reg Reg, value int32) asm.Fragment
- func AndRegReg(dst, src Reg) asm.Fragment
- func Call(label asm.Label) asm.Fragment
- func CallReg(target Reg) asm.Fragment
- func Cli() asm.Fragment
- func CmpRegImm(reg Reg, value int32) asm.Fragment
- func CmpRegReg(dst, src Reg) asm.Fragment
- func EmitBytes(fragment asm.Fragment) ([]byte, error)
- func EmitProgram(fragment asm.Fragment) (asm.Program, error)
- func EmitStandaloneELF(f asm.Fragment) ([]byte, error)
- func EmitStandaloneELFWithConfig(f asm.Fragment, cfg StandaloneELFConfig) ([]byte, error)
- func Hlt() asm.Fragment
- func IRet() asm.Fragment
- func ImulRegImm(dst, src Reg, value int32) asm.Fragment
- func Jump(label asm.Label) asm.Fragment
- func JumpIfAbove(label asm.Label) asm.Fragment
- func JumpIfAboveOrEqual(label asm.Label) asm.Fragment
- func JumpIfBelowOrEqual(label asm.Label) asm.Fragment
- func JumpIfEqual(label asm.Label) asm.Fragment
- func JumpIfGreater(label asm.Label) asm.Fragment
- func JumpIfLess(label asm.Label) asm.Fragment
- func JumpIfNegative(label asm.Label) asm.Fragment
- func JumpIfNotEqual(label asm.Label) asm.Fragment
- func JumpIfNotZero(label asm.Label) asm.Fragment
- func JumpIfZero(label asm.Label) asm.Fragment
- func JumpRaw(value asm.Variable) asm.Fragment
- func LeaRelative(dst Reg, offset int32) asm.Fragment
- func Lgdt(mem Memory) asm.Fragment
- func Lidt(mem Memory) asm.Fragment
- func LoadAddress(dst Reg, variable asm.Variable) asm.Fragment
- func LoadConstantBytes(target asm.Variable, data []byte) asm.Fragment
- func LoadConstantString(target asm.Variable, s string) asm.Fragment
- func LoadPointerArray(target asm.Variable, values []asm.Variable) asm.Fragment
- func MovFromCR(dst Reg, ctrl ControlReg) asm.Fragment
- func MovFromMemory(dst Reg, mem Memory) asm.Fragment
- func MovImmediate(dst Reg, value int64) asm.Fragment
- func MovReg(dst, src Reg) asm.Fragment
- func MovStoreImm8(mem Memory, value byte) asm.Fragment
- func MovStoreImm32(mem Memory, value uint32) asm.Fragment
- func MovToCR(ctrl ControlReg, src Reg) asm.Fragment
- func MovToMemory(mem Memory, src Reg) asm.Fragment
- func MovZX8(dst Reg, mem Memory) asm.Fragment
- func MovZX16(dst Reg, mem Memory) asm.Fragment
- func Move(dst, src asm.Variable) asm.Fragment
- func MustCompileErrno0(f asm.Fragment) func() gosyscall.Errno
- func MustCompileUnaryInt(f asm.Fragment) func(int) int
- func MustCompileUnaryInt32(f asm.Fragment) func(int32) int32
- func MustCompileUnaryInt64(f asm.Fragment) func(int64) int64
- func OrRegImm(reg Reg, value int32) asm.Fragment
- func OrRegReg(dst, src Reg) asm.Fragment
- func OutDXAL() asm.Fragment
- func PopReg(reg Reg) asm.Fragment
- func PrepareAssembly(code []byte, relocations []int, bssSize ...int) (func(), func(), error)
- func Print(s string) asm.Fragment
- func Printf(format string, args ...asm.Value) asm.Fragment
- func PushReg(reg Reg) asm.Fragment
- func Rdmsr() asm.Fragment
- func ReserveZero(target asm.Variable, size int) asm.Fragment
- func Ret() asm.Fragment
- func ShlRegImm(reg Reg, count uint8) asm.Fragment
- func ShrRegImm(reg Reg, count uint8) asm.Fragment
- func StandaloneELF(prog asm.Program) ([]byte, error)
- func StandaloneELFWithConfig(prog asm.Program, cfg StandaloneELFConfig) ([]byte, error)
- func Sti() asm.Fragment
- func SubRegReg(dst, src Reg) asm.Fragment
- func Syscall(number defs.Syscall, args ...asm.Value) asm.Fragment
- func SyscallWrite(fd asm.Value, buf asm.Value, count asm.Value) asm.Fragment
- func SyscallWriteString(fd asm.Value, s string) asm.Fragment
- func TestZero(reg asm.Variable) asm.Fragment
- func UseRegister(v asm.Variable) asm.Value
- func Wrmsr() asm.Fragment
- func XorRegReg(dst, src Reg) asm.Fragment
- type Context
- func (c *Context) AddConstant(target asm.Variable, data []byte)
- func (c *Context) AddZeroConstant(target asm.Variable, size int)
- func (c *Context) ConstantLocation(v asm.Variable) (constantLocation, bool)
- func (c *Context) EmitBytes(code []byte)
- func (c *Context) GetLabel(label asm.Label) (int, bool)
- func (c *Context) SetLabel(label asm.Label)
- type ControlReg
- type Func
- type Memory
- type Reg
- type StandaloneELFConfig
Constants ¶
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 EmitStandaloneELF ¶
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 LoadPointerArray ¶
func MustCompileErrno0 ¶
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 ¶
MustCompileUnaryInt compiles the fragment into a function that takes and returns Go ints.
func MustCompileUnaryInt32 ¶
MustCompileUnaryInt32 compiles the fragment into a function operating on int32 values.
func MustCompileUnaryInt64 ¶
MustCompileUnaryInt64 compiles the fragment into a function operating on int64 values.
func PrepareAssembly ¶
func Printf ¶
Printf writes a formatted string to stdout. Format only supports %x for hexadecimal output.
func StandaloneELF ¶
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.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) ConstantLocation ¶
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 MustCompile ¶
func PrepareAssemblyWithArgs ¶
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).
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory describes an effective address used by memory operands.
type Reg ¶
type Reg struct {
// contains filtered or unexported fields
}
Reg represents a general-purpose register with an explicit operand size.
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.