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