Exemple #1
0
func writePrefixRegInsnTo(code gen.OpCoder, p prefix, t types.T, opcode []byte, ro, rm byte) {
	if opcode == nil {
		panic("instruction not supported")
	}

	p.writeTo(code, t, ro, 0, rm)
	code.Write(opcode)
	writeModTo(code, ModReg, ro, rm)
}
Exemple #2
0
func writePrefixStackInsnTo(code gen.OpCoder, p prefix, t types.T, opcode []byte, reg regs.R, disp int32) {
	mod, imm := dispMod(t, regStackPtr, disp)

	p.writeTo(code, t, byte(reg), 0, 0)
	code.Write(opcode)
	writeModTo(code, mod, byte(reg), MemSIB)
	writeSibTo(code, 0, regStackPtr, regStackPtr)
	imm.writeTo(code)
}
Exemple #3
0
func (i insnRexM) opStack(code gen.OpCoder, t types.T, disp int32) {
	mod, imm := dispMod(t, regStackPtr, disp)

	writeRexSizeTo(code, t, 0, 0, 0)
	code.Write(i.opcode)
	writeModTo(code, mod, i.ro, MemSIB)
	writeSibTo(code, 0, regStackPtr, regStackPtr)
	imm.writeTo(code)
}
Exemple #4
0
func writePrefixAddrInsnTo(code gen.OpCoder, p prefix, t types.T, opcode []byte, reg regs.R, scale uint8, index regs.R, addr int32) {
	if opcode == nil {
		panic("instruction not supported")
	}

	p.writeTo(code, t, byte(reg), 0, 0)
	code.Write(opcode)
	writeModTo(code, ModMem, byte(reg), MemSIB)
	writeSibTo(code, scale, index, NoBase)
	writeInt32To(code, addr)
}
Exemple #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
}
Exemple #6
0
func (p *floatSizePrefix) writeTo(code gen.OpCoder, t types.T, ro, index, rmOrBase byte) {
	switch t.Size() {
	case types.Size32:
		code.Write(p.size32)

	case types.Size64:
		code.Write(p.size64)

	default:
		panic(t)
	}

	writeRexTo(code, 0, ro, index, rmOrBase)
}
Exemple #7
0
func (i insnRexM) opIndirect(code gen.OpCoder, t types.T, reg regs.R, disp int32) {
	mod, imm := dispMod(t, reg, disp)

	writeRexSizeTo(code, t, 0, 0, byte(reg))
	code.Write(i.opcode)

	if reg != 12 {
		writeModTo(code, mod, i.ro, byte(reg))
	} else {
		writeModTo(code, mod, i.ro, MemSIB)
		writeSibTo(code, 0, NoIndex, reg)
	}

	imm.writeTo(code)
}
Exemple #8
0
func writePrefixIndirectInsnTo(code gen.OpCoder, p prefix, t types.T, opcode []byte, reg regs.R, scale uint8, index, base regs.R, disp int32) {
	if opcode == nil {
		panic("instruction not supported")
	}

	mod, imm := dispMod(t, base, disp)

	p.writeTo(code, t, byte(reg), byte(index), byte(base))
	code.Write(opcode)

	if scale == 0 && index == NoIndex && base != 12 {
		writeModTo(code, mod, byte(reg), byte(base))
	} else {
		writeModTo(code, mod, byte(reg), MemSIB)
		writeSibTo(code, scale, index, base)
	}

	imm.writeTo(code)
}
Exemple #9
0
func (opcode insnConst) op(code gen.OpCoder) {
	code.Write(opcode)
}
Exemple #10
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))
}
Exemple #11
0
func (i insnPrefixRexRM) opReg(code gen.OpCoder, floatType, intType types.T, target, source regs.R) {
	i.prefix.writeTo(code, floatType, 0, 0, 0)
	writeRexSizeTo(code, intType, byte(target), 0, byte(source))
	code.Write(i.opcode)
	writeModTo(code, ModReg, byte(target), byte(source))
}
Exemple #12
0
func (bytes constPrefix) writeTo(code gen.OpCoder, t types.T, ro, index, rmOrBase byte) {
	code.Write(bytes)
}
Exemple #13
0
func (opcode insnAddr32) writeTo(code gen.OpCoder, offset int32) {
	code.Write(opcode)
	writeInt32To(code, int32(offset))
}
Exemple #14
0
func (opcode insnRex) op(code gen.OpCoder, t types.T) {
	writeRexSizeTo(code, t, 0, 0, 0)
	code.Write(opcode)
}
Exemple #15
0
func (i insnRexOM) opReg(code gen.OpCoder, reg regs.R) {
	writeRexTo(code, 0, 0, 0, byte(reg))
	code.Write(i.opcode)
	writeModTo(code, ModReg, i.ro, byte(reg))
}
Exemple #16
0
func (opcode insnI) op(code gen.OpCoder, imm imm) {
	code.Write(opcode)
	imm.writeTo(code)
}
Exemple #17
0
func (i insnRexM) opReg(code gen.OpCoder, t types.T, reg regs.R) {
	writeRexSizeTo(code, t, 0, 0, byte(reg))
	code.Write(i.opcode)
	writeModTo(code, ModReg, i.ro, byte(reg))
}