func (i insnO) op(code gen.OpCoder, reg regs.R) { if reg >= 8 { panic("register not supported by instruction") } code.WriteByte(i.opbase + byte(reg)) }
func writeSibTo(code gen.OpCoder, scale byte, index, base regs.R) { if scale >= 4 { panic("scale factor out of bounds") } code.WriteByte((scale << 6) | (byte(index&7) << 3) | byte(base&7)) }
func (i insnPrefixMI) opImm(code gen.OpCoder, t types.T, reg regs.R, value int32) { opcode, imm := i.immOpcode(value) i.prefix.writeTo(code, t, 0, 0, byte(reg)) code.WriteByte(opcode) writeModTo(code, ModReg, i.ro, byte(reg)) imm.writeTo(code) }
func (i insnPrefixMI) opImmToStack(code gen.OpCoder, t types.T, disp, value int32) { mod, immDisp := dispMod(t, regStackPtr, disp) opcode, immValue := i.immOpcode(value) i.prefix.writeTo(code, t, 0, 0, 0) code.WriteByte(opcode) writeModTo(code, mod, i.ro, MemSIB) writeSibTo(code, 0, regStackPtr, regStackPtr) immDisp.writeTo(code) immValue.writeTo(code) }
func (opcode insnAddr8) op(code gen.OpCoder, addr int32) (ok bool) { insnSize := int32(len(opcode)) + 1 siteAddr := code.Len() + insnSize offset := addr - siteAddr if offset >= -0x80 && offset < 0x80 { code.Write(opcode) code.WriteByte(uint8(offset)) ok = true } return }
func writeRexTo(code gen.OpCoder, rex, ro, index, rmOrBase byte) { if ro >= 8 { rex |= rexR } if index >= 8 { rex |= rexX } if rmOrBase >= 8 { rex |= rexB } if rex != 0 { code.WriteByte(rex) } }
func (i insnPrefixMI) opImmToIndirect(code gen.OpCoder, t types.T, scale uint8, index, base regs.R, disp, value int32) { mod, immDisp := dispMod(t, base, disp) opcode, immValue := i.immOpcode(value) i.prefix.writeTo(code, t, 0, byte(index), byte(base)) code.WriteByte(opcode) if scale == 0 && index == NoIndex && base != 12 { writeModTo(code, mod, i.ro, byte(base)) } else { writeModTo(code, mod, i.ro, MemSIB) writeSibTo(code, scale, index, base) } immDisp.writeTo(code) immValue.writeTo(code) }
func writeModTo(code gen.OpCoder, mod mod, ro, rm byte) { code.WriteByte(byte(mod) | ((ro & 7) << 3) | (rm & 7)) }
func (i insnSuffixRMI) opReg(code gen.OpCoder, t types.T, target, source regs.R, value int8) { code.Write(i.opcode) i.suffix.writeTo(code, t, byte(target), 0, byte(source)) writeModTo(code, ModReg, byte(target), byte(source)) code.WriteByte(uint8(value)) }
func (i insnPrefixMI) opImm8(code gen.OpCoder, t types.T, reg regs.R, value uint8) { i.prefix.writeTo(code, t, 0, 0, byte(reg)) code.WriteByte(i.opcode8) writeModTo(code, ModReg, i.ro, byte(reg)) code.WriteByte(value) }
func (i insnRexOI) op(code gen.OpCoder, t types.T, reg regs.R, imm imm) { writeRexSizeTo(code, t, 0, 0, byte(reg)) code.WriteByte(i.opbase + (byte(reg) & 7)) imm.writeTo(code) }
func (data16RexSizePrefix) writeTo(code gen.OpCoder, t types.T, ro, index, rmOrBase byte) { code.WriteByte(0x66) writeRexSizeTo(code, t, ro, index, rmOrBase) }