/src/capstonev5/arch/X86/X86Mapping.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* Capstone Disassembly Engine */ | 
| 2 |  | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */ | 
| 3 |  |  | 
| 4 |  | #ifdef CAPSTONE_HAS_X86 | 
| 5 |  |  | 
| 6 |  | #if defined(CAPSTONE_HAS_OSXKERNEL) | 
| 7 |  | #include <Availability.h> | 
| 8 |  | #endif | 
| 9 |  |  | 
| 10 |  | #include <string.h> | 
| 11 |  | #ifndef CAPSTONE_HAS_OSXKERNEL | 
| 12 |  | #include <stdlib.h> | 
| 13 |  | #endif | 
| 14 |  |  | 
| 15 |  | #include "X86Mapping.h" | 
| 16 |  | #include "X86DisassemblerDecoder.h" | 
| 17 |  |  | 
| 18 |  | #include "../../utils.h" | 
| 19 |  |  | 
| 20 |  |  | 
| 21 |  | const uint64_t arch_masks[9] = { | 
| 22 |  |   0, 0xff, | 
| 23 |  |   0xffff, // 16bit | 
| 24 |  |   0, | 
| 25 |  |   0xffffffff, // 32bit | 
| 26 |  |   0, 0, 0, | 
| 27 |  |   0xffffffffffffffffLL  // 64bit | 
| 28 |  | }; | 
| 29 |  |  | 
| 30 |  | static const x86_reg sib_base_map[] = { | 
| 31 |  |   X86_REG_INVALID, | 
| 32 |  | #define ENTRY(x) X86_REG_##x, | 
| 33 |  |   ALL_SIB_BASES | 
| 34 |  | #undef ENTRY | 
| 35 |  | }; | 
| 36 |  |  | 
| 37 |  | // Fill-ins to make the compiler happy.  These constants are never actually | 
| 38 |  | // assigned; they are just filler to make an automatically-generated switch | 
| 39 |  | // statement work. | 
| 40 |  | enum { | 
| 41 |  |   X86_REG_BX_SI = 500, | 
| 42 |  |   X86_REG_BX_DI = 501, | 
| 43 |  |   X86_REG_BP_SI = 502, | 
| 44 |  |   X86_REG_BP_DI = 503, | 
| 45 |  |   X86_REG_sib   = 504, | 
| 46 |  |   X86_REG_sib64 = 505 | 
| 47 |  | }; | 
| 48 |  |  | 
| 49 |  | static const x86_reg sib_index_map[] = { | 
| 50 |  |   X86_REG_INVALID, | 
| 51 |  | #define ENTRY(x) X86_REG_##x, | 
| 52 |  |   ALL_EA_BASES | 
| 53 |  |   REGS_XMM | 
| 54 |  |   REGS_YMM | 
| 55 |  |   REGS_ZMM | 
| 56 |  | #undef ENTRY | 
| 57 |  | }; | 
| 58 |  |  | 
| 59 |  | static const x86_reg segment_map[] = { | 
| 60 |  |   X86_REG_INVALID, | 
| 61 |  |   X86_REG_CS, | 
| 62 |  |   X86_REG_SS, | 
| 63 |  |   X86_REG_DS, | 
| 64 |  |   X86_REG_ES, | 
| 65 |  |   X86_REG_FS, | 
| 66 |  |   X86_REG_GS, | 
| 67 |  | }; | 
| 68 |  |  | 
| 69 |  | x86_reg x86_map_sib_base(int r) | 
| 70 | 354k | { | 
| 71 | 354k |   return sib_base_map[r]; | 
| 72 | 354k | } | 
| 73 |  |  | 
| 74 |  | x86_reg x86_map_sib_index(int r) | 
| 75 | 354k | { | 
| 76 | 354k |   return sib_index_map[r]; | 
| 77 | 354k | } | 
| 78 |  |  | 
| 79 |  | x86_reg x86_map_segment(int r) | 
| 80 | 0 | { | 
| 81 | 0 |   return segment_map[r]; | 
| 82 | 0 | } | 
| 83 |  |  | 
| 84 |  | #ifndef CAPSTONE_DIET | 
| 85 |  | static const name_map reg_name_maps[] = { | 
| 86 |  |   { X86_REG_INVALID, NULL }, | 
| 87 |  |  | 
| 88 |  |   { X86_REG_AH, "ah" }, | 
| 89 |  |   { X86_REG_AL, "al" }, | 
| 90 |  |   { X86_REG_AX, "ax" }, | 
| 91 |  |   { X86_REG_BH, "bh" }, | 
| 92 |  |   { X86_REG_BL, "bl" }, | 
| 93 |  |   { X86_REG_BP, "bp" }, | 
| 94 |  |   { X86_REG_BPL, "bpl" }, | 
| 95 |  |   { X86_REG_BX, "bx" }, | 
| 96 |  |   { X86_REG_CH, "ch" }, | 
| 97 |  |   { X86_REG_CL, "cl" }, | 
| 98 |  |   { X86_REG_CS, "cs" }, | 
| 99 |  |   { X86_REG_CX, "cx" }, | 
| 100 |  |   { X86_REG_DH, "dh" }, | 
| 101 |  |   { X86_REG_DI, "di" }, | 
| 102 |  |   { X86_REG_DIL, "dil" }, | 
| 103 |  |   { X86_REG_DL, "dl" }, | 
| 104 |  |   { X86_REG_DS, "ds" }, | 
| 105 |  |   { X86_REG_DX, "dx" }, | 
| 106 |  |   { X86_REG_EAX, "eax" }, | 
| 107 |  |   { X86_REG_EBP, "ebp" }, | 
| 108 |  |   { X86_REG_EBX, "ebx" }, | 
| 109 |  |   { X86_REG_ECX, "ecx" }, | 
| 110 |  |   { X86_REG_EDI, "edi" }, | 
| 111 |  |   { X86_REG_EDX, "edx" }, | 
| 112 |  |   { X86_REG_EFLAGS, "flags" }, | 
| 113 |  |   { X86_REG_EIP, "eip" }, | 
| 114 |  |   { X86_REG_EIZ, "eiz" }, | 
| 115 |  |   { X86_REG_ES, "es" }, | 
| 116 |  |   { X86_REG_ESI, "esi" }, | 
| 117 |  |   { X86_REG_ESP, "esp" }, | 
| 118 |  |   { X86_REG_FPSW, "fpsw" }, | 
| 119 |  |   { X86_REG_FS, "fs" }, | 
| 120 |  |   { X86_REG_GS, "gs" }, | 
| 121 |  |   { X86_REG_IP, "ip" }, | 
| 122 |  |   { X86_REG_RAX, "rax" }, | 
| 123 |  |   { X86_REG_RBP, "rbp" }, | 
| 124 |  |   { X86_REG_RBX, "rbx" }, | 
| 125 |  |   { X86_REG_RCX, "rcx" }, | 
| 126 |  |   { X86_REG_RDI, "rdi" }, | 
| 127 |  |   { X86_REG_RDX, "rdx" }, | 
| 128 |  |   { X86_REG_RIP, "rip" }, | 
| 129 |  |   { X86_REG_RIZ, "riz" }, | 
| 130 |  |   { X86_REG_RSI, "rsi" }, | 
| 131 |  |   { X86_REG_RSP, "rsp" }, | 
| 132 |  |   { X86_REG_SI, "si" }, | 
| 133 |  |   { X86_REG_SIL, "sil" }, | 
| 134 |  |   { X86_REG_SP, "sp" }, | 
| 135 |  |   { X86_REG_SPL, "spl" }, | 
| 136 |  |   { X86_REG_SS, "ss" }, | 
| 137 |  |   { X86_REG_CR0, "cr0" }, | 
| 138 |  |   { X86_REG_CR1, "cr1" }, | 
| 139 |  |   { X86_REG_CR2, "cr2" }, | 
| 140 |  |   { X86_REG_CR3, "cr3" }, | 
| 141 |  |   { X86_REG_CR4, "cr4" }, | 
| 142 |  |   { X86_REG_CR5, "cr5" }, | 
| 143 |  |   { X86_REG_CR6, "cr6" }, | 
| 144 |  |   { X86_REG_CR7, "cr7" }, | 
| 145 |  |   { X86_REG_CR8, "cr8" }, | 
| 146 |  |   { X86_REG_CR9, "cr9" }, | 
| 147 |  |   { X86_REG_CR10, "cr10" }, | 
| 148 |  |   { X86_REG_CR11, "cr11" }, | 
| 149 |  |   { X86_REG_CR12, "cr12" }, | 
| 150 |  |   { X86_REG_CR13, "cr13" }, | 
| 151 |  |   { X86_REG_CR14, "cr14" }, | 
| 152 |  |   { X86_REG_CR15, "cr15" }, | 
| 153 |  |   { X86_REG_DR0, "dr0" }, | 
| 154 |  |   { X86_REG_DR1, "dr1" }, | 
| 155 |  |   { X86_REG_DR2, "dr2" }, | 
| 156 |  |   { X86_REG_DR3, "dr3" }, | 
| 157 |  |   { X86_REG_DR4, "dr4" }, | 
| 158 |  |   { X86_REG_DR5, "dr5" }, | 
| 159 |  |   { X86_REG_DR6, "dr6" }, | 
| 160 |  |   { X86_REG_DR7, "dr7" }, | 
| 161 |  |   { X86_REG_DR8, "dr8" }, | 
| 162 |  |   { X86_REG_DR9, "dr9" }, | 
| 163 |  |   { X86_REG_DR10, "dr10" }, | 
| 164 |  |   { X86_REG_DR11, "dr11" }, | 
| 165 |  |   { X86_REG_DR12, "dr12" }, | 
| 166 |  |   { X86_REG_DR13, "dr13" }, | 
| 167 |  |   { X86_REG_DR14, "dr14" }, | 
| 168 |  |   { X86_REG_DR15, "dr15" }, | 
| 169 |  |   { X86_REG_FP0, "fp0" }, | 
| 170 |  |   { X86_REG_FP1, "fp1" }, | 
| 171 |  |   { X86_REG_FP2, "fp2" }, | 
| 172 |  |   { X86_REG_FP3, "fp3" }, | 
| 173 |  |   { X86_REG_FP4, "fp4" }, | 
| 174 |  |   { X86_REG_FP5, "fp5" }, | 
| 175 |  |   { X86_REG_FP6, "fp6" }, | 
| 176 |  |   { X86_REG_FP7, "fp7" }, | 
| 177 |  |   { X86_REG_K0, "k0" }, | 
| 178 |  |   { X86_REG_K1, "k1" }, | 
| 179 |  |   { X86_REG_K2, "k2" }, | 
| 180 |  |   { X86_REG_K3, "k3" }, | 
| 181 |  |   { X86_REG_K4, "k4" }, | 
| 182 |  |   { X86_REG_K5, "k5" }, | 
| 183 |  |   { X86_REG_K6, "k6" }, | 
| 184 |  |   { X86_REG_K7, "k7" }, | 
| 185 |  |   { X86_REG_MM0, "mm0" }, | 
| 186 |  |   { X86_REG_MM1, "mm1" }, | 
| 187 |  |   { X86_REG_MM2, "mm2" }, | 
| 188 |  |   { X86_REG_MM3, "mm3" }, | 
| 189 |  |   { X86_REG_MM4, "mm4" }, | 
| 190 |  |   { X86_REG_MM5, "mm5" }, | 
| 191 |  |   { X86_REG_MM6, "mm6" }, | 
| 192 |  |   { X86_REG_MM7, "mm7" }, | 
| 193 |  |   { X86_REG_R8, "r8" }, | 
| 194 |  |   { X86_REG_R9, "r9" }, | 
| 195 |  |   { X86_REG_R10, "r10" }, | 
| 196 |  |   { X86_REG_R11, "r11" }, | 
| 197 |  |   { X86_REG_R12, "r12" }, | 
| 198 |  |   { X86_REG_R13, "r13" }, | 
| 199 |  |   { X86_REG_R14, "r14" }, | 
| 200 |  |   { X86_REG_R15, "r15" }, | 
| 201 |  |   { X86_REG_ST0, "st(0)" }, | 
| 202 |  |   { X86_REG_ST1, "st(1)" }, | 
| 203 |  |   { X86_REG_ST2, "st(2)" }, | 
| 204 |  |   { X86_REG_ST3, "st(3)" }, | 
| 205 |  |   { X86_REG_ST4, "st(4)" }, | 
| 206 |  |   { X86_REG_ST5, "st(5)" }, | 
| 207 |  |   { X86_REG_ST6, "st(6)" }, | 
| 208 |  |   { X86_REG_ST7, "st(7)" }, | 
| 209 |  |   { X86_REG_XMM0, "xmm0" }, | 
| 210 |  |   { X86_REG_XMM1, "xmm1" }, | 
| 211 |  |   { X86_REG_XMM2, "xmm2" }, | 
| 212 |  |   { X86_REG_XMM3, "xmm3" }, | 
| 213 |  |   { X86_REG_XMM4, "xmm4" }, | 
| 214 |  |   { X86_REG_XMM5, "xmm5" }, | 
| 215 |  |   { X86_REG_XMM6, "xmm6" }, | 
| 216 |  |   { X86_REG_XMM7, "xmm7" }, | 
| 217 |  |   { X86_REG_XMM8, "xmm8" }, | 
| 218 |  |   { X86_REG_XMM9, "xmm9" }, | 
| 219 |  |   { X86_REG_XMM10, "xmm10" }, | 
| 220 |  |   { X86_REG_XMM11, "xmm11" }, | 
| 221 |  |   { X86_REG_XMM12, "xmm12" }, | 
| 222 |  |   { X86_REG_XMM13, "xmm13" }, | 
| 223 |  |   { X86_REG_XMM14, "xmm14" }, | 
| 224 |  |   { X86_REG_XMM15, "xmm15" }, | 
| 225 |  |   { X86_REG_XMM16, "xmm16" }, | 
| 226 |  |   { X86_REG_XMM17, "xmm17" }, | 
| 227 |  |   { X86_REG_XMM18, "xmm18" }, | 
| 228 |  |   { X86_REG_XMM19, "xmm19" }, | 
| 229 |  |   { X86_REG_XMM20, "xmm20" }, | 
| 230 |  |   { X86_REG_XMM21, "xmm21" }, | 
| 231 |  |   { X86_REG_XMM22, "xmm22" }, | 
| 232 |  |   { X86_REG_XMM23, "xmm23" }, | 
| 233 |  |   { X86_REG_XMM24, "xmm24" }, | 
| 234 |  |   { X86_REG_XMM25, "xmm25" }, | 
| 235 |  |   { X86_REG_XMM26, "xmm26" }, | 
| 236 |  |   { X86_REG_XMM27, "xmm27" }, | 
| 237 |  |   { X86_REG_XMM28, "xmm28" }, | 
| 238 |  |   { X86_REG_XMM29, "xmm29" }, | 
| 239 |  |   { X86_REG_XMM30, "xmm30" }, | 
| 240 |  |   { X86_REG_XMM31, "xmm31" }, | 
| 241 |  |   { X86_REG_YMM0, "ymm0" }, | 
| 242 |  |   { X86_REG_YMM1, "ymm1" }, | 
| 243 |  |   { X86_REG_YMM2, "ymm2" }, | 
| 244 |  |   { X86_REG_YMM3, "ymm3" }, | 
| 245 |  |   { X86_REG_YMM4, "ymm4" }, | 
| 246 |  |   { X86_REG_YMM5, "ymm5" }, | 
| 247 |  |   { X86_REG_YMM6, "ymm6" }, | 
| 248 |  |   { X86_REG_YMM7, "ymm7" }, | 
| 249 |  |   { X86_REG_YMM8, "ymm8" }, | 
| 250 |  |   { X86_REG_YMM9, "ymm9" }, | 
| 251 |  |   { X86_REG_YMM10, "ymm10" }, | 
| 252 |  |   { X86_REG_YMM11, "ymm11" }, | 
| 253 |  |   { X86_REG_YMM12, "ymm12" }, | 
| 254 |  |   { X86_REG_YMM13, "ymm13" }, | 
| 255 |  |   { X86_REG_YMM14, "ymm14" }, | 
| 256 |  |   { X86_REG_YMM15, "ymm15" }, | 
| 257 |  |   { X86_REG_YMM16, "ymm16" }, | 
| 258 |  |   { X86_REG_YMM17, "ymm17" }, | 
| 259 |  |   { X86_REG_YMM18, "ymm18" }, | 
| 260 |  |   { X86_REG_YMM19, "ymm19" }, | 
| 261 |  |   { X86_REG_YMM20, "ymm20" }, | 
| 262 |  |   { X86_REG_YMM21, "ymm21" }, | 
| 263 |  |   { X86_REG_YMM22, "ymm22" }, | 
| 264 |  |   { X86_REG_YMM23, "ymm23" }, | 
| 265 |  |   { X86_REG_YMM24, "ymm24" }, | 
| 266 |  |   { X86_REG_YMM25, "ymm25" }, | 
| 267 |  |   { X86_REG_YMM26, "ymm26" }, | 
| 268 |  |   { X86_REG_YMM27, "ymm27" }, | 
| 269 |  |   { X86_REG_YMM28, "ymm28" }, | 
| 270 |  |   { X86_REG_YMM29, "ymm29" }, | 
| 271 |  |   { X86_REG_YMM30, "ymm30" }, | 
| 272 |  |   { X86_REG_YMM31, "ymm31" }, | 
| 273 |  |   { X86_REG_ZMM0, "zmm0" }, | 
| 274 |  |   { X86_REG_ZMM1, "zmm1" }, | 
| 275 |  |   { X86_REG_ZMM2, "zmm2" }, | 
| 276 |  |   { X86_REG_ZMM3, "zmm3" }, | 
| 277 |  |   { X86_REG_ZMM4, "zmm4" }, | 
| 278 |  |   { X86_REG_ZMM5, "zmm5" }, | 
| 279 |  |   { X86_REG_ZMM6, "zmm6" }, | 
| 280 |  |   { X86_REG_ZMM7, "zmm7" }, | 
| 281 |  |   { X86_REG_ZMM8, "zmm8" }, | 
| 282 |  |   { X86_REG_ZMM9, "zmm9" }, | 
| 283 |  |   { X86_REG_ZMM10, "zmm10" }, | 
| 284 |  |   { X86_REG_ZMM11, "zmm11" }, | 
| 285 |  |   { X86_REG_ZMM12, "zmm12" }, | 
| 286 |  |   { X86_REG_ZMM13, "zmm13" }, | 
| 287 |  |   { X86_REG_ZMM14, "zmm14" }, | 
| 288 |  |   { X86_REG_ZMM15, "zmm15" }, | 
| 289 |  |   { X86_REG_ZMM16, "zmm16" }, | 
| 290 |  |   { X86_REG_ZMM17, "zmm17" }, | 
| 291 |  |   { X86_REG_ZMM18, "zmm18" }, | 
| 292 |  |   { X86_REG_ZMM19, "zmm19" }, | 
| 293 |  |   { X86_REG_ZMM20, "zmm20" }, | 
| 294 |  |   { X86_REG_ZMM21, "zmm21" }, | 
| 295 |  |   { X86_REG_ZMM22, "zmm22" }, | 
| 296 |  |   { X86_REG_ZMM23, "zmm23" }, | 
| 297 |  |   { X86_REG_ZMM24, "zmm24" }, | 
| 298 |  |   { X86_REG_ZMM25, "zmm25" }, | 
| 299 |  |   { X86_REG_ZMM26, "zmm26" }, | 
| 300 |  |   { X86_REG_ZMM27, "zmm27" }, | 
| 301 |  |   { X86_REG_ZMM28, "zmm28" }, | 
| 302 |  |   { X86_REG_ZMM29, "zmm29" }, | 
| 303 |  |   { X86_REG_ZMM30, "zmm30" }, | 
| 304 |  |   { X86_REG_ZMM31, "zmm31" }, | 
| 305 |  |   { X86_REG_R8B, "r8b" }, | 
| 306 |  |   { X86_REG_R9B, "r9b" }, | 
| 307 |  |   { X86_REG_R10B, "r10b" }, | 
| 308 |  |   { X86_REG_R11B, "r11b" }, | 
| 309 |  |   { X86_REG_R12B, "r12b" }, | 
| 310 |  |   { X86_REG_R13B, "r13b" }, | 
| 311 |  |   { X86_REG_R14B, "r14b" }, | 
| 312 |  |   { X86_REG_R15B, "r15b" }, | 
| 313 |  |   { X86_REG_R8D, "r8d" }, | 
| 314 |  |   { X86_REG_R9D, "r9d" }, | 
| 315 |  |   { X86_REG_R10D, "r10d" }, | 
| 316 |  |   { X86_REG_R11D, "r11d" }, | 
| 317 |  |   { X86_REG_R12D, "r12d" }, | 
| 318 |  |   { X86_REG_R13D, "r13d" }, | 
| 319 |  |   { X86_REG_R14D, "r14d" }, | 
| 320 |  |   { X86_REG_R15D, "r15d" }, | 
| 321 |  |   { X86_REG_R8W, "r8w" }, | 
| 322 |  |   { X86_REG_R9W, "r9w" }, | 
| 323 |  |   { X86_REG_R10W, "r10w" }, | 
| 324 |  |   { X86_REG_R11W, "r11w" }, | 
| 325 |  |   { X86_REG_R12W, "r12w" }, | 
| 326 |  |   { X86_REG_R13W, "r13w" }, | 
| 327 |  |   { X86_REG_R14W, "r14w" }, | 
| 328 |  |   { X86_REG_R15W, "r15w" }, | 
| 329 |  |  | 
| 330 |  |   { X86_REG_BND0, "bnd0" }, | 
| 331 |  |   { X86_REG_BND1, "bnd1" }, | 
| 332 |  |   { X86_REG_BND2, "bnd2" }, | 
| 333 |  |   { X86_REG_BND3, "bnd3" }, | 
| 334 |  | }; | 
| 335 |  | #endif | 
| 336 |  |  | 
| 337 |  | // register size in non-64bit mode | 
| 338 |  | const uint8_t regsize_map_32 [] = { | 
| 339 |  |   0,  //  { X86_REG_INVALID, NULL }, | 
| 340 |  |   1,  // { X86_REG_AH, "ah" }, | 
| 341 |  |   1,  // { X86_REG_AL, "al" }, | 
| 342 |  |   2,  // { X86_REG_AX, "ax" }, | 
| 343 |  |   1,  // { X86_REG_BH, "bh" }, | 
| 344 |  |   1,  // { X86_REG_BL, "bl" }, | 
| 345 |  |   2,  // { X86_REG_BP, "bp" }, | 
| 346 |  |   1,  // { X86_REG_BPL, "bpl" }, | 
| 347 |  |   2,  // { X86_REG_BX, "bx" }, | 
| 348 |  |   1,  // { X86_REG_CH, "ch" }, | 
| 349 |  |   1,  // { X86_REG_CL, "cl" }, | 
| 350 |  |   2,  // { X86_REG_CS, "cs" }, | 
| 351 |  |   2,  // { X86_REG_CX, "cx" }, | 
| 352 |  |   1,  // { X86_REG_DH, "dh" }, | 
| 353 |  |   2,  // { X86_REG_DI, "di" }, | 
| 354 |  |   1,  // { X86_REG_DIL, "dil" }, | 
| 355 |  |   1,  // { X86_REG_DL, "dl" }, | 
| 356 |  |   2,  // { X86_REG_DS, "ds" }, | 
| 357 |  |   2,  // { X86_REG_DX, "dx" }, | 
| 358 |  |   4,  // { X86_REG_EAX, "eax" }, | 
| 359 |  |   4,  // { X86_REG_EBP, "ebp" }, | 
| 360 |  |   4,  // { X86_REG_EBX, "ebx" }, | 
| 361 |  |   4,  // { X86_REG_ECX, "ecx" }, | 
| 362 |  |   4,  // { X86_REG_EDI, "edi" }, | 
| 363 |  |   4,  // { X86_REG_EDX, "edx" }, | 
| 364 |  |   4,  // { X86_REG_EFLAGS, "flags" }, | 
| 365 |  |   4,  // { X86_REG_EIP, "eip" }, | 
| 366 |  |   4,  // { X86_REG_EIZ, "eiz" }, | 
| 367 |  |   2,  // { X86_REG_ES, "es" }, | 
| 368 |  |   4,  // { X86_REG_ESI, "esi" }, | 
| 369 |  |   4,  // { X86_REG_ESP, "esp" }, | 
| 370 |  |   10, // { X86_REG_FPSW, "fpsw" }, | 
| 371 |  |   2,  // { X86_REG_FS, "fs" }, | 
| 372 |  |   2,  // { X86_REG_GS, "gs" }, | 
| 373 |  |   2,  // { X86_REG_IP, "ip" }, | 
| 374 |  |   8,  // { X86_REG_RAX, "rax" }, | 
| 375 |  |   8,  // { X86_REG_RBP, "rbp" }, | 
| 376 |  |   8,  // { X86_REG_RBX, "rbx" }, | 
| 377 |  |   8,  // { X86_REG_RCX, "rcx" }, | 
| 378 |  |   8,  // { X86_REG_RDI, "rdi" }, | 
| 379 |  |   8,  // { X86_REG_RDX, "rdx" }, | 
| 380 |  |   8,  // { X86_REG_RIP, "rip" }, | 
| 381 |  |   8,  // { X86_REG_RIZ, "riz" }, | 
| 382 |  |   8,  // { X86_REG_RSI, "rsi" }, | 
| 383 |  |   8,  // { X86_REG_RSP, "rsp" }, | 
| 384 |  |   2,  // { X86_REG_SI, "si" }, | 
| 385 |  |   1,  // { X86_REG_SIL, "sil" }, | 
| 386 |  |   2,  // { X86_REG_SP, "sp" }, | 
| 387 |  |   1,  // { X86_REG_SPL, "spl" }, | 
| 388 |  |   2,  // { X86_REG_SS, "ss" }, | 
| 389 |  |   4,  // { X86_REG_CR0, "cr0" }, | 
| 390 |  |   4,  // { X86_REG_CR1, "cr1" }, | 
| 391 |  |   4,  // { X86_REG_CR2, "cr2" }, | 
| 392 |  |   4,  // { X86_REG_CR3, "cr3" }, | 
| 393 |  |   4,  // { X86_REG_CR4, "cr4" }, | 
| 394 |  |   8,  // { X86_REG_CR5, "cr5" }, | 
| 395 |  |   8,  // { X86_REG_CR6, "cr6" }, | 
| 396 |  |   8,  // { X86_REG_CR7, "cr7" }, | 
| 397 |  |   8,  // { X86_REG_CR8, "cr8" }, | 
| 398 |  |   8,  // { X86_REG_CR9, "cr9" }, | 
| 399 |  |   8,  // { X86_REG_CR10, "cr10" }, | 
| 400 |  |   8,  // { X86_REG_CR11, "cr11" }, | 
| 401 |  |   8,  // { X86_REG_CR12, "cr12" }, | 
| 402 |  |   8,  // { X86_REG_CR13, "cr13" }, | 
| 403 |  |   8,  // { X86_REG_CR14, "cr14" }, | 
| 404 |  |   8,  // { X86_REG_CR15, "cr15" }, | 
| 405 |  |   4,  // { X86_REG_DR0, "dr0" }, | 
| 406 |  |   4,  // { X86_REG_DR1, "dr1" }, | 
| 407 |  |   4,  // { X86_REG_DR2, "dr2" }, | 
| 408 |  |   4,  // { X86_REG_DR3, "dr3" }, | 
| 409 |  |   4,  // { X86_REG_DR4, "dr4" }, | 
| 410 |  |   4,  // { X86_REG_DR5, "dr5" }, | 
| 411 |  |   4,  // { X86_REG_DR6, "dr6" }, | 
| 412 |  |   4,  // { X86_REG_DR7, "dr7" }, | 
| 413 |  |   4,  // { X86_REG_DR8, "dr8" }, | 
| 414 |  |   4,  // { X86_REG_DR9, "dr9" }, | 
| 415 |  |   4,  // { X86_REG_DR10, "dr10" }, | 
| 416 |  |   4,  // { X86_REG_DR11, "dr11" }, | 
| 417 |  |   4,  // { X86_REG_DR12, "dr12" }, | 
| 418 |  |   4,  // { X86_REG_DR13, "dr13" }, | 
| 419 |  |   4,  // { X86_REG_DR14, "dr14" }, | 
| 420 |  |   4,  // { X86_REG_DR15, "dr15" }, | 
| 421 |  |   10, // { X86_REG_FP0, "fp0" }, | 
| 422 |  |   10, // { X86_REG_FP1, "fp1" }, | 
| 423 |  |   10, // { X86_REG_FP2, "fp2" }, | 
| 424 |  |   10, // { X86_REG_FP3, "fp3" }, | 
| 425 |  |   10, // { X86_REG_FP4, "fp4" }, | 
| 426 |  |   10, // { X86_REG_FP5, "fp5" }, | 
| 427 |  |   10, // { X86_REG_FP6, "fp6" }, | 
| 428 |  |   10, // { X86_REG_FP7, "fp7" }, | 
| 429 |  |   2,  // { X86_REG_K0, "k0" }, | 
| 430 |  |   2,  // { X86_REG_K1, "k1" }, | 
| 431 |  |   2,  // { X86_REG_K2, "k2" }, | 
| 432 |  |   2,  // { X86_REG_K3, "k3" }, | 
| 433 |  |   2,  // { X86_REG_K4, "k4" }, | 
| 434 |  |   2,  // { X86_REG_K5, "k5" }, | 
| 435 |  |   2,  // { X86_REG_K6, "k6" }, | 
| 436 |  |   2,  // { X86_REG_K7, "k7" }, | 
| 437 |  |   8,  // { X86_REG_MM0, "mm0" }, | 
| 438 |  |   8,  // { X86_REG_MM1, "mm1" }, | 
| 439 |  |   8,  // { X86_REG_MM2, "mm2" }, | 
| 440 |  |   8,  // { X86_REG_MM3, "mm3" }, | 
| 441 |  |   8,  // { X86_REG_MM4, "mm4" }, | 
| 442 |  |   8,  // { X86_REG_MM5, "mm5" }, | 
| 443 |  |   8,  // { X86_REG_MM6, "mm6" }, | 
| 444 |  |   8,  // { X86_REG_MM7, "mm7" }, | 
| 445 |  |   8,  // { X86_REG_R8, "r8" }, | 
| 446 |  |   8,  // { X86_REG_R9, "r9" }, | 
| 447 |  |   8,  // { X86_REG_R10, "r10" }, | 
| 448 |  |   8,  // { X86_REG_R11, "r11" }, | 
| 449 |  |   8,  // { X86_REG_R12, "r12" }, | 
| 450 |  |   8,  // { X86_REG_R13, "r13" }, | 
| 451 |  |   8,  // { X86_REG_R14, "r14" }, | 
| 452 |  |   8,  // { X86_REG_R15, "r15" }, | 
| 453 |  |   10, // { X86_REG_ST0, "st0" }, | 
| 454 |  |   10, // { X86_REG_ST1, "st1" }, | 
| 455 |  |   10, // { X86_REG_ST2, "st2" }, | 
| 456 |  |   10, // { X86_REG_ST3, "st3" }, | 
| 457 |  |   10, // { X86_REG_ST4, "st4" }, | 
| 458 |  |   10, // { X86_REG_ST5, "st5" }, | 
| 459 |  |   10, // { X86_REG_ST6, "st6" }, | 
| 460 |  |   10, // { X86_REG_ST7, "st7" }, | 
| 461 |  |   16, // { X86_REG_XMM0, "xmm0" }, | 
| 462 |  |   16, // { X86_REG_XMM1, "xmm1" }, | 
| 463 |  |   16, // { X86_REG_XMM2, "xmm2" }, | 
| 464 |  |   16, // { X86_REG_XMM3, "xmm3" }, | 
| 465 |  |   16, // { X86_REG_XMM4, "xmm4" }, | 
| 466 |  |   16, // { X86_REG_XMM5, "xmm5" }, | 
| 467 |  |   16, // { X86_REG_XMM6, "xmm6" }, | 
| 468 |  |   16, // { X86_REG_XMM7, "xmm7" }, | 
| 469 |  |   16, // { X86_REG_XMM8, "xmm8" }, | 
| 470 |  |   16, // { X86_REG_XMM9, "xmm9" }, | 
| 471 |  |   16, // { X86_REG_XMM10, "xmm10" }, | 
| 472 |  |   16, // { X86_REG_XMM11, "xmm11" }, | 
| 473 |  |   16, // { X86_REG_XMM12, "xmm12" }, | 
| 474 |  |   16, // { X86_REG_XMM13, "xmm13" }, | 
| 475 |  |   16, // { X86_REG_XMM14, "xmm14" }, | 
| 476 |  |   16, // { X86_REG_XMM15, "xmm15" }, | 
| 477 |  |   16, // { X86_REG_XMM16, "xmm16" }, | 
| 478 |  |   16, // { X86_REG_XMM17, "xmm17" }, | 
| 479 |  |   16, // { X86_REG_XMM18, "xmm18" }, | 
| 480 |  |   16, // { X86_REG_XMM19, "xmm19" }, | 
| 481 |  |   16, // { X86_REG_XMM20, "xmm20" }, | 
| 482 |  |   16, // { X86_REG_XMM21, "xmm21" }, | 
| 483 |  |   16, // { X86_REG_XMM22, "xmm22" }, | 
| 484 |  |   16, // { X86_REG_XMM23, "xmm23" }, | 
| 485 |  |   16, // { X86_REG_XMM24, "xmm24" }, | 
| 486 |  |   16, // { X86_REG_XMM25, "xmm25" }, | 
| 487 |  |   16, // { X86_REG_XMM26, "xmm26" }, | 
| 488 |  |   16, // { X86_REG_XMM27, "xmm27" }, | 
| 489 |  |   16, // { X86_REG_XMM28, "xmm28" }, | 
| 490 |  |   16, // { X86_REG_XMM29, "xmm29" }, | 
| 491 |  |   16, // { X86_REG_XMM30, "xmm30" }, | 
| 492 |  |   16, // { X86_REG_XMM31, "xmm31" }, | 
| 493 |  |   32, // { X86_REG_YMM0, "ymm0" }, | 
| 494 |  |   32, // { X86_REG_YMM1, "ymm1" }, | 
| 495 |  |   32, // { X86_REG_YMM2, "ymm2" }, | 
| 496 |  |   32, // { X86_REG_YMM3, "ymm3" }, | 
| 497 |  |   32, // { X86_REG_YMM4, "ymm4" }, | 
| 498 |  |   32, // { X86_REG_YMM5, "ymm5" }, | 
| 499 |  |   32, // { X86_REG_YMM6, "ymm6" }, | 
| 500 |  |   32, // { X86_REG_YMM7, "ymm7" }, | 
| 501 |  |   32, // { X86_REG_YMM8, "ymm8" }, | 
| 502 |  |   32, // { X86_REG_YMM9, "ymm9" }, | 
| 503 |  |   32, // { X86_REG_YMM10, "ymm10" }, | 
| 504 |  |   32, // { X86_REG_YMM11, "ymm11" }, | 
| 505 |  |   32, // { X86_REG_YMM12, "ymm12" }, | 
| 506 |  |   32, // { X86_REG_YMM13, "ymm13" }, | 
| 507 |  |   32, // { X86_REG_YMM14, "ymm14" }, | 
| 508 |  |   32, // { X86_REG_YMM15, "ymm15" }, | 
| 509 |  |   32, // { X86_REG_YMM16, "ymm16" }, | 
| 510 |  |   32, // { X86_REG_YMM17, "ymm17" }, | 
| 511 |  |   32, // { X86_REG_YMM18, "ymm18" }, | 
| 512 |  |   32, // { X86_REG_YMM19, "ymm19" }, | 
| 513 |  |   32, // { X86_REG_YMM20, "ymm20" }, | 
| 514 |  |   32, // { X86_REG_YMM21, "ymm21" }, | 
| 515 |  |   32, // { X86_REG_YMM22, "ymm22" }, | 
| 516 |  |   32, // { X86_REG_YMM23, "ymm23" }, | 
| 517 |  |   32, // { X86_REG_YMM24, "ymm24" }, | 
| 518 |  |   32, // { X86_REG_YMM25, "ymm25" }, | 
| 519 |  |   32, // { X86_REG_YMM26, "ymm26" }, | 
| 520 |  |   32, // { X86_REG_YMM27, "ymm27" }, | 
| 521 |  |   32, // { X86_REG_YMM28, "ymm28" }, | 
| 522 |  |   32, // { X86_REG_YMM29, "ymm29" }, | 
| 523 |  |   32, // { X86_REG_YMM30, "ymm30" }, | 
| 524 |  |   32, // { X86_REG_YMM31, "ymm31" }, | 
| 525 |  |   64, // { X86_REG_ZMM0, "zmm0" }, | 
| 526 |  |   64, // { X86_REG_ZMM1, "zmm1" }, | 
| 527 |  |   64, // { X86_REG_ZMM2, "zmm2" }, | 
| 528 |  |   64, // { X86_REG_ZMM3, "zmm3" }, | 
| 529 |  |   64, // { X86_REG_ZMM4, "zmm4" }, | 
| 530 |  |   64, // { X86_REG_ZMM5, "zmm5" }, | 
| 531 |  |   64, // { X86_REG_ZMM6, "zmm6" }, | 
| 532 |  |   64, // { X86_REG_ZMM7, "zmm7" }, | 
| 533 |  |   64, // { X86_REG_ZMM8, "zmm8" }, | 
| 534 |  |   64, // { X86_REG_ZMM9, "zmm9" }, | 
| 535 |  |   64, // { X86_REG_ZMM10, "zmm10" }, | 
| 536 |  |   64, // { X86_REG_ZMM11, "zmm11" }, | 
| 537 |  |   64, // { X86_REG_ZMM12, "zmm12" }, | 
| 538 |  |   64, // { X86_REG_ZMM13, "zmm13" }, | 
| 539 |  |   64, // { X86_REG_ZMM14, "zmm14" }, | 
| 540 |  |   64, // { X86_REG_ZMM15, "zmm15" }, | 
| 541 |  |   64, // { X86_REG_ZMM16, "zmm16" }, | 
| 542 |  |   64, // { X86_REG_ZMM17, "zmm17" }, | 
| 543 |  |   64, // { X86_REG_ZMM18, "zmm18" }, | 
| 544 |  |   64, // { X86_REG_ZMM19, "zmm19" }, | 
| 545 |  |   64, // { X86_REG_ZMM20, "zmm20" }, | 
| 546 |  |   64, // { X86_REG_ZMM21, "zmm21" }, | 
| 547 |  |   64, // { X86_REG_ZMM22, "zmm22" }, | 
| 548 |  |   64, // { X86_REG_ZMM23, "zmm23" }, | 
| 549 |  |   64, // { X86_REG_ZMM24, "zmm24" }, | 
| 550 |  |   64, // { X86_REG_ZMM25, "zmm25" }, | 
| 551 |  |   64, // { X86_REG_ZMM26, "zmm26" }, | 
| 552 |  |   64, // { X86_REG_ZMM27, "zmm27" }, | 
| 553 |  |   64, // { X86_REG_ZMM28, "zmm28" }, | 
| 554 |  |   64, // { X86_REG_ZMM29, "zmm29" }, | 
| 555 |  |   64, // { X86_REG_ZMM30, "zmm30" }, | 
| 556 |  |   64, // { X86_REG_ZMM31, "zmm31" }, | 
| 557 |  |   1,  // { X86_REG_R8B, "r8b" }, | 
| 558 |  |   1,  // { X86_REG_R9B, "r9b" }, | 
| 559 |  |   1,  // { X86_REG_R10B, "r10b" }, | 
| 560 |  |   1,  // { X86_REG_R11B, "r11b" }, | 
| 561 |  |   1,  // { X86_REG_R12B, "r12b" }, | 
| 562 |  |   1,  // { X86_REG_R13B, "r13b" }, | 
| 563 |  |   1,  // { X86_REG_R14B, "r14b" }, | 
| 564 |  |   1,  // { X86_REG_R15B, "r15b" }, | 
| 565 |  |   4,  // { X86_REG_R8D, "r8d" }, | 
| 566 |  |   4,  // { X86_REG_R9D, "r9d" }, | 
| 567 |  |   4,  // { X86_REG_R10D, "r10d" }, | 
| 568 |  |   4,  // { X86_REG_R11D, "r11d" }, | 
| 569 |  |   4,  // { X86_REG_R12D, "r12d" }, | 
| 570 |  |   4,  // { X86_REG_R13D, "r13d" }, | 
| 571 |  |   4,  // { X86_REG_R14D, "r14d" }, | 
| 572 |  |   4,  // { X86_REG_R15D, "r15d" }, | 
| 573 |  |   2,  // { X86_REG_R8W, "r8w" }, | 
| 574 |  |   2,  // { X86_REG_R9W, "r9w" }, | 
| 575 |  |   2,  // { X86_REG_R10W, "r10w" }, | 
| 576 |  |   2,  // { X86_REG_R11W, "r11w" }, | 
| 577 |  |   2,  // { X86_REG_R12W, "r12w" }, | 
| 578 |  |   2,  // { X86_REG_R13W, "r13w" }, | 
| 579 |  |   2,  // { X86_REG_R14W, "r14w" }, | 
| 580 |  |   2,  // { X86_REG_R15W, "r15w" }, | 
| 581 |  |   16, // { X86_REG_BND0, "bnd0" }, | 
| 582 |  |   16, // { X86_REG_BND1, "bnd0" }, | 
| 583 |  |   16, // { X86_REG_BND2, "bnd0" }, | 
| 584 |  |   16, // { X86_REG_BND3, "bnd0" }, | 
| 585 |  | }; | 
| 586 |  |  | 
| 587 |  | // register size in 64bit mode | 
| 588 |  | const uint8_t regsize_map_64 [] = { | 
| 589 |  |   0,  //  { X86_REG_INVALID, NULL }, | 
| 590 |  |   1,  // { X86_REG_AH, "ah" }, | 
| 591 |  |   1,  // { X86_REG_AL, "al" }, | 
| 592 |  |   2,  // { X86_REG_AX, "ax" }, | 
| 593 |  |   1,  // { X86_REG_BH, "bh" }, | 
| 594 |  |   1,  // { X86_REG_BL, "bl" }, | 
| 595 |  |   2,  // { X86_REG_BP, "bp" }, | 
| 596 |  |   1,  // { X86_REG_BPL, "bpl" }, | 
| 597 |  |   2,  // { X86_REG_BX, "bx" }, | 
| 598 |  |   1,  // { X86_REG_CH, "ch" }, | 
| 599 |  |   1,  // { X86_REG_CL, "cl" }, | 
| 600 |  |   2,  // { X86_REG_CS, "cs" }, | 
| 601 |  |   2,  // { X86_REG_CX, "cx" }, | 
| 602 |  |   1,  // { X86_REG_DH, "dh" }, | 
| 603 |  |   2,  // { X86_REG_DI, "di" }, | 
| 604 |  |   1,  // { X86_REG_DIL, "dil" }, | 
| 605 |  |   1,  // { X86_REG_DL, "dl" }, | 
| 606 |  |   2,  // { X86_REG_DS, "ds" }, | 
| 607 |  |   2,  // { X86_REG_DX, "dx" }, | 
| 608 |  |   4,  // { X86_REG_EAX, "eax" }, | 
| 609 |  |   4,  // { X86_REG_EBP, "ebp" }, | 
| 610 |  |   4,  // { X86_REG_EBX, "ebx" }, | 
| 611 |  |   4,  // { X86_REG_ECX, "ecx" }, | 
| 612 |  |   4,  // { X86_REG_EDI, "edi" }, | 
| 613 |  |   4,  // { X86_REG_EDX, "edx" }, | 
| 614 |  |   8,  // { X86_REG_EFLAGS, "flags" }, | 
| 615 |  |   4,  // { X86_REG_EIP, "eip" }, | 
| 616 |  |   4,  // { X86_REG_EIZ, "eiz" }, | 
| 617 |  |   2,  // { X86_REG_ES, "es" }, | 
| 618 |  |   4,  // { X86_REG_ESI, "esi" }, | 
| 619 |  |   4,  // { X86_REG_ESP, "esp" }, | 
| 620 |  |   10, // { X86_REG_FPSW, "fpsw" }, | 
| 621 |  |   2,  // { X86_REG_FS, "fs" }, | 
| 622 |  |   2,  // { X86_REG_GS, "gs" }, | 
| 623 |  |   2,  // { X86_REG_IP, "ip" }, | 
| 624 |  |   8,  // { X86_REG_RAX, "rax" }, | 
| 625 |  |   8,  // { X86_REG_RBP, "rbp" }, | 
| 626 |  |   8,  // { X86_REG_RBX, "rbx" }, | 
| 627 |  |   8,  // { X86_REG_RCX, "rcx" }, | 
| 628 |  |   8,  // { X86_REG_RDI, "rdi" }, | 
| 629 |  |   8,  // { X86_REG_RDX, "rdx" }, | 
| 630 |  |   8,  // { X86_REG_RIP, "rip" }, | 
| 631 |  |   8,  // { X86_REG_RIZ, "riz" }, | 
| 632 |  |   8,  // { X86_REG_RSI, "rsi" }, | 
| 633 |  |   8,  // { X86_REG_RSP, "rsp" }, | 
| 634 |  |   2,  // { X86_REG_SI, "si" }, | 
| 635 |  |   1,  // { X86_REG_SIL, "sil" }, | 
| 636 |  |   2,  // { X86_REG_SP, "sp" }, | 
| 637 |  |   1,  // { X86_REG_SPL, "spl" }, | 
| 638 |  |   2,  // { X86_REG_SS, "ss" }, | 
| 639 |  |   8,  // { X86_REG_CR0, "cr0" }, | 
| 640 |  |   8,  // { X86_REG_CR1, "cr1" }, | 
| 641 |  |   8,  // { X86_REG_CR2, "cr2" }, | 
| 642 |  |   8,  // { X86_REG_CR3, "cr3" }, | 
| 643 |  |   8,  // { X86_REG_CR4, "cr4" }, | 
| 644 |  |   8,  // { X86_REG_CR5, "cr5" }, | 
| 645 |  |   8,  // { X86_REG_CR6, "cr6" }, | 
| 646 |  |   8,  // { X86_REG_CR7, "cr7" }, | 
| 647 |  |   8,  // { X86_REG_CR8, "cr8" }, | 
| 648 |  |   8,  // { X86_REG_CR9, "cr9" }, | 
| 649 |  |   8,  // { X86_REG_CR10, "cr10" }, | 
| 650 |  |   8,  // { X86_REG_CR11, "cr11" }, | 
| 651 |  |   8,  // { X86_REG_CR12, "cr12" }, | 
| 652 |  |   8,  // { X86_REG_CR13, "cr13" }, | 
| 653 |  |   8,  // { X86_REG_CR14, "cr14" }, | 
| 654 |  |   8,  // { X86_REG_CR15, "cr15" }, | 
| 655 |  |   8,  // { X86_REG_DR0, "dr0" }, | 
| 656 |  |   8,  // { X86_REG_DR1, "dr1" }, | 
| 657 |  |   8,  // { X86_REG_DR2, "dr2" }, | 
| 658 |  |   8,  // { X86_REG_DR3, "dr3" }, | 
| 659 |  |   8,  // { X86_REG_DR4, "dr4" }, | 
| 660 |  |   8,  // { X86_REG_DR5, "dr5" }, | 
| 661 |  |   8,  // { X86_REG_DR6, "dr6" }, | 
| 662 |  |   8,  // { X86_REG_DR7, "dr7" }, | 
| 663 |  |   8,  // { X86_REG_DR8, "dr8" }, | 
| 664 |  |   8,  // { X86_REG_DR9, "dr9" }, | 
| 665 |  |   8,  // { X86_REG_DR10, "dr10" }, | 
| 666 |  |   8,  // { X86_REG_DR11, "dr11" }, | 
| 667 |  |   8,  // { X86_REG_DR12, "dr12" }, | 
| 668 |  |   8,  // { X86_REG_DR13, "dr13" }, | 
| 669 |  |   8,  // { X86_REG_DR14, "dr14" }, | 
| 670 |  |   8,  // { X86_REG_DR15, "dr15" }, | 
| 671 |  |   10, // { X86_REG_FP0, "fp0" }, | 
| 672 |  |   10, // { X86_REG_FP1, "fp1" }, | 
| 673 |  |   10, // { X86_REG_FP2, "fp2" }, | 
| 674 |  |   10, // { X86_REG_FP3, "fp3" }, | 
| 675 |  |   10, // { X86_REG_FP4, "fp4" }, | 
| 676 |  |   10, // { X86_REG_FP5, "fp5" }, | 
| 677 |  |   10, // { X86_REG_FP6, "fp6" }, | 
| 678 |  |   10, // { X86_REG_FP7, "fp7" }, | 
| 679 |  |   2,  // { X86_REG_K0, "k0" }, | 
| 680 |  |   2,  // { X86_REG_K1, "k1" }, | 
| 681 |  |   2,  // { X86_REG_K2, "k2" }, | 
| 682 |  |   2,  // { X86_REG_K3, "k3" }, | 
| 683 |  |   2,  // { X86_REG_K4, "k4" }, | 
| 684 |  |   2,  // { X86_REG_K5, "k5" }, | 
| 685 |  |   2,  // { X86_REG_K6, "k6" }, | 
| 686 |  |   2,  // { X86_REG_K7, "k7" }, | 
| 687 |  |   8,  // { X86_REG_MM0, "mm0" }, | 
| 688 |  |   8,  // { X86_REG_MM1, "mm1" }, | 
| 689 |  |   8,  // { X86_REG_MM2, "mm2" }, | 
| 690 |  |   8,  // { X86_REG_MM3, "mm3" }, | 
| 691 |  |   8,  // { X86_REG_MM4, "mm4" }, | 
| 692 |  |   8,  // { X86_REG_MM5, "mm5" }, | 
| 693 |  |   8,  // { X86_REG_MM6, "mm6" }, | 
| 694 |  |   8,  // { X86_REG_MM7, "mm7" }, | 
| 695 |  |   8,  // { X86_REG_R8, "r8" }, | 
| 696 |  |   8,  // { X86_REG_R9, "r9" }, | 
| 697 |  |   8,  // { X86_REG_R10, "r10" }, | 
| 698 |  |   8,  // { X86_REG_R11, "r11" }, | 
| 699 |  |   8,  // { X86_REG_R12, "r12" }, | 
| 700 |  |   8,  // { X86_REG_R13, "r13" }, | 
| 701 |  |   8,  // { X86_REG_R14, "r14" }, | 
| 702 |  |   8,  // { X86_REG_R15, "r15" }, | 
| 703 |  |   10, // { X86_REG_ST0, "st0" }, | 
| 704 |  |   10, // { X86_REG_ST1, "st1" }, | 
| 705 |  |   10, // { X86_REG_ST2, "st2" }, | 
| 706 |  |   10, // { X86_REG_ST3, "st3" }, | 
| 707 |  |   10, // { X86_REG_ST4, "st4" }, | 
| 708 |  |   10, // { X86_REG_ST5, "st5" }, | 
| 709 |  |   10, // { X86_REG_ST6, "st6" }, | 
| 710 |  |   10, // { X86_REG_ST7, "st7" }, | 
| 711 |  |   16, // { X86_REG_XMM0, "xmm0" }, | 
| 712 |  |   16, // { X86_REG_XMM1, "xmm1" }, | 
| 713 |  |   16, // { X86_REG_XMM2, "xmm2" }, | 
| 714 |  |   16, // { X86_REG_XMM3, "xmm3" }, | 
| 715 |  |   16, // { X86_REG_XMM4, "xmm4" }, | 
| 716 |  |   16, // { X86_REG_XMM5, "xmm5" }, | 
| 717 |  |   16, // { X86_REG_XMM6, "xmm6" }, | 
| 718 |  |   16, // { X86_REG_XMM7, "xmm7" }, | 
| 719 |  |   16, // { X86_REG_XMM8, "xmm8" }, | 
| 720 |  |   16, // { X86_REG_XMM9, "xmm9" }, | 
| 721 |  |   16, // { X86_REG_XMM10, "xmm10" }, | 
| 722 |  |   16, // { X86_REG_XMM11, "xmm11" }, | 
| 723 |  |   16, // { X86_REG_XMM12, "xmm12" }, | 
| 724 |  |   16, // { X86_REG_XMM13, "xmm13" }, | 
| 725 |  |   16, // { X86_REG_XMM14, "xmm14" }, | 
| 726 |  |   16, // { X86_REG_XMM15, "xmm15" }, | 
| 727 |  |   16, // { X86_REG_XMM16, "xmm16" }, | 
| 728 |  |   16, // { X86_REG_XMM17, "xmm17" }, | 
| 729 |  |   16, // { X86_REG_XMM18, "xmm18" }, | 
| 730 |  |   16, // { X86_REG_XMM19, "xmm19" }, | 
| 731 |  |   16, // { X86_REG_XMM20, "xmm20" }, | 
| 732 |  |   16, // { X86_REG_XMM21, "xmm21" }, | 
| 733 |  |   16, // { X86_REG_XMM22, "xmm22" }, | 
| 734 |  |   16, // { X86_REG_XMM23, "xmm23" }, | 
| 735 |  |   16, // { X86_REG_XMM24, "xmm24" }, | 
| 736 |  |   16, // { X86_REG_XMM25, "xmm25" }, | 
| 737 |  |   16, // { X86_REG_XMM26, "xmm26" }, | 
| 738 |  |   16, // { X86_REG_XMM27, "xmm27" }, | 
| 739 |  |   16, // { X86_REG_XMM28, "xmm28" }, | 
| 740 |  |   16, // { X86_REG_XMM29, "xmm29" }, | 
| 741 |  |   16, // { X86_REG_XMM30, "xmm30" }, | 
| 742 |  |   16, // { X86_REG_XMM31, "xmm31" }, | 
| 743 |  |   32, // { X86_REG_YMM0, "ymm0" }, | 
| 744 |  |   32, // { X86_REG_YMM1, "ymm1" }, | 
| 745 |  |   32, // { X86_REG_YMM2, "ymm2" }, | 
| 746 |  |   32, // { X86_REG_YMM3, "ymm3" }, | 
| 747 |  |   32, // { X86_REG_YMM4, "ymm4" }, | 
| 748 |  |   32, // { X86_REG_YMM5, "ymm5" }, | 
| 749 |  |   32, // { X86_REG_YMM6, "ymm6" }, | 
| 750 |  |   32, // { X86_REG_YMM7, "ymm7" }, | 
| 751 |  |   32, // { X86_REG_YMM8, "ymm8" }, | 
| 752 |  |   32, // { X86_REG_YMM9, "ymm9" }, | 
| 753 |  |   32, // { X86_REG_YMM10, "ymm10" }, | 
| 754 |  |   32, // { X86_REG_YMM11, "ymm11" }, | 
| 755 |  |   32, // { X86_REG_YMM12, "ymm12" }, | 
| 756 |  |   32, // { X86_REG_YMM13, "ymm13" }, | 
| 757 |  |   32, // { X86_REG_YMM14, "ymm14" }, | 
| 758 |  |   32, // { X86_REG_YMM15, "ymm15" }, | 
| 759 |  |   32, // { X86_REG_YMM16, "ymm16" }, | 
| 760 |  |   32, // { X86_REG_YMM17, "ymm17" }, | 
| 761 |  |   32, // { X86_REG_YMM18, "ymm18" }, | 
| 762 |  |   32, // { X86_REG_YMM19, "ymm19" }, | 
| 763 |  |   32, // { X86_REG_YMM20, "ymm20" }, | 
| 764 |  |   32, // { X86_REG_YMM21, "ymm21" }, | 
| 765 |  |   32, // { X86_REG_YMM22, "ymm22" }, | 
| 766 |  |   32, // { X86_REG_YMM23, "ymm23" }, | 
| 767 |  |   32, // { X86_REG_YMM24, "ymm24" }, | 
| 768 |  |   32, // { X86_REG_YMM25, "ymm25" }, | 
| 769 |  |   32, // { X86_REG_YMM26, "ymm26" }, | 
| 770 |  |   32, // { X86_REG_YMM27, "ymm27" }, | 
| 771 |  |   32, // { X86_REG_YMM28, "ymm28" }, | 
| 772 |  |   32, // { X86_REG_YMM29, "ymm29" }, | 
| 773 |  |   32, // { X86_REG_YMM30, "ymm30" }, | 
| 774 |  |   32, // { X86_REG_YMM31, "ymm31" }, | 
| 775 |  |   64, // { X86_REG_ZMM0, "zmm0" }, | 
| 776 |  |   64, // { X86_REG_ZMM1, "zmm1" }, | 
| 777 |  |   64, // { X86_REG_ZMM2, "zmm2" }, | 
| 778 |  |   64, // { X86_REG_ZMM3, "zmm3" }, | 
| 779 |  |   64, // { X86_REG_ZMM4, "zmm4" }, | 
| 780 |  |   64, // { X86_REG_ZMM5, "zmm5" }, | 
| 781 |  |   64, // { X86_REG_ZMM6, "zmm6" }, | 
| 782 |  |   64, // { X86_REG_ZMM7, "zmm7" }, | 
| 783 |  |   64, // { X86_REG_ZMM8, "zmm8" }, | 
| 784 |  |   64, // { X86_REG_ZMM9, "zmm9" }, | 
| 785 |  |   64, // { X86_REG_ZMM10, "zmm10" }, | 
| 786 |  |   64, // { X86_REG_ZMM11, "zmm11" }, | 
| 787 |  |   64, // { X86_REG_ZMM12, "zmm12" }, | 
| 788 |  |   64, // { X86_REG_ZMM13, "zmm13" }, | 
| 789 |  |   64, // { X86_REG_ZMM14, "zmm14" }, | 
| 790 |  |   64, // { X86_REG_ZMM15, "zmm15" }, | 
| 791 |  |   64, // { X86_REG_ZMM16, "zmm16" }, | 
| 792 |  |   64, // { X86_REG_ZMM17, "zmm17" }, | 
| 793 |  |   64, // { X86_REG_ZMM18, "zmm18" }, | 
| 794 |  |   64, // { X86_REG_ZMM19, "zmm19" }, | 
| 795 |  |   64, // { X86_REG_ZMM20, "zmm20" }, | 
| 796 |  |   64, // { X86_REG_ZMM21, "zmm21" }, | 
| 797 |  |   64, // { X86_REG_ZMM22, "zmm22" }, | 
| 798 |  |   64, // { X86_REG_ZMM23, "zmm23" }, | 
| 799 |  |   64, // { X86_REG_ZMM24, "zmm24" }, | 
| 800 |  |   64, // { X86_REG_ZMM25, "zmm25" }, | 
| 801 |  |   64, // { X86_REG_ZMM26, "zmm26" }, | 
| 802 |  |   64, // { X86_REG_ZMM27, "zmm27" }, | 
| 803 |  |   64, // { X86_REG_ZMM28, "zmm28" }, | 
| 804 |  |   64, // { X86_REG_ZMM29, "zmm29" }, | 
| 805 |  |   64, // { X86_REG_ZMM30, "zmm30" }, | 
| 806 |  |   64, // { X86_REG_ZMM31, "zmm31" }, | 
| 807 |  |   1,  // { X86_REG_R8B, "r8b" }, | 
| 808 |  |   1,  // { X86_REG_R9B, "r9b" }, | 
| 809 |  |   1,  // { X86_REG_R10B, "r10b" }, | 
| 810 |  |   1,  // { X86_REG_R11B, "r11b" }, | 
| 811 |  |   1,  // { X86_REG_R12B, "r12b" }, | 
| 812 |  |   1,  // { X86_REG_R13B, "r13b" }, | 
| 813 |  |   1,  // { X86_REG_R14B, "r14b" }, | 
| 814 |  |   1,  // { X86_REG_R15B, "r15b" }, | 
| 815 |  |   4,  // { X86_REG_R8D, "r8d" }, | 
| 816 |  |   4,  // { X86_REG_R9D, "r9d" }, | 
| 817 |  |   4,  // { X86_REG_R10D, "r10d" }, | 
| 818 |  |   4,  // { X86_REG_R11D, "r11d" }, | 
| 819 |  |   4,  // { X86_REG_R12D, "r12d" }, | 
| 820 |  |   4,  // { X86_REG_R13D, "r13d" }, | 
| 821 |  |   4,  // { X86_REG_R14D, "r14d" }, | 
| 822 |  |   4,  // { X86_REG_R15D, "r15d" }, | 
| 823 |  |   2,  // { X86_REG_R8W, "r8w" }, | 
| 824 |  |   2,  // { X86_REG_R9W, "r9w" }, | 
| 825 |  |   2,  // { X86_REG_R10W, "r10w" }, | 
| 826 |  |   2,  // { X86_REG_R11W, "r11w" }, | 
| 827 |  |   2,  // { X86_REG_R12W, "r12w" }, | 
| 828 |  |   2,  // { X86_REG_R13W, "r13w" }, | 
| 829 |  |   2,  // { X86_REG_R14W, "r14w" }, | 
| 830 |  |   2,  // { X86_REG_R15W, "r15w" }, | 
| 831 |  |   16, // { X86_REG_BND0, "bnd0" }, | 
| 832 |  |   16, // { X86_REG_BND1, "bnd0" }, | 
| 833 |  |   16, // { X86_REG_BND2, "bnd0" }, | 
| 834 |  |   16, // { X86_REG_BND3, "bnd0" }, | 
| 835 |  | }; | 
| 836 |  |  | 
| 837 |  | const char *X86_reg_name(csh handle, unsigned int reg) | 
| 838 | 463k | { | 
| 839 | 463k | #ifndef CAPSTONE_DIET | 
| 840 | 463k |   cs_struct *ud = (cs_struct *)handle; | 
| 841 |  |  | 
| 842 | 463k |   if (reg >= ARR_SIZE(reg_name_maps)) | 
| 843 | 0 |     return NULL; | 
| 844 |  |  | 
| 845 | 463k |   if (reg == X86_REG_EFLAGS) { | 
| 846 | 240k |     if (ud->mode & CS_MODE_32) | 
| 847 | 75.0k |       return "eflags"; | 
| 848 | 165k |     if (ud->mode & CS_MODE_64) | 
| 849 | 76.9k |       return "rflags"; | 
| 850 | 165k |   } | 
| 851 |  |  | 
| 852 | 311k |   return reg_name_maps[reg].name; | 
| 853 |  | #else | 
| 854 |  |   return NULL; | 
| 855 |  | #endif | 
| 856 | 463k | } | 
| 857 |  |  | 
| 858 |  | #ifndef CAPSTONE_DIET | 
| 859 |  | static const char * const insn_name_maps[] = { | 
| 860 |  |   NULL, // X86_INS_INVALID | 
| 861 |  | #ifndef CAPSTONE_X86_REDUCE | 
| 862 |  | #include "X86MappingInsnName.inc" | 
| 863 |  | #else | 
| 864 |  | #include "X86MappingInsnName_reduce.inc" | 
| 865 |  | #endif | 
| 866 |  | }; | 
| 867 |  | #endif | 
| 868 |  |  | 
| 869 |  | // NOTE: insn_name_maps[] is sorted in order | 
| 870 |  | const char *X86_insn_name(csh handle, unsigned int id) | 
| 871 | 354k | { | 
| 872 | 354k | #ifndef CAPSTONE_DIET | 
| 873 | 354k |   if (id >= ARR_SIZE(insn_name_maps)) | 
| 874 | 0 |     return NULL; | 
| 875 |  |  | 
| 876 | 354k |   return insn_name_maps[id]; | 
| 877 |  | #else | 
| 878 |  |   return NULL; | 
| 879 |  | #endif | 
| 880 | 354k | } | 
| 881 |  |  | 
| 882 |  | #ifndef CAPSTONE_DIET | 
| 883 |  | static const name_map group_name_maps[] = { | 
| 884 |  |   // generic groups | 
| 885 |  |   { X86_GRP_INVALID, NULL }, | 
| 886 |  |   { X86_GRP_JUMP, "jump" }, | 
| 887 |  |   { X86_GRP_CALL, "call" }, | 
| 888 |  |   { X86_GRP_RET, "ret" }, | 
| 889 |  |   { X86_GRP_INT, "int" }, | 
| 890 |  |   { X86_GRP_IRET, "iret" }, | 
| 891 |  |   { X86_GRP_PRIVILEGE, "privilege" }, | 
| 892 |  |   { X86_GRP_BRANCH_RELATIVE, "branch_relative" }, | 
| 893 |  |  | 
| 894 |  |   // architecture-specific groups | 
| 895 |  |   { X86_GRP_VM, "vm" }, | 
| 896 |  |   { X86_GRP_3DNOW, "3dnow" }, | 
| 897 |  |   { X86_GRP_AES, "aes" }, | 
| 898 |  |   { X86_GRP_ADX, "adx" }, | 
| 899 |  |   { X86_GRP_AVX, "avx" }, | 
| 900 |  |   { X86_GRP_AVX2, "avx2" }, | 
| 901 |  |   { X86_GRP_AVX512, "avx512" }, | 
| 902 |  |   { X86_GRP_BMI, "bmi" }, | 
| 903 |  |   { X86_GRP_BMI2, "bmi2" }, | 
| 904 |  |   { X86_GRP_CMOV, "cmov" }, | 
| 905 |  |   { X86_GRP_F16C, "fc16" }, | 
| 906 |  |   { X86_GRP_FMA, "fma" }, | 
| 907 |  |   { X86_GRP_FMA4, "fma4" }, | 
| 908 |  |   { X86_GRP_FSGSBASE, "fsgsbase" }, | 
| 909 |  |   { X86_GRP_HLE, "hle" }, | 
| 910 |  |   { X86_GRP_MMX, "mmx" }, | 
| 911 |  |   { X86_GRP_MODE32, "mode32" }, | 
| 912 |  |   { X86_GRP_MODE64, "mode64" }, | 
| 913 |  |   { X86_GRP_RTM, "rtm" }, | 
| 914 |  |   { X86_GRP_SHA, "sha" }, | 
| 915 |  |   { X86_GRP_SSE1, "sse1" }, | 
| 916 |  |   { X86_GRP_SSE2, "sse2" }, | 
| 917 |  |   { X86_GRP_SSE3, "sse3" }, | 
| 918 |  |   { X86_GRP_SSE41, "sse41" }, | 
| 919 |  |   { X86_GRP_SSE42, "sse42" }, | 
| 920 |  |   { X86_GRP_SSE4A, "sse4a" }, | 
| 921 |  |   { X86_GRP_SSSE3, "ssse3" }, | 
| 922 |  |   { X86_GRP_PCLMUL, "pclmul" }, | 
| 923 |  |   { X86_GRP_XOP, "xop" }, | 
| 924 |  |   { X86_GRP_CDI, "cdi" }, | 
| 925 |  |   { X86_GRP_ERI, "eri" }, | 
| 926 |  |   { X86_GRP_TBM, "tbm" }, | 
| 927 |  |   { X86_GRP_16BITMODE, "16bitmode" }, | 
| 928 |  |   { X86_GRP_NOT64BITMODE, "not64bitmode" }, | 
| 929 |  |   { X86_GRP_SGX,  "sgx" }, | 
| 930 |  |   { X86_GRP_DQI,  "dqi" }, | 
| 931 |  |   { X86_GRP_BWI,  "bwi" }, | 
| 932 |  |   { X86_GRP_PFI,  "pfi" }, | 
| 933 |  |   { X86_GRP_VLX,  "vlx" }, | 
| 934 |  |   { X86_GRP_SMAP, "smap" }, | 
| 935 |  |   { X86_GRP_NOVLX, "novlx" }, | 
| 936 |  |   { X86_GRP_FPU, "fpu" }, | 
| 937 |  | }; | 
| 938 |  | #endif | 
| 939 |  |  | 
| 940 |  | const char *X86_group_name(csh handle, unsigned int id) | 
| 941 | 149k | { | 
| 942 | 149k | #ifndef CAPSTONE_DIET | 
| 943 | 149k |   return id2name(group_name_maps, ARR_SIZE(group_name_maps), id); | 
| 944 |  | #else | 
| 945 |  |   return NULL; | 
| 946 |  | #endif | 
| 947 | 149k | } | 
| 948 |  |  | 
| 949 |  | #define GET_INSTRINFO_ENUM | 
| 950 |  | #ifdef CAPSTONE_X86_REDUCE | 
| 951 |  | #include "X86GenInstrInfo_reduce.inc" | 
| 952 |  |  | 
| 953 |  | const insn_map_x86 insns[] = {  // reduce x86 instructions | 
| 954 |  | #include "X86MappingInsn_reduce.inc" | 
| 955 |  | }; | 
| 956 |  | #else | 
| 957 |  | #include "X86GenInstrInfo.inc" | 
| 958 |  |  | 
| 959 |  | const insn_map_x86 insns[] = {  // full x86 instructions | 
| 960 |  | #include "X86MappingInsn.inc" | 
| 961 |  | }; | 
| 962 |  | #endif | 
| 963 |  |  | 
| 964 |  | #ifndef CAPSTONE_DIET | 
| 965 |  | // in arr, replace r1 = r2 | 
| 966 |  | static void arr_replace(uint16_t *arr, uint8_t max, x86_reg r1, x86_reg r2) | 
| 967 | 43.5k | { | 
| 968 | 43.5k |   uint8_t i; | 
| 969 |  |  | 
| 970 | 65.5k |   for(i = 0; i < max; i++) { | 
| 971 | 63.6k |     if (arr[i] == r1) { | 
| 972 | 41.6k |       arr[i] = r2; | 
| 973 | 41.6k |       break; | 
| 974 | 41.6k |     } | 
| 975 | 63.6k |   } | 
| 976 | 43.5k | } | 
| 977 |  | #endif | 
| 978 |  |  | 
| 979 |  | // look for @id in @insns | 
| 980 |  | // return -1 if not found | 
| 981 |  | unsigned int find_insn(unsigned int id) | 
| 982 | 1.23M | { | 
| 983 |  |   // binary searching since the IDs are sorted in order | 
| 984 | 1.23M |   unsigned int left, right, m; | 
| 985 | 1.23M |   unsigned int max = ARR_SIZE(insns); | 
| 986 |  |  | 
| 987 | 1.23M |   right = max - 1; | 
| 988 |  |  | 
| 989 | 1.23M |   if (id < insns[0].id || id > insns[right].id) | 
| 990 |  |     // not found | 
| 991 | 37 |     return -1; | 
| 992 |  |  | 
| 993 | 1.23M |   left = 0; | 
| 994 |  |  | 
| 995 | 16.1M |   while(left <= right) { | 
| 996 | 16.1M |     m = (left + right) / 2; | 
| 997 | 16.1M |     if (id == insns[m].id) { | 
| 998 | 1.23M |       return m; | 
| 999 | 1.23M |     } | 
| 1000 |  |  | 
| 1001 | 14.9M |     if (id < insns[m].id) | 
| 1002 | 8.98M |       right = m - 1; | 
| 1003 | 5.94M |     else | 
| 1004 | 5.94M |       left = m + 1; | 
| 1005 | 14.9M |   } | 
| 1006 |  |  | 
| 1007 |  |   // not found | 
| 1008 |  |   // printf("NOT FOUNDDDDDDDDDDDDDDD id = %u\n", id); | 
| 1009 | 0 |   return -1; | 
| 1010 | 1.23M | } | 
| 1011 |  |  | 
| 1012 |  | // given internal insn id, return public instruction info | 
| 1013 |  | void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id) | 
| 1014 | 354k | { | 
| 1015 | 354k |   unsigned int i = find_insn(id); | 
| 1016 | 354k |   if (i != -1) { | 
| 1017 | 354k |     insn->id = insns[i].mapid; | 
| 1018 |  |  | 
| 1019 | 354k |     if (h->detail) { | 
| 1020 | 354k | #ifndef CAPSTONE_DIET | 
| 1021 | 354k |       memcpy(insn->detail->regs_read, insns[i].regs_use, sizeof(insns[i].regs_use)); | 
| 1022 | 354k |       insn->detail->regs_read_count = (uint8_t)count_positive(insns[i].regs_use); | 
| 1023 |  |  | 
| 1024 |  |       // special cases when regs_write[] depends on arch | 
| 1025 | 354k |       switch(id) { | 
| 1026 | 354k |         default: | 
| 1027 | 354k |           memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod)); | 
| 1028 | 354k |           insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod); | 
| 1029 | 354k |           break; | 
| 1030 | 30 |         case X86_RDTSC: | 
| 1031 | 30 |           if (h->mode == CS_MODE_64) { | 
| 1032 | 6 |             memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod)); | 
| 1033 | 6 |             insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod); | 
| 1034 | 24 |           } else { | 
| 1035 | 24 |             insn->detail->regs_write[0] = X86_REG_EAX; | 
| 1036 | 24 |             insn->detail->regs_write[1] = X86_REG_EDX; | 
| 1037 | 24 |             insn->detail->regs_write_count = 2; | 
| 1038 | 24 |           } | 
| 1039 | 30 |           break; | 
| 1040 | 120 |         case X86_RDTSCP: | 
| 1041 | 120 |           if (h->mode == CS_MODE_64) { | 
| 1042 | 82 |             memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod)); | 
| 1043 | 82 |             insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod); | 
| 1044 | 82 |           } else { | 
| 1045 | 38 |             insn->detail->regs_write[0] = X86_REG_EAX; | 
| 1046 | 38 |             insn->detail->regs_write[1] = X86_REG_ECX; | 
| 1047 | 38 |             insn->detail->regs_write[2] = X86_REG_EDX; | 
| 1048 | 38 |             insn->detail->regs_write_count = 3; | 
| 1049 | 38 |           } | 
| 1050 | 120 |           break; | 
| 1051 | 354k |       } | 
| 1052 |  |  | 
| 1053 | 354k |       switch(insn->id) { | 
| 1054 | 323k |         default: | 
| 1055 | 323k |           break; | 
| 1056 |  |  | 
| 1057 | 323k |         case X86_INS_LOOP: | 
| 1058 | 2.53k |         case X86_INS_LOOPE: | 
| 1059 | 3.08k |         case X86_INS_LOOPNE: | 
| 1060 | 3.08k |           switch(h->mode) { | 
| 1061 | 0 |             default: break; | 
| 1062 | 1.45k |             case CS_MODE_16: | 
| 1063 | 1.45k |                  insn->detail->regs_read[0] = X86_REG_CX; | 
| 1064 | 1.45k |                  insn->detail->regs_read_count = 1; | 
| 1065 | 1.45k |                  insn->detail->regs_write[0] = X86_REG_CX; | 
| 1066 | 1.45k |                  insn->detail->regs_write_count = 1; | 
| 1067 | 1.45k |                  break; | 
| 1068 | 654 |             case CS_MODE_32: | 
| 1069 | 654 |                  insn->detail->regs_read[0] = X86_REG_ECX; | 
| 1070 | 654 |                  insn->detail->regs_read_count = 1; | 
| 1071 | 654 |                  insn->detail->regs_write[0] = X86_REG_ECX; | 
| 1072 | 654 |                  insn->detail->regs_write_count = 1; | 
| 1073 | 654 |                  break; | 
| 1074 | 981 |             case CS_MODE_64: | 
| 1075 | 981 |                  insn->detail->regs_read[0] = X86_REG_RCX; | 
| 1076 | 981 |                  insn->detail->regs_read_count = 1; | 
| 1077 | 981 |                  insn->detail->regs_write[0] = X86_REG_RCX; | 
| 1078 | 981 |                  insn->detail->regs_write_count = 1; | 
| 1079 | 981 |                  break; | 
| 1080 | 3.08k |           } | 
| 1081 |  |  | 
| 1082 |  |           // LOOPE & LOOPNE also read EFLAGS | 
| 1083 | 3.08k |           if (insn->id != X86_INS_LOOP) { | 
| 1084 | 1.62k |             insn->detail->regs_read[1] = X86_REG_EFLAGS; | 
| 1085 | 1.62k |             insn->detail->regs_read_count = 2; | 
| 1086 | 1.62k |           } | 
| 1087 |  |  | 
| 1088 | 3.08k |           break; | 
| 1089 |  |  | 
| 1090 | 1.32k |         case X86_INS_LODSB: | 
| 1091 | 2.50k |         case X86_INS_LODSD: | 
| 1092 | 3.71k |         case X86_INS_LODSQ: | 
| 1093 | 4.72k |         case X86_INS_LODSW: | 
| 1094 | 4.72k |           switch(h->mode) { | 
| 1095 | 698 |             default: | 
| 1096 | 698 |               break; | 
| 1097 | 1.67k |             case CS_MODE_16: | 
| 1098 | 1.67k |               arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_ESI, X86_REG_SI); | 
| 1099 | 1.67k |               arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_ESI, X86_REG_SI); | 
| 1100 | 1.67k |               break; | 
| 1101 | 2.35k |             case CS_MODE_64: | 
| 1102 | 2.35k |               arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_ESI, X86_REG_RSI); | 
| 1103 | 2.35k |               arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_ESI, X86_REG_RSI); | 
| 1104 | 2.35k |               break; | 
| 1105 | 4.72k |           } | 
| 1106 | 4.72k |           break; | 
| 1107 |  |  | 
| 1108 | 4.72k |         case X86_INS_SCASB: | 
| 1109 | 2.49k |         case X86_INS_SCASW: | 
| 1110 | 3.10k |         case X86_INS_SCASQ: | 
| 1111 | 5.76k |         case X86_INS_STOSB: | 
| 1112 | 7.25k |         case X86_INS_STOSD: | 
| 1113 | 7.44k |         case X86_INS_STOSQ: | 
| 1114 | 8.54k |         case X86_INS_STOSW: | 
| 1115 | 8.54k |           switch(h->mode) { | 
| 1116 | 2.74k |             default: | 
| 1117 | 2.74k |               break; | 
| 1118 | 3.01k |             case CS_MODE_16: | 
| 1119 | 3.01k |               arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_EDI, X86_REG_DI); | 
| 1120 | 3.01k |               arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_EDI, X86_REG_DI); | 
| 1121 | 3.01k |               break; | 
| 1122 | 2.78k |             case CS_MODE_64: | 
| 1123 | 2.78k |               arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_EDI, X86_REG_RDI); | 
| 1124 | 2.78k |               arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_EDI, X86_REG_RDI); | 
| 1125 | 2.78k |               break; | 
| 1126 | 8.54k |           } | 
| 1127 | 8.54k |           break; | 
| 1128 |  |  | 
| 1129 | 8.54k |         case X86_INS_CMPSB: | 
| 1130 | 3.50k |         case X86_INS_CMPSD: | 
| 1131 | 3.79k |         case X86_INS_CMPSQ: | 
| 1132 | 4.98k |         case X86_INS_CMPSW: | 
| 1133 | 6.31k |         case X86_INS_MOVSB: | 
| 1134 | 7.20k |         case X86_INS_MOVSW: | 
| 1135 | 8.31k |         case X86_INS_MOVSD: | 
| 1136 | 8.41k |         case X86_INS_MOVSQ: | 
| 1137 | 8.41k |           switch(h->mode) { | 
| 1138 | 2.43k |             default: | 
| 1139 | 2.43k |               break; | 
| 1140 | 3.52k |             case CS_MODE_16: | 
| 1141 | 3.52k |               arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_EDI, X86_REG_DI); | 
| 1142 | 3.52k |               arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_EDI, X86_REG_DI); | 
| 1143 | 3.52k |               arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_ESI, X86_REG_SI); | 
| 1144 | 3.52k |               arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_ESI, X86_REG_SI); | 
| 1145 | 3.52k |               break; | 
| 1146 | 2.45k |             case CS_MODE_64: | 
| 1147 | 2.45k |               arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_EDI, X86_REG_RDI); | 
| 1148 | 2.45k |               arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_EDI, X86_REG_RDI); | 
| 1149 | 2.45k |               arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_ESI, X86_REG_RSI); | 
| 1150 | 2.45k |               arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_ESI, X86_REG_RSI); | 
| 1151 | 2.45k |               break; | 
| 1152 | 8.41k |           } | 
| 1153 | 8.41k |           break; | 
| 1154 |  |  | 
| 1155 | 8.41k |         case X86_INS_RET: | 
| 1156 | 6.32k |           switch(h->mode) { | 
| 1157 | 2.51k |             case CS_MODE_16: | 
| 1158 | 2.51k |               insn->detail->regs_write[0] = X86_REG_SP; | 
| 1159 | 2.51k |               insn->detail->regs_read[0] = X86_REG_SP; | 
| 1160 | 2.51k |               break; | 
| 1161 | 2.55k |             case CS_MODE_32: | 
| 1162 | 2.55k |               insn->detail->regs_write[0] = X86_REG_ESP; | 
| 1163 | 2.55k |               insn->detail->regs_read[0] = X86_REG_ESP; | 
| 1164 | 2.55k |               break; | 
| 1165 | 1.26k |             default:  // 64-bit | 
| 1166 | 1.26k |               insn->detail->regs_write[0] = X86_REG_RSP; | 
| 1167 | 1.26k |               insn->detail->regs_read[0] = X86_REG_RSP; | 
| 1168 | 1.26k |               break; | 
| 1169 | 6.32k |           } | 
| 1170 | 6.32k |           insn->detail->regs_write_count = 1; | 
| 1171 | 6.32k |           insn->detail->regs_read_count = 1; | 
| 1172 | 6.32k |           break; | 
| 1173 | 354k |       } | 
| 1174 |  |  | 
| 1175 | 354k |       memcpy(insn->detail->groups, insns[i].groups, sizeof(insns[i].groups)); | 
| 1176 | 354k |       insn->detail->groups_count = (uint8_t)count_positive8(insns[i].groups); | 
| 1177 |  |  | 
| 1178 | 354k |       if (insns[i].branch || insns[i].indirect_branch) { | 
| 1179 |  |         // this insn also belongs to JUMP group. add JUMP group | 
| 1180 | 22.1k |         insn->detail->groups[insn->detail->groups_count] = X86_GRP_JUMP; | 
| 1181 | 22.1k |         insn->detail->groups_count++; | 
| 1182 | 22.1k |       } | 
| 1183 |  |  | 
| 1184 | 354k |       switch (insns[i].id) { | 
| 1185 | 574 |         case X86_OUT8ir: | 
| 1186 | 930 |         case X86_OUT16ir: | 
| 1187 | 1.45k |         case X86_OUT32ir: | 
| 1188 | 1.45k |           if (insn->detail->x86.operands[0].imm == -78) { | 
| 1189 |  |             // Writing to port 0xb2 causes an SMI on most platforms | 
| 1190 |  |             // See: http://cs.gmu.edu/~tr-admin/papers/GMU-CS-TR-2011-8.pdf | 
| 1191 | 0 |             insn->detail->groups[insn->detail->groups_count] = X86_GRP_INT; | 
| 1192 | 0 |             insn->detail->groups_count++; | 
| 1193 | 0 |           } | 
| 1194 | 1.45k |           break; | 
| 1195 |  |  | 
| 1196 | 352k |         default: | 
| 1197 | 352k |           break; | 
| 1198 | 354k |       } | 
| 1199 | 354k | #endif | 
| 1200 | 354k |     } | 
| 1201 | 354k |   } | 
| 1202 | 354k | } | 
| 1203 |  |  | 
| 1204 |  | // map special instructions with accumulate registers. | 
| 1205 |  | // this is needed because LLVM embeds these register names into AsmStrs[], | 
| 1206 |  | // but not separately in operands | 
| 1207 |  | struct insn_reg { | 
| 1208 |  |   uint16_t insn; | 
| 1209 |  |   x86_reg reg; | 
| 1210 |  |   enum cs_ac_type access; | 
| 1211 |  | }; | 
| 1212 |  |  | 
| 1213 |  | struct insn_reg2 { | 
| 1214 |  |   uint16_t insn; | 
| 1215 |  |   x86_reg reg1, reg2; | 
| 1216 |  |   enum cs_ac_type access1, access2; | 
| 1217 |  | }; | 
| 1218 |  |  | 
| 1219 |  | static const struct insn_reg insn_regs_att[] = { | 
| 1220 |  |   { X86_INSB, X86_REG_DX, CS_AC_READ }, | 
| 1221 |  |   { X86_INSL, X86_REG_DX, CS_AC_READ }, | 
| 1222 |  |   { X86_INSW, X86_REG_DX, CS_AC_READ }, | 
| 1223 |  |   { X86_MOV16o16a, X86_REG_AX, CS_AC_READ }, | 
| 1224 |  |   { X86_MOV16o32a, X86_REG_AX, CS_AC_READ }, | 
| 1225 |  |   { X86_MOV16o64a, X86_REG_AX, CS_AC_READ }, | 
| 1226 |  |   { X86_MOV32o16a, X86_REG_EAX, CS_AC_READ }, | 
| 1227 |  |   { X86_MOV32o32a, X86_REG_EAX, CS_AC_READ }, | 
| 1228 |  |   { X86_MOV32o64a, X86_REG_EAX, CS_AC_READ }, | 
| 1229 |  |   { X86_MOV64o32a, X86_REG_RAX, CS_AC_READ }, | 
| 1230 |  |   { X86_MOV64o64a, X86_REG_RAX, CS_AC_READ }, | 
| 1231 |  |   { X86_MOV8o16a, X86_REG_AL, CS_AC_READ }, | 
| 1232 |  |   { X86_MOV8o32a, X86_REG_AL, CS_AC_READ }, | 
| 1233 |  |   { X86_MOV8o64a, X86_REG_AL, CS_AC_READ }, | 
| 1234 |  |   { X86_OUT16ir, X86_REG_AX, CS_AC_READ }, | 
| 1235 |  |   { X86_OUT32ir, X86_REG_EAX, CS_AC_READ }, | 
| 1236 |  |   { X86_OUT8ir, X86_REG_AL, CS_AC_READ }, | 
| 1237 |  |   { X86_POPDS16, X86_REG_DS, CS_AC_WRITE }, | 
| 1238 |  |   { X86_POPDS32, X86_REG_DS, CS_AC_WRITE }, | 
| 1239 |  |   { X86_POPES16, X86_REG_ES, CS_AC_WRITE }, | 
| 1240 |  |   { X86_POPES32, X86_REG_ES, CS_AC_WRITE }, | 
| 1241 |  |   { X86_POPFS16, X86_REG_FS, CS_AC_WRITE }, | 
| 1242 |  |   { X86_POPFS32, X86_REG_FS, CS_AC_WRITE }, | 
| 1243 |  |   { X86_POPFS64, X86_REG_FS, CS_AC_WRITE }, | 
| 1244 |  |   { X86_POPGS16, X86_REG_GS, CS_AC_WRITE }, | 
| 1245 |  |   { X86_POPGS32, X86_REG_GS, CS_AC_WRITE }, | 
| 1246 |  |   { X86_POPGS64, X86_REG_GS, CS_AC_WRITE }, | 
| 1247 |  |   { X86_POPSS16, X86_REG_SS, CS_AC_WRITE }, | 
| 1248 |  |   { X86_POPSS32, X86_REG_SS, CS_AC_WRITE }, | 
| 1249 |  |   { X86_PUSHCS16, X86_REG_CS, CS_AC_READ }, | 
| 1250 |  |   { X86_PUSHCS32, X86_REG_CS, CS_AC_READ }, | 
| 1251 |  |   { X86_PUSHDS16, X86_REG_DS, CS_AC_READ }, | 
| 1252 |  |   { X86_PUSHDS32, X86_REG_DS, CS_AC_READ }, | 
| 1253 |  |   { X86_PUSHES16, X86_REG_ES, CS_AC_READ }, | 
| 1254 |  |   { X86_PUSHES32, X86_REG_ES, CS_AC_READ }, | 
| 1255 |  |   { X86_PUSHFS16, X86_REG_FS, CS_AC_READ }, | 
| 1256 |  |   { X86_PUSHFS32, X86_REG_FS, CS_AC_READ }, | 
| 1257 |  |   { X86_PUSHFS64, X86_REG_FS, CS_AC_READ }, | 
| 1258 |  |   { X86_PUSHGS16, X86_REG_GS, CS_AC_READ }, | 
| 1259 |  |   { X86_PUSHGS32, X86_REG_GS, CS_AC_READ }, | 
| 1260 |  |   { X86_PUSHGS64, X86_REG_GS, CS_AC_READ }, | 
| 1261 |  |   { X86_PUSHSS16, X86_REG_SS, CS_AC_READ }, | 
| 1262 |  |   { X86_PUSHSS32, X86_REG_SS, CS_AC_READ }, | 
| 1263 |  |   { X86_RCL16rCL, X86_REG_CL, CS_AC_READ }, | 
| 1264 |  |   { X86_RCL32rCL, X86_REG_CL, CS_AC_READ }, | 
| 1265 |  |   { X86_RCL64rCL, X86_REG_CL, CS_AC_READ }, | 
| 1266 |  |   { X86_RCL8rCL, X86_REG_CL, CS_AC_READ }, | 
| 1267 |  |   { X86_RCR16rCL, X86_REG_CL, CS_AC_READ }, | 
| 1268 |  |   { X86_RCR32rCL, X86_REG_CL, CS_AC_READ }, | 
| 1269 |  |   { X86_RCR64rCL, X86_REG_CL, CS_AC_READ }, | 
| 1270 |  |   { X86_RCR8rCL, X86_REG_CL, CS_AC_READ }, | 
| 1271 |  |   { X86_ROL16rCL, X86_REG_CL, CS_AC_READ }, | 
| 1272 |  |   { X86_ROL32rCL, X86_REG_CL, CS_AC_READ }, | 
| 1273 |  |   { X86_ROL64rCL, X86_REG_CL, CS_AC_READ }, | 
| 1274 |  |   { X86_ROL8rCL, X86_REG_CL, CS_AC_READ }, | 
| 1275 |  |   { X86_ROR16rCL, X86_REG_CL, CS_AC_READ }, | 
| 1276 |  |   { X86_ROR32rCL, X86_REG_CL, CS_AC_READ }, | 
| 1277 |  |   { X86_ROR64rCL, X86_REG_CL, CS_AC_READ }, | 
| 1278 |  |   { X86_ROR8rCL, X86_REG_CL, CS_AC_READ }, | 
| 1279 |  |   { X86_SAL16rCL, X86_REG_CL, CS_AC_READ }, | 
| 1280 |  |   { X86_SAL32rCL, X86_REG_CL, CS_AC_READ }, | 
| 1281 |  |   { X86_SAL64rCL, X86_REG_CL, CS_AC_READ }, | 
| 1282 |  |   { X86_SAL8rCL, X86_REG_CL, CS_AC_READ }, | 
| 1283 |  |   { X86_SAR16rCL, X86_REG_CL, CS_AC_READ }, | 
| 1284 |  |   { X86_SAR32rCL, X86_REG_CL, CS_AC_READ }, | 
| 1285 |  |   { X86_SAR64rCL, X86_REG_CL, CS_AC_READ }, | 
| 1286 |  |   { X86_SAR8rCL, X86_REG_CL, CS_AC_READ }, | 
| 1287 |  |   { X86_SHL16rCL, X86_REG_CL, CS_AC_READ }, | 
| 1288 |  |   { X86_SHL32rCL, X86_REG_CL, CS_AC_READ }, | 
| 1289 |  |   { X86_SHL64rCL, X86_REG_CL, CS_AC_READ }, | 
| 1290 |  |   { X86_SHL8rCL, X86_REG_CL, CS_AC_READ }, | 
| 1291 |  |   { X86_SHLD16mrCL, X86_REG_CL, CS_AC_READ }, | 
| 1292 |  |   { X86_SHLD16rrCL, X86_REG_CL, CS_AC_READ }, | 
| 1293 |  |   { X86_SHLD32mrCL, X86_REG_CL, CS_AC_READ }, | 
| 1294 |  |   { X86_SHLD32rrCL, X86_REG_CL, CS_AC_READ }, | 
| 1295 |  |   { X86_SHLD64mrCL, X86_REG_CL, CS_AC_READ }, | 
| 1296 |  |   { X86_SHLD64rrCL, X86_REG_CL, CS_AC_READ }, | 
| 1297 |  |   { X86_SHR16rCL, X86_REG_CL, CS_AC_READ }, | 
| 1298 |  |   { X86_SHR32rCL, X86_REG_CL, CS_AC_READ }, | 
| 1299 |  |   { X86_SHR64rCL, X86_REG_CL, CS_AC_READ }, | 
| 1300 |  |   { X86_SHR8rCL, X86_REG_CL, CS_AC_READ }, | 
| 1301 |  |   { X86_SHRD16mrCL, X86_REG_CL, CS_AC_READ }, | 
| 1302 |  |   { X86_SHRD16rrCL, X86_REG_CL, CS_AC_READ }, | 
| 1303 |  |   { X86_SHRD32mrCL, X86_REG_CL, CS_AC_READ }, | 
| 1304 |  |   { X86_SHRD32rrCL, X86_REG_CL, CS_AC_READ }, | 
| 1305 |  |   { X86_SHRD64mrCL, X86_REG_CL, CS_AC_READ }, | 
| 1306 |  |   { X86_SHRD64rrCL, X86_REG_CL, CS_AC_READ }, | 
| 1307 |  |   { X86_XCHG16ar, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1308 |  |   { X86_XCHG32ar, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1309 |  |   { X86_XCHG64ar, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1310 |  | }; | 
| 1311 |  |  | 
| 1312 |  | static const struct insn_reg insn_regs_att_extra[] = { | 
| 1313 |  |   // dummy entry, to avoid empty array | 
| 1314 |  |   { 0, 0 }, | 
| 1315 |  | #ifndef CAPSTONE_X86_REDUCE | 
| 1316 |  |   { X86_ADD_FrST0, X86_REG_ST0, CS_AC_READ }, | 
| 1317 |  |   { X86_DIVR_FrST0, X86_REG_ST0, CS_AC_READ }, | 
| 1318 |  |   { X86_DIV_FrST0, X86_REG_ST0, CS_AC_READ }, | 
| 1319 |  |   { X86_FNSTSW16r, X86_REG_AX, CS_AC_READ }, | 
| 1320 |  |   { X86_MUL_FrST0, X86_REG_ST0, CS_AC_READ }, | 
| 1321 |  |   { X86_SKINIT, X86_REG_EAX, CS_AC_READ }, | 
| 1322 |  |   { X86_SUBR_FrST0, X86_REG_ST0, CS_AC_READ }, | 
| 1323 |  |   { X86_SUB_FrST0, X86_REG_ST0, CS_AC_READ }, | 
| 1324 |  |   { X86_VMLOAD32, X86_REG_EAX, CS_AC_READ }, | 
| 1325 |  |   { X86_VMLOAD64, X86_REG_RAX, CS_AC_READ }, | 
| 1326 |  |   { X86_VMRUN32, X86_REG_EAX, CS_AC_READ }, | 
| 1327 |  |   { X86_VMRUN64, X86_REG_RAX, CS_AC_READ }, | 
| 1328 |  |   { X86_VMSAVE32, X86_REG_EAX, CS_AC_READ }, | 
| 1329 |  |   { X86_VMSAVE64, X86_REG_RAX, CS_AC_READ }, | 
| 1330 |  | #endif | 
| 1331 |  | }; | 
| 1332 |  |  | 
| 1333 |  | static const struct insn_reg insn_regs_intel[] = { | 
| 1334 |  |   { X86_ADC16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1335 |  |   { X86_ADC32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1336 |  |   { X86_ADC64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1337 |  |   { X86_ADC8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1338 |  |   { X86_ADD16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1339 |  |   { X86_ADD32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1340 |  |   { X86_ADD64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1341 |  |   { X86_ADD8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1342 |  |   { X86_AND16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1343 |  |   { X86_AND32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1344 |  |   { X86_AND64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1345 |  |   { X86_AND8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1346 |  |   { X86_CMP16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1347 |  |   { X86_CMP32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1348 |  |   { X86_CMP64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1349 |  |   { X86_CMP8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1350 |  |   { X86_IN16ri, X86_REG_AX, CS_AC_WRITE }, | 
| 1351 |  |   { X86_IN32ri, X86_REG_EAX, CS_AC_WRITE }, | 
| 1352 |  |   { X86_IN8ri, X86_REG_AL, CS_AC_WRITE }, | 
| 1353 |  |   { X86_LODSB, X86_REG_AL, CS_AC_WRITE }, | 
| 1354 |  |   { X86_LODSL, X86_REG_EAX, CS_AC_WRITE }, | 
| 1355 |  |   { X86_LODSQ, X86_REG_RAX, CS_AC_WRITE }, | 
| 1356 |  |   { X86_LODSW, X86_REG_AX, CS_AC_WRITE }, | 
| 1357 |  |   { X86_MOV16ao16, X86_REG_AX, CS_AC_WRITE },    // 16-bit A1 1020                  // mov     ax, word ptr [0x2010] | 
| 1358 |  |   { X86_MOV16ao32, X86_REG_AX, CS_AC_WRITE },    // 32-bit A1 10203040              // mov     ax, word ptr [0x40302010] | 
| 1359 |  |   { X86_MOV16ao64, X86_REG_AX, CS_AC_WRITE },    // 64-bit 66 A1 1020304050607080   // movabs  ax, word ptr [0x8070605040302010] | 
| 1360 |  |   { X86_MOV32ao16, X86_REG_EAX, CS_AC_WRITE },   // 32-bit 67 A1 1020               // mov     eax, dword ptr [0x2010] | 
| 1361 |  |   { X86_MOV32ao32, X86_REG_EAX, CS_AC_WRITE },   // 32-bit A1 10203040              // mov     eax, dword ptr [0x40302010] | 
| 1362 |  |   { X86_MOV32ao64, X86_REG_EAX, CS_AC_WRITE },   // 64-bit A1 1020304050607080      // movabs  eax, dword ptr [0x8070605040302010] | 
| 1363 |  |   { X86_MOV64ao32, X86_REG_RAX, CS_AC_WRITE },   // 64-bit 48 8B04 10203040         // mov     rax, qword ptr [0x40302010] | 
| 1364 |  |   { X86_MOV64ao64, X86_REG_RAX, CS_AC_WRITE },   // 64-bit 48 A1 1020304050607080   // movabs  rax, qword ptr [0x8070605040302010] | 
| 1365 |  |   { X86_MOV8ao16, X86_REG_AL, CS_AC_WRITE },     // 16-bit A0 1020                  // mov     al, byte ptr [0x2010] | 
| 1366 |  |   { X86_MOV8ao32, X86_REG_AL, CS_AC_WRITE },     // 32-bit A0 10203040              // mov     al, byte ptr [0x40302010] | 
| 1367 |  |   { X86_MOV8ao64, X86_REG_AL, CS_AC_WRITE },     // 64-bit 66 A0 1020304050607080   // movabs  al, byte ptr [0x8070605040302010] | 
| 1368 |  |   { X86_OR16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1369 |  |   { X86_OR32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1370 |  |   { X86_OR64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1371 |  |   { X86_OR8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1372 |  |   { X86_OUTSB, X86_REG_DX, CS_AC_WRITE }, | 
| 1373 |  |   { X86_OUTSL, X86_REG_DX, CS_AC_WRITE }, | 
| 1374 |  |   { X86_OUTSW, X86_REG_DX, CS_AC_WRITE }, | 
| 1375 |  |   { X86_POPDS16, X86_REG_DS, CS_AC_WRITE }, | 
| 1376 |  |   { X86_POPDS32, X86_REG_DS, CS_AC_WRITE }, | 
| 1377 |  |   { X86_POPES16, X86_REG_ES, CS_AC_WRITE }, | 
| 1378 |  |   { X86_POPES32, X86_REG_ES, CS_AC_WRITE }, | 
| 1379 |  |   { X86_POPFS16, X86_REG_FS, CS_AC_WRITE }, | 
| 1380 |  |   { X86_POPFS32, X86_REG_FS, CS_AC_WRITE }, | 
| 1381 |  |   { X86_POPFS64, X86_REG_FS, CS_AC_WRITE }, | 
| 1382 |  |   { X86_POPGS16, X86_REG_GS, CS_AC_WRITE }, | 
| 1383 |  |   { X86_POPGS32, X86_REG_GS, CS_AC_WRITE }, | 
| 1384 |  |   { X86_POPGS64, X86_REG_GS, CS_AC_WRITE }, | 
| 1385 |  |   { X86_POPSS16, X86_REG_SS, CS_AC_WRITE }, | 
| 1386 |  |   { X86_POPSS32, X86_REG_SS, CS_AC_WRITE }, | 
| 1387 |  |   { X86_PUSHCS16, X86_REG_CS, CS_AC_READ }, | 
| 1388 |  |   { X86_PUSHCS32, X86_REG_CS, CS_AC_READ }, | 
| 1389 |  |   { X86_PUSHDS16, X86_REG_DS, CS_AC_READ }, | 
| 1390 |  |   { X86_PUSHDS32, X86_REG_DS, CS_AC_READ }, | 
| 1391 |  |   { X86_PUSHES16, X86_REG_ES, CS_AC_READ }, | 
| 1392 |  |   { X86_PUSHES32, X86_REG_ES, CS_AC_READ }, | 
| 1393 |  |   { X86_PUSHFS16, X86_REG_FS, CS_AC_READ }, | 
| 1394 |  |   { X86_PUSHFS32, X86_REG_FS, CS_AC_READ }, | 
| 1395 |  |   { X86_PUSHFS64, X86_REG_FS, CS_AC_READ }, | 
| 1396 |  |   { X86_PUSHGS16, X86_REG_GS, CS_AC_READ }, | 
| 1397 |  |   { X86_PUSHGS32, X86_REG_GS, CS_AC_READ }, | 
| 1398 |  |   { X86_PUSHGS64, X86_REG_GS, CS_AC_READ }, | 
| 1399 |  |   { X86_PUSHSS16, X86_REG_SS, CS_AC_READ }, | 
| 1400 |  |   { X86_PUSHSS32, X86_REG_SS, CS_AC_READ }, | 
| 1401 |  |   { X86_SBB16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1402 |  |   { X86_SBB32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1403 |  |   { X86_SBB64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1404 |  |   { X86_SBB8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1405 |  |   { X86_SCASB, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1406 |  |   { X86_SCASL, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1407 |  |   { X86_SCASQ, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1408 |  |   { X86_SCASW, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1409 |  |   { X86_SUB16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1410 |  |   { X86_SUB32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1411 |  |   { X86_SUB64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1412 |  |   { X86_SUB8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1413 |  |   { X86_TEST16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1414 |  |   { X86_TEST32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1415 |  |   { X86_TEST64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1416 |  |   { X86_TEST8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1417 |  |   { X86_XOR16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ }, | 
| 1418 |  |   { X86_XOR32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1419 |  |   { X86_XOR64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ }, | 
| 1420 |  |   { X86_XOR8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ }, | 
| 1421 |  | }; | 
| 1422 |  |  | 
| 1423 |  | static const struct insn_reg insn_regs_intel_extra[] = { | 
| 1424 |  |   // dummy entry, to avoid empty array | 
| 1425 |  |   { 0, 0, 0 }, | 
| 1426 |  | #ifndef CAPSTONE_X86_REDUCE | 
| 1427 |  |   { X86_CMOVBE_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1428 |  |   { X86_CMOVB_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1429 |  |   { X86_CMOVE_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1430 |  |   { X86_CMOVNBE_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1431 |  |   { X86_CMOVNB_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1432 |  |   { X86_CMOVNE_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1433 |  |   { X86_CMOVNP_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1434 |  |   { X86_CMOVP_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1435 |  |   // { X86_COMP_FST0r, X86_REG_ST0, CS_AC_WRITE }, | 
| 1436 |  |   // { X86_COM_FST0r, X86_REG_ST0, CS_AC_WRITE }, | 
| 1437 |  |   { X86_FNSTSW16r, X86_REG_AX, CS_AC_WRITE }, | 
| 1438 |  |   { X86_SKINIT, X86_REG_EAX, CS_AC_WRITE }, | 
| 1439 |  |   { X86_VMLOAD32, X86_REG_EAX, CS_AC_WRITE }, | 
| 1440 |  |   { X86_VMLOAD64, X86_REG_RAX, CS_AC_WRITE }, | 
| 1441 |  |   { X86_VMRUN32, X86_REG_EAX, CS_AC_WRITE }, | 
| 1442 |  |   { X86_VMRUN64, X86_REG_RAX, CS_AC_WRITE }, | 
| 1443 |  |   { X86_VMSAVE32, X86_REG_EAX, CS_AC_READ }, | 
| 1444 |  |   { X86_VMSAVE64, X86_REG_RAX, CS_AC_READ }, | 
| 1445 |  |   { X86_XCH_F, X86_REG_ST0, CS_AC_WRITE }, | 
| 1446 |  | #endif | 
| 1447 |  | }; | 
| 1448 |  |  | 
| 1449 |  | static const struct insn_reg2 insn_regs_intel2[] = { | 
| 1450 |  |   { X86_IN16rr, X86_REG_AX, X86_REG_DX, CS_AC_WRITE, CS_AC_READ }, | 
| 1451 |  |   { X86_IN32rr, X86_REG_EAX, X86_REG_DX, CS_AC_WRITE, CS_AC_READ }, | 
| 1452 |  |   { X86_IN8rr, X86_REG_AL, X86_REG_DX, CS_AC_WRITE, CS_AC_READ }, | 
| 1453 |  |   { X86_INVLPGA32, X86_REG_EAX, X86_REG_ECX, CS_AC_READ, CS_AC_READ }, | 
| 1454 |  |   { X86_INVLPGA64, X86_REG_RAX, X86_REG_ECX, CS_AC_READ, CS_AC_READ }, | 
| 1455 |  |   { X86_OUT16rr, X86_REG_DX, X86_REG_AX, CS_AC_READ, CS_AC_READ }, | 
| 1456 |  |   { X86_OUT32rr, X86_REG_DX, X86_REG_EAX, CS_AC_READ, CS_AC_READ }, | 
| 1457 |  |   { X86_OUT8rr, X86_REG_DX, X86_REG_AL, CS_AC_READ, CS_AC_READ }, | 
| 1458 |  | }; | 
| 1459 |  |  | 
| 1460 |  | static int binary_search1(const struct insn_reg *insns, unsigned int max, unsigned int id) | 
| 1461 | 681k | { | 
| 1462 | 681k |   unsigned int first, last, mid; | 
| 1463 |  |  | 
| 1464 | 681k |   first = 0; | 
| 1465 | 681k |   last = max -1; | 
| 1466 |  |  | 
| 1467 | 681k |   if (insns[0].insn > id || insns[last].insn < id) { | 
| 1468 |  |     // not found | 
| 1469 | 101k |     return -1; | 
| 1470 | 101k |   } | 
| 1471 |  |  | 
| 1472 | 3.54M |   while (first <= last) { | 
| 1473 | 2.99M |     mid = (first + last) / 2; | 
| 1474 | 2.99M |     if (insns[mid].insn < id) { | 
| 1475 | 1.41M |       first = mid + 1; | 
| 1476 | 1.58M |     } else if (insns[mid].insn == id) { | 
| 1477 | 27.2k |       return mid; | 
| 1478 | 1.55M |     } else { | 
| 1479 | 1.55M |       if (mid == 0) | 
| 1480 | 0 |         break; | 
| 1481 | 1.55M |       last = mid - 1; | 
| 1482 | 1.55M |     } | 
| 1483 | 2.99M |   } | 
| 1484 |  |  | 
| 1485 |  |   // not found | 
| 1486 | 553k |   return -1; | 
| 1487 | 580k | } | 
| 1488 |  |  | 
| 1489 |  | static int binary_search2(const struct insn_reg2 *insns, unsigned int max, unsigned int id) | 
| 1490 | 326k | { | 
| 1491 | 326k |   unsigned int first, last, mid; | 
| 1492 |  |  | 
| 1493 | 326k |   first = 0; | 
| 1494 | 326k |   last = max -1; | 
| 1495 |  |  | 
| 1496 | 326k |   if (insns[0].insn > id || insns[last].insn < id) { | 
| 1497 |  |     // not found | 
| 1498 | 242k |     return -1; | 
| 1499 | 242k |   } | 
| 1500 |  |  | 
| 1501 | 333k |   while (first <= last) { | 
| 1502 | 254k |     mid = (first + last) / 2; | 
| 1503 | 254k |     if (insns[mid].insn < id) { | 
| 1504 | 165k |       first = mid + 1; | 
| 1505 | 165k |     } else if (insns[mid].insn == id) { | 
| 1506 | 5.81k |       return mid; | 
| 1507 | 82.6k |     } else { | 
| 1508 | 82.6k |       if (mid == 0) | 
| 1509 | 0 |         break; | 
| 1510 | 82.6k |       last = mid - 1; | 
| 1511 | 82.6k |     } | 
| 1512 | 254k |   } | 
| 1513 |  |  | 
| 1514 |  |   // not found | 
| 1515 | 78.9k |   return -1; | 
| 1516 | 84.7k | } | 
| 1517 |  |  | 
| 1518 |  | // return register of given instruction id | 
| 1519 |  | // return 0 if not found | 
| 1520 |  | // this is to handle instructions embedding accumulate registers into AsmStrs[] | 
| 1521 |  | x86_reg X86_insn_reg_intel(unsigned int id, enum cs_ac_type *access) | 
| 1522 | 164k | { | 
| 1523 | 164k |   int i; | 
| 1524 |  |  | 
| 1525 | 164k |   i = binary_search1(insn_regs_intel, ARR_SIZE(insn_regs_intel), id); | 
| 1526 | 164k |   if (i != -1) { | 
| 1527 | 16.1k |     if (access) { | 
| 1528 | 16.1k |       *access = insn_regs_intel[i].access; | 
| 1529 | 16.1k |     } | 
| 1530 | 16.1k |     return insn_regs_intel[i].reg; | 
| 1531 | 16.1k |   } | 
| 1532 |  |  | 
| 1533 | 148k |   i = binary_search1(insn_regs_intel_extra, ARR_SIZE(insn_regs_intel_extra), id); | 
| 1534 | 148k |   if (i != -1) { | 
| 1535 | 360 |     if (access) { | 
| 1536 | 360 |       *access = insn_regs_intel_extra[i].access; | 
| 1537 | 360 |     } | 
| 1538 | 360 |     return insn_regs_intel_extra[i].reg; | 
| 1539 | 360 |   } | 
| 1540 |  |  | 
| 1541 |  |   // not found | 
| 1542 | 147k |   return 0; | 
| 1543 | 148k | } | 
| 1544 |  |  | 
| 1545 |  | bool X86_insn_reg_intel2(unsigned int id, x86_reg *reg1, enum cs_ac_type *access1, x86_reg *reg2, enum cs_ac_type *access2) | 
| 1546 | 147k | { | 
| 1547 | 147k |   int i = binary_search2(insn_regs_intel2, ARR_SIZE(insn_regs_intel2), id); | 
| 1548 | 147k |   if (i != -1) { | 
| 1549 | 2.91k |     *reg1 = insn_regs_intel2[i].reg1; | 
| 1550 | 2.91k |     *reg2 = insn_regs_intel2[i].reg2; | 
| 1551 | 2.91k |     if (access1) | 
| 1552 | 2.91k |       *access1 = insn_regs_intel2[i].access1; | 
| 1553 | 2.91k |     if (access2) | 
| 1554 | 2.91k |       *access2 = insn_regs_intel2[i].access2; | 
| 1555 | 2.91k |     return true; | 
| 1556 | 2.91k |   } | 
| 1557 |  |  | 
| 1558 |  |   // not found | 
| 1559 | 144k |   return false; | 
| 1560 | 147k | } | 
| 1561 |  |  | 
| 1562 |  | x86_reg X86_insn_reg_att(unsigned int id, enum cs_ac_type *access) | 
| 1563 | 190k | { | 
| 1564 | 190k |   int i; | 
| 1565 |  |  | 
| 1566 | 190k |   i = binary_search1(insn_regs_att, ARR_SIZE(insn_regs_att), id); | 
| 1567 | 190k |   if (i != -1) { | 
| 1568 | 10.6k |     if (access) | 
| 1569 | 10.6k |       *access = insn_regs_att[i].access; | 
| 1570 | 10.6k |     return insn_regs_att[i].reg; | 
| 1571 | 10.6k |   } | 
| 1572 |  |  | 
| 1573 | 179k |   i = binary_search1(insn_regs_att_extra, ARR_SIZE(insn_regs_att_extra), id); | 
| 1574 | 179k |   if (i != -1) { | 
| 1575 | 69 |     if (access) | 
| 1576 | 69 |       *access = insn_regs_att_extra[i].access; | 
| 1577 | 69 |     return insn_regs_att_extra[i].reg; | 
| 1578 | 69 |   } | 
| 1579 |  |  | 
| 1580 |  |   // not found | 
| 1581 | 179k |   return 0; | 
| 1582 | 179k | } | 
| 1583 |  |  | 
| 1584 |  | // ATT just reuses Intel data, but with the order of registers reversed | 
| 1585 |  | bool X86_insn_reg_att2(unsigned int id, x86_reg *reg1, enum cs_ac_type *access1, x86_reg *reg2, enum cs_ac_type *access2) | 
| 1586 | 179k | { | 
| 1587 | 179k |   int i = binary_search2(insn_regs_intel2, ARR_SIZE(insn_regs_intel2), id); | 
| 1588 | 179k |   if (i != -1) { | 
| 1589 | 2.89k |     *reg1 = insn_regs_intel2[i].reg2; | 
| 1590 | 2.89k |     *reg2 = insn_regs_intel2[i].reg1; | 
| 1591 | 2.89k |     if (access1) | 
| 1592 | 2.89k |       *access1 = insn_regs_intel2[i].access2; | 
| 1593 | 2.89k |     if (access2) | 
| 1594 | 2.89k |       *access2 = insn_regs_intel2[i].access1; | 
| 1595 | 2.89k |     return true; | 
| 1596 | 2.89k |   } | 
| 1597 |  |  | 
| 1598 |  |   // not found | 
| 1599 | 176k |   return false; | 
| 1600 | 179k | } | 
| 1601 |  |  | 
| 1602 |  | // given MCInst's id, find out if this insn is valid for REPNE prefix | 
| 1603 |  | static bool valid_repne(cs_struct *h, unsigned int opcode) | 
| 1604 | 11.3k | { | 
| 1605 | 11.3k |   unsigned int id; | 
| 1606 | 11.3k |   unsigned int i = find_insn(opcode); | 
| 1607 | 11.3k |   if (i != -1) { | 
| 1608 | 11.3k |     id = insns[i].mapid; | 
| 1609 | 11.3k |     switch(id) { | 
| 1610 | 6.93k |       default: | 
| 1611 | 6.93k |         return false; | 
| 1612 |  |  | 
| 1613 | 229 |       case X86_INS_CMPSB: | 
| 1614 | 480 |       case X86_INS_CMPSS: | 
| 1615 | 727 |       case X86_INS_CMPSW: | 
| 1616 | 737 |       case X86_INS_CMPSQ: | 
| 1617 |  |  | 
| 1618 | 790 |       case X86_INS_SCASB: | 
| 1619 | 857 |       case X86_INS_SCASW: | 
| 1620 | 1.07k |       case X86_INS_SCASQ: | 
| 1621 |  |  | 
| 1622 | 1.09k |       case X86_INS_MOVSB: | 
| 1623 | 1.12k |       case X86_INS_MOVSS: | 
| 1624 | 1.21k |       case X86_INS_MOVSW: | 
| 1625 | 1.24k |       case X86_INS_MOVSQ: | 
| 1626 |  |  | 
| 1627 | 1.37k |       case X86_INS_LODSB: | 
| 1628 | 1.39k |       case X86_INS_LODSW: | 
| 1629 | 1.50k |       case X86_INS_LODSD: | 
| 1630 | 2.28k |       case X86_INS_LODSQ: | 
| 1631 |  |  | 
| 1632 | 2.32k |       case X86_INS_STOSB: | 
| 1633 | 2.35k |       case X86_INS_STOSW: | 
| 1634 | 2.46k |       case X86_INS_STOSD: | 
| 1635 | 2.60k |       case X86_INS_STOSQ: | 
| 1636 |  |  | 
| 1637 | 2.77k |       case X86_INS_INSB: | 
| 1638 | 2.86k |       case X86_INS_INSW: | 
| 1639 | 2.95k |       case X86_INS_INSD: | 
| 1640 |  |  | 
| 1641 | 3.11k |       case X86_INS_OUTSB: | 
| 1642 | 3.19k |       case X86_INS_OUTSW: | 
| 1643 | 3.42k |       case X86_INS_OUTSD: | 
| 1644 |  |  | 
| 1645 | 3.42k |         return true; | 
| 1646 |  |  | 
| 1647 | 497 |       case X86_INS_MOVSD: | 
| 1648 | 497 |         if (opcode == X86_MOVSW) // REP MOVSB | 
| 1649 | 0 |           return true; | 
| 1650 | 497 |         return false; | 
| 1651 |  |  | 
| 1652 | 157 |       case X86_INS_CMPSD: | 
| 1653 | 157 |         if (opcode == X86_CMPSL) // REP CMPSD | 
| 1654 | 119 |           return true; | 
| 1655 | 38 |         return false; | 
| 1656 |  |  | 
| 1657 | 334 |       case X86_INS_SCASD: | 
| 1658 | 334 |         if (opcode == X86_SCASL) // REP SCASD | 
| 1659 | 334 |           return true; | 
| 1660 | 0 |         return false; | 
| 1661 | 11.3k |     } | 
| 1662 | 11.3k |   } | 
| 1663 |  |  | 
| 1664 |  |   // not found | 
| 1665 | 0 |   return false; | 
| 1666 | 11.3k | } | 
| 1667 |  |  | 
| 1668 |  | // given MCInst's id, find out if this insn is valid for BND prefix | 
| 1669 |  | // BND prefix is valid for CALL/JMP/RET | 
| 1670 |  | #ifndef CAPSTONE_DIET | 
| 1671 |  | static bool valid_bnd(cs_struct *h, unsigned int opcode) | 
| 1672 | 7.46k | { | 
| 1673 | 7.46k |   unsigned int id; | 
| 1674 | 7.46k |   unsigned int i = find_insn(opcode); | 
| 1675 | 7.46k |   if (i != -1) { | 
| 1676 | 7.46k |     id = insns[i].mapid; | 
| 1677 | 7.46k |     switch(id) { | 
| 1678 | 4.77k |       default: | 
| 1679 | 4.77k |         return false; | 
| 1680 |  |  | 
| 1681 | 59 |       case X86_INS_JAE: | 
| 1682 | 319 |       case X86_INS_JA: | 
| 1683 | 366 |       case X86_INS_JBE: | 
| 1684 | 458 |       case X86_INS_JB: | 
| 1685 | 515 |       case X86_INS_JCXZ: | 
| 1686 | 550 |       case X86_INS_JECXZ: | 
| 1687 | 818 |       case X86_INS_JE: | 
| 1688 | 919 |       case X86_INS_JGE: | 
| 1689 | 1.04k |       case X86_INS_JG: | 
| 1690 | 1.22k |       case X86_INS_JLE: | 
| 1691 | 1.27k |       case X86_INS_JL: | 
| 1692 | 1.41k |       case X86_INS_JMP: | 
| 1693 | 1.55k |       case X86_INS_JNE: | 
| 1694 | 1.77k |       case X86_INS_JNO: | 
| 1695 | 1.79k |       case X86_INS_JNP: | 
| 1696 | 1.85k |       case X86_INS_JNS: | 
| 1697 | 1.91k |       case X86_INS_JO: | 
| 1698 | 1.96k |       case X86_INS_JP: | 
| 1699 | 2.01k |       case X86_INS_JRCXZ: | 
| 1700 | 2.25k |       case X86_INS_JS: | 
| 1701 |  |  | 
| 1702 | 2.39k |       case X86_INS_CALL: | 
| 1703 | 2.56k |       case X86_INS_RET: | 
| 1704 | 2.67k |       case X86_INS_RETF: | 
| 1705 | 2.69k |       case X86_INS_RETFQ: | 
| 1706 | 2.69k |         return true; | 
| 1707 | 7.46k |     } | 
| 1708 | 7.46k |   } | 
| 1709 |  |  | 
| 1710 |  |   // not found | 
| 1711 | 0 |   return false; | 
| 1712 | 7.46k | } | 
| 1713 |  | #endif | 
| 1714 |  |  | 
| 1715 |  | // return true if the opcode is XCHG [mem] | 
| 1716 |  | static bool xchg_mem(unsigned int opcode) | 
| 1717 | 19.5k | { | 
| 1718 | 19.5k |   switch(opcode) { | 
| 1719 | 18.7k |     default: | 
| 1720 | 18.7k |       return false; | 
| 1721 | 165 |     case X86_XCHG8rm: | 
| 1722 | 523 |     case X86_XCHG16rm: | 
| 1723 | 702 |     case X86_XCHG32rm: | 
| 1724 | 764 |     case X86_XCHG64rm: | 
| 1725 | 764 |          return true; | 
| 1726 | 19.5k |   } | 
| 1727 | 19.5k | } | 
| 1728 |  |  | 
| 1729 |  | // given MCInst's id, find out if this insn is valid for REP prefix | 
| 1730 |  | static bool valid_rep(cs_struct *h, unsigned int opcode) | 
| 1731 | 7.70k | { | 
| 1732 | 7.70k |   unsigned int id; | 
| 1733 | 7.70k |   unsigned int i = find_insn(opcode); | 
| 1734 | 7.70k |   if (i != -1) { | 
| 1735 | 7.70k |     id = insns[i].mapid; | 
| 1736 | 7.70k |     switch(id) { | 
| 1737 | 6.36k |       default: | 
| 1738 | 6.36k |         return false; | 
| 1739 |  |  | 
| 1740 | 14 |       case X86_INS_MOVSB: | 
| 1741 | 39 |       case X86_INS_MOVSW: | 
| 1742 | 82 |       case X86_INS_MOVSQ: | 
| 1743 |  |  | 
| 1744 | 295 |       case X86_INS_LODSB: | 
| 1745 | 334 |       case X86_INS_LODSW: | 
| 1746 | 350 |       case X86_INS_LODSQ: | 
| 1747 |  |  | 
| 1748 | 377 |       case X86_INS_STOSB: | 
| 1749 | 566 |       case X86_INS_STOSW: | 
| 1750 | 575 |       case X86_INS_STOSQ: | 
| 1751 |  |  | 
| 1752 | 792 |       case X86_INS_INSB: | 
| 1753 | 850 |       case X86_INS_INSW: | 
| 1754 | 882 |       case X86_INS_INSD: | 
| 1755 |  |  | 
| 1756 | 963 |       case X86_INS_OUTSB: | 
| 1757 | 1.02k |       case X86_INS_OUTSW: | 
| 1758 | 1.10k |       case X86_INS_OUTSD: | 
| 1759 | 1.10k |         return true; | 
| 1760 |  |  | 
| 1761 |  |       // following are some confused instructions, which have the same | 
| 1762 |  |       // mnemonics in 128bit media instructions. Intel is horribly crazy! | 
| 1763 | 20 |       case X86_INS_MOVSD: | 
| 1764 | 20 |         if (opcode == X86_MOVSL) // REP MOVSD | 
| 1765 | 15 |           return true; | 
| 1766 | 5 |         return false; | 
| 1767 |  |  | 
| 1768 | 75 |       case X86_INS_LODSD: | 
| 1769 | 75 |         if (opcode == X86_LODSL) // REP LODSD | 
| 1770 | 75 |           return true; | 
| 1771 | 0 |         return false; | 
| 1772 |  |  | 
| 1773 | 139 |       case X86_INS_STOSD: | 
| 1774 | 139 |         if (opcode == X86_STOSL) // REP STOSD | 
| 1775 | 139 |           return true; | 
| 1776 | 0 |         return false; | 
| 1777 | 7.70k |     } | 
| 1778 | 7.70k |   } | 
| 1779 |  |  | 
| 1780 |  |   // not found | 
| 1781 | 0 |   return false; | 
| 1782 | 7.70k | } | 
| 1783 |  |  | 
| 1784 |  | // given MCInst's id, find if this is a "repz ret" instruction | 
| 1785 |  | // gcc generates "repz ret" (f3 c3) instructions in some cases as an | 
| 1786 |  | // optimization for AMD platforms, see: | 
| 1787 |  | // https://gcc.gnu.org/legacy-ml/gcc-patches/2003-05/msg02117.html | 
| 1788 |  | static bool valid_ret_repz(cs_struct *h, unsigned int opcode) | 
| 1789 | 5.18k | { | 
| 1790 | 5.18k |   unsigned int id; | 
| 1791 | 5.18k |   unsigned int i = find_insn(opcode); | 
| 1792 |  |  | 
| 1793 | 5.18k |   if (i != -1) { | 
| 1794 | 5.18k |     id = insns[i].mapid; | 
| 1795 | 5.18k |     return id == X86_INS_RET; | 
| 1796 | 5.18k |   } | 
| 1797 |  |  | 
| 1798 |  |   // not found | 
| 1799 | 0 |   return false; | 
| 1800 | 5.18k | } | 
| 1801 |  |  | 
| 1802 |  | // given MCInst's id, find out if this insn is valid for REPE prefix | 
| 1803 |  | static bool valid_repe(cs_struct *h, unsigned int opcode) | 
| 1804 | 6.37k | { | 
| 1805 | 6.37k |   unsigned int id; | 
| 1806 | 6.37k |   unsigned int i = find_insn(opcode); | 
| 1807 | 6.37k |   if (i != -1) { | 
| 1808 | 6.37k |     id = insns[i].mapid; | 
| 1809 | 6.37k |     switch(id) { | 
| 1810 | 5.09k |       default: | 
| 1811 | 5.09k |         return false; | 
| 1812 |  |  | 
| 1813 | 57 |       case X86_INS_CMPSB: | 
| 1814 | 73 |       case X86_INS_CMPSW: | 
| 1815 | 320 |       case X86_INS_CMPSQ: | 
| 1816 |  |  | 
| 1817 | 358 |       case X86_INS_SCASB: | 
| 1818 | 536 |       case X86_INS_SCASW: | 
| 1819 | 799 |       case X86_INS_SCASQ: | 
| 1820 | 799 |         return true; | 
| 1821 |  |  | 
| 1822 |  |       // following are some confused instructions, which have the same | 
| 1823 |  |       // mnemonics in 128bit media instructions. Intel is horribly crazy! | 
| 1824 | 114 |       case X86_INS_CMPSD: | 
| 1825 | 114 |         if (opcode == X86_CMPSL) // REP CMPSD | 
| 1826 | 25 |           return true; | 
| 1827 | 89 |         return false; | 
| 1828 |  |  | 
| 1829 | 363 |       case X86_INS_SCASD: | 
| 1830 | 363 |         if (opcode == X86_SCASL) // REP SCASD | 
| 1831 | 363 |           return true; | 
| 1832 | 0 |         return false; | 
| 1833 | 6.37k |     } | 
| 1834 | 6.37k |   } | 
| 1835 |  |  | 
| 1836 |  |   // not found | 
| 1837 | 0 |   return false; | 
| 1838 | 6.37k | } | 
| 1839 |  |  | 
| 1840 |  | // Given MCInst's id, find out if this insn is valid for NOTRACK prefix. | 
| 1841 |  | // NOTRACK prefix is valid for CALL/JMP. | 
| 1842 |  | static bool valid_notrack(cs_struct *h, unsigned int opcode) | 
| 1843 | 760 | { | 
| 1844 | 760 |   unsigned int id; | 
| 1845 | 760 |   unsigned int i = find_insn(opcode); | 
| 1846 | 760 |   if (i != -1) { | 
| 1847 | 760 |     id = insns[i].mapid; | 
| 1848 | 760 |     switch(id) { | 
| 1849 | 602 |       default: | 
| 1850 | 602 |         return false; | 
| 1851 | 152 |       case X86_INS_CALL: | 
| 1852 | 158 |       case X86_INS_JMP: | 
| 1853 | 158 |         return true; | 
| 1854 | 760 |     } | 
| 1855 | 760 |   } | 
| 1856 |  |  | 
| 1857 |  |   // not found | 
| 1858 | 0 |   return false; | 
| 1859 | 760 | } | 
| 1860 |  |  | 
| 1861 |  | #ifndef CAPSTONE_DIET | 
| 1862 |  | // add *CX register to regs_read[] & regs_write[] | 
| 1863 |  | static void add_cx(MCInst *MI) | 
| 1864 | 6.39k | { | 
| 1865 | 6.39k |   if (MI->csh->detail) { | 
| 1866 | 6.39k |     x86_reg cx; | 
| 1867 |  |  | 
| 1868 | 6.39k |     if (MI->csh->mode & CS_MODE_16) | 
| 1869 | 1.60k |       cx = X86_REG_CX; | 
| 1870 | 4.79k |     else if (MI->csh->mode & CS_MODE_32) | 
| 1871 | 1.81k |       cx = X86_REG_ECX; | 
| 1872 | 2.98k |     else  // 64-bit | 
| 1873 | 2.98k |       cx = X86_REG_RCX; | 
| 1874 |  |  | 
| 1875 | 6.39k |     MI->flat_insn->detail->regs_read[MI->flat_insn->detail->regs_read_count] = cx; | 
| 1876 | 6.39k |     MI->flat_insn->detail->regs_read_count++; | 
| 1877 |  |  | 
| 1878 | 6.39k |     MI->flat_insn->detail->regs_write[MI->flat_insn->detail->regs_write_count] = cx; | 
| 1879 | 6.39k |     MI->flat_insn->detail->regs_write_count++; | 
| 1880 | 6.39k |   } | 
| 1881 | 6.39k | } | 
| 1882 |  | #endif | 
| 1883 |  |  | 
| 1884 |  | // return true if we patch the mnemonic | 
| 1885 |  | bool X86_lockrep(MCInst *MI, SStream *O) | 
| 1886 | 354k | { | 
| 1887 | 354k |   unsigned int opcode; | 
| 1888 | 354k |   bool res = false; | 
| 1889 |  |  | 
| 1890 | 354k |   switch(MI->x86_prefix[0]) { | 
| 1891 | 325k |     default: | 
| 1892 | 325k |       break; | 
| 1893 | 325k |     case 0xf0: | 
| 1894 | 9.57k | #ifndef CAPSTONE_DIET | 
| 1895 | 9.57k |       if (MI->xAcquireRelease == 0xf2) | 
| 1896 | 238 |         SStream_concat(O, "xacquire|lock|"); | 
| 1897 | 9.33k |       else if (MI->xAcquireRelease == 0xf3) | 
| 1898 | 296 |         SStream_concat(O, "xrelease|lock|"); | 
| 1899 | 9.04k |       else | 
| 1900 | 9.04k |         SStream_concat(O, "lock|"); | 
| 1901 | 9.57k | #endif | 
| 1902 | 9.57k |       break; | 
| 1903 | 11.6k |     case 0xf2:  // repne | 
| 1904 | 11.6k |       opcode = MCInst_getOpcode(MI); | 
| 1905 |  |  | 
| 1906 | 11.6k | #ifndef CAPSTONE_DIET // only care about memonic in standard (non-diet) mode | 
| 1907 | 11.6k |       if (xchg_mem(opcode) && MI->xAcquireRelease) { | 
| 1908 | 344 |         SStream_concat(O, "xacquire|"); | 
| 1909 | 11.3k |       } else if (valid_repne(MI->csh, opcode)) { | 
| 1910 | 3.87k |         SStream_concat(O, "repne|"); | 
| 1911 | 3.87k |         add_cx(MI); | 
| 1912 | 7.46k |       } else if (valid_bnd(MI->csh, opcode)) { | 
| 1913 | 2.69k |         SStream_concat(O, "bnd|"); | 
| 1914 | 4.77k |       } else { | 
| 1915 |  |         // invalid prefix | 
| 1916 | 4.77k |         MI->x86_prefix[0] = 0; | 
| 1917 |  |  | 
| 1918 |  |         // handle special cases | 
| 1919 | 4.77k | #ifndef CAPSTONE_X86_REDUCE | 
| 1920 |  | #if 0 | 
| 1921 |  |         if (opcode == X86_MULPDrr) { | 
| 1922 |  |           MCInst_setOpcode(MI, X86_MULSDrr); | 
| 1923 |  |           SStream_concat0(O, "mulsd\t"); | 
| 1924 |  |           res = true; | 
| 1925 |  |         } | 
| 1926 |  | #endif | 
| 1927 | 4.77k | #endif | 
| 1928 | 4.77k |       } | 
| 1929 |  | #else // diet mode -> only patch opcode in special cases | 
| 1930 |  |       if (!valid_repne(MI->csh, opcode)) { | 
| 1931 |  |         MI->x86_prefix[0] = 0; | 
| 1932 |  |       } | 
| 1933 |  | #ifndef CAPSTONE_X86_REDUCE | 
| 1934 |  | #if 0 | 
| 1935 |  |       // handle special cases | 
| 1936 |  |       if (opcode == X86_MULPDrr) { | 
| 1937 |  |         MCInst_setOpcode(MI, X86_MULSDrr); | 
| 1938 |  |       } | 
| 1939 |  | #endif | 
| 1940 |  | #endif | 
| 1941 |  | #endif | 
| 1942 | 11.6k |       break; | 
| 1943 |  |  | 
| 1944 | 7.81k |     case 0xf3: | 
| 1945 | 7.81k |       opcode = MCInst_getOpcode(MI); | 
| 1946 |  |  | 
| 1947 | 7.81k | #ifndef CAPSTONE_DIET // only care about memonic in standard (non-diet) mode | 
| 1948 | 7.81k |       if (xchg_mem(opcode) && MI->xAcquireRelease) { | 
| 1949 | 111 |         SStream_concat(O, "xrelease|"); | 
| 1950 | 7.70k |       } else if (valid_rep(MI->csh, opcode)) { | 
| 1951 | 1.33k |         SStream_concat(O, "rep|"); | 
| 1952 | 1.33k |         add_cx(MI); | 
| 1953 | 6.37k |       } else if (valid_repe(MI->csh, opcode)) { | 
| 1954 | 1.18k |         SStream_concat(O, "repe|"); | 
| 1955 | 1.18k |         add_cx(MI); | 
| 1956 | 5.18k |       } else if (valid_ret_repz(MI->csh, opcode)) { | 
| 1957 | 176 |         SStream_concat(O, "repz|"); | 
| 1958 | 5.00k |       } else { | 
| 1959 |  |         // invalid prefix | 
| 1960 | 5.00k |         MI->x86_prefix[0] = 0; | 
| 1961 |  |  | 
| 1962 |  |         // handle special cases | 
| 1963 | 5.00k | #ifndef CAPSTONE_X86_REDUCE | 
| 1964 |  | #if 0 | 
| 1965 |  |         // FIXME: remove this special case? | 
| 1966 |  |         if (opcode == X86_MULPDrr) { | 
| 1967 |  |           MCInst_setOpcode(MI, X86_MULSSrr); | 
| 1968 |  |           SStream_concat0(O, "mulss\t"); | 
| 1969 |  |           res = true; | 
| 1970 |  |         } | 
| 1971 |  | #endif | 
| 1972 | 5.00k | #endif | 
| 1973 | 5.00k |       } | 
| 1974 |  | #else // diet mode -> only patch opcode in special cases | 
| 1975 |  |       if (!valid_rep(MI->csh, opcode) && !valid_repe(MI->csh, opcode)) { | 
| 1976 |  |         MI->x86_prefix[0] = 0; | 
| 1977 |  |       } | 
| 1978 |  | #ifndef CAPSTONE_X86_REDUCE | 
| 1979 |  | #if 0 | 
| 1980 |  |       // handle special cases | 
| 1981 |  |       // FIXME: remove this special case? | 
| 1982 |  |       if (opcode == X86_MULPDrr) { | 
| 1983 |  |         MCInst_setOpcode(MI, X86_MULSSrr); | 
| 1984 |  |       } | 
| 1985 |  | #endif | 
| 1986 |  | #endif | 
| 1987 |  | #endif | 
| 1988 | 7.81k |       break; | 
| 1989 | 354k |   } | 
| 1990 |  |  | 
| 1991 | 354k |   switch(MI->x86_prefix[1]) { | 
| 1992 | 353k |     default: | 
| 1993 | 353k |       break; | 
| 1994 | 353k |     case 0x3e: | 
| 1995 | 760 |       opcode = MCInst_getOpcode(MI); | 
| 1996 | 760 |       if (valid_notrack(MI->csh, opcode)) { | 
| 1997 | 158 |         SStream_concat(O, "notrack|"); | 
| 1998 | 158 |       } | 
| 1999 | 760 |       break; | 
| 2000 | 354k |   } | 
| 2001 |  |  | 
| 2002 |  |   // copy normalized prefix[] back to x86.prefix[] | 
| 2003 | 354k |   if (MI->csh->detail) | 
| 2004 | 354k |     memcpy(MI->flat_insn->detail->x86.prefix, MI->x86_prefix, ARR_SIZE(MI->x86_prefix)); | 
| 2005 |  |  | 
| 2006 | 354k |   return res; | 
| 2007 | 354k | } | 
| 2008 |  |  | 
| 2009 |  | void op_addReg(MCInst *MI, int reg) | 
| 2010 | 27.7k | { | 
| 2011 | 27.7k |   if (MI->csh->detail) { | 
| 2012 | 27.7k |     MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_REG; | 
| 2013 | 27.7k |     MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].reg = reg; | 
| 2014 | 27.7k |     MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->csh->regsize_map[reg]; | 
| 2015 | 27.7k |     MI->flat_insn->detail->x86.op_count++; | 
| 2016 | 27.7k |   } | 
| 2017 |  |  | 
| 2018 | 27.7k |   if (MI->op1_size == 0) | 
| 2019 | 17.2k |     MI->op1_size = MI->csh->regsize_map[reg]; | 
| 2020 | 27.7k | } | 
| 2021 |  |  | 
| 2022 |  | void op_addImm(MCInst *MI, int v) | 
| 2023 | 2.34k | { | 
| 2024 | 2.34k |   if (MI->csh->detail) { | 
| 2025 | 2.34k |     MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM; | 
| 2026 | 2.34k |     MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = v; | 
| 2027 |  |     // if op_count > 0, then this operand's size is taken from the destination op | 
| 2028 | 2.34k |     if (MI->csh->syntax != CS_OPT_SYNTAX_ATT) { | 
| 2029 | 2.34k |       if (MI->flat_insn->detail->x86.op_count > 0) | 
| 2030 | 2.34k |         MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->flat_insn->detail->x86.operands[0].size; | 
| 2031 | 0 |       else | 
| 2032 | 0 |         MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size; | 
| 2033 | 2.34k |     } else | 
| 2034 | 0 |       MI->has_imm = true; | 
| 2035 | 2.34k |     MI->flat_insn->detail->x86.op_count++; | 
| 2036 | 2.34k |   } | 
| 2037 |  |  | 
| 2038 | 2.34k |   if (MI->op1_size == 0) | 
| 2039 | 0 |     MI->op1_size = MI->imm_size; | 
| 2040 | 2.34k | } | 
| 2041 |  |  | 
| 2042 |  | void op_addXopCC(MCInst *MI, int v) | 
| 2043 | 629 | { | 
| 2044 | 629 |   if (MI->csh->detail) { | 
| 2045 | 629 |     MI->flat_insn->detail->x86.xop_cc = v; | 
| 2046 | 629 |   } | 
| 2047 | 629 | } | 
| 2048 |  |  | 
| 2049 |  | void op_addSseCC(MCInst *MI, int v) | 
| 2050 | 0 | { | 
| 2051 | 0 |   if (MI->csh->detail) { | 
| 2052 | 0 |     MI->flat_insn->detail->x86.sse_cc = v; | 
| 2053 | 0 |   } | 
| 2054 | 0 | } | 
| 2055 |  |  | 
| 2056 |  | void op_addAvxCC(MCInst *MI, int v) | 
| 2057 | 3.96k | { | 
| 2058 | 3.96k |   if (MI->csh->detail) { | 
| 2059 | 3.96k |     MI->flat_insn->detail->x86.avx_cc = v; | 
| 2060 | 3.96k |   } | 
| 2061 | 3.96k | } | 
| 2062 |  |  | 
| 2063 |  | void op_addAvxRoundingMode(MCInst *MI, int v) | 
| 2064 | 1.81k | { | 
| 2065 | 1.81k |   if (MI->csh->detail) { | 
| 2066 | 1.81k |     MI->flat_insn->detail->x86.avx_rm = v; | 
| 2067 | 1.81k |   } | 
| 2068 | 1.81k | } | 
| 2069 |  |  | 
| 2070 |  | // below functions supply details to X86GenAsmWriter*.inc | 
| 2071 |  | void op_addAvxZeroOpmask(MCInst *MI) | 
| 2072 | 3.36k | { | 
| 2073 | 3.36k |   if (MI->csh->detail) { | 
| 2074 |  |     // link with the previous operand | 
| 2075 | 3.36k |     MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count - 1].avx_zero_opmask = true; | 
| 2076 | 3.36k |   } | 
| 2077 | 3.36k | } | 
| 2078 |  |  | 
| 2079 |  | void op_addAvxSae(MCInst *MI) | 
| 2080 | 2.78k | { | 
| 2081 | 2.78k |   if (MI->csh->detail) { | 
| 2082 | 2.78k |     MI->flat_insn->detail->x86.avx_sae = true; | 
| 2083 | 2.78k |   } | 
| 2084 | 2.78k | } | 
| 2085 |  |  | 
| 2086 |  | void op_addAvxBroadcast(MCInst *MI, x86_avx_bcast v) | 
| 2087 | 2.08k | { | 
| 2088 | 2.08k |   if (MI->csh->detail) { | 
| 2089 |  |     // link with the previous operand | 
| 2090 | 2.08k |     MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count - 1].avx_bcast = v; | 
| 2091 | 2.08k |   } | 
| 2092 | 2.08k | } | 
| 2093 |  |  | 
| 2094 |  | #ifndef CAPSTONE_DIET | 
| 2095 |  | // map instruction to its characteristics | 
| 2096 |  | typedef struct insn_op { | 
| 2097 |  |   uint64_t flags; // how this instruction update EFLAGS(arithmetic instrcutions) of FPU FLAGS(for FPU instructions) | 
| 2098 |  |   uint8_t access[6]; | 
| 2099 |  | } insn_op; | 
| 2100 |  |  | 
| 2101 |  | static const insn_op insn_ops[] = { | 
| 2102 |  | #ifdef CAPSTONE_X86_REDUCE | 
| 2103 |  | #include "X86MappingInsnOp_reduce.inc" | 
| 2104 |  | #else | 
| 2105 |  | #include "X86MappingInsnOp.inc" | 
| 2106 |  | #endif | 
| 2107 |  | }; | 
| 2108 |  |  | 
| 2109 |  | // given internal insn id, return operand access info | 
| 2110 |  | const uint8_t *X86_get_op_access(cs_struct *h, unsigned int id, uint64_t *eflags) | 
| 2111 | 833k | { | 
| 2112 | 833k |   unsigned int i = find_insn(id); | 
| 2113 | 833k |   if (i != -1) { | 
| 2114 | 833k |     *eflags = insn_ops[i].flags; | 
| 2115 | 833k |     return insn_ops[i].access; | 
| 2116 | 833k |   } | 
| 2117 |  |  | 
| 2118 | 0 |   return NULL; | 
| 2119 | 833k | } | 
| 2120 |  |  | 
| 2121 |  | void X86_reg_access(const cs_insn *insn, | 
| 2122 |  |     cs_regs regs_read, uint8_t *regs_read_count, | 
| 2123 |  |     cs_regs regs_write, uint8_t *regs_write_count) | 
| 2124 | 0 | { | 
| 2125 | 0 |   uint8_t i; | 
| 2126 | 0 |   uint8_t read_count, write_count; | 
| 2127 | 0 |   cs_x86 *x86 = &(insn->detail->x86); | 
| 2128 |  | 
 | 
| 2129 | 0 |   read_count = insn->detail->regs_read_count; | 
| 2130 | 0 |   write_count = insn->detail->regs_write_count; | 
| 2131 |  |  | 
| 2132 |  |   // implicit registers | 
| 2133 | 0 |   memcpy(regs_read, insn->detail->regs_read, read_count * sizeof(insn->detail->regs_read[0])); | 
| 2134 | 0 |   memcpy(regs_write, insn->detail->regs_write, write_count * sizeof(insn->detail->regs_write[0])); | 
| 2135 |  |  | 
| 2136 |  |   // explicit registers | 
| 2137 | 0 |   for (i = 0; i < x86->op_count; i++) { | 
| 2138 | 0 |     cs_x86_op *op = &(x86->operands[i]); | 
| 2139 | 0 |     switch((int)op->type) { | 
| 2140 | 0 |       case X86_OP_REG: | 
| 2141 | 0 |         if ((op->access & CS_AC_READ) && !arr_exist(regs_read, read_count, op->reg)) { | 
| 2142 | 0 |           regs_read[read_count] = op->reg; | 
| 2143 | 0 |           read_count++; | 
| 2144 | 0 |         } | 
| 2145 | 0 |         if ((op->access & CS_AC_WRITE) && !arr_exist(regs_write, write_count, op->reg)) { | 
| 2146 | 0 |           regs_write[write_count] = op->reg; | 
| 2147 | 0 |           write_count++; | 
| 2148 | 0 |         } | 
| 2149 | 0 |         break; | 
| 2150 | 0 |       case X86_OP_MEM: | 
| 2151 |  |         // registers appeared in memory references always being read | 
| 2152 | 0 |         if ((op->mem.segment != X86_REG_INVALID)) { | 
| 2153 | 0 |           regs_read[read_count] = op->mem.segment; | 
| 2154 | 0 |           read_count++; | 
| 2155 | 0 |         } | 
| 2156 | 0 |         if ((op->mem.base != X86_REG_INVALID) && !arr_exist(regs_read, read_count, op->mem.base)) { | 
| 2157 | 0 |           regs_read[read_count] = op->mem.base; | 
| 2158 | 0 |           read_count++; | 
| 2159 | 0 |         } | 
| 2160 | 0 |         if ((op->mem.index != X86_REG_INVALID) && !arr_exist(regs_read, read_count, op->mem.index)) { | 
| 2161 | 0 |           regs_read[read_count] = op->mem.index; | 
| 2162 | 0 |           read_count++; | 
| 2163 | 0 |         } | 
| 2164 | 0 |       default: | 
| 2165 | 0 |         break; | 
| 2166 | 0 |     } | 
| 2167 | 0 |   } | 
| 2168 |  |  | 
| 2169 | 0 |   *regs_read_count = read_count; | 
| 2170 | 0 |   *regs_write_count = write_count; | 
| 2171 | 0 | } | 
| 2172 |  | #endif | 
| 2173 |  |  | 
| 2174 |  | // map immediate size to instruction id | 
| 2175 |  | // this array is sorted for binary searching | 
| 2176 |  | static const struct size_id { | 
| 2177 |  |   uint8_t   enc_size; | 
| 2178 |  |   uint8_t   size; | 
| 2179 |  |   uint16_t  id; | 
| 2180 |  | } x86_imm_size[] = { | 
| 2181 |  | #include "X86ImmSize.inc" | 
| 2182 |  | }; | 
| 2183 |  |  | 
| 2184 |  | // given the instruction name, return the size of its immediate operand (or 0) | 
| 2185 |  | uint8_t X86_immediate_size(unsigned int id, uint8_t *enc_size) | 
| 2186 | 54.8k | { | 
| 2187 |  |   // binary searching since the IDs are sorted in order | 
| 2188 | 54.8k |   unsigned int left, right, m; | 
| 2189 |  |  | 
| 2190 | 54.8k |   right = ARR_SIZE(x86_imm_size) - 1; | 
| 2191 |  |  | 
| 2192 | 54.8k |   if (id < x86_imm_size[0].id || id > x86_imm_size[right].id) | 
| 2193 |  |     // not found | 
| 2194 | 0 |     return 0; | 
| 2195 |  |  | 
| 2196 | 54.8k |   left = 0; | 
| 2197 |  |  | 
| 2198 | 435k |   while (left <= right) { | 
| 2199 | 413k |     m = (left + right) / 2; | 
| 2200 | 413k |     if (id == x86_imm_size[m].id) { | 
| 2201 | 32.7k |       if (enc_size != NULL) | 
| 2202 | 32.1k |         *enc_size = x86_imm_size[m].enc_size; | 
| 2203 |  |  | 
| 2204 | 32.7k |       return x86_imm_size[m].size; | 
| 2205 | 32.7k |     } | 
| 2206 |  |  | 
| 2207 | 380k |     if (id > x86_imm_size[m].id) | 
| 2208 | 181k |       left = m + 1; | 
| 2209 | 198k |     else { | 
| 2210 | 198k |       if (m == 0) | 
| 2211 | 0 |         break; | 
| 2212 | 198k |       right = m - 1; | 
| 2213 | 198k |     } | 
| 2214 | 380k |   } | 
| 2215 |  |  | 
| 2216 |  |   // not found | 
| 2217 | 22.0k |   return 0; | 
| 2218 | 54.8k | } | 
| 2219 |  |  | 
| 2220 |  | #define GET_REGINFO_ENUM | 
| 2221 |  | #include "X86GenRegisterInfo.inc" | 
| 2222 |  |  | 
| 2223 |  | // map internal register id to public register id | 
| 2224 |  | static const struct register_map { | 
| 2225 |  |   unsigned short    id; | 
| 2226 |  |   unsigned short    pub_id; | 
| 2227 |  | } reg_map [] = { | 
| 2228 |  |   // first dummy map | 
| 2229 |  |   { 0, 0 }, | 
| 2230 |  | #include "X86MappingReg.inc" | 
| 2231 |  | }; | 
| 2232 |  |  | 
| 2233 |  | // return 0 on invalid input, or public register ID otherwise | 
| 2234 |  | // NOTE: reg_map is sorted in order of internal register | 
| 2235 |  | unsigned short X86_register_map(unsigned short id) | 
| 2236 | 909k | { | 
| 2237 | 909k |   if (id < ARR_SIZE(reg_map)) | 
| 2238 | 909k |     return reg_map[id].pub_id; | 
| 2239 |  |  | 
| 2240 | 0 |   return 0; | 
| 2241 | 909k | } | 
| 2242 |  |  | 
| 2243 |  | #endif |