mirror of
https://github.com/Ed94/perfaware.git
synced 2026-09-14 03:39:23 +00:00
826 lines
35 KiB
C
826 lines
35 KiB
C
#ifdef INTELLISENSE_DIRECTIVES
|
|
# pragma once
|
|
# include "duffle/dsl.h"
|
|
#endif
|
|
|
|
typedef Struct_(X8616_BytePattern) { U1 bits; U1 mask; };
|
|
typedef Struct_(X8616_BitField) { U1 shift; U1 width; };
|
|
|
|
typedef Struct_(X8616_OpcodeFields) {
|
|
X8616_BitField d;
|
|
X8616_BitField w;
|
|
X8616_BitField s;
|
|
X8616_BitField v;
|
|
X8616_BitField z;
|
|
X8616_BitField reg;
|
|
X8616_BitField sr;
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Op) {
|
|
x8616_op_invalid = 0x00,
|
|
x8616_op_nop = 0x01,
|
|
x8616_op_mov = 0x02,
|
|
x8616_op_add = 0x03,
|
|
x8616_op_or = 0x04,
|
|
x8616_op_adc = 0x05,
|
|
x8616_op_sbb = 0x06,
|
|
x8616_op_and = 0x07,
|
|
x8616_op_sub = 0x08,
|
|
x8616_op_xor = 0x09,
|
|
x8616_op_cmp = 0x0A,
|
|
x8616_op_push = 0x0B,
|
|
x8616_op_pop = 0x0C,
|
|
x8616_op_xchg = 0x0D,
|
|
x8616_op_in = 0x0E,
|
|
x8616_op_out = 0x0F,
|
|
x8616_op_xlat = 0x10,
|
|
x8616_op_lea = 0x11,
|
|
x8616_op_lds = 0x12,
|
|
x8616_op_les = 0x13,
|
|
x8616_op_lahf = 0x14,
|
|
x8616_op_sahf = 0x15,
|
|
x8616_op_pushf = 0x16,
|
|
x8616_op_popf = 0x17,
|
|
x8616_op_inc = 0x18,
|
|
x8616_op_aaa = 0x19,
|
|
x8616_op_daa = 0x1A,
|
|
x8616_op_dec = 0x1B,
|
|
x8616_op_neg = 0x1C,
|
|
x8616_op_aas = 0x1D,
|
|
x8616_op_das = 0x1E,
|
|
x8616_op_mul = 0x1F,
|
|
x8616_op_imul = 0x20,
|
|
x8616_op_aam = 0x21,
|
|
x8616_op_div = 0x22,
|
|
x8616_op_idiv = 0x23,
|
|
x8616_op_aad = 0x24,
|
|
x8616_op_cbw = 0x25,
|
|
x8616_op_cwd = 0x26,
|
|
x8616_op_not = 0x27,
|
|
x8616_op_shl = 0x28,
|
|
x8616_op_shr = 0x29,
|
|
x8616_op_sar = 0x2A,
|
|
x8616_op_rol = 0x2B,
|
|
x8616_op_ror = 0x2C,
|
|
x8616_op_rcl = 0x2D,
|
|
x8616_op_rcr = 0x2E,
|
|
x8616_op_test = 0x2F,
|
|
x8616_op_rep = 0x30,
|
|
x8616_op_movs = 0x31,
|
|
x8616_op_cmps = 0x32,
|
|
x8616_op_scas = 0x33,
|
|
x8616_op_lods = 0x34,
|
|
x8616_op_stos = 0x35,
|
|
x8616_op_call = 0x36,
|
|
x8616_op_jmp = 0x37,
|
|
x8616_op_ret = 0x38,
|
|
x8616_op_retf = 0x39,
|
|
x8616_op_je = 0x3A,
|
|
x8616_op_jl = 0x3B,
|
|
x8616_op_jle = 0x3C,
|
|
x8616_op_jb = 0x3D,
|
|
x8616_op_jbe = 0x3E,
|
|
x8616_op_jp = 0x3F,
|
|
x8616_op_jo = 0x40,
|
|
x8616_op_js = 0x41,
|
|
x8616_op_jne = 0x42,
|
|
x8616_op_jnl = 0x43,
|
|
x8616_op_jg = 0x44,
|
|
x8616_op_jnb = 0x45,
|
|
x8616_op_ja = 0x46,
|
|
x8616_op_jnp = 0x47,
|
|
x8616_op_jno = 0x48,
|
|
x8616_op_jns = 0x49,
|
|
x8616_op_loop = 0x4A,
|
|
x8616_op_loopz = 0x4B,
|
|
x8616_op_loopnz = 0x4C,
|
|
x8616_op_jcxz = 0x4D,
|
|
x8616_op_int = 0x4E,
|
|
x8616_op_int3 = 0x4F,
|
|
x8616_op_into = 0x50,
|
|
x8616_op_iret = 0x51,
|
|
x8616_op_clc = 0x52,
|
|
x8616_op_cmc = 0x53,
|
|
x8616_op_stc = 0x54,
|
|
x8616_op_cld = 0x55,
|
|
x8616_op_std = 0x56,
|
|
x8616_op_cli = 0x57,
|
|
x8616_op_sti = 0x58,
|
|
x8616_op_hlt = 0x59,
|
|
x8616_op_wait = 0x5A,
|
|
x8616_op_lock = 0x5B,
|
|
x8616_op_segment = 0x5C,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Operand) {
|
|
x8616_operand_none = 0x00,
|
|
x8616_operand_rm = 0x01,
|
|
x8616_operand_reg_modrm = 0x02,
|
|
x8616_operand_reg_opcode = 0x03,
|
|
x8616_operand_segment_modrm = 0x04,
|
|
x8616_operand_segment_opcode = 0x05,
|
|
x8616_operand_acc = 0x06,
|
|
x8616_operand_imm = 0x07,
|
|
x8616_operand_imm8 = 0x08,
|
|
x8616_operand_imm16 = 0x09,
|
|
x8616_operand_mem_direct = 0x0A,
|
|
x8616_operand_rel8 = 0x0B,
|
|
x8616_operand_rel16 = 0x0C,
|
|
x8616_operand_far_ptr = 0x0D,
|
|
x8616_operand_dx = 0x0E,
|
|
x8616_operand_shift_count = 0x0F,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_WidthMode) {
|
|
x8616_width_dynamic = 0x0,
|
|
x8616_width_byte = 0x1,
|
|
x8616_width_word = 0x2,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_EncodingFlags) {
|
|
x8616_encoding_none = 0b00000000,
|
|
x8616_encoding_far = 0b00000001,
|
|
x8616_encoding_prefix = 0b00000010,
|
|
};
|
|
|
|
/* mod_rm (Optional): Fixed constraint on the ModR/M byte.
|
|
post_opcode (Optional): Fixed byte immediately following the opcode.
|
|
fields: Variable fields carried by the opcode byte. width == 0: field is absent.
|
|
operands: Operand order describes d == 0.
|
|
If d exists and decodes to 1, operands[0] and operands[1] are swapped.
|
|
width: Explicit width only when the encoding has no w field.
|
|
flags: Encoding metadata not represented by an explicit operand. */
|
|
typedef Struct_(X8616_Encoding) {
|
|
X8616_BytePattern opcode;
|
|
X8616_BytePattern mod_rm;
|
|
X8616_BytePattern post_opcode;
|
|
X8616_OpcodeFields fields;
|
|
X8616_Operand operands[2];
|
|
X8616_WidthMode width;
|
|
X8616_EncodingFlags flags;
|
|
X8616_Op op;
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Width) {
|
|
x8616_w_byte = 0b0,
|
|
x8616_w_word = 0b1,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Direction) {
|
|
x8616_d_rm_dst = 0b0,
|
|
x8616_d_reg_dst = 0b1,
|
|
x8616_d_acc_dst = 0b0,
|
|
x8616_d_mem_dst = 0b1,
|
|
x8616_d_seg_dst = 0b1,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Sign) {
|
|
x8616_s_full = 0b0,
|
|
x8616_s_extend = 0b1,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_VariableShift) {
|
|
x8616_v_one = 0b0,
|
|
x8616_v_cl = 0b1,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Repeat) {
|
|
x8616_repne = 0b0,
|
|
x8616_rep = 0b1,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Mod) {
|
|
x8616_mod_mem = 0b00,
|
|
x8616_mod_mem_d8 = 0b01,
|
|
x8616_mod_mem_d16 = 0b10,
|
|
x8616_mod_reg = 0b11,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Reg8) {
|
|
x8616_al = 0b000,
|
|
x8616_cl = 0b001,
|
|
x8616_dl = 0b010,
|
|
x8616_bl = 0b011,
|
|
x8616_ah = 0b100,
|
|
x8616_ch = 0b101,
|
|
x8616_dh = 0b110,
|
|
x8616_bh = 0b111,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Reg16) {
|
|
x8616_ax = 0b000,
|
|
x8616_cx = 0b001,
|
|
x8616_dx = 0b010,
|
|
x8616_bx = 0b011,
|
|
x8616_sp = 0b100,
|
|
x8616_bp = 0b101,
|
|
x8616_si = 0b110,
|
|
x8616_di = 0b111,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Segment) {
|
|
x8616_es = 0b00,
|
|
x8616_cs = 0b01,
|
|
x8616_ss = 0b10,
|
|
x8616_ds = 0b11,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_EA) {
|
|
x8616_ea_bx_si = 0b000,
|
|
x8616_ea_bx_di = 0b001,
|
|
x8616_ea_bp_si = 0b010,
|
|
x8616_ea_bp_di = 0b011,
|
|
x8616_ea_si = 0b100,
|
|
x8616_ea_di = 0b101,
|
|
x8616_ea_bp = 0b110, // mod 01/10
|
|
x8616_ea_direct = 0b110, // mod 00
|
|
x8616_ea_bx = 0b111,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_ALU) {
|
|
x8616_add = 0b000,
|
|
x8616_or = 0b001,
|
|
x8616_adc = 0b010,
|
|
x8616_sbb = 0b011,
|
|
x8616_and = 0b100,
|
|
x8616_sub = 0b101,
|
|
x8616_xor = 0b110,
|
|
x8616_cmp = 0b111,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Group3) {
|
|
x8616_g3_test = 0b000,
|
|
x8616_g3_not = 0b010,
|
|
x8616_g3_neg = 0b011,
|
|
x8616_g3_mul = 0b100,
|
|
x8616_g3_imul = 0b101,
|
|
x8616_g3_div = 0b110,
|
|
x8616_g3_idiv = 0b111,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_IncDec) {
|
|
x8616_inc = 0b000,
|
|
x8616_dec = 0b001,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_GroupFF) {
|
|
x8616_ff_call_near = 0b010,
|
|
x8616_ff_call_far = 0b011,
|
|
x8616_ff_jmp_near = 0b100,
|
|
x8616_ff_jmp_far = 0b101,
|
|
x8616_ff_push = 0b110,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Shift) {
|
|
x8616_rol = 0b000,
|
|
x8616_ror = 0b001,
|
|
x8616_rcl = 0b010,
|
|
x8616_rcr = 0b011,
|
|
x8616_shl = 0b100,
|
|
x8616_shr = 0b101,
|
|
x8616_sar = 0b111,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Condition) {
|
|
x8616_cc_o = 0b0000,
|
|
x8616_cc_no = 0b0001,
|
|
x8616_cc_b = 0b0010,
|
|
x8616_cc_nb = 0b0011,
|
|
x8616_cc_e = 0b0100,
|
|
x8616_cc_ne = 0b0101,
|
|
x8616_cc_be = 0b0110,
|
|
x8616_cc_a = 0b0111,
|
|
x8616_cc_s = 0b1000,
|
|
x8616_cc_ns = 0b1001,
|
|
x8616_cc_p = 0b1010,
|
|
x8616_cc_np = 0b1011,
|
|
x8616_cc_l = 0b1100,
|
|
x8616_cc_nl = 0b1101,
|
|
x8616_cc_le = 0b1110,
|
|
x8616_cc_g = 0b1111,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_OpcodePrefix) {
|
|
x8616_opcode_mov_rm_r = 0b100010,
|
|
x8616_opcode_mov_rm_i = 0b1100011,
|
|
x8616_opcode_mov_r_i = 0b1011,
|
|
x8616_opcode_mov_acc_mem = 0b101000,
|
|
x8616_opcode_mov_seg_rm = 0b100011,
|
|
|
|
x8616_opcode_push_reg = 0b01010,
|
|
x8616_opcode_pop_reg = 0b01011,
|
|
x8616_opcode_xchg_rm_r = 0b1000011,
|
|
x8616_opcode_xchg_ax_reg = 0b10010,
|
|
|
|
x8616_opcode_in_i = 0b1110010,
|
|
x8616_opcode_in_dx = 0b1110110,
|
|
x8616_opcode_out_i = 0b1110011,
|
|
x8616_opcode_out_dx = 0b1110111,
|
|
|
|
x8616_opcode_alu_rm_i = 0b100000,
|
|
x8616_opcode_logic_rm_i = 0b1000000,
|
|
x8616_opcode_incdec_rm = 0b1111111,
|
|
x8616_opcode_inc_reg = 0b01000,
|
|
x8616_opcode_dec_reg = 0b01001,
|
|
x8616_opcode_group3 = 0b1111011,
|
|
x8616_opcode_shift_rm = 0b110100,
|
|
x8616_opcode_test_rm_r = 0b1000010,
|
|
x8616_opcode_test_acc_i = 0b1010100,
|
|
|
|
x8616_opcode_rep = 0b1111001,
|
|
x8616_opcode_movs = 0b1010010,
|
|
x8616_opcode_cmps = 0b1010011,
|
|
x8616_opcode_scas = 0b1010111,
|
|
x8616_opcode_lods = 0b1010110,
|
|
x8616_opcode_stos = 0b1010101,
|
|
|
|
x8616_opcode_jcc = 0b0111,
|
|
};
|
|
|
|
typedef Enum_(U1, X8616_Opcode) {
|
|
x8616_opcode_group_ff = 0b11111111,
|
|
x8616_opcode_pop_rm = 0b10001111,
|
|
x8616_opcode_xlat = 0b11010111,
|
|
x8616_opcode_lea = 0b10001101,
|
|
x8616_opcode_lds = 0b11000101,
|
|
x8616_opcode_les = 0b11000100,
|
|
x8616_opcode_lahf = 0b10011111,
|
|
x8616_opcode_sahf = 0b10011110,
|
|
x8616_opcode_pushf = 0b10011100,
|
|
x8616_opcode_popf = 0b10011101,
|
|
|
|
x8616_opcode_aaa = 0b00110111,
|
|
x8616_opcode_daa = 0b00100111,
|
|
x8616_opcode_aas = 0b00111111,
|
|
x8616_opcode_das = 0b00101111,
|
|
x8616_opcode_aam = 0b11010100,
|
|
x8616_opcode_aad = 0b11010101,
|
|
x8616_opcode_cbw = 0b10011000,
|
|
x8616_opcode_cwd = 0b10011001,
|
|
|
|
x8616_opcode_call_rel16 = 0b11101000,
|
|
x8616_opcode_call_far = 0b10011010,
|
|
x8616_opcode_jmp_rel16 = 0b11101001,
|
|
x8616_opcode_jmp_rel8 = 0b11101011,
|
|
x8616_opcode_jmp_far = 0b11101010,
|
|
x8616_opcode_ret = 0b11000011,
|
|
x8616_opcode_ret_i = 0b11000010,
|
|
x8616_opcode_retf = 0b11001011,
|
|
x8616_opcode_retf_i = 0b11001010,
|
|
|
|
x8616_opcode_loopnz = 0b11100000,
|
|
x8616_opcode_loopz = 0b11100001,
|
|
x8616_opcode_loop = 0b11100010,
|
|
x8616_opcode_jcxz = 0b11100011,
|
|
|
|
x8616_opcode_int = 0b11001101,
|
|
x8616_opcode_int3 = 0b11001100,
|
|
x8616_opcode_into = 0b11001110,
|
|
x8616_opcode_iret = 0b11001111,
|
|
|
|
x8616_opcode_clc = 0b11111000,
|
|
x8616_opcode_cmc = 0b11110101,
|
|
x8616_opcode_stc = 0b11111001,
|
|
x8616_opcode_cld = 0b11111100,
|
|
x8616_opcode_std = 0b11111101,
|
|
x8616_opcode_cli = 0b11111010,
|
|
x8616_opcode_sti = 0b11111011,
|
|
x8616_opcode_hlt = 0b11110100,
|
|
x8616_opcode_wait = 0b10011011,
|
|
x8616_opcode_lock = 0b11110000,
|
|
|
|
x8616_opcode_nop = 0b10010000,
|
|
};
|
|
|
|
enum {
|
|
X8616_OPCODE_MASK = 0b11111111,
|
|
|
|
X8616_OPCODE_ALU_ACC_I_FIXED = 0b10,
|
|
X8616_POST_OPCODE_AAM_AAD = 0b00001010,
|
|
|
|
// ModR/M:
|
|
// 7 6 5 4 3 2 1 0
|
|
// +-----+-------+-------+
|
|
// | mod | reg | r/m |
|
|
// +-----+-------+-------+
|
|
|
|
X8616_MODRM_RM_SHIFT = 0,
|
|
X8616_MODRM_REG_SHIFT = 3,
|
|
X8616_MODRM_MOD_SHIFT = 6,
|
|
X8616_MODRM_RM_MASK = 0b00000111,
|
|
X8616_MODRM_REG_MASK = 0b00111000,
|
|
X8616_MODRM_MOD_MASK = 0b11000000,
|
|
|
|
// Segment register occupies bits 4..3 in the segment-register MOV form.
|
|
|
|
X8616_MODRM_SR_SHIFT = 3,
|
|
X8616_MODRM_SR_MASK = 0b00011000,
|
|
X8616_MODRM_SEG_FIXED_MASK = 0b00100000,
|
|
|
|
// ... d w
|
|
|
|
X8616_OPCODE_DW_W_SHIFT = 0,
|
|
X8616_OPCODE_DW_D_SHIFT = 1,
|
|
X8616_OPCODE_DW_PREFIX_SHIFT = X8616_OPCODE_DW_D_SHIFT + 1,
|
|
X8616_OPCODE_DW_PREFIX_MASK = 0b11111100,
|
|
|
|
// ... s w
|
|
|
|
X8616_OPCODE_SW_W_SHIFT = 0,
|
|
X8616_OPCODE_SW_S_SHIFT = 1,
|
|
X8616_OPCODE_SW_PREFIX_SHIFT = X8616_OPCODE_SW_S_SHIFT + 1,
|
|
X8616_OPCODE_SW_PREFIX_MASK = 0b11111100,
|
|
|
|
// ... v w
|
|
|
|
X8616_OPCODE_VW_W_SHIFT = 0,
|
|
X8616_OPCODE_VW_V_SHIFT = 1,
|
|
X8616_OPCODE_VW_PREFIX_SHIFT = X8616_OPCODE_VW_V_SHIFT + 1,
|
|
X8616_OPCODE_VW_PREFIX_MASK = 0b11111100,
|
|
|
|
// ... z
|
|
|
|
X8616_OPCODE_Z_Z_SHIFT = 0,
|
|
X8616_OPCODE_Z_PREFIX_SHIFT = X8616_OPCODE_Z_Z_SHIFT + 1,
|
|
X8616_OPCODE_Z_PREFIX_MASK = 0b11111110,
|
|
|
|
// ... w
|
|
|
|
X8616_OPCODE_W_W_SHIFT = 0,
|
|
X8616_OPCODE_W_PREFIX_SHIFT = X8616_OPCODE_W_W_SHIFT + 1,
|
|
X8616_OPCODE_W_PREFIX_MASK = 0b11111110,
|
|
|
|
// ... reg
|
|
|
|
X8616_OPCODE_REG_REG_SHIFT = 0,
|
|
X8616_OPCODE_REG_REG_WIDTH = 3,
|
|
X8616_OPCODE_REG_REG_MASK = 0b00000111,
|
|
X8616_OPCODE_REG_PREFIX_SHIFT = X8616_OPCODE_REG_REG_SHIFT + X8616_OPCODE_REG_REG_WIDTH,
|
|
X8616_OPCODE_REG_PREFIX_MASK = 0b11111000,
|
|
|
|
// ... w reg
|
|
|
|
X8616_OPCODE_WREG_REG_SHIFT = 0,
|
|
X8616_OPCODE_WREG_REG_WIDTH = 3,
|
|
X8616_OPCODE_WREG_REG_MASK = 0b00000111,
|
|
X8616_OPCODE_WREG_W_SHIFT = X8616_OPCODE_WREG_REG_SHIFT + X8616_OPCODE_WREG_REG_WIDTH,
|
|
X8616_OPCODE_WREG_W_MASK = 0b00001000,
|
|
X8616_OPCODE_WREG_PREFIX_SHIFT = X8616_OPCODE_WREG_W_SHIFT + 1,
|
|
X8616_OPCODE_WREG_PREFIX_MASK = 0b11110000,
|
|
|
|
// ... d 0
|
|
|
|
X8616_OPCODE_D0_D_SHIFT = 1,
|
|
X8616_OPCODE_D0_PREFIX_SHIFT = X8616_OPCODE_D0_D_SHIFT + 1,
|
|
X8616_OPCODE_D0_PREFIX_MASK = 0b11111101,
|
|
|
|
// xxx sr xxx
|
|
|
|
X8616_OPCODE_SR_SHIFT = 3,
|
|
X8616_OPCODE_SR_WIDTH = 2,
|
|
X8616_OPCODE_SR_MASK = 0b00011000,
|
|
X8616_OPCODE_SR_PATTERN_MASK = 0b11100111,
|
|
X8616_OPCODE_PUSH_SR_FIXED = 0b00000110,
|
|
X8616_OPCODE_POP_SR_FIXED = 0b00000111,
|
|
X8616_OPCODE_SEG_FIXED = 0b00100110,
|
|
|
|
// 0111 cccc
|
|
|
|
X8616_OPCODE_CC_SHIFT = 0,
|
|
X8616_OPCODE_CC_WIDTH = 4,
|
|
X8616_OPCODE_CC_MASK = 0b00001111,
|
|
X8616_OPCODE_CC_PREFIX_SHIFT = X8616_OPCODE_CC_WIDTH,
|
|
|
|
// 00 op ...
|
|
|
|
X8616_OPCODE_ALU_OP_SHIFT = 3,
|
|
};
|
|
|
|
// ============================================================================
|
|
// Encoding Helpers
|
|
|
|
FI_ U1 x8616_byte_pattern_matches(U1 byte, X8616_BytePattern pattern) { return (byte & pattern.mask) == pattern.bits; }
|
|
FI_ U1 x8616_bit_field_exists (X8616_BitField field) { return field.width != 0; }
|
|
FI_ U1 x8616_bit_field_extract (U1 byte, X8616_BitField field) { return (byte >> field.shift) & u1_((1u << field.width) - 1u); }
|
|
FI_ U1 x8616_modrm_rm (U1 modrm) { return (modrm & X8616_MODRM_RM_MASK) >> X8616_MODRM_RM_SHIFT; }
|
|
FI_ U1 x8616_modrm_reg (U1 modrm) { return (modrm & X8616_MODRM_REG_MASK) >> X8616_MODRM_REG_SHIFT; }
|
|
FI_ U1 x8616_modrm_mod (U1 modrm) { return (modrm & X8616_MODRM_MOD_MASK) >> X8616_MODRM_MOD_SHIFT; }
|
|
FI_ U1 x8616_modrm_sr (U1 modrm) { return (modrm & X8616_MODRM_SR_MASK) >> X8616_MODRM_SR_SHIFT; }
|
|
|
|
// ============================================================================
|
|
// Emission DSL
|
|
// `enc_*` produces one encoded byte.
|
|
// `emit_*` expands to one or more comma-separated bytes.
|
|
//
|
|
// Intended use:
|
|
// RO_ global U1 code[] = {
|
|
// x8616_mov_r16_i(x8616_ax, 0x1234),
|
|
// x8616_mov_r16_r16(x8616_bx, x8616_ax),
|
|
// x8616_add_r16_r16(x8616_ax, x8616_bx),
|
|
// x8616_jne(-4),
|
|
// };
|
|
// ============================================================================
|
|
|
|
// Byte fields
|
|
|
|
#define x8616_enc_dw_prefix(prefix) ((prefix) << X8616_OPCODE_DW_PREFIX_SHIFT)
|
|
#define x8616_enc_sw_prefix(prefix) ((prefix) << X8616_OPCODE_SW_PREFIX_SHIFT)
|
|
#define x8616_enc_vw_prefix(prefix) ((prefix) << X8616_OPCODE_VW_PREFIX_SHIFT)
|
|
#define x8616_enc_z_prefix(prefix) ((prefix) << X8616_OPCODE_Z_PREFIX_SHIFT)
|
|
#define x8616_enc_w_prefix(prefix) ((prefix) << X8616_OPCODE_W_PREFIX_SHIFT)
|
|
#define x8616_enc_reg_prefix(prefix) ((prefix) << X8616_OPCODE_REG_PREFIX_SHIFT)
|
|
#define x8616_enc_wreg_prefix(prefix) ((prefix) << X8616_OPCODE_WREG_PREFIX_SHIFT)
|
|
#define x8616_enc_d0_prefix(prefix) ((prefix) << X8616_OPCODE_D0_PREFIX_SHIFT)
|
|
|
|
#define x8616_enc_d(d) ((d) << X8616_OPCODE_DW_D_SHIFT)
|
|
#define x8616_enc_s(s) ((s) << X8616_OPCODE_SW_S_SHIFT)
|
|
#define x8616_enc_v(v) ((v) << X8616_OPCODE_VW_V_SHIFT)
|
|
#define x8616_enc_z(z) ((z) << X8616_OPCODE_Z_Z_SHIFT)
|
|
#define x8616_enc_width(w) ((w) << X8616_OPCODE_W_W_SHIFT)
|
|
#define x8616_enc_wreg_width(w) ((w) << X8616_OPCODE_WREG_W_SHIFT)
|
|
#define x8616_enc_opcode_reg(r) ((r) << X8616_OPCODE_REG_REG_SHIFT)
|
|
#define x8616_enc_opcode_sr(sr) ((sr) << X8616_OPCODE_SR_SHIFT)
|
|
#define x8616_enc_cc(cc) ((cc) << X8616_OPCODE_CC_SHIFT)
|
|
|
|
#define x8616_enc_modrm_mod(mod) ((mod) << X8616_MODRM_MOD_SHIFT)
|
|
#define x8616_enc_modrm_reg(reg) ((reg) << X8616_MODRM_REG_SHIFT)
|
|
#define x8616_enc_modrm_rm(rm) ((rm) << X8616_MODRM_RM_SHIFT)
|
|
#define x8616_enc_modrm_sr(sr) ((sr) << X8616_MODRM_SR_SHIFT)
|
|
|
|
#define x8616_enc_dw(prefix,d,w) C_(U1, x8616_enc_dw_prefix(prefix) | x8616_enc_d(d) | x8616_enc_width(w))
|
|
#define x8616_enc_sw(prefix,s,w) C_(U1, x8616_enc_sw_prefix(prefix) | x8616_enc_s(s) | x8616_enc_width(w))
|
|
#define x8616_enc_vw(prefix,v,w) C_(U1, x8616_enc_vw_prefix(prefix) | x8616_enc_v(v) | x8616_enc_width(w))
|
|
#define x8616_enc_zp(prefix,z) C_(U1, x8616_enc_z_prefix(prefix) | x8616_enc_z(z))
|
|
#define x8616_enc_w(prefix,w) C_(U1, x8616_enc_w_prefix(prefix) | x8616_enc_width(w))
|
|
#define x8616_enc_reg(prefix,reg) C_(U1, x8616_enc_reg_prefix(prefix) | x8616_enc_opcode_reg(reg))
|
|
#define x8616_enc_wreg(prefix,w,reg) C_(U1, x8616_enc_wreg_prefix(prefix) | x8616_enc_wreg_width(w) | x8616_enc_opcode_reg(reg))
|
|
#define x8616_enc_d0(prefix,d) C_(U1, x8616_enc_d0_prefix(prefix) | x8616_enc_d(d))
|
|
#define x8616_enc_sr(fixed,sr) C_(U1, fixed | x8616_enc_opcode_sr(sr))
|
|
#define x8616_enc_jcc(cc) C_(U1, (x8616_opcode_jcc << X8616_OPCODE_CC_PREFIX_SHIFT) | x8616_enc_cc(cc))
|
|
#define x8616_enc_modrm(mod,reg,rm) C_(U1, x8616_enc_modrm_mod(mod) | x8616_enc_modrm_reg(reg) | x8616_enc_modrm_rm(rm))
|
|
#define x8616_enc_modrm_seg(mod,sr,rm) C_(U1, x8616_enc_modrm_mod(mod) | x8616_enc_modrm_sr(sr) | x8616_enc_modrm_rm(rm))
|
|
|
|
#define x8616_enc_alu_op(alu) ((alu) << X8616_OPCODE_ALU_OP_SHIFT)
|
|
#define x8616_enc_alu_acc_i_fixed (X8616_OPCODE_ALU_ACC_I_FIXED << X8616_OPCODE_W_PREFIX_SHIFT)
|
|
#define x8616_enc_alu_rm_r(alu,d,w) C_(U1, x8616_enc_alu_op(alu) | x8616_enc_d(d) | x8616_enc_width(w))
|
|
#define x8616_enc_alu_acc_i(alu,w) C_(U1, x8616_enc_alu_op(alu) | x8616_enc_alu_acc_i_fixed | x8616_enc_width(w))
|
|
|
|
// Scalar / generic packets
|
|
|
|
#define x8616_emit_u2(value) u1_(u2_(value) >> 0), u1_(u2_(value) >> 8)
|
|
#define x8616_emit_s2(value) x8616_emit_u2(value)
|
|
#define x8616_emit_op(opcode) u1_(opcode)
|
|
#define x8616_emit_op_i8(opcode,imm) u1_(opcode), u1_(imm)
|
|
#define x8616_emit_op_i16(opcode,imm) u1_(opcode), x8616_emit_u2(imm)
|
|
#define x8616_emit_op_far(opcode,seg,off) u1_(opcode), x8616_emit_u2(off), x8616_emit_u2(seg)
|
|
|
|
#define x8616_emit_modrm(opcode,mod,reg,rm) u1_(opcode), x8616_enc_modrm(mod,reg,rm)
|
|
#define x8616_emit_modrm_d8(opcode,reg,rm,disp) x8616_emit_modrm(opcode,x8616_mod_mem_d8,reg,rm), u1_(disp)
|
|
#define x8616_emit_modrm_d16(opcode,reg,rm,disp) x8616_emit_modrm(opcode,x8616_mod_mem_d16,reg,rm), x8616_emit_s2(disp)
|
|
#define x8616_emit_modrm_direct(opcode,reg,addr) x8616_emit_modrm(opcode,x8616_mod_mem,reg,x8616_ea_direct), x8616_emit_u2(addr)
|
|
#define x8616_emit_modrm_i8(opcode,mod,reg,rm,imm) x8616_emit_modrm(opcode,mod,reg,rm), u1_(imm)
|
|
#define x8616_emit_modrm_i16(opcode,mod,reg,rm,imm) x8616_emit_modrm(opcode,mod,reg,rm), x8616_emit_u2(imm)
|
|
#define x8616_emit_modrm_d8_i8(opcode,reg,rm,disp,imm) x8616_emit_modrm_d8(opcode,reg,rm,disp), u1_(imm)
|
|
#define x8616_emit_modrm_d8_i16(opcode,reg,rm,disp,imm) x8616_emit_modrm_d8(opcode,reg,rm,disp), x8616_emit_u2(imm)
|
|
#define x8616_emit_modrm_d16_i8(opcode,reg,rm,disp,imm) x8616_emit_modrm_d16(opcode,reg,rm,disp), u1_(imm)
|
|
#define x8616_emit_modrm_d16_i16(opcode,reg,rm,disp,imm) x8616_emit_modrm_d16(opcode,reg,rm,disp), x8616_emit_u2(imm)
|
|
|
|
// r/m + register / immediate packets
|
|
|
|
#define x8616_emit_rm_r(prefix,d,w,mod,reg,rm) x8616_enc_dw(prefix,d,w), x8616_enc_modrm(mod,reg,rm)
|
|
#define x8616_emit_rm_r_d8(prefix,d,w,reg,rm,disp) x8616_emit_rm_r(prefix,d,w,x8616_mod_mem_d8,reg,rm), u1_(disp)
|
|
#define x8616_emit_rm_r_d16(prefix,d,w,reg,rm,disp) x8616_emit_rm_r(prefix,d,w,x8616_mod_mem_d16,reg,rm), x8616_emit_s2(disp)
|
|
#define x8616_emit_rm_r_direct(prefix,d,w,reg,addr) x8616_emit_rm_r(prefix,d,w,x8616_mod_mem,reg,x8616_ea_direct), x8616_emit_u2(addr)
|
|
|
|
#define x8616_emit_rm_i8_w(prefix,ext,mod,rm,imm) x8616_enc_w(prefix,x8616_w_byte), x8616_enc_modrm(mod,ext,rm), u1_(imm)
|
|
#define x8616_emit_rm_i16_w(prefix,ext,mod,rm,imm) x8616_enc_w(prefix,x8616_w_word), x8616_enc_modrm(mod,ext,rm), x8616_emit_u2(imm)
|
|
#define x8616_emit_rm_i8_w_d8(prefix,ext,rm,disp,imm) x8616_enc_w(prefix,x8616_w_byte), x8616_enc_modrm(x8616_mod_mem_d8,ext,rm), u1_(disp), u1_(imm)
|
|
#define x8616_emit_rm_i16_w_d8(prefix,ext,rm,disp,imm) x8616_enc_w(prefix,x8616_w_word), x8616_enc_modrm(x8616_mod_mem_d8,ext,rm), u1_(disp), x8616_emit_u2(imm)
|
|
#define x8616_emit_rm_i8_w_d16(prefix,ext,rm,disp,imm) x8616_enc_w(prefix,x8616_w_byte), x8616_enc_modrm(x8616_mod_mem_d16,ext,rm), x8616_emit_s2(disp), u1_(imm)
|
|
#define x8616_emit_rm_i16_w_d16(prefix,ext,rm,disp,imm) x8616_enc_w(prefix,x8616_w_word), x8616_enc_modrm(x8616_mod_mem_d16,ext,rm), x8616_emit_s2(disp), x8616_emit_u2(imm)
|
|
|
|
#define x8616_emit_rm_i8(prefix,s,w,ext,mod,rm,imm) x8616_enc_sw(prefix,s,w), x8616_enc_modrm(mod,ext,rm), u1_(imm)
|
|
#define x8616_emit_rm_i16(prefix,ext,mod,rm,imm) x8616_enc_sw(prefix,x8616_s_full,x8616_w_word), x8616_enc_modrm(mod,ext,rm), x8616_emit_u2(imm)
|
|
#define x8616_emit_rm_i8_d8(prefix,s,w,ext,rm,disp,imm) x8616_enc_sw(prefix,s,w), x8616_enc_modrm(x8616_mod_mem_d8,ext,rm), u1_(disp), u1_(imm)
|
|
#define x8616_emit_rm_i16_d8(prefix,ext,rm,disp,imm) x8616_enc_sw(prefix,x8616_s_full,x8616_w_word), x8616_enc_modrm(x8616_mod_mem_d8,ext,rm), u1_(disp), x8616_emit_u2(imm)
|
|
#define x8616_emit_rm_i8_d16(prefix,s,w,ext,rm,disp,imm) x8616_enc_sw(prefix,s,w), x8616_enc_modrm(x8616_mod_mem_d16,ext,rm), x8616_emit_s2(disp), u1_(imm)
|
|
#define x8616_emit_rm_i16_d16(prefix,ext,rm,disp,imm) x8616_enc_sw(prefix,x8616_s_full,x8616_w_word), x8616_enc_modrm(x8616_mod_mem_d16,ext,rm), x8616_emit_s2(disp), x8616_emit_u2(imm)
|
|
|
|
// Segment-register packet
|
|
|
|
#define x8616_emit_seg_rm(d,mod,sr,rm) x8616_enc_d0(x8616_opcode_mov_seg_rm,d), x8616_enc_modrm_seg(mod,sr,rm)
|
|
#define x8616_emit_seg_rm_d8(d,sr,rm,disp) x8616_emit_seg_rm(d,x8616_mod_mem_d8,sr,rm), u1_(disp)
|
|
#define x8616_emit_seg_rm_d16(d,sr,rm,disp) x8616_emit_seg_rm(d,x8616_mod_mem_d16,sr,rm), x8616_emit_s2(disp)
|
|
#define x8616_emit_seg_rm_direct(d,sr,addr) x8616_emit_seg_rm(d,x8616_mod_mem,sr,x8616_ea_direct), x8616_emit_u2(addr)
|
|
|
|
// MOV
|
|
|
|
#define x8616_nop() x8616_emit_op(x8616_opcode_nop)
|
|
#define x8616_mov_r8_r8(dst,src) x8616_emit_rm_r(x8616_opcode_mov_rm_r,x8616_d_reg_dst,x8616_w_byte,x8616_mod_reg,dst,src)
|
|
#define x8616_mov_r16_r16(dst,src) x8616_emit_rm_r(x8616_opcode_mov_rm_r,x8616_d_reg_dst,x8616_w_word,x8616_mod_reg,dst,src)
|
|
#define x8616_mov_r8_i(dst,imm) x8616_enc_wreg(x8616_opcode_mov_r_i,x8616_w_byte,dst), u1_(imm)
|
|
#define x8616_mov_r16_i(dst,imm) x8616_enc_wreg(x8616_opcode_mov_r_i,x8616_w_word,dst), x8616_emit_u2(imm)
|
|
#define x8616_mov_al_moffs(addr) x8616_enc_dw(x8616_opcode_mov_acc_mem,x8616_d_acc_dst,x8616_w_byte), x8616_emit_u2(addr)
|
|
#define x8616_mov_ax_moffs(addr) x8616_enc_dw(x8616_opcode_mov_acc_mem,x8616_d_acc_dst,x8616_w_word), x8616_emit_u2(addr)
|
|
#define x8616_mov_moffs_al(addr) x8616_enc_dw(x8616_opcode_mov_acc_mem,x8616_d_mem_dst,x8616_w_byte), x8616_emit_u2(addr)
|
|
#define x8616_mov_moffs_ax(addr) x8616_enc_dw(x8616_opcode_mov_acc_mem,x8616_d_mem_dst,x8616_w_word), x8616_emit_u2(addr)
|
|
#define x8616_mov_rm_seg(mod,rm,sr) x8616_emit_seg_rm(x8616_d_rm_dst,mod,sr,rm)
|
|
#define x8616_mov_seg_rm(sr,mod,rm) x8616_emit_seg_rm(x8616_d_seg_dst,mod,sr,rm)
|
|
|
|
// Stack / exchange
|
|
|
|
#define x8616_push_r16(reg) x8616_enc_reg(x8616_opcode_push_reg,reg)
|
|
#define x8616_pop_r16(reg) x8616_enc_reg(x8616_opcode_pop_reg,reg)
|
|
#define x8616_push_seg(seg) x8616_enc_sr(X8616_OPCODE_PUSH_SR_FIXED,seg)
|
|
#define x8616_pop_seg(seg) x8616_enc_sr(X8616_OPCODE_POP_SR_FIXED,seg)
|
|
#define x8616_push_rm(mod,rm) x8616_emit_modrm(x8616_opcode_group_ff,mod,x8616_ff_push,rm)
|
|
#define x8616_pop_rm(mod,rm) x8616_emit_modrm(x8616_opcode_pop_rm,mod,0b000,rm)
|
|
|
|
#define x8616_xchg_r8_r8(a,b) x8616_enc_w(x8616_opcode_xchg_rm_r,x8616_w_byte), x8616_enc_modrm(x8616_mod_reg,a,b)
|
|
#define x8616_xchg_r16_r16(a,b) x8616_enc_w(x8616_opcode_xchg_rm_r,x8616_w_word), x8616_enc_modrm(x8616_mod_reg,a,b)
|
|
#define x8616_xchg_ax_r16(reg) x8616_enc_reg(x8616_opcode_xchg_ax_reg,reg)
|
|
|
|
// I/O / address load
|
|
|
|
#define x8616_in_al_i(port) x8616_enc_w(x8616_opcode_in_i,x8616_w_byte), u1_(port)
|
|
#define x8616_in_ax_i(port) x8616_enc_w(x8616_opcode_in_i,x8616_w_word), u1_(port)
|
|
#define x8616_in_al_dx() x8616_enc_w(x8616_opcode_in_dx,x8616_w_byte)
|
|
#define x8616_in_ax_dx() x8616_enc_w(x8616_opcode_in_dx,x8616_w_word)
|
|
#define x8616_out_i_al(port) x8616_enc_w(x8616_opcode_out_i,x8616_w_byte), u1_(port)
|
|
#define x8616_out_i_ax(port) x8616_enc_w(x8616_opcode_out_i,x8616_w_word), u1_(port)
|
|
#define x8616_out_dx_al() x8616_enc_w(x8616_opcode_out_dx,x8616_w_byte)
|
|
#define x8616_out_dx_ax() x8616_enc_w(x8616_opcode_out_dx,x8616_w_word)
|
|
|
|
#define x8616_xlat() x8616_emit_op(x8616_opcode_xlat)
|
|
#define x8616_lea(reg,mod,rm) x8616_emit_modrm(x8616_opcode_lea,mod,reg,rm)
|
|
#define x8616_lds(reg,mod,rm) x8616_emit_modrm(x8616_opcode_lds,mod,reg,rm)
|
|
#define x8616_les(reg,mod,rm) x8616_emit_modrm(x8616_opcode_les,mod,reg,rm)
|
|
#define x8616_lahf() x8616_emit_op(x8616_opcode_lahf)
|
|
#define x8616_sahf() x8616_emit_op(x8616_opcode_sahf)
|
|
#define x8616_pushf() x8616_emit_op(x8616_opcode_pushf)
|
|
#define x8616_popf() x8616_emit_op(x8616_opcode_popf)
|
|
|
|
// Arithmetic / logical
|
|
|
|
#define x8616_emit_alu_r8_r8(alu,dst,src) x8616_enc_alu_rm_r(alu,x8616_d_reg_dst,x8616_w_byte), x8616_enc_modrm(x8616_mod_reg,dst,src)
|
|
#define x8616_emit_alu_r16_r16(alu,dst,src) x8616_enc_alu_rm_r(alu,x8616_d_reg_dst,x8616_w_word), x8616_enc_modrm(x8616_mod_reg,dst,src)
|
|
#define x8616_emit_alu_r8_i(alu,dst,imm) x8616_emit_rm_i8(x8616_opcode_alu_rm_i,x8616_s_full,x8616_w_byte,alu,x8616_mod_reg,dst,imm)
|
|
#define x8616_emit_alu_r16_i(alu,dst,imm) x8616_emit_rm_i16(x8616_opcode_alu_rm_i,alu,x8616_mod_reg,dst,imm)
|
|
#define x8616_emit_alu_r16_i8s(alu,dst,imm) x8616_emit_rm_i8(x8616_opcode_alu_rm_i,x8616_s_extend,x8616_w_word,alu,x8616_mod_reg,dst,imm)
|
|
#define x8616_emit_logic_r8_i(alu,dst,imm) x8616_emit_rm_i8_w(x8616_opcode_logic_rm_i,alu,x8616_mod_reg,dst,imm)
|
|
#define x8616_emit_logic_r16_i(alu,dst,imm) x8616_emit_rm_i16_w(x8616_opcode_logic_rm_i,alu,x8616_mod_reg,dst,imm)
|
|
#define x8616_emit_alu_al_i(alu,imm) x8616_enc_alu_acc_i(alu,x8616_w_byte), u1_(imm)
|
|
#define x8616_emit_alu_ax_i(alu,imm) x8616_enc_alu_acc_i(alu,x8616_w_word), x8616_emit_u2(imm)
|
|
|
|
#define x8616_add_r8_r8(dst,src) x8616_emit_alu_r8_r8(x8616_add,dst,src)
|
|
#define x8616_add_r16_r16(dst,src) x8616_emit_alu_r16_r16(x8616_add,dst,src)
|
|
#define x8616_or_r8_r8(dst,src) x8616_emit_alu_r8_r8(x8616_or,dst,src)
|
|
#define x8616_or_r16_r16(dst,src) x8616_emit_alu_r16_r16(x8616_or,dst,src)
|
|
#define x8616_adc_r8_r8(dst,src) x8616_emit_alu_r8_r8(x8616_adc,dst,src)
|
|
#define x8616_adc_r16_r16(dst,src) x8616_emit_alu_r16_r16(x8616_adc,dst,src)
|
|
#define x8616_sbb_r8_r8(dst,src) x8616_emit_alu_r8_r8(x8616_sbb,dst,src)
|
|
#define x8616_sbb_r16_r16(dst,src) x8616_emit_alu_r16_r16(x8616_sbb,dst,src)
|
|
#define x8616_and_r8_r8(dst,src) x8616_emit_alu_r8_r8(x8616_and,dst,src)
|
|
#define x8616_and_r16_r16(dst,src) x8616_emit_alu_r16_r16(x8616_and,dst,src)
|
|
#define x8616_sub_r8_r8(dst,src) x8616_emit_alu_r8_r8(x8616_sub,dst,src)
|
|
#define x8616_sub_r16_r16(dst,src) x8616_emit_alu_r16_r16(x8616_sub,dst,src)
|
|
#define x8616_xor_r8_r8(dst,src) x8616_emit_alu_r8_r8(x8616_xor,dst,src)
|
|
#define x8616_xor_r16_r16(dst,src) x8616_emit_alu_r16_r16(x8616_xor,dst,src)
|
|
#define x8616_cmp_r8_r8(dst,src) x8616_emit_alu_r8_r8(x8616_cmp,dst,src)
|
|
#define x8616_cmp_r16_r16(dst,src) x8616_emit_alu_r16_r16(x8616_cmp,dst,src)
|
|
|
|
#define x8616_add_r8_i(dst,imm) x8616_emit_alu_r8_i(x8616_add,dst,imm)
|
|
#define x8616_add_r16_i(dst,imm) x8616_emit_alu_r16_i(x8616_add,dst,imm)
|
|
#define x8616_add_r16_i8s(dst,imm) x8616_emit_alu_r16_i8s(x8616_add,dst,imm)
|
|
#define x8616_or_r8_i(dst,imm) x8616_emit_logic_r8_i(x8616_or,dst,imm)
|
|
#define x8616_or_r16_i(dst,imm) x8616_emit_logic_r16_i(x8616_or,dst,imm)
|
|
#define x8616_adc_r8_i(dst,imm) x8616_emit_alu_r8_i(x8616_adc,dst,imm)
|
|
#define x8616_adc_r16_i(dst,imm) x8616_emit_alu_r16_i(x8616_adc,dst,imm)
|
|
#define x8616_adc_r16_i8s(dst,imm) x8616_emit_alu_r16_i8s(x8616_adc,dst,imm)
|
|
#define x8616_sbb_r8_i(dst,imm) x8616_emit_alu_r8_i(x8616_sbb,dst,imm)
|
|
#define x8616_sbb_r16_i(dst,imm) x8616_emit_alu_r16_i(x8616_sbb,dst,imm)
|
|
#define x8616_sbb_r16_i8s(dst,imm) x8616_emit_alu_r16_i8s(x8616_sbb,dst,imm)
|
|
#define x8616_and_r8_i(dst,imm) x8616_emit_logic_r8_i(x8616_and,dst,imm)
|
|
#define x8616_and_r16_i(dst,imm) x8616_emit_logic_r16_i(x8616_and,dst,imm)
|
|
#define x8616_sub_r8_i(dst,imm) x8616_emit_alu_r8_i(x8616_sub,dst,imm)
|
|
#define x8616_sub_r16_i(dst,imm) x8616_emit_alu_r16_i(x8616_sub,dst,imm)
|
|
#define x8616_sub_r16_i8s(dst,imm) x8616_emit_alu_r16_i8s(x8616_sub,dst,imm)
|
|
#define x8616_xor_r8_i(dst,imm) x8616_emit_logic_r8_i(x8616_xor,dst,imm)
|
|
#define x8616_xor_r16_i(dst,imm) x8616_emit_logic_r16_i(x8616_xor,dst,imm)
|
|
#define x8616_cmp_r8_i(dst,imm) x8616_emit_alu_r8_i(x8616_cmp,dst,imm)
|
|
#define x8616_cmp_r16_i(dst,imm) x8616_emit_alu_r16_i(x8616_cmp,dst,imm)
|
|
#define x8616_cmp_r16_i8s(dst,imm) x8616_emit_alu_r16_i8s(x8616_cmp,dst,imm)
|
|
|
|
// INC / DEC / unary
|
|
|
|
#define x8616_inc_r16(reg) x8616_enc_reg(x8616_opcode_inc_reg,reg)
|
|
#define x8616_dec_r16(reg) x8616_enc_reg(x8616_opcode_dec_reg,reg)
|
|
#define x8616_inc_rm(w,mod,rm) x8616_emit_modrm(x8616_enc_w(x8616_opcode_incdec_rm,w),mod,x8616_inc,rm)
|
|
#define x8616_dec_rm(w,mod,rm) x8616_emit_modrm(x8616_enc_w(x8616_opcode_incdec_rm,w),mod,x8616_dec,rm)
|
|
|
|
#define x8616_unary_rm(ext,w,mod,rm) x8616_emit_modrm(x8616_enc_w(x8616_opcode_group3,w),mod,ext,rm)
|
|
#define x8616_not_rm(w,mod,rm) x8616_unary_rm(x8616_g3_not,w,mod,rm)
|
|
#define x8616_neg_rm(w,mod,rm) x8616_unary_rm(x8616_g3_neg,w,mod,rm)
|
|
#define x8616_mul_rm(w,mod,rm) x8616_unary_rm(x8616_g3_mul,w,mod,rm)
|
|
#define x8616_imul_rm(w,mod,rm) x8616_unary_rm(x8616_g3_imul,w,mod,rm)
|
|
#define x8616_div_rm(w,mod,rm) x8616_unary_rm(x8616_g3_div,w,mod,rm)
|
|
#define x8616_idiv_rm(w,mod,rm) x8616_unary_rm(x8616_g3_idiv,w,mod,rm)
|
|
|
|
#define x8616_aaa() x8616_emit_op(x8616_opcode_aaa)
|
|
#define x8616_daa() x8616_emit_op(x8616_opcode_daa)
|
|
#define x8616_aas() x8616_emit_op(x8616_opcode_aas)
|
|
#define x8616_das() x8616_emit_op(x8616_opcode_das)
|
|
#define x8616_aam() x8616_emit_op_i8(x8616_opcode_aam,X8616_POST_OPCODE_AAM_AAD)
|
|
#define x8616_aad() x8616_emit_op_i8(x8616_opcode_aad,X8616_POST_OPCODE_AAM_AAD)
|
|
#define x8616_cbw() x8616_emit_op(x8616_opcode_cbw)
|
|
#define x8616_cwd() x8616_emit_op(x8616_opcode_cwd)
|
|
|
|
// Shift / rotate / TEST
|
|
|
|
#define x8616_shift_rm(shift,v,w,mod,rm) x8616_emit_modrm(x8616_enc_vw(x8616_opcode_shift_rm,v,w),mod,shift,rm)
|
|
#define x8616_shl_r8_1(reg) x8616_shift_rm(x8616_shl,x8616_v_one,x8616_w_byte,x8616_mod_reg,reg)
|
|
#define x8616_shl_r16_1(reg) x8616_shift_rm(x8616_shl,x8616_v_one,x8616_w_word,x8616_mod_reg,reg)
|
|
#define x8616_shl_r8_cl(reg) x8616_shift_rm(x8616_shl,x8616_v_cl,x8616_w_byte,x8616_mod_reg,reg)
|
|
#define x8616_shl_r16_cl(reg) x8616_shift_rm(x8616_shl,x8616_v_cl,x8616_w_word,x8616_mod_reg,reg)
|
|
|
|
#define x8616_test_r8_r8(a,b) x8616_enc_w(x8616_opcode_test_rm_r,x8616_w_byte), x8616_enc_modrm(x8616_mod_reg,b,a)
|
|
#define x8616_test_r16_r16(a,b) x8616_enc_w(x8616_opcode_test_rm_r,x8616_w_word), x8616_enc_modrm(x8616_mod_reg,b,a)
|
|
#define x8616_test_r8_i(reg,imm) x8616_emit_modrm_i8(x8616_enc_w(x8616_opcode_group3,x8616_w_byte),x8616_mod_reg,x8616_g3_test,reg,imm)
|
|
#define x8616_test_r16_i(reg,imm) x8616_emit_modrm_i16(x8616_enc_w(x8616_opcode_group3,x8616_w_word),x8616_mod_reg,x8616_g3_test,reg,imm)
|
|
#define x8616_test_al_i(imm) x8616_enc_w(x8616_opcode_test_acc_i,x8616_w_byte), u1_(imm)
|
|
#define x8616_test_ax_i(imm) x8616_enc_w(x8616_opcode_test_acc_i,x8616_w_word), x8616_emit_u2(imm)
|
|
|
|
// String / prefixes
|
|
|
|
#define x8616_rep_prefix() x8616_enc_zp(x8616_opcode_rep,x8616_rep)
|
|
#define x8616_repne_prefix() x8616_enc_zp(x8616_opcode_rep,x8616_repne)
|
|
#define x8616_movsb() x8616_enc_w(x8616_opcode_movs,x8616_w_byte)
|
|
#define x8616_movsw() x8616_enc_w(x8616_opcode_movs,x8616_w_word)
|
|
#define x8616_cmpsb() x8616_enc_w(x8616_opcode_cmps,x8616_w_byte)
|
|
#define x8616_cmpsw() x8616_enc_w(x8616_opcode_cmps,x8616_w_word)
|
|
#define x8616_scasb() x8616_enc_w(x8616_opcode_scas,x8616_w_byte)
|
|
#define x8616_scasw() x8616_enc_w(x8616_opcode_scas,x8616_w_word)
|
|
#define x8616_lodsb() x8616_enc_w(x8616_opcode_lods,x8616_w_byte)
|
|
#define x8616_lodsw() x8616_enc_w(x8616_opcode_lods,x8616_w_word)
|
|
#define x8616_stosb() x8616_enc_w(x8616_opcode_stos,x8616_w_byte)
|
|
#define x8616_stosw() x8616_enc_w(x8616_opcode_stos,x8616_w_word)
|
|
#define x8616_lock_prefix() x8616_emit_op(x8616_opcode_lock)
|
|
#define x8616_segment_prefix(seg) x8616_enc_sr(X8616_OPCODE_SEG_FIXED,seg)
|
|
|
|
// Control transfer
|
|
|
|
#define x8616_call_rel16(rel) x8616_emit_op_i16(x8616_opcode_call_rel16,rel)
|
|
#define x8616_call_far(seg,off) x8616_emit_op_far(x8616_opcode_call_far,seg,off)
|
|
#define x8616_call_rm(mod,rm) x8616_emit_modrm(x8616_opcode_group_ff,mod,x8616_ff_call_near,rm)
|
|
#define x8616_call_far_rm(mod,rm) x8616_emit_modrm(x8616_opcode_group_ff,mod,x8616_ff_call_far,rm)
|
|
|
|
#define x8616_jmp_rel16(rel) x8616_emit_op_i16(x8616_opcode_jmp_rel16,rel)
|
|
#define x8616_jmp_rel8(rel) x8616_emit_op_i8(x8616_opcode_jmp_rel8,rel)
|
|
#define x8616_jmp_far(seg,off) x8616_emit_op_far(x8616_opcode_jmp_far,seg,off)
|
|
#define x8616_jmp_rm(mod,rm) x8616_emit_modrm(x8616_opcode_group_ff,mod,x8616_ff_jmp_near,rm)
|
|
#define x8616_jmp_far_rm(mod,rm) x8616_emit_modrm(x8616_opcode_group_ff,mod,x8616_ff_jmp_far,rm)
|
|
|
|
#define x8616_ret() x8616_emit_op(x8616_opcode_ret)
|
|
#define x8616_ret_i(bytes) x8616_emit_op_i16(x8616_opcode_ret_i,bytes)
|
|
#define x8616_retf() x8616_emit_op(x8616_opcode_retf)
|
|
#define x8616_retf_i(bytes) x8616_emit_op_i16(x8616_opcode_retf_i,bytes)
|
|
|
|
#define x8616_jcc(cc,rel) x8616_enc_jcc(cc), u1_(rel)
|
|
#define x8616_jo(rel) x8616_jcc(x8616_cc_o,rel)
|
|
#define x8616_jno(rel) x8616_jcc(x8616_cc_no,rel)
|
|
#define x8616_jb(rel) x8616_jcc(x8616_cc_b,rel)
|
|
#define x8616_jnb(rel) x8616_jcc(x8616_cc_nb,rel)
|
|
#define x8616_je(rel) x8616_jcc(x8616_cc_e,rel)
|
|
#define x8616_jne(rel) x8616_jcc(x8616_cc_ne,rel)
|
|
#define x8616_jbe(rel) x8616_jcc(x8616_cc_be,rel)
|
|
#define x8616_ja(rel) x8616_jcc(x8616_cc_a,rel)
|
|
#define x8616_js(rel) x8616_jcc(x8616_cc_s,rel)
|
|
#define x8616_jns(rel) x8616_jcc(x8616_cc_ns,rel)
|
|
#define x8616_jp(rel) x8616_jcc(x8616_cc_p,rel)
|
|
#define x8616_jnp(rel) x8616_jcc(x8616_cc_np,rel)
|
|
#define x8616_jl(rel) x8616_jcc(x8616_cc_l,rel)
|
|
#define x8616_jnl(rel) x8616_jcc(x8616_cc_nl,rel)
|
|
#define x8616_jle(rel) x8616_jcc(x8616_cc_le,rel)
|
|
#define x8616_jg(rel) x8616_jcc(x8616_cc_g,rel)
|
|
|
|
#define x8616_loopnz(rel) x8616_emit_op_i8(x8616_opcode_loopnz,rel)
|
|
#define x8616_loopz(rel) x8616_emit_op_i8(x8616_opcode_loopz,rel)
|
|
#define x8616_loop(rel) x8616_emit_op_i8(x8616_opcode_loop,rel)
|
|
#define x8616_jcxz(rel) x8616_emit_op_i8(x8616_opcode_jcxz,rel)
|
|
|
|
// Interrupt / flags / machine control
|
|
|
|
#define x8616_int(vector) x8616_emit_op_i8(x8616_opcode_int,vector)
|
|
#define x8616_int3() x8616_emit_op(x8616_opcode_int3)
|
|
#define x8616_into() x8616_emit_op(x8616_opcode_into)
|
|
#define x8616_iret() x8616_emit_op(x8616_opcode_iret)
|
|
#define x8616_clc() x8616_emit_op(x8616_opcode_clc)
|
|
#define x8616_cmc() x8616_emit_op(x8616_opcode_cmc)
|
|
#define x8616_stc() x8616_emit_op(x8616_opcode_stc)
|
|
#define x8616_cld() x8616_emit_op(x8616_opcode_cld)
|
|
#define x8616_std() x8616_emit_op(x8616_opcode_std)
|
|
#define x8616_cli() x8616_emit_op(x8616_opcode_cli)
|
|
#define x8616_sti() x8616_emit_op(x8616_opcode_sti)
|
|
#define x8616_hlt() x8616_emit_op(x8616_opcode_hlt)
|
|
#define x8616_wait() x8616_emit_op(x8616_opcode_wait)
|