34 : honor_operand_types(
false) {
50 honor_operand_types = b;
56 return honor_operand_types;
74 static const unsigned od_e_mask = 0x00000070;
75 static const unsigned od_e_pres = 0x00000080;
76 static const unsigned od_e0 = 0x00000000 | od_e_pres;
77 static const unsigned od_e1 = 0x00000010 | od_e_pres;
78 static const unsigned od_e2 = 0x00000020 | od_e_pres;
79 static const unsigned od_e3 = 0x00000030 | od_e_pres;
80 static const unsigned od_e4 = 0x00000040 | od_e_pres;
81 static const unsigned od_e5 = 0x00000050 | od_e_pres;
82 static const unsigned od_e6 = 0x00000060 | od_e_pres;
83 static const unsigned od_e7 = 0x00000070 | od_e_pres;
84 static size_t od_e_val(
unsigned opcode_mods) {
return (opcode_mods & od_e_mask)>>4; }
89 static const unsigned od_rex_pres = 0x00000001;
90 static const unsigned od_rex_mask = 0x00000f00;
91 static const unsigned od_rex = 0x00000000 | od_rex_pres;
92 static const unsigned od_rexb = 0x00000100 | od_rex_pres;
93 static const unsigned od_rexx = 0x00000200 | od_rex_pres;
94 static const unsigned od_rexxb = 0x00000300 | od_rex_pres;
95 static const unsigned od_rexr = 0x00000400 | od_rex_pres;
96 static const unsigned od_rexrb = 0x00000500 | od_rex_pres;
97 static const unsigned od_rexrx = 0x00000600 | od_rex_pres;
98 static const unsigned od_rexrxb = 0x00000700 | od_rex_pres;
99 static const unsigned od_rexw = 0x00000800 | od_rex_pres;
100 static const unsigned od_rexwb = 0x00000900 | od_rex_pres;
101 static const unsigned od_rexwx = 0x00000a00 | od_rex_pres;
102 static const unsigned od_rexwxb = 0x00000b00 | od_rex_pres;
103 static const unsigned od_rexwr = 0x00000c00 | od_rex_pres;
104 static const unsigned od_rexwrb = 0x00000d00 | od_rex_pres;
105 static const unsigned od_rexwrx = 0x00000e00 | od_rex_pres;
106 static const unsigned od_rexwrxb = 0x00000f00 | od_rex_pres;
107 static uint8_t od_rex_byte(
unsigned opcode_mods) {
return 0x40 | ((opcode_mods & od_rex_mask) >> 8); }
111 static const unsigned od_modrm = 0x00000002;
115 static const unsigned od_c_mask = 0x00007000;
116 static const unsigned od_cb = 0x00001000;
117 static const unsigned od_cw = 0x00002000;
118 static const unsigned od_cd = 0x00003000;
119 static const unsigned od_cp = 0x00004000;
120 static const unsigned od_co = 0x00005000;
121 static const unsigned od_ct = 0x00006000;
125 static const unsigned od_i_mask = 0x00070000;
126 static const unsigned od_ib = 0x00010000;
127 static const unsigned od_iw = 0x00020000;
128 static const unsigned od_id = 0x00030000;
129 static const unsigned od_io = 0x00040000;
133 static const unsigned od_r_mask = 0x00700000;
134 static const unsigned od_rb = 0x00100000;
135 static const unsigned od_rw = 0x00200000;
136 static const unsigned od_rd = 0x00300000;
137 static const unsigned od_ro = 0x00400000;
142 static const unsigned od_i = 0x00000004;
329 static const unsigned COMPAT_LEGACY = 0x01;
330 static const unsigned COMPAT_64 = 0x02;
333 static uint8_t build_modrm(
unsigned mod,
unsigned reg,
unsigned rm) {
334 return ((mod&0x3)<<6) | ((reg&0x7)<<3) | (rm&0x7);
338 static unsigned modrm_mod(uint8_t modrm) {
return modrm>>6; }
341 static unsigned modrm_reg(uint8_t modrm) {
return (modrm>>3) & 0x7; }
344 static unsigned modrm_rm(uint8_t modrm) {
return modrm & 0x7; }
347 static uint8_t build_sib(
unsigned ss,
unsigned index,
unsigned base) {
348 return ((ss&0x3)<<6) | ((index&0x7)<<3) | (base&0x7);
352 static unsigned sib_ss(uint8_t sib) {
return sib>>6; }
355 static unsigned sib_index(uint8_t sib) {
return (sib>>3) & 0x7; }
358 static unsigned sib_base(uint8_t sib) {
return sib & 0x7; }
365 InsnDefn(
const std::string &mnemonic,
X86InstructionKind kind,
unsigned compatibility, uint64_t opcode,
366 unsigned opcode_modifiers, OperandDefn op1=od_none, OperandDefn op2=od_none, OperandDefn op3=od_none,
367 OperandDefn op4=od_none)
368 : mnemonic(mnemonic), kind(kind), compatibility(compatibility), opcode(opcode), opcode_modifiers(opcode_modifiers) {
369 if (op1) operands.push_back(op1);
370 if (op2) operands.push_back(op2);
371 if (op3) operands.push_back(op3);
372 if (op4) operands.push_back(op4);
374 std::string to_str()
const;
375 void set_location(
const std::string &s) {
378 std::string mnemonic;
380 unsigned compatibility;
382 unsigned opcode_modifiers;
383 std::vector<OperandDefn> operands;
384 std::string location;
387 enum MemoryReferencePattern
400 typedef std::vector<const InsnDefn*> DictionaryPage;
403 typedef std::map<X86InstructionKind, DictionaryPage> InsnDictionary;
406 static void initAssemblyRules();
407 static void initAssemblyRules_part1();
408 static void initAssemblyRules_part2();
409 static void initAssemblyRules_part3();
410 static void initAssemblyRules_part4();
411 static void initAssemblyRules_part5();
412 static void initAssemblyRules_part6();
413 static void initAssemblyRules_part7();
414 static void initAssemblyRules_part8();
415 static void initAssemblyRules_part9();
418 static void define(
const InsnDefn *d) {
419 defns[d->kind].push_back(d);
432 SgUnsignedCharList fixup_prefix_bytes(
SgAsmX86Instruction *insn, SgUnsignedCharList source);
441 void matches(
const InsnDefn *defn,
SgAsmX86Instruction *insn, int64_t *disp, int64_t *imm)
const;
460 uint8_t *sib, int64_t *displacement, uint8_t *rex)
const;
463 void build_modreg(
const InsnDefn*,
SgAsmX86Instruction*,
size_t argno, uint8_t *modrm, uint8_t *rex)
const;
469 static InsnDictionary defns;
470 bool honor_operand_types;