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