1 //===-- X86ATTInstPrinter.cpp - AT&T assembly instruction printing --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file includes code for rendering MCInst instances as AT&T-style
11 // assembly.
12 //
13 //===----------------------------------------------------------------------===//
14
15 /* Capstone Disassembly Engine */
16 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
17
18 // this code is only relevant when DIET mode is disable
19 #if defined(CAPSTONE_HAS_X86) && !defined(CAPSTONE_DIET) && !defined(CAPSTONE_X86_ATT_DISABLE)
20
21 #if defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)
22 #pragma warning(disable:4996) // disable MSVC's warning on strncpy()
23 #pragma warning(disable:28719) // disable MSVC's warning on strncpy()
24 #endif
25
26 #if !defined(CAPSTONE_HAS_OSXKERNEL)
27 #include <ctype.h>
28 #endif
29 #include <capstone/platform.h>
30
31 #if defined(CAPSTONE_HAS_OSXKERNEL)
32 #include <Availability.h>
33 #include <libkern/libkern.h>
34 #else
35 #include <stdio.h>
36 #include <stdlib.h>
37 #endif
38
39 #include <string.h>
40
41 #include "../../utils.h"
42 #include "../../MCInst.h"
43 #include "../../SStream.h"
44 #include "../../MCRegisterInfo.h"
45 #include "X86Mapping.h"
46 #include "X86BaseInfo.h"
47
48
49 #define GET_INSTRINFO_ENUM
50 #ifdef CAPSTONE_X86_REDUCE
51 #include "X86GenInstrInfo_reduce.inc"
52 #else
53 #include "X86GenInstrInfo.inc"
54 #endif
55
56 static void printMemReference(MCInst *MI, unsigned Op, SStream *O);
57 static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
58
59
set_mem_access(MCInst * MI,bool status)60 static void set_mem_access(MCInst *MI, bool status)
61 {
62 if (MI->csh->detail != CS_OPT_ON)
63 return;
64
65 MI->csh->doing_mem = status;
66 if (!status)
67 // done, create the next operand slot
68 MI->flat_insn->detail->x86.op_count++;
69 }
70
printopaquemem(MCInst * MI,unsigned OpNo,SStream * O)71 static void printopaquemem(MCInst *MI, unsigned OpNo, SStream *O)
72 {
73 switch(MI->csh->mode) {
74 case CS_MODE_16:
75 switch(MI->flat_insn->id) {
76 default:
77 MI->x86opsize = 2;
78 break;
79 case X86_INS_LJMP:
80 case X86_INS_LCALL:
81 MI->x86opsize = 4;
82 break;
83 case X86_INS_SGDT:
84 case X86_INS_SIDT:
85 case X86_INS_LGDT:
86 case X86_INS_LIDT:
87 MI->x86opsize = 6;
88 break;
89 }
90 break;
91 case CS_MODE_32:
92 switch(MI->flat_insn->id) {
93 default:
94 MI->x86opsize = 4;
95 break;
96 case X86_INS_LJMP:
97 case X86_INS_LCALL:
98 case X86_INS_SGDT:
99 case X86_INS_SIDT:
100 case X86_INS_LGDT:
101 case X86_INS_LIDT:
102 MI->x86opsize = 6;
103 break;
104 }
105 break;
106 case CS_MODE_64:
107 switch(MI->flat_insn->id) {
108 default:
109 MI->x86opsize = 8;
110 break;
111 case X86_INS_LJMP:
112 case X86_INS_LCALL:
113 case X86_INS_SGDT:
114 case X86_INS_SIDT:
115 case X86_INS_LGDT:
116 case X86_INS_LIDT:
117 MI->x86opsize = 10;
118 break;
119 }
120 break;
121 default: // never reach
122 break;
123 }
124
125 printMemReference(MI, OpNo, O);
126 }
127
printi8mem(MCInst * MI,unsigned OpNo,SStream * O)128 static void printi8mem(MCInst *MI, unsigned OpNo, SStream *O)
129 {
130 MI->x86opsize = 1;
131 printMemReference(MI, OpNo, O);
132 }
133
printi16mem(MCInst * MI,unsigned OpNo,SStream * O)134 static void printi16mem(MCInst *MI, unsigned OpNo, SStream *O)
135 {
136 MI->x86opsize = 2;
137
138 printMemReference(MI, OpNo, O);
139 }
140
printi32mem(MCInst * MI,unsigned OpNo,SStream * O)141 static void printi32mem(MCInst *MI, unsigned OpNo, SStream *O)
142 {
143 MI->x86opsize = 4;
144
145 printMemReference(MI, OpNo, O);
146 }
147
printi64mem(MCInst * MI,unsigned OpNo,SStream * O)148 static void printi64mem(MCInst *MI, unsigned OpNo, SStream *O)
149 {
150 MI->x86opsize = 8;
151 printMemReference(MI, OpNo, O);
152 }
153
printi128mem(MCInst * MI,unsigned OpNo,SStream * O)154 static void printi128mem(MCInst *MI, unsigned OpNo, SStream *O)
155 {
156 MI->x86opsize = 16;
157 printMemReference(MI, OpNo, O);
158 }
159
160 #ifndef CAPSTONE_X86_REDUCE
printi256mem(MCInst * MI,unsigned OpNo,SStream * O)161 static void printi256mem(MCInst *MI, unsigned OpNo, SStream *O)
162 {
163 MI->x86opsize = 32;
164 printMemReference(MI, OpNo, O);
165 }
166
printi512mem(MCInst * MI,unsigned OpNo,SStream * O)167 static void printi512mem(MCInst *MI, unsigned OpNo, SStream *O)
168 {
169 MI->x86opsize = 64;
170 printMemReference(MI, OpNo, O);
171 }
172
printf32mem(MCInst * MI,unsigned OpNo,SStream * O)173 static void printf32mem(MCInst *MI, unsigned OpNo, SStream *O)
174 {
175 switch(MCInst_getOpcode(MI)) {
176 default:
177 MI->x86opsize = 4;
178 break;
179 case X86_FBSTPm:
180 case X86_FBLDm:
181 // TODO: fix this in tablegen instead
182 MI->x86opsize = 10;
183 break;
184 case X86_FSTENVm:
185 case X86_FLDENVm:
186 // TODO: fix this in tablegen instead
187 switch(MI->csh->mode) {
188 default: // never reach
189 break;
190 case CS_MODE_16:
191 MI->x86opsize = 14;
192 break;
193 case CS_MODE_32:
194 case CS_MODE_64:
195 MI->x86opsize = 28;
196 break;
197 }
198 break;
199 }
200
201 printMemReference(MI, OpNo, O);
202 }
203
printf64mem(MCInst * MI,unsigned OpNo,SStream * O)204 static void printf64mem(MCInst *MI, unsigned OpNo, SStream *O)
205 {
206 MI->x86opsize = 8;
207 printMemReference(MI, OpNo, O);
208 }
209
printf80mem(MCInst * MI,unsigned OpNo,SStream * O)210 static void printf80mem(MCInst *MI, unsigned OpNo, SStream *O)
211 {
212 MI->x86opsize = 10;
213 printMemReference(MI, OpNo, O);
214 }
215
printf128mem(MCInst * MI,unsigned OpNo,SStream * O)216 static void printf128mem(MCInst *MI, unsigned OpNo, SStream *O)
217 {
218 MI->x86opsize = 16;
219 printMemReference(MI, OpNo, O);
220 }
221
printf256mem(MCInst * MI,unsigned OpNo,SStream * O)222 static void printf256mem(MCInst *MI, unsigned OpNo, SStream *O)
223 {
224 MI->x86opsize = 32;
225 printMemReference(MI, OpNo, O);
226 }
227
printf512mem(MCInst * MI,unsigned OpNo,SStream * O)228 static void printf512mem(MCInst *MI, unsigned OpNo, SStream *O)
229 {
230 MI->x86opsize = 64;
231 printMemReference(MI, OpNo, O);
232 }
233
printSSECC(MCInst * MI,unsigned Op,SStream * OS)234 static void printSSECC(MCInst *MI, unsigned Op, SStream *OS)
235 {
236 uint8_t Imm = (uint8_t)(MCOperand_getImm(MCInst_getOperand(MI, Op)) & 7);
237 switch (Imm) {
238 default: break; // never reach
239 case 0: SStream_concat0(OS, "eq"); op_addSseCC(MI, X86_SSE_CC_EQ); break;
240 case 1: SStream_concat0(OS, "lt"); op_addSseCC(MI, X86_SSE_CC_LT); break;
241 case 2: SStream_concat0(OS, "le"); op_addSseCC(MI, X86_SSE_CC_LE); break;
242 case 3: SStream_concat0(OS, "unord"); op_addSseCC(MI, X86_SSE_CC_UNORD); break;
243 case 4: SStream_concat0(OS, "neq"); op_addSseCC(MI, X86_SSE_CC_NEQ); break;
244 case 5: SStream_concat0(OS, "nlt"); op_addSseCC(MI, X86_SSE_CC_NLT); break;
245 case 6: SStream_concat0(OS, "nle"); op_addSseCC(MI, X86_SSE_CC_NLE); break;
246 case 7: SStream_concat0(OS, "ord"); op_addSseCC(MI, X86_SSE_CC_ORD); break;
247 }
248
249 MI->popcode_adjust = Imm + 1;
250 }
251
printAVXCC(MCInst * MI,unsigned Op,SStream * O)252 static void printAVXCC(MCInst *MI, unsigned Op, SStream *O)
253 {
254 uint8_t Imm = (uint8_t)(MCOperand_getImm(MCInst_getOperand(MI, Op)) & 0x1f);
255 switch (Imm) {
256 default: break;//printf("Invalid avxcc argument!\n"); break;
257 case 0: SStream_concat0(O, "eq"); op_addAvxCC(MI, X86_AVX_CC_EQ); break;
258 case 1: SStream_concat0(O, "lt"); op_addAvxCC(MI, X86_AVX_CC_LT); break;
259 case 2: SStream_concat0(O, "le"); op_addAvxCC(MI, X86_AVX_CC_LE); break;
260 case 3: SStream_concat0(O, "unord"); op_addAvxCC(MI, X86_AVX_CC_UNORD); break;
261 case 4: SStream_concat0(O, "neq"); op_addAvxCC(MI, X86_AVX_CC_NEQ); break;
262 case 5: SStream_concat0(O, "nlt"); op_addAvxCC(MI, X86_AVX_CC_NLT); break;
263 case 6: SStream_concat0(O, "nle"); op_addAvxCC(MI, X86_AVX_CC_NLE); break;
264 case 7: SStream_concat0(O, "ord"); op_addAvxCC(MI, X86_AVX_CC_ORD); break;
265 case 8: SStream_concat0(O, "eq_uq"); op_addAvxCC(MI, X86_AVX_CC_EQ_UQ); break;
266 case 9: SStream_concat0(O, "nge"); op_addAvxCC(MI, X86_AVX_CC_NGE); break;
267 case 0xa: SStream_concat0(O, "ngt"); op_addAvxCC(MI, X86_AVX_CC_NGT); break;
268 case 0xb: SStream_concat0(O, "false"); op_addAvxCC(MI, X86_AVX_CC_FALSE); break;
269 case 0xc: SStream_concat0(O, "neq_oq"); op_addAvxCC(MI, X86_AVX_CC_NEQ_OQ); break;
270 case 0xd: SStream_concat0(O, "ge"); op_addAvxCC(MI, X86_AVX_CC_GE); break;
271 case 0xe: SStream_concat0(O, "gt"); op_addAvxCC(MI, X86_AVX_CC_GT); break;
272 case 0xf: SStream_concat0(O, "true"); op_addAvxCC(MI, X86_AVX_CC_TRUE); break;
273 case 0x10: SStream_concat0(O, "eq_os"); op_addAvxCC(MI, X86_AVX_CC_EQ_OS); break;
274 case 0x11: SStream_concat0(O, "lt_oq"); op_addAvxCC(MI, X86_AVX_CC_LT_OQ); break;
275 case 0x12: SStream_concat0(O, "le_oq"); op_addAvxCC(MI, X86_AVX_CC_LE_OQ); break;
276 case 0x13: SStream_concat0(O, "unord_s"); op_addAvxCC(MI, X86_AVX_CC_UNORD_S); break;
277 case 0x14: SStream_concat0(O, "neq_us"); op_addAvxCC(MI, X86_AVX_CC_NEQ_US); break;
278 case 0x15: SStream_concat0(O, "nlt_uq"); op_addAvxCC(MI, X86_AVX_CC_NLT_UQ); break;
279 case 0x16: SStream_concat0(O, "nle_uq"); op_addAvxCC(MI, X86_AVX_CC_NLE_UQ); break;
280 case 0x17: SStream_concat0(O, "ord_s"); op_addAvxCC(MI, X86_AVX_CC_ORD_S); break;
281 case 0x18: SStream_concat0(O, "eq_us"); op_addAvxCC(MI, X86_AVX_CC_EQ_US); break;
282 case 0x19: SStream_concat0(O, "nge_uq"); op_addAvxCC(MI, X86_AVX_CC_NGE_UQ); break;
283 case 0x1a: SStream_concat0(O, "ngt_uq"); op_addAvxCC(MI, X86_AVX_CC_NGT_UQ); break;
284 case 0x1b: SStream_concat0(O, "false_os"); op_addAvxCC(MI, X86_AVX_CC_FALSE_OS); break;
285 case 0x1c: SStream_concat0(O, "neq_os"); op_addAvxCC(MI, X86_AVX_CC_NEQ_OS); break;
286 case 0x1d: SStream_concat0(O, "ge_oq"); op_addAvxCC(MI, X86_AVX_CC_GE_OQ); break;
287 case 0x1e: SStream_concat0(O, "gt_oq"); op_addAvxCC(MI, X86_AVX_CC_GT_OQ); break;
288 case 0x1f: SStream_concat0(O, "true_us"); op_addAvxCC(MI, X86_AVX_CC_TRUE_US); break;
289 }
290
291 MI->popcode_adjust = Imm + 1;
292 }
293
printXOPCC(MCInst * MI,unsigned Op,SStream * O)294 static void printXOPCC(MCInst *MI, unsigned Op, SStream *O)
295 {
296 int64_t Imm = MCOperand_getImm(MCInst_getOperand(MI, Op));
297
298 switch (Imm) {
299 default: // llvm_unreachable("Invalid xopcc argument!");
300 case 0: SStream_concat0(O, "lt"); op_addXopCC(MI, X86_XOP_CC_LT); break;
301 case 1: SStream_concat0(O, "le"); op_addXopCC(MI, X86_XOP_CC_LE); break;
302 case 2: SStream_concat0(O, "gt"); op_addXopCC(MI, X86_XOP_CC_GT); break;
303 case 3: SStream_concat0(O, "ge"); op_addXopCC(MI, X86_XOP_CC_GE); break;
304 case 4: SStream_concat0(O, "eq"); op_addXopCC(MI, X86_XOP_CC_EQ); break;
305 case 5: SStream_concat0(O, "neq"); op_addXopCC(MI, X86_XOP_CC_NEQ); break;
306 case 6: SStream_concat0(O, "false"); op_addXopCC(MI, X86_XOP_CC_FALSE); break;
307 case 7: SStream_concat0(O, "true"); op_addXopCC(MI, X86_XOP_CC_TRUE); break;
308 }
309 }
310
printRoundingControl(MCInst * MI,unsigned Op,SStream * O)311 static void printRoundingControl(MCInst *MI, unsigned Op, SStream *O)
312 {
313 int64_t Imm = MCOperand_getImm(MCInst_getOperand(MI, Op)) & 0x3;
314 switch (Imm) {
315 case 0: SStream_concat0(O, "{rn-sae}"); op_addAvxSae(MI); op_addAvxRoundingMode(MI, X86_AVX_RM_RN); break;
316 case 1: SStream_concat0(O, "{rd-sae}"); op_addAvxSae(MI); op_addAvxRoundingMode(MI, X86_AVX_RM_RD); break;
317 case 2: SStream_concat0(O, "{ru-sae}"); op_addAvxSae(MI); op_addAvxRoundingMode(MI, X86_AVX_RM_RU); break;
318 case 3: SStream_concat0(O, "{rz-sae}"); op_addAvxSae(MI); op_addAvxRoundingMode(MI, X86_AVX_RM_RZ); break;
319 default: break; // nev0er reach
320 }
321 }
322
323 #endif
324
325 static void printRegName(SStream *OS, unsigned RegNo);
326
327 // local printOperand, without updating public operands
_printOperand(MCInst * MI,unsigned OpNo,SStream * O)328 static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
329 {
330 MCOperand *Op = MCInst_getOperand(MI, OpNo);
331 if (MCOperand_isReg(Op)) {
332 printRegName(O, MCOperand_getReg(Op));
333 } else if (MCOperand_isImm(Op)) {
334 uint8_t encsize;
335 uint8_t opsize = X86_immediate_size(MCInst_getOpcode(MI), &encsize);
336
337 // Print X86 immediates as signed values.
338 int64_t imm = MCOperand_getImm(Op);
339 if (imm < 0) {
340 if (MI->csh->imm_unsigned) {
341 if (opsize) {
342 switch(opsize) {
343 default:
344 break;
345 case 1:
346 imm &= 0xff;
347 break;
348 case 2:
349 imm &= 0xffff;
350 break;
351 case 4:
352 imm &= 0xffffffff;
353 break;
354 }
355 }
356
357 SStream_concat(O, "$0x%"PRIx64, imm);
358 } else {
359 if (imm < -HEX_THRESHOLD)
360 SStream_concat(O, "$-0x%"PRIx64, -imm);
361 else
362 SStream_concat(O, "$-%"PRIu64, -imm);
363 }
364 } else {
365 if (imm > HEX_THRESHOLD)
366 SStream_concat(O, "$0x%"PRIx64, imm);
367 else
368 SStream_concat(O, "$%"PRIu64, imm);
369 }
370 }
371 }
372
373 // convert Intel access info to AT&T access info
get_op_access(cs_struct * h,unsigned int id,uint8_t * access,uint64_t * eflags)374 static void get_op_access(cs_struct *h, unsigned int id, uint8_t *access, uint64_t *eflags)
375 {
376 uint8_t count, i;
377 uint8_t *arr = X86_get_op_access(h, id, eflags);
378
379 if (!arr) {
380 access[0] = 0;
381 return;
382 }
383
384 // find the non-zero last entry
385 for(count = 0; arr[count]; count++);
386
387 if (count == 0)
388 return;
389
390 // copy in reverse order this access array from Intel syntax -> AT&T syntax
391 count--;
392 for(i = 0; i <= count; i++) {
393 if (arr[count - i] != CS_AC_IGNORE)
394 access[i] = arr[count - i];
395 else
396 access[i] = 0;
397 }
398 }
399
printSrcIdx(MCInst * MI,unsigned Op,SStream * O)400 static void printSrcIdx(MCInst *MI, unsigned Op, SStream *O)
401 {
402 MCOperand *SegReg;
403 int reg;
404
405 if (MI->csh->detail) {
406 uint8_t access[6];
407
408 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
409 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
410 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
411 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
412 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
413 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
414 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
415
416 get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
417 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
418 }
419
420 SegReg = MCInst_getOperand(MI, Op+1);
421 reg = MCOperand_getReg(SegReg);
422
423 // If this has a segment register, print it.
424 if (reg) {
425 _printOperand(MI, Op+1, O);
426 if (MI->csh->detail) {
427 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = reg;
428 }
429
430 SStream_concat0(O, ":");
431 }
432
433 SStream_concat0(O, "(");
434 set_mem_access(MI, true);
435
436 printOperand(MI, Op, O);
437
438 SStream_concat0(O, ")");
439 set_mem_access(MI, false);
440 }
441
printDstIdx(MCInst * MI,unsigned Op,SStream * O)442 static void printDstIdx(MCInst *MI, unsigned Op, SStream *O)
443 {
444 if (MI->csh->detail) {
445 uint8_t access[6];
446
447 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
448 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
449 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
450 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
451 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
452 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
453 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
454
455 get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
456 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
457 }
458
459 // DI accesses are always ES-based on non-64bit mode
460 if (MI->csh->mode != CS_MODE_64) {
461 SStream_concat0(O, "%es:(");
462 if (MI->csh->detail) {
463 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_ES;
464 }
465 } else
466 SStream_concat0(O, "(");
467
468 set_mem_access(MI, true);
469
470 printOperand(MI, Op, O);
471
472 SStream_concat0(O, ")");
473 set_mem_access(MI, false);
474 }
475
printSrcIdx8(MCInst * MI,unsigned OpNo,SStream * O)476 static void printSrcIdx8(MCInst *MI, unsigned OpNo, SStream *O)
477 {
478 MI->x86opsize = 1;
479 printSrcIdx(MI, OpNo, O);
480 }
481
printSrcIdx16(MCInst * MI,unsigned OpNo,SStream * O)482 static void printSrcIdx16(MCInst *MI, unsigned OpNo, SStream *O)
483 {
484 MI->x86opsize = 2;
485 printSrcIdx(MI, OpNo, O);
486 }
487
printSrcIdx32(MCInst * MI,unsigned OpNo,SStream * O)488 static void printSrcIdx32(MCInst *MI, unsigned OpNo, SStream *O)
489 {
490 MI->x86opsize = 4;
491 printSrcIdx(MI, OpNo, O);
492 }
493
printSrcIdx64(MCInst * MI,unsigned OpNo,SStream * O)494 static void printSrcIdx64(MCInst *MI, unsigned OpNo, SStream *O)
495 {
496 MI->x86opsize = 8;
497 printSrcIdx(MI, OpNo, O);
498 }
499
printDstIdx8(MCInst * MI,unsigned OpNo,SStream * O)500 static void printDstIdx8(MCInst *MI, unsigned OpNo, SStream *O)
501 {
502 MI->x86opsize = 1;
503 printDstIdx(MI, OpNo, O);
504 }
505
printDstIdx16(MCInst * MI,unsigned OpNo,SStream * O)506 static void printDstIdx16(MCInst *MI, unsigned OpNo, SStream *O)
507 {
508 MI->x86opsize = 2;
509 printDstIdx(MI, OpNo, O);
510 }
511
printDstIdx32(MCInst * MI,unsigned OpNo,SStream * O)512 static void printDstIdx32(MCInst *MI, unsigned OpNo, SStream *O)
513 {
514 MI->x86opsize = 4;
515 printDstIdx(MI, OpNo, O);
516 }
517
printDstIdx64(MCInst * MI,unsigned OpNo,SStream * O)518 static void printDstIdx64(MCInst *MI, unsigned OpNo, SStream *O)
519 {
520 MI->x86opsize = 8;
521 printDstIdx(MI, OpNo, O);
522 }
523
printMemOffset(MCInst * MI,unsigned Op,SStream * O)524 static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
525 {
526 MCOperand *DispSpec = MCInst_getOperand(MI, Op);
527 MCOperand *SegReg = MCInst_getOperand(MI, Op+1);
528 int reg;
529
530 if (MI->csh->detail) {
531 uint8_t access[6];
532
533 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
534 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
535 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
536 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
537 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
538 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
539 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
540
541 get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
542 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
543 }
544
545 // If this has a segment register, print it.
546 reg = MCOperand_getReg(SegReg);
547 if (reg) {
548 _printOperand(MI, Op + 1, O);
549 SStream_concat0(O, ":");
550 if (MI->csh->detail) {
551 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = reg;
552 }
553 }
554
555 if (MCOperand_isImm(DispSpec)) {
556 int64_t imm = MCOperand_getImm(DispSpec);
557 if (MI->csh->detail)
558 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = imm;
559 if (imm < 0) {
560 SStream_concat(O, "0x%"PRIx64, arch_masks[MI->csh->mode] & imm);
561 } else {
562 if (imm > HEX_THRESHOLD)
563 SStream_concat(O, "0x%"PRIx64, imm);
564 else
565 SStream_concat(O, "%"PRIu64, imm);
566 }
567 }
568
569 if (MI->csh->detail)
570 MI->flat_insn->detail->x86.op_count++;
571 }
572
573 #ifndef CAPSTONE_X86_REDUCE
printU8Imm(MCInst * MI,unsigned Op,SStream * O)574 static void printU8Imm(MCInst *MI, unsigned Op, SStream *O)
575 {
576 uint8_t val = MCOperand_getImm(MCInst_getOperand(MI, Op)) & 0xff;
577
578 if (val > HEX_THRESHOLD)
579 SStream_concat(O, "$0x%x", val);
580 else
581 SStream_concat(O, "$%u", val);
582
583 if (MI->csh->detail) {
584 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
585 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = val;
586 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = 1;
587 MI->flat_insn->detail->x86.op_count++;
588 }
589 }
590 #endif
591
printMemOffs8(MCInst * MI,unsigned OpNo,SStream * O)592 static void printMemOffs8(MCInst *MI, unsigned OpNo, SStream *O)
593 {
594 MI->x86opsize = 1;
595 printMemOffset(MI, OpNo, O);
596 }
597
printMemOffs16(MCInst * MI,unsigned OpNo,SStream * O)598 static void printMemOffs16(MCInst *MI, unsigned OpNo, SStream *O)
599 {
600 MI->x86opsize = 2;
601 printMemOffset(MI, OpNo, O);
602 }
603
printMemOffs32(MCInst * MI,unsigned OpNo,SStream * O)604 static void printMemOffs32(MCInst *MI, unsigned OpNo, SStream *O)
605 {
606 MI->x86opsize = 4;
607 printMemOffset(MI, OpNo, O);
608 }
609
printMemOffs64(MCInst * MI,unsigned OpNo,SStream * O)610 static void printMemOffs64(MCInst *MI, unsigned OpNo, SStream *O)
611 {
612 MI->x86opsize = 8;
613 printMemOffset(MI, OpNo, O);
614 }
615
616 /// printPCRelImm - This is used to print an immediate value that ends up
617 /// being encoded as a pc-relative value (e.g. for jumps and calls). These
618 /// print slightly differently than normal immediates. For example, a $ is not
619 /// emitted.
printPCRelImm(MCInst * MI,unsigned OpNo,SStream * O)620 static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O)
621 {
622 MCOperand *Op = MCInst_getOperand(MI, OpNo);
623 if (MCOperand_isImm(Op)) {
624 int64_t imm = MCOperand_getImm(Op) + MI->flat_insn->size + MI->address;
625
626 // truncat imm for non-64bit
627 if (MI->csh->mode != CS_MODE_64) {
628 imm = imm & 0xffffffff;
629 }
630
631 if (MI->csh->mode == CS_MODE_16 &&
632 (MI->Opcode != X86_JMP_4 && MI->Opcode != X86_CALLpcrel32))
633 imm = imm & 0xffff;
634
635 // Hack: X86 16bit with opcode X86_JMP_4
636 if (MI->csh->mode == CS_MODE_16 &&
637 (MI->Opcode == X86_JMP_4 && MI->x86_prefix[2] != 0x66))
638 imm = imm & 0xffff;
639
640 // CALL/JMP rel16 is special
641 if (MI->Opcode == X86_CALLpcrel16 || MI->Opcode == X86_JMP_2)
642 imm = imm & 0xffff;
643
644 if (imm < 0) {
645 SStream_concat(O, "0x%"PRIx64, imm);
646 } else {
647 if (imm > HEX_THRESHOLD)
648 SStream_concat(O, "0x%"PRIx64, imm);
649 else
650 SStream_concat(O, "%"PRIu64, imm);
651 }
652 if (MI->csh->detail) {
653 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
654 MI->has_imm = true;
655 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
656 MI->flat_insn->detail->x86.op_count++;
657 }
658 }
659 }
660
printOperand(MCInst * MI,unsigned OpNo,SStream * O)661 static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
662 {
663 MCOperand *Op = MCInst_getOperand(MI, OpNo);
664 if (MCOperand_isReg(Op)) {
665 unsigned int reg = MCOperand_getReg(Op);
666 printRegName(O, reg);
667 if (MI->csh->detail) {
668 if (MI->csh->doing_mem) {
669 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = reg;
670 } else {
671 uint8_t access[6];
672
673 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_REG;
674 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].reg = reg;
675 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->csh->regsize_map[reg];
676
677 get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
678 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
679
680 MI->flat_insn->detail->x86.op_count++;
681 }
682 }
683 } else if (MCOperand_isImm(Op)) {
684 // Print X86 immediates as signed values.
685 uint8_t encsize;
686 int64_t imm = MCOperand_getImm(Op);
687 uint8_t opsize = X86_immediate_size(MCInst_getOpcode(MI), &encsize);
688
689 if (opsize == 1) // print 1 byte immediate in positive form
690 imm = imm & 0xff;
691
692 switch(MI->flat_insn->id) {
693 default:
694 if (imm >= 0) {
695 if (imm > HEX_THRESHOLD)
696 SStream_concat(O, "$0x%"PRIx64, imm);
697 else
698 SStream_concat(O, "$%"PRIu64, imm);
699 } else {
700 if (MI->csh->imm_unsigned) {
701 if (opsize) {
702 switch(opsize) {
703 default:
704 break;
705 case 1:
706 imm &= 0xff;
707 break;
708 case 2:
709 imm &= 0xffff;
710 break;
711 case 4:
712 imm &= 0xffffffff;
713 break;
714 }
715 }
716
717 SStream_concat(O, "$0x%"PRIx64, imm);
718 } else {
719 if (imm == 0x8000000000000000LL) // imm == -imm
720 SStream_concat0(O, "$0x8000000000000000");
721 else if (imm < -HEX_THRESHOLD)
722 SStream_concat(O, "$-0x%"PRIx64, -imm);
723 else
724 SStream_concat(O, "$-%"PRIu64, -imm);
725 }
726 }
727 break;
728
729 case X86_INS_MOVABS:
730 // do not print number in negative form
731 SStream_concat(O, "$0x%"PRIx64, imm);
732 break;
733
734 case X86_INS_IN:
735 case X86_INS_OUT:
736 case X86_INS_INT:
737 // do not print number in negative form
738 imm = imm & 0xff;
739 if (imm >= 0 && imm <= HEX_THRESHOLD)
740 SStream_concat(O, "$%u", imm);
741 else {
742 SStream_concat(O, "$0x%x", imm);
743 }
744 break;
745
746 case X86_INS_LCALL:
747 case X86_INS_LJMP:
748 // always print address in positive form
749 if (OpNo == 1) { // selector is ptr16
750 imm = imm & 0xffff;
751 opsize = 2;
752 }
753 SStream_concat(O, "$0x%"PRIx64, imm);
754 break;
755
756 case X86_INS_AND:
757 case X86_INS_OR:
758 case X86_INS_XOR:
759 // do not print number in negative form
760 if (imm >= 0 && imm <= HEX_THRESHOLD)
761 SStream_concat(O, "$%u", imm);
762 else {
763 imm = arch_masks[opsize? opsize : MI->imm_size] & imm;
764 SStream_concat(O, "$0x%"PRIx64, imm);
765 }
766 break;
767
768 case X86_INS_RET:
769 case X86_INS_RETF:
770 // RET imm16
771 if (imm >= 0 && imm <= HEX_THRESHOLD)
772 SStream_concat(O, "$%u", imm);
773 else {
774 imm = 0xffff & imm;
775 SStream_concat(O, "$0x%x", imm);
776 }
777 break;
778 }
779
780 if (MI->csh->detail) {
781 if (MI->csh->doing_mem) {
782 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
783 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = imm;
784 } else {
785 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
786 MI->has_imm = true;
787 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
788
789 if (opsize > 0) {
790 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
791 MI->flat_insn->detail->x86.encoding.imm_size = encsize;
792 } else if (MI->op1_size > 0)
793 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->op1_size;
794 else
795 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
796
797 MI->flat_insn->detail->x86.op_count++;
798 }
799 }
800 }
801 }
802
printMemReference(MCInst * MI,unsigned Op,SStream * O)803 static void printMemReference(MCInst *MI, unsigned Op, SStream *O)
804 {
805 MCOperand *BaseReg = MCInst_getOperand(MI, Op + X86_AddrBaseReg);
806 MCOperand *IndexReg = MCInst_getOperand(MI, Op + X86_AddrIndexReg);
807 MCOperand *DispSpec = MCInst_getOperand(MI, Op + X86_AddrDisp);
808 MCOperand *SegReg = MCInst_getOperand(MI, Op + X86_AddrSegmentReg);
809 uint64_t ScaleVal;
810 int segreg;
811 int64_t DispVal = 1;
812
813 if (MI->csh->detail) {
814 uint8_t access[6];
815
816 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
817 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
818 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
819 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = MCOperand_getReg(BaseReg);
820 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = MCOperand_getReg(IndexReg);
821 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
822 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
823
824 get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
825 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
826 }
827
828 // If this has a segment register, print it.
829 segreg = MCOperand_getReg(SegReg);
830 if (segreg) {
831 _printOperand(MI, Op + X86_AddrSegmentReg, O);
832 if (MI->csh->detail) {
833 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = segreg;
834 }
835
836 SStream_concat0(O, ":");
837 }
838
839 if (MCOperand_isImm(DispSpec)) {
840 DispVal = MCOperand_getImm(DispSpec);
841 if (MI->csh->detail)
842 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = DispVal;
843 if (DispVal) {
844 if (MCOperand_getReg(IndexReg) || MCOperand_getReg(BaseReg)) {
845 printInt64(O, DispVal);
846 } else {
847 // only immediate as address of memory
848 if (DispVal < 0) {
849 SStream_concat(O, "0x%"PRIx64, arch_masks[MI->csh->mode] & DispVal);
850 } else {
851 if (DispVal > HEX_THRESHOLD)
852 SStream_concat(O, "0x%"PRIx64, DispVal);
853 else
854 SStream_concat(O, "%"PRIu64, DispVal);
855 }
856 }
857 } else {
858 }
859 }
860
861 if (MCOperand_getReg(IndexReg) || MCOperand_getReg(BaseReg)) {
862 SStream_concat0(O, "(");
863
864 if (MCOperand_getReg(BaseReg))
865 _printOperand(MI, Op + X86_AddrBaseReg, O);
866
867 if (MCOperand_getReg(IndexReg)) {
868 SStream_concat0(O, ", ");
869 _printOperand(MI, Op + X86_AddrIndexReg, O);
870 ScaleVal = MCOperand_getImm(MCInst_getOperand(MI, Op + X86_AddrScaleAmt));
871 if (MI->csh->detail)
872 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = (int)ScaleVal;
873 if (ScaleVal != 1) {
874 SStream_concat(O, ", %u", ScaleVal);
875 }
876 }
877 SStream_concat0(O, ")");
878 } else {
879 if (!DispVal)
880 SStream_concat0(O, "0");
881 }
882
883 if (MI->csh->detail)
884 MI->flat_insn->detail->x86.op_count++;
885 }
886
printanymem(MCInst * MI,unsigned OpNo,SStream * O)887 static void printanymem(MCInst *MI, unsigned OpNo, SStream *O)
888 {
889 switch(MI->Opcode) {
890 default: break;
891 case X86_LEA16r:
892 MI->x86opsize = 2;
893 break;
894 case X86_LEA32r:
895 case X86_LEA64_32r:
896 MI->x86opsize = 4;
897 break;
898 case X86_LEA64r:
899 MI->x86opsize = 8;
900 break;
901 }
902 printMemReference(MI, OpNo, O);
903 }
904
905 #include "X86InstPrinter.h"
906
907 #define GET_REGINFO_ENUM
908 #include "X86GenRegisterInfo.inc"
909
910 // Include the auto-generated portion of the assembly writer.
911 #define PRINT_ALIAS_INSTR
912 #ifdef CAPSTONE_X86_REDUCE
913 #include "X86GenAsmWriter_reduce.inc"
914 #else
915 #include "X86GenAsmWriter.inc"
916 #endif
917
printRegName(SStream * OS,unsigned RegNo)918 static void printRegName(SStream *OS, unsigned RegNo)
919 {
920 SStream_concat(OS, "%%%s", getRegisterName(RegNo));
921 }
922
X86_ATT_printInst(MCInst * MI,SStream * OS,void * info)923 void X86_ATT_printInst(MCInst *MI, SStream *OS, void *info)
924 {
925 char *mnem;
926 x86_reg reg, reg2;
927 enum cs_ac_type access1, access2;
928 int i;
929
930 // perhaps this instruction does not need printer
931 if (MI->assembly[0]) {
932 strncpy(OS->buffer, MI->assembly, sizeof(OS->buffer));
933 return;
934 }
935
936 // Output CALLpcrel32 as "callq" in 64-bit mode.
937 // In Intel annotation it's always emitted as "call".
938 //
939 // TODO: Probably this hack should be redesigned via InstAlias in
940 // InstrInfo.td as soon as Requires clause is supported properly
941 // for InstAlias.
942 if (MI->csh->mode == CS_MODE_64 && MCInst_getOpcode(MI) == X86_CALLpcrel32) {
943 SStream_concat0(OS, "callq\t");
944 MCInst_setOpcodePub(MI, X86_INS_CALL);
945 printPCRelImm(MI, 0, OS);
946 return;
947 }
948
949 // Try to print any aliases first.
950 mnem = printAliasInstr(MI, OS, info);
951 if (mnem)
952 cs_mem_free(mnem);
953 else
954 printInstruction(MI, OS, info);
955
956 // HACK TODO: fix this in machine description
957 switch(MI->flat_insn->id) {
958 default: break;
959 case X86_INS_SYSEXIT:
960 SStream_Init(OS);
961 SStream_concat0(OS, "sysexit");
962 break;
963 }
964
965 if (MI->has_imm) {
966 // if op_count > 1, then this operand's size is taken from the destination op
967 if (MI->flat_insn->detail->x86.op_count > 1) {
968 if (MI->flat_insn->id != X86_INS_LCALL && MI->flat_insn->id != X86_INS_LJMP) {
969 for (i = 0; i < MI->flat_insn->detail->x86.op_count; i++) {
970 if (MI->flat_insn->detail->x86.operands[i].type == X86_OP_IMM)
971 MI->flat_insn->detail->x86.operands[i].size =
972 MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count - 1].size;
973 }
974 }
975 } else
976 MI->flat_insn->detail->x86.operands[0].size = MI->imm_size;
977 }
978
979 if (MI->csh->detail) {
980 uint8_t access[6] = {0};
981
982 // some instructions need to supply immediate 1 in the first op
983 switch(MCInst_getOpcode(MI)) {
984 default:
985 break;
986 case X86_SHL8r1:
987 case X86_SHL16r1:
988 case X86_SHL32r1:
989 case X86_SHL64r1:
990 case X86_SAL8r1:
991 case X86_SAL16r1:
992 case X86_SAL32r1:
993 case X86_SAL64r1:
994 case X86_SHR8r1:
995 case X86_SHR16r1:
996 case X86_SHR32r1:
997 case X86_SHR64r1:
998 case X86_SAR8r1:
999 case X86_SAR16r1:
1000 case X86_SAR32r1:
1001 case X86_SAR64r1:
1002 case X86_RCL8r1:
1003 case X86_RCL16r1:
1004 case X86_RCL32r1:
1005 case X86_RCL64r1:
1006 case X86_RCR8r1:
1007 case X86_RCR16r1:
1008 case X86_RCR32r1:
1009 case X86_RCR64r1:
1010 case X86_ROL8r1:
1011 case X86_ROL16r1:
1012 case X86_ROL32r1:
1013 case X86_ROL64r1:
1014 case X86_ROR8r1:
1015 case X86_ROR16r1:
1016 case X86_ROR32r1:
1017 case X86_ROR64r1:
1018 case X86_SHL8m1:
1019 case X86_SHL16m1:
1020 case X86_SHL32m1:
1021 case X86_SHL64m1:
1022 case X86_SAL8m1:
1023 case X86_SAL16m1:
1024 case X86_SAL32m1:
1025 case X86_SAL64m1:
1026 case X86_SHR8m1:
1027 case X86_SHR16m1:
1028 case X86_SHR32m1:
1029 case X86_SHR64m1:
1030 case X86_SAR8m1:
1031 case X86_SAR16m1:
1032 case X86_SAR32m1:
1033 case X86_SAR64m1:
1034 case X86_RCL8m1:
1035 case X86_RCL16m1:
1036 case X86_RCL32m1:
1037 case X86_RCL64m1:
1038 case X86_RCR8m1:
1039 case X86_RCR16m1:
1040 case X86_RCR32m1:
1041 case X86_RCR64m1:
1042 case X86_ROL8m1:
1043 case X86_ROL16m1:
1044 case X86_ROL32m1:
1045 case X86_ROL64m1:
1046 case X86_ROR8m1:
1047 case X86_ROR16m1:
1048 case X86_ROR32m1:
1049 case X86_ROR64m1:
1050 // shift all the ops right to leave 1st slot for this new register op
1051 memmove(&(MI->flat_insn->detail->x86.operands[1]), &(MI->flat_insn->detail->x86.operands[0]),
1052 sizeof(MI->flat_insn->detail->x86.operands[0]) * (ARR_SIZE(MI->flat_insn->detail->x86.operands) - 1));
1053 MI->flat_insn->detail->x86.operands[0].type = X86_OP_IMM;
1054 MI->flat_insn->detail->x86.operands[0].imm = 1;
1055 MI->flat_insn->detail->x86.operands[0].size = 1;
1056 MI->flat_insn->detail->x86.op_count++;
1057 }
1058
1059 // special instruction needs to supply register op
1060 // first op can be embedded in the asm by llvm.
1061 // so we have to add the missing register as the first operand
1062
1063 //printf(">>> opcode = %u\n", MCInst_getOpcode(MI));
1064
1065 reg = X86_insn_reg_att(MCInst_getOpcode(MI), &access1);
1066 if (reg) {
1067 // shift all the ops right to leave 1st slot for this new register op
1068 memmove(&(MI->flat_insn->detail->x86.operands[1]), &(MI->flat_insn->detail->x86.operands[0]),
1069 sizeof(MI->flat_insn->detail->x86.operands[0]) * (ARR_SIZE(MI->flat_insn->detail->x86.operands) - 1));
1070 MI->flat_insn->detail->x86.operands[0].type = X86_OP_REG;
1071 MI->flat_insn->detail->x86.operands[0].reg = reg;
1072 MI->flat_insn->detail->x86.operands[0].size = MI->csh->regsize_map[reg];
1073 MI->flat_insn->detail->x86.operands[0].access = access1;
1074
1075 MI->flat_insn->detail->x86.op_count++;
1076 } else {
1077 if (X86_insn_reg_att2(MCInst_getOpcode(MI), ®, &access1, ®2, &access2)) {
1078
1079 MI->flat_insn->detail->x86.operands[0].type = X86_OP_REG;
1080 MI->flat_insn->detail->x86.operands[0].reg = reg;
1081 MI->flat_insn->detail->x86.operands[0].size = MI->csh->regsize_map[reg];
1082 MI->flat_insn->detail->x86.operands[0].access = access1;
1083 MI->flat_insn->detail->x86.operands[1].type = X86_OP_REG;
1084 MI->flat_insn->detail->x86.operands[1].reg = reg2;
1085 MI->flat_insn->detail->x86.operands[1].size = MI->csh->regsize_map[reg2];
1086 MI->flat_insn->detail->x86.operands[0].access = access2;
1087 MI->flat_insn->detail->x86.op_count = 2;
1088 }
1089 }
1090
1091 #ifndef CAPSTONE_DIET
1092 get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
1093 MI->flat_insn->detail->x86.operands[0].access = access[0];
1094 MI->flat_insn->detail->x86.operands[1].access = access[1];
1095 #endif
1096 }
1097 }
1098
1099 #endif
1100