Maybe if I touch this file the buildbots will actually rerun configure like they...
[oota-llvm.git] / lib / Target / X86 / Disassembler / X86DisassemblerDecoder.h
1 //===-- X86DisassemblerDecoderInternal.h - Disassembler decoder -*- C++ -*-===//
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 is part of the X86 Disassembler.
11 // It contains the public interface of the instruction decoder.
12 // Documentation for the disassembler can be found in X86Disassembler.h.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef X86DISASSEMBLERDECODER_H
17 #define X86DISASSEMBLERDECODER_H
18
19 #define INSTRUCTION_SPECIFIER_FIELDS \
20   uint16_t operands;
21
22 #define INSTRUCTION_IDS     \
23   uint16_t instructionIDs;
24
25 #include "X86DisassemblerDecoderCommon.h"
26
27 #undef INSTRUCTION_SPECIFIER_FIELDS
28 #undef INSTRUCTION_IDS
29
30 namespace llvm {
31 namespace X86Disassembler {
32
33 /*
34  * Accessor functions for various fields of an Intel instruction
35  */
36 #define modFromModRM(modRM)  (((modRM) & 0xc0) >> 6)
37 #define regFromModRM(modRM)  (((modRM) & 0x38) >> 3)
38 #define rmFromModRM(modRM)   ((modRM) & 0x7)
39 #define scaleFromSIB(sib)    (((sib) & 0xc0) >> 6)
40 #define indexFromSIB(sib)    (((sib) & 0x38) >> 3)
41 #define baseFromSIB(sib)     ((sib) & 0x7)
42 #define wFromREX(rex)        (((rex) & 0x8) >> 3)
43 #define rFromREX(rex)        (((rex) & 0x4) >> 2)
44 #define xFromREX(rex)        (((rex) & 0x2) >> 1)
45 #define bFromREX(rex)        ((rex) & 0x1)
46
47 #define rFromEVEX2of4(evex)     (((~(evex)) & 0x80) >> 7)
48 #define xFromEVEX2of4(evex)     (((~(evex)) & 0x40) >> 6)
49 #define bFromEVEX2of4(evex)     (((~(evex)) & 0x20) >> 5)
50 #define r2FromEVEX2of4(evex)    (((~(evex)) & 0x10) >> 4)
51 #define mmFromEVEX2of4(evex)    ((evex) & 0x3)
52 #define wFromEVEX3of4(evex)     (((evex) & 0x80) >> 7)
53 #define vvvvFromEVEX3of4(evex)  (((~(evex)) & 0x78) >> 3)
54 #define ppFromEVEX3of4(evex)    ((evex) & 0x3)
55 #define zFromEVEX4of4(evex)     (((evex) & 0x80) >> 7)
56 #define l2FromEVEX4of4(evex)    (((evex) & 0x40) >> 6)
57 #define lFromEVEX4of4(evex)     (((evex) & 0x20) >> 5)
58 #define bFromEVEX4of4(evex)     (((evex) & 0x10) >> 4)
59 #define v2FromEVEX4of4(evex)    (((~evex) & 0x8) >> 3)
60 #define aaaFromEVEX4of4(evex)   ((evex) & 0x7)
61
62 #define rFromVEX2of3(vex)       (((~(vex)) & 0x80) >> 7)
63 #define xFromVEX2of3(vex)       (((~(vex)) & 0x40) >> 6)
64 #define bFromVEX2of3(vex)       (((~(vex)) & 0x20) >> 5)
65 #define mmmmmFromVEX2of3(vex)   ((vex) & 0x1f)
66 #define wFromVEX3of3(vex)       (((vex) & 0x80) >> 7)
67 #define vvvvFromVEX3of3(vex)    (((~(vex)) & 0x78) >> 3)
68 #define lFromVEX3of3(vex)       (((vex) & 0x4) >> 2)
69 #define ppFromVEX3of3(vex)      ((vex) & 0x3)
70
71 #define rFromVEX2of2(vex)       (((~(vex)) & 0x80) >> 7)
72 #define vvvvFromVEX2of2(vex)    (((~(vex)) & 0x78) >> 3)
73 #define lFromVEX2of2(vex)       (((vex) & 0x4) >> 2)
74 #define ppFromVEX2of2(vex)      ((vex) & 0x3)
75
76 #define rFromXOP2of3(xop)       (((~(xop)) & 0x80) >> 7)
77 #define xFromXOP2of3(xop)       (((~(xop)) & 0x40) >> 6)
78 #define bFromXOP2of3(xop)       (((~(xop)) & 0x20) >> 5)
79 #define mmmmmFromXOP2of3(xop)   ((xop) & 0x1f)
80 #define wFromXOP3of3(xop)       (((xop) & 0x80) >> 7)
81 #define vvvvFromXOP3of3(vex)    (((~(vex)) & 0x78) >> 3)
82 #define lFromXOP3of3(xop)       (((xop) & 0x4) >> 2)
83 #define ppFromXOP3of3(xop)      ((xop) & 0x3)
84
85 /*
86  * These enums represent Intel registers for use by the decoder.
87  */
88
89 #define REGS_8BIT     \
90   ENTRY(AL)           \
91   ENTRY(CL)           \
92   ENTRY(DL)           \
93   ENTRY(BL)           \
94   ENTRY(AH)           \
95   ENTRY(CH)           \
96   ENTRY(DH)           \
97   ENTRY(BH)           \
98   ENTRY(R8B)          \
99   ENTRY(R9B)          \
100   ENTRY(R10B)         \
101   ENTRY(R11B)         \
102   ENTRY(R12B)         \
103   ENTRY(R13B)         \
104   ENTRY(R14B)         \
105   ENTRY(R15B)         \
106   ENTRY(SPL)          \
107   ENTRY(BPL)          \
108   ENTRY(SIL)          \
109   ENTRY(DIL)
110
111 #define EA_BASES_16BIT  \
112   ENTRY(BX_SI)          \
113   ENTRY(BX_DI)          \
114   ENTRY(BP_SI)          \
115   ENTRY(BP_DI)          \
116   ENTRY(SI)             \
117   ENTRY(DI)             \
118   ENTRY(BP)             \
119   ENTRY(BX)             \
120   ENTRY(R8W)            \
121   ENTRY(R9W)            \
122   ENTRY(R10W)           \
123   ENTRY(R11W)           \
124   ENTRY(R12W)           \
125   ENTRY(R13W)           \
126   ENTRY(R14W)           \
127   ENTRY(R15W)
128
129 #define REGS_16BIT    \
130   ENTRY(AX)           \
131   ENTRY(CX)           \
132   ENTRY(DX)           \
133   ENTRY(BX)           \
134   ENTRY(SP)           \
135   ENTRY(BP)           \
136   ENTRY(SI)           \
137   ENTRY(DI)           \
138   ENTRY(R8W)          \
139   ENTRY(R9W)          \
140   ENTRY(R10W)         \
141   ENTRY(R11W)         \
142   ENTRY(R12W)         \
143   ENTRY(R13W)         \
144   ENTRY(R14W)         \
145   ENTRY(R15W)
146
147 #define EA_BASES_32BIT  \
148   ENTRY(EAX)            \
149   ENTRY(ECX)            \
150   ENTRY(EDX)            \
151   ENTRY(EBX)            \
152   ENTRY(sib)            \
153   ENTRY(EBP)            \
154   ENTRY(ESI)            \
155   ENTRY(EDI)            \
156   ENTRY(R8D)            \
157   ENTRY(R9D)            \
158   ENTRY(R10D)           \
159   ENTRY(R11D)           \
160   ENTRY(R12D)           \
161   ENTRY(R13D)           \
162   ENTRY(R14D)           \
163   ENTRY(R15D)
164
165 #define REGS_32BIT  \
166   ENTRY(EAX)        \
167   ENTRY(ECX)        \
168   ENTRY(EDX)        \
169   ENTRY(EBX)        \
170   ENTRY(ESP)        \
171   ENTRY(EBP)        \
172   ENTRY(ESI)        \
173   ENTRY(EDI)        \
174   ENTRY(R8D)        \
175   ENTRY(R9D)        \
176   ENTRY(R10D)       \
177   ENTRY(R11D)       \
178   ENTRY(R12D)       \
179   ENTRY(R13D)       \
180   ENTRY(R14D)       \
181   ENTRY(R15D)
182
183 #define EA_BASES_64BIT  \
184   ENTRY(RAX)            \
185   ENTRY(RCX)            \
186   ENTRY(RDX)            \
187   ENTRY(RBX)            \
188   ENTRY(sib64)          \
189   ENTRY(RBP)            \
190   ENTRY(RSI)            \
191   ENTRY(RDI)            \
192   ENTRY(R8)             \
193   ENTRY(R9)             \
194   ENTRY(R10)            \
195   ENTRY(R11)            \
196   ENTRY(R12)            \
197   ENTRY(R13)            \
198   ENTRY(R14)            \
199   ENTRY(R15)
200
201 #define REGS_64BIT  \
202   ENTRY(RAX)        \
203   ENTRY(RCX)        \
204   ENTRY(RDX)        \
205   ENTRY(RBX)        \
206   ENTRY(RSP)        \
207   ENTRY(RBP)        \
208   ENTRY(RSI)        \
209   ENTRY(RDI)        \
210   ENTRY(R8)         \
211   ENTRY(R9)         \
212   ENTRY(R10)        \
213   ENTRY(R11)        \
214   ENTRY(R12)        \
215   ENTRY(R13)        \
216   ENTRY(R14)        \
217   ENTRY(R15)
218
219 #define REGS_MMX  \
220   ENTRY(MM0)      \
221   ENTRY(MM1)      \
222   ENTRY(MM2)      \
223   ENTRY(MM3)      \
224   ENTRY(MM4)      \
225   ENTRY(MM5)      \
226   ENTRY(MM6)      \
227   ENTRY(MM7)
228
229 #define REGS_XMM  \
230   ENTRY(XMM0)     \
231   ENTRY(XMM1)     \
232   ENTRY(XMM2)     \
233   ENTRY(XMM3)     \
234   ENTRY(XMM4)     \
235   ENTRY(XMM5)     \
236   ENTRY(XMM6)     \
237   ENTRY(XMM7)     \
238   ENTRY(XMM8)     \
239   ENTRY(XMM9)     \
240   ENTRY(XMM10)    \
241   ENTRY(XMM11)    \
242   ENTRY(XMM12)    \
243   ENTRY(XMM13)    \
244   ENTRY(XMM14)    \
245   ENTRY(XMM15)    \
246   ENTRY(XMM16)    \
247   ENTRY(XMM17)    \
248   ENTRY(XMM18)    \
249   ENTRY(XMM19)    \
250   ENTRY(XMM20)    \
251   ENTRY(XMM21)    \
252   ENTRY(XMM22)    \
253   ENTRY(XMM23)    \
254   ENTRY(XMM24)    \
255   ENTRY(XMM25)    \
256   ENTRY(XMM26)    \
257   ENTRY(XMM27)    \
258   ENTRY(XMM28)    \
259   ENTRY(XMM29)    \
260   ENTRY(XMM30)    \
261   ENTRY(XMM31)
262
263 #define REGS_YMM  \
264   ENTRY(YMM0)     \
265   ENTRY(YMM1)     \
266   ENTRY(YMM2)     \
267   ENTRY(YMM3)     \
268   ENTRY(YMM4)     \
269   ENTRY(YMM5)     \
270   ENTRY(YMM6)     \
271   ENTRY(YMM7)     \
272   ENTRY(YMM8)     \
273   ENTRY(YMM9)     \
274   ENTRY(YMM10)    \
275   ENTRY(YMM11)    \
276   ENTRY(YMM12)    \
277   ENTRY(YMM13)    \
278   ENTRY(YMM14)    \
279   ENTRY(YMM15)    \
280   ENTRY(YMM16)    \
281   ENTRY(YMM17)    \
282   ENTRY(YMM18)    \
283   ENTRY(YMM19)    \
284   ENTRY(YMM20)    \
285   ENTRY(YMM21)    \
286   ENTRY(YMM22)    \
287   ENTRY(YMM23)    \
288   ENTRY(YMM24)    \
289   ENTRY(YMM25)    \
290   ENTRY(YMM26)    \
291   ENTRY(YMM27)    \
292   ENTRY(YMM28)    \
293   ENTRY(YMM29)    \
294   ENTRY(YMM30)    \
295   ENTRY(YMM31)
296
297 #define REGS_ZMM  \
298   ENTRY(ZMM0)     \
299   ENTRY(ZMM1)     \
300   ENTRY(ZMM2)     \
301   ENTRY(ZMM3)     \
302   ENTRY(ZMM4)     \
303   ENTRY(ZMM5)     \
304   ENTRY(ZMM6)     \
305   ENTRY(ZMM7)     \
306   ENTRY(ZMM8)     \
307   ENTRY(ZMM9)     \
308   ENTRY(ZMM10)    \
309   ENTRY(ZMM11)    \
310   ENTRY(ZMM12)    \
311   ENTRY(ZMM13)    \
312   ENTRY(ZMM14)    \
313   ENTRY(ZMM15)    \
314   ENTRY(ZMM16)    \
315   ENTRY(ZMM17)    \
316   ENTRY(ZMM18)    \
317   ENTRY(ZMM19)    \
318   ENTRY(ZMM20)    \
319   ENTRY(ZMM21)    \
320   ENTRY(ZMM22)    \
321   ENTRY(ZMM23)    \
322   ENTRY(ZMM24)    \
323   ENTRY(ZMM25)    \
324   ENTRY(ZMM26)    \
325   ENTRY(ZMM27)    \
326   ENTRY(ZMM28)    \
327   ENTRY(ZMM29)    \
328   ENTRY(ZMM30)    \
329   ENTRY(ZMM31)
330
331 #define REGS_MASKS \
332   ENTRY(K0)        \
333   ENTRY(K1)        \
334   ENTRY(K2)        \
335   ENTRY(K3)        \
336   ENTRY(K4)        \
337   ENTRY(K5)        \
338   ENTRY(K6)        \
339   ENTRY(K7)
340
341 #define REGS_SEGMENT \
342   ENTRY(ES)          \
343   ENTRY(CS)          \
344   ENTRY(SS)          \
345   ENTRY(DS)          \
346   ENTRY(FS)          \
347   ENTRY(GS)
348
349 #define REGS_DEBUG  \
350   ENTRY(DR0)        \
351   ENTRY(DR1)        \
352   ENTRY(DR2)        \
353   ENTRY(DR3)        \
354   ENTRY(DR4)        \
355   ENTRY(DR5)        \
356   ENTRY(DR6)        \
357   ENTRY(DR7)
358
359 #define REGS_CONTROL  \
360   ENTRY(CR0)          \
361   ENTRY(CR1)          \
362   ENTRY(CR2)          \
363   ENTRY(CR3)          \
364   ENTRY(CR4)          \
365   ENTRY(CR5)          \
366   ENTRY(CR6)          \
367   ENTRY(CR7)          \
368   ENTRY(CR8)
369
370 #define ALL_EA_BASES  \
371   EA_BASES_16BIT      \
372   EA_BASES_32BIT      \
373   EA_BASES_64BIT
374
375 #define ALL_SIB_BASES \
376   REGS_32BIT          \
377   REGS_64BIT
378
379 #define ALL_REGS      \
380   REGS_8BIT           \
381   REGS_16BIT          \
382   REGS_32BIT          \
383   REGS_64BIT          \
384   REGS_MMX            \
385   REGS_XMM            \
386   REGS_YMM            \
387   REGS_ZMM            \
388   REGS_MASKS          \
389   REGS_SEGMENT        \
390   REGS_DEBUG          \
391   REGS_CONTROL        \
392   ENTRY(RIP)
393
394 /*
395  * EABase - All possible values of the base field for effective-address
396  *   computations, a.k.a. the Mod and R/M fields of the ModR/M byte.  We
397  *   distinguish between bases (EA_BASE_*) and registers that just happen to be
398  *   referred to when Mod == 0b11 (EA_REG_*).
399  */
400 typedef enum {
401   EA_BASE_NONE,
402 #define ENTRY(x) EA_BASE_##x,
403   ALL_EA_BASES
404 #undef ENTRY
405 #define ENTRY(x) EA_REG_##x,
406   ALL_REGS
407 #undef ENTRY
408   EA_max
409 } EABase;
410
411 /*
412  * SIBIndex - All possible values of the SIB index field.
413  *   Borrows entries from ALL_EA_BASES with the special case that
414  *   sib is synonymous with NONE.
415  * Vector SIB: index can be XMM or YMM.
416  */
417 typedef enum {
418   SIB_INDEX_NONE,
419 #define ENTRY(x) SIB_INDEX_##x,
420   ALL_EA_BASES
421   REGS_XMM
422   REGS_YMM
423   REGS_ZMM
424 #undef ENTRY
425   SIB_INDEX_max
426 } SIBIndex;
427
428 /*
429  * SIBBase - All possible values of the SIB base field.
430  */
431 typedef enum {
432   SIB_BASE_NONE,
433 #define ENTRY(x) SIB_BASE_##x,
434   ALL_SIB_BASES
435 #undef ENTRY
436   SIB_BASE_max
437 } SIBBase;
438
439 /*
440  * EADisplacement - Possible displacement types for effective-address
441  *   computations.
442  */
443 typedef enum {
444   EA_DISP_NONE,
445   EA_DISP_8,
446   EA_DISP_16,
447   EA_DISP_32
448 } EADisplacement;
449
450 /*
451  * Reg - All possible values of the reg field in the ModR/M byte.
452  */
453 typedef enum {
454 #define ENTRY(x) MODRM_REG_##x,
455   ALL_REGS
456 #undef ENTRY
457   MODRM_REG_max
458 } Reg;
459
460 /*
461  * SegmentOverride - All possible segment overrides.
462  */
463 typedef enum {
464   SEG_OVERRIDE_NONE,
465   SEG_OVERRIDE_CS,
466   SEG_OVERRIDE_SS,
467   SEG_OVERRIDE_DS,
468   SEG_OVERRIDE_ES,
469   SEG_OVERRIDE_FS,
470   SEG_OVERRIDE_GS,
471   SEG_OVERRIDE_max
472 } SegmentOverride;
473
474 /*
475  * VEXLeadingOpcodeByte - Possible values for the VEX.m-mmmm field
476  */
477
478 typedef enum {
479   VEX_LOB_0F = 0x1,
480   VEX_LOB_0F38 = 0x2,
481   VEX_LOB_0F3A = 0x3
482 } VEXLeadingOpcodeByte;
483
484 typedef enum {
485   XOP_MAP_SELECT_8 = 0x8,
486   XOP_MAP_SELECT_9 = 0x9,
487   XOP_MAP_SELECT_A = 0xA
488 } XOPMapSelect;
489
490 /*
491  * VEXPrefixCode - Possible values for the VEX.pp/EVEX.pp field
492  */
493
494 typedef enum {
495   VEX_PREFIX_NONE = 0x0,
496   VEX_PREFIX_66 = 0x1,
497   VEX_PREFIX_F3 = 0x2,
498   VEX_PREFIX_F2 = 0x3
499 } VEXPrefixCode;
500
501 typedef enum {
502   TYPE_NO_VEX_XOP   = 0x0,
503   TYPE_VEX_2B       = 0x1,
504   TYPE_VEX_3B       = 0x2,
505   TYPE_EVEX         = 0x3,
506   TYPE_XOP          = 0x4
507 } VectorExtensionType;
508
509 typedef uint8_t BOOL;
510
511 /*
512  * byteReader_t - Type for the byte reader that the consumer must provide to
513  *   the decoder.  Reads a single byte from the instruction's address space.
514  * @param arg     - A baton that the consumer can associate with any internal
515  *                  state that it needs.
516  * @param byte    - A pointer to a single byte in memory that should be set to
517  *                  contain the value at address.
518  * @param address - The address in the instruction's address space that should
519  *                  be read from.
520  * @return        - -1 if the byte cannot be read for any reason; 0 otherwise.
521  */
522 typedef int (*byteReader_t)(const void* arg, uint8_t* byte, uint64_t address);
523
524 /*
525  * dlog_t - Type for the logging function that the consumer can provide to
526  *   get debugging output from the decoder.
527  * @param arg     - A baton that the consumer can associate with any internal
528  *                  state that it needs.
529  * @param log     - A string that contains the message.  Will be reused after
530  *                  the logger returns.
531  */
532 typedef void (*dlog_t)(void* arg, const char *log);
533
534 /*
535  * The x86 internal instruction, which is produced by the decoder.
536  */
537 struct InternalInstruction {
538   /* Reader interface (C) */
539   byteReader_t reader;
540   /* Opaque value passed to the reader */
541   const void* readerArg;
542   /* The address of the next byte to read via the reader */
543   uint64_t readerCursor;
544
545   /* Logger interface (C) */
546   dlog_t dlog;
547   /* Opaque value passed to the logger */
548   void* dlogArg;
549
550   /* General instruction information */
551
552   /* The mode to disassemble for (64-bit, protected, real) */
553   DisassemblerMode mode;
554   /* The start of the instruction, usable with the reader */
555   uint64_t startLocation;
556   /* The length of the instruction, in bytes */
557   size_t length;
558
559   /* Prefix state */
560
561   /* 1 if the prefix byte corresponding to the entry is present; 0 if not */
562   uint8_t prefixPresent[0x100];
563   /* contains the location (for use with the reader) of the prefix byte */
564   uint64_t prefixLocations[0x100];
565   /* The value of the vector extension prefix(EVEX/VEX/XOP), if present */
566   uint8_t vectorExtensionPrefix[4];
567   /* The type of the vector extension prefix */
568   VectorExtensionType vectorExtensionType;
569   /* The value of the REX prefix, if present */
570   uint8_t rexPrefix;
571   /* The location where a mandatory prefix would have to be (i.e., right before
572      the opcode, or right before the REX prefix if one is present) */
573   uint64_t necessaryPrefixLocation;
574   /* The segment override type */
575   SegmentOverride segmentOverride;
576   /* 1 if the prefix byte, 0xf2 or 0xf3 is xacquire or xrelease */
577   BOOL xAcquireRelease;
578
579   /* Sizes of various critical pieces of data, in bytes */
580   uint8_t registerSize;
581   uint8_t addressSize;
582   uint8_t displacementSize;
583   uint8_t immediateSize;
584
585   /* Offsets from the start of the instruction to the pieces of data, which is
586      needed to find relocation entries for adding symbolic operands */
587   uint8_t displacementOffset;
588   uint8_t immediateOffset;
589
590   /* opcode state */
591
592   /* The last byte of the opcode, not counting any ModR/M extension */
593   uint8_t opcode;
594   /* The ModR/M byte of the instruction, if it is an opcode extension */
595   uint8_t modRMExtension;
596
597   /* decode state */
598
599   /* The type of opcode, used for indexing into the array of decode tables */
600   OpcodeType opcodeType;
601   /* The instruction ID, extracted from the decode table */
602   uint16_t instructionID;
603   /* The specifier for the instruction, from the instruction info table */
604   const struct InstructionSpecifier *spec;
605
606   /* state for additional bytes, consumed during operand decode.  Pattern:
607      consumed___ indicates that the byte was already consumed and does not
608      need to be consumed again */
609
610   /* The VEX.vvvv field, which contains a third register operand for some AVX
611      instructions */
612   Reg                           vvvv;
613
614   /* The writemask for AVX-512 instructions which is contained in EVEX.aaa */
615   Reg                           writemask;
616
617   /* The ModR/M byte, which contains most register operands and some portion of
618      all memory operands */
619   BOOL                          consumedModRM;
620   uint8_t                       modRM;
621
622   /* The SIB byte, used for more complex 32- or 64-bit memory operands */
623   BOOL                          consumedSIB;
624   uint8_t                       sib;
625
626   /* The displacement, used for memory operands */
627   BOOL                          consumedDisplacement;
628   int32_t                       displacement;
629
630   /* Immediates.  There can be two in some cases */
631   uint8_t                       numImmediatesConsumed;
632   uint8_t                       numImmediatesTranslated;
633   uint64_t                      immediates[2];
634
635   /* A register or immediate operand encoded into the opcode */
636   Reg                           opcodeRegister;
637
638   /* Portions of the ModR/M byte */
639
640   /* These fields determine the allowable values for the ModR/M fields, which
641      depend on operand and address widths */
642   EABase                        eaBaseBase;
643   EABase                        eaRegBase;
644   Reg                           regBase;
645
646   /* The Mod and R/M fields can encode a base for an effective address, or a
647      register.  These are separated into two fields here */
648   EABase                        eaBase;
649   EADisplacement                eaDisplacement;
650   /* The reg field always encodes a register */
651   Reg                           reg;
652
653   /* SIB state */
654   SIBIndex                      sibIndex;
655   uint8_t                       sibScale;
656   SIBBase                       sibBase;
657
658   const struct OperandSpecifier *operands;
659 };
660
661 /* decodeInstruction - Decode one instruction and store the decoding results in
662  *   a buffer provided by the consumer.
663  * @param insn      - The buffer to store the instruction in.  Allocated by the
664  *                    consumer.
665  * @param reader    - The byteReader_t for the bytes to be read.
666  * @param readerArg - An argument to pass to the reader for storing context
667  *                    specific to the consumer.  May be NULL.
668  * @param logger    - The dlog_t to be used in printing status messages from the
669  *                    disassembler.  May be NULL.
670  * @param loggerArg - An argument to pass to the logger for storing context
671  *                    specific to the logger.  May be NULL.
672  * @param startLoc  - The address (in the reader's address space) of the first
673  *                    byte in the instruction.
674  * @param mode      - The mode (16-bit, 32-bit, 64-bit) to decode in.
675  * @return          - Nonzero if there was an error during decode, 0 otherwise.
676  */
677 int decodeInstruction(struct InternalInstruction* insn,
678                       byteReader_t reader,
679                       const void* readerArg,
680                       dlog_t logger,
681                       void* loggerArg,
682                       const void* miiArg,
683                       uint64_t startLoc,
684                       DisassemblerMode mode);
685
686 /* \brief Debug - Print a message to debugs()
687  * @param file  - The name of the file printing the debug message.
688  * @param line  - The line number that printed the debug message.
689  * @param s     - The message to print.
690  */
691
692 void Debug(const char *file, unsigned line, const char *s);
693
694 const char *GetInstrName(unsigned Opcode, const void *mii);
695
696 } // namespace X86Disassembler
697 } // namespace llvm
698
699 #endif