Beispiel #1
0
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))
}
Beispiel #2
0
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))
}
Beispiel #3
0
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)
}
Beispiel #4
0
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)
}
Beispiel #5
0
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
}
Beispiel #6
0
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)
	}
}
Beispiel #7
0
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)
}
Beispiel #8
0
func writeModTo(code gen.OpCoder, mod mod, ro, rm byte) {
	code.WriteByte(byte(mod) | ((ro & 7) << 3) | (rm & 7))
}
Beispiel #9
0
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))
}
Beispiel #10
0
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)
}
Beispiel #11
0
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)
}
Beispiel #12
0
func (data16RexSizePrefix) writeTo(code gen.OpCoder, t types.T, ro, index, rmOrBase byte) {
	code.WriteByte(0x66)
	writeRexSizeTo(code, t, ro, index, rmOrBase)
}