LLVM API Documentation
00001 //===-- X86DisassemblerDecoderInternal.h - Disassembler decoder -*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file is part of the X86 Disassembler. 00011 // It contains the public interface of the instruction decoder. 00012 // Documentation for the disassembler can be found in X86Disassembler.h. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_LIB_TARGET_X86_DISASSEMBLER_X86DISASSEMBLERDECODER_H 00017 #define LLVM_LIB_TARGET_X86_DISASSEMBLER_X86DISASSEMBLERDECODER_H 00018 00019 #include "X86DisassemblerDecoderCommon.h" 00020 #include "llvm/ADT/ArrayRef.h" 00021 00022 namespace llvm { 00023 namespace X86Disassembler { 00024 00025 // Accessor functions for various fields of an Intel instruction 00026 #define modFromModRM(modRM) (((modRM) & 0xc0) >> 6) 00027 #define regFromModRM(modRM) (((modRM) & 0x38) >> 3) 00028 #define rmFromModRM(modRM) ((modRM) & 0x7) 00029 #define scaleFromSIB(sib) (((sib) & 0xc0) >> 6) 00030 #define indexFromSIB(sib) (((sib) & 0x38) >> 3) 00031 #define baseFromSIB(sib) ((sib) & 0x7) 00032 #define wFromREX(rex) (((rex) & 0x8) >> 3) 00033 #define rFromREX(rex) (((rex) & 0x4) >> 2) 00034 #define xFromREX(rex) (((rex) & 0x2) >> 1) 00035 #define bFromREX(rex) ((rex) & 0x1) 00036 00037 #define rFromEVEX2of4(evex) (((~(evex)) & 0x80) >> 7) 00038 #define xFromEVEX2of4(evex) (((~(evex)) & 0x40) >> 6) 00039 #define bFromEVEX2of4(evex) (((~(evex)) & 0x20) >> 5) 00040 #define r2FromEVEX2of4(evex) (((~(evex)) & 0x10) >> 4) 00041 #define mmFromEVEX2of4(evex) ((evex) & 0x3) 00042 #define wFromEVEX3of4(evex) (((evex) & 0x80) >> 7) 00043 #define vvvvFromEVEX3of4(evex) (((~(evex)) & 0x78) >> 3) 00044 #define ppFromEVEX3of4(evex) ((evex) & 0x3) 00045 #define zFromEVEX4of4(evex) (((evex) & 0x80) >> 7) 00046 #define l2FromEVEX4of4(evex) (((evex) & 0x40) >> 6) 00047 #define lFromEVEX4of4(evex) (((evex) & 0x20) >> 5) 00048 #define bFromEVEX4of4(evex) (((evex) & 0x10) >> 4) 00049 #define v2FromEVEX4of4(evex) (((~evex) & 0x8) >> 3) 00050 #define aaaFromEVEX4of4(evex) ((evex) & 0x7) 00051 00052 #define rFromVEX2of3(vex) (((~(vex)) & 0x80) >> 7) 00053 #define xFromVEX2of3(vex) (((~(vex)) & 0x40) >> 6) 00054 #define bFromVEX2of3(vex) (((~(vex)) & 0x20) >> 5) 00055 #define mmmmmFromVEX2of3(vex) ((vex) & 0x1f) 00056 #define wFromVEX3of3(vex) (((vex) & 0x80) >> 7) 00057 #define vvvvFromVEX3of3(vex) (((~(vex)) & 0x78) >> 3) 00058 #define lFromVEX3of3(vex) (((vex) & 0x4) >> 2) 00059 #define ppFromVEX3of3(vex) ((vex) & 0x3) 00060 00061 #define rFromVEX2of2(vex) (((~(vex)) & 0x80) >> 7) 00062 #define vvvvFromVEX2of2(vex) (((~(vex)) & 0x78) >> 3) 00063 #define lFromVEX2of2(vex) (((vex) & 0x4) >> 2) 00064 #define ppFromVEX2of2(vex) ((vex) & 0x3) 00065 00066 #define rFromXOP2of3(xop) (((~(xop)) & 0x80) >> 7) 00067 #define xFromXOP2of3(xop) (((~(xop)) & 0x40) >> 6) 00068 #define bFromXOP2of3(xop) (((~(xop)) & 0x20) >> 5) 00069 #define mmmmmFromXOP2of3(xop) ((xop) & 0x1f) 00070 #define wFromXOP3of3(xop) (((xop) & 0x80) >> 7) 00071 #define vvvvFromXOP3of3(vex) (((~(vex)) & 0x78) >> 3) 00072 #define lFromXOP3of3(xop) (((xop) & 0x4) >> 2) 00073 #define ppFromXOP3of3(xop) ((xop) & 0x3) 00074 00075 // These enums represent Intel registers for use by the decoder. 00076 #define REGS_8BIT \ 00077 ENTRY(AL) \ 00078 ENTRY(CL) \ 00079 ENTRY(DL) \ 00080 ENTRY(BL) \ 00081 ENTRY(AH) \ 00082 ENTRY(CH) \ 00083 ENTRY(DH) \ 00084 ENTRY(BH) \ 00085 ENTRY(R8B) \ 00086 ENTRY(R9B) \ 00087 ENTRY(R10B) \ 00088 ENTRY(R11B) \ 00089 ENTRY(R12B) \ 00090 ENTRY(R13B) \ 00091 ENTRY(R14B) \ 00092 ENTRY(R15B) \ 00093 ENTRY(SPL) \ 00094 ENTRY(BPL) \ 00095 ENTRY(SIL) \ 00096 ENTRY(DIL) 00097 00098 #define EA_BASES_16BIT \ 00099 ENTRY(BX_SI) \ 00100 ENTRY(BX_DI) \ 00101 ENTRY(BP_SI) \ 00102 ENTRY(BP_DI) \ 00103 ENTRY(SI) \ 00104 ENTRY(DI) \ 00105 ENTRY(BP) \ 00106 ENTRY(BX) \ 00107 ENTRY(R8W) \ 00108 ENTRY(R9W) \ 00109 ENTRY(R10W) \ 00110 ENTRY(R11W) \ 00111 ENTRY(R12W) \ 00112 ENTRY(R13W) \ 00113 ENTRY(R14W) \ 00114 ENTRY(R15W) 00115 00116 #define REGS_16BIT \ 00117 ENTRY(AX) \ 00118 ENTRY(CX) \ 00119 ENTRY(DX) \ 00120 ENTRY(BX) \ 00121 ENTRY(SP) \ 00122 ENTRY(BP) \ 00123 ENTRY(SI) \ 00124 ENTRY(DI) \ 00125 ENTRY(R8W) \ 00126 ENTRY(R9W) \ 00127 ENTRY(R10W) \ 00128 ENTRY(R11W) \ 00129 ENTRY(R12W) \ 00130 ENTRY(R13W) \ 00131 ENTRY(R14W) \ 00132 ENTRY(R15W) 00133 00134 #define EA_BASES_32BIT \ 00135 ENTRY(EAX) \ 00136 ENTRY(ECX) \ 00137 ENTRY(EDX) \ 00138 ENTRY(EBX) \ 00139 ENTRY(sib) \ 00140 ENTRY(EBP) \ 00141 ENTRY(ESI) \ 00142 ENTRY(EDI) \ 00143 ENTRY(R8D) \ 00144 ENTRY(R9D) \ 00145 ENTRY(R10D) \ 00146 ENTRY(R11D) \ 00147 ENTRY(R12D) \ 00148 ENTRY(R13D) \ 00149 ENTRY(R14D) \ 00150 ENTRY(R15D) 00151 00152 #define REGS_32BIT \ 00153 ENTRY(EAX) \ 00154 ENTRY(ECX) \ 00155 ENTRY(EDX) \ 00156 ENTRY(EBX) \ 00157 ENTRY(ESP) \ 00158 ENTRY(EBP) \ 00159 ENTRY(ESI) \ 00160 ENTRY(EDI) \ 00161 ENTRY(R8D) \ 00162 ENTRY(R9D) \ 00163 ENTRY(R10D) \ 00164 ENTRY(R11D) \ 00165 ENTRY(R12D) \ 00166 ENTRY(R13D) \ 00167 ENTRY(R14D) \ 00168 ENTRY(R15D) 00169 00170 #define EA_BASES_64BIT \ 00171 ENTRY(RAX) \ 00172 ENTRY(RCX) \ 00173 ENTRY(RDX) \ 00174 ENTRY(RBX) \ 00175 ENTRY(sib64) \ 00176 ENTRY(RBP) \ 00177 ENTRY(RSI) \ 00178 ENTRY(RDI) \ 00179 ENTRY(R8) \ 00180 ENTRY(R9) \ 00181 ENTRY(R10) \ 00182 ENTRY(R11) \ 00183 ENTRY(R12) \ 00184 ENTRY(R13) \ 00185 ENTRY(R14) \ 00186 ENTRY(R15) 00187 00188 #define REGS_64BIT \ 00189 ENTRY(RAX) \ 00190 ENTRY(RCX) \ 00191 ENTRY(RDX) \ 00192 ENTRY(RBX) \ 00193 ENTRY(RSP) \ 00194 ENTRY(RBP) \ 00195 ENTRY(RSI) \ 00196 ENTRY(RDI) \ 00197 ENTRY(R8) \ 00198 ENTRY(R9) \ 00199 ENTRY(R10) \ 00200 ENTRY(R11) \ 00201 ENTRY(R12) \ 00202 ENTRY(R13) \ 00203 ENTRY(R14) \ 00204 ENTRY(R15) 00205 00206 #define REGS_MMX \ 00207 ENTRY(MM0) \ 00208 ENTRY(MM1) \ 00209 ENTRY(MM2) \ 00210 ENTRY(MM3) \ 00211 ENTRY(MM4) \ 00212 ENTRY(MM5) \ 00213 ENTRY(MM6) \ 00214 ENTRY(MM7) 00215 00216 #define REGS_XMM \ 00217 ENTRY(XMM0) \ 00218 ENTRY(XMM1) \ 00219 ENTRY(XMM2) \ 00220 ENTRY(XMM3) \ 00221 ENTRY(XMM4) \ 00222 ENTRY(XMM5) \ 00223 ENTRY(XMM6) \ 00224 ENTRY(XMM7) \ 00225 ENTRY(XMM8) \ 00226 ENTRY(XMM9) \ 00227 ENTRY(XMM10) \ 00228 ENTRY(XMM11) \ 00229 ENTRY(XMM12) \ 00230 ENTRY(XMM13) \ 00231 ENTRY(XMM14) \ 00232 ENTRY(XMM15) \ 00233 ENTRY(XMM16) \ 00234 ENTRY(XMM17) \ 00235 ENTRY(XMM18) \ 00236 ENTRY(XMM19) \ 00237 ENTRY(XMM20) \ 00238 ENTRY(XMM21) \ 00239 ENTRY(XMM22) \ 00240 ENTRY(XMM23) \ 00241 ENTRY(XMM24) \ 00242 ENTRY(XMM25) \ 00243 ENTRY(XMM26) \ 00244 ENTRY(XMM27) \ 00245 ENTRY(XMM28) \ 00246 ENTRY(XMM29) \ 00247 ENTRY(XMM30) \ 00248 ENTRY(XMM31) 00249 00250 #define REGS_YMM \ 00251 ENTRY(YMM0) \ 00252 ENTRY(YMM1) \ 00253 ENTRY(YMM2) \ 00254 ENTRY(YMM3) \ 00255 ENTRY(YMM4) \ 00256 ENTRY(YMM5) \ 00257 ENTRY(YMM6) \ 00258 ENTRY(YMM7) \ 00259 ENTRY(YMM8) \ 00260 ENTRY(YMM9) \ 00261 ENTRY(YMM10) \ 00262 ENTRY(YMM11) \ 00263 ENTRY(YMM12) \ 00264 ENTRY(YMM13) \ 00265 ENTRY(YMM14) \ 00266 ENTRY(YMM15) \ 00267 ENTRY(YMM16) \ 00268 ENTRY(YMM17) \ 00269 ENTRY(YMM18) \ 00270 ENTRY(YMM19) \ 00271 ENTRY(YMM20) \ 00272 ENTRY(YMM21) \ 00273 ENTRY(YMM22) \ 00274 ENTRY(YMM23) \ 00275 ENTRY(YMM24) \ 00276 ENTRY(YMM25) \ 00277 ENTRY(YMM26) \ 00278 ENTRY(YMM27) \ 00279 ENTRY(YMM28) \ 00280 ENTRY(YMM29) \ 00281 ENTRY(YMM30) \ 00282 ENTRY(YMM31) 00283 00284 #define REGS_ZMM \ 00285 ENTRY(ZMM0) \ 00286 ENTRY(ZMM1) \ 00287 ENTRY(ZMM2) \ 00288 ENTRY(ZMM3) \ 00289 ENTRY(ZMM4) \ 00290 ENTRY(ZMM5) \ 00291 ENTRY(ZMM6) \ 00292 ENTRY(ZMM7) \ 00293 ENTRY(ZMM8) \ 00294 ENTRY(ZMM9) \ 00295 ENTRY(ZMM10) \ 00296 ENTRY(ZMM11) \ 00297 ENTRY(ZMM12) \ 00298 ENTRY(ZMM13) \ 00299 ENTRY(ZMM14) \ 00300 ENTRY(ZMM15) \ 00301 ENTRY(ZMM16) \ 00302 ENTRY(ZMM17) \ 00303 ENTRY(ZMM18) \ 00304 ENTRY(ZMM19) \ 00305 ENTRY(ZMM20) \ 00306 ENTRY(ZMM21) \ 00307 ENTRY(ZMM22) \ 00308 ENTRY(ZMM23) \ 00309 ENTRY(ZMM24) \ 00310 ENTRY(ZMM25) \ 00311 ENTRY(ZMM26) \ 00312 ENTRY(ZMM27) \ 00313 ENTRY(ZMM28) \ 00314 ENTRY(ZMM29) \ 00315 ENTRY(ZMM30) \ 00316 ENTRY(ZMM31) 00317 00318 #define REGS_MASKS \ 00319 ENTRY(K0) \ 00320 ENTRY(K1) \ 00321 ENTRY(K2) \ 00322 ENTRY(K3) \ 00323 ENTRY(K4) \ 00324 ENTRY(K5) \ 00325 ENTRY(K6) \ 00326 ENTRY(K7) 00327 00328 #define REGS_SEGMENT \ 00329 ENTRY(ES) \ 00330 ENTRY(CS) \ 00331 ENTRY(SS) \ 00332 ENTRY(DS) \ 00333 ENTRY(FS) \ 00334 ENTRY(GS) 00335 00336 #define REGS_DEBUG \ 00337 ENTRY(DR0) \ 00338 ENTRY(DR1) \ 00339 ENTRY(DR2) \ 00340 ENTRY(DR3) \ 00341 ENTRY(DR4) \ 00342 ENTRY(DR5) \ 00343 ENTRY(DR6) \ 00344 ENTRY(DR7) 00345 00346 #define REGS_CONTROL \ 00347 ENTRY(CR0) \ 00348 ENTRY(CR1) \ 00349 ENTRY(CR2) \ 00350 ENTRY(CR3) \ 00351 ENTRY(CR4) \ 00352 ENTRY(CR5) \ 00353 ENTRY(CR6) \ 00354 ENTRY(CR7) \ 00355 ENTRY(CR8) 00356 00357 #define ALL_EA_BASES \ 00358 EA_BASES_16BIT \ 00359 EA_BASES_32BIT \ 00360 EA_BASES_64BIT 00361 00362 #define ALL_SIB_BASES \ 00363 REGS_32BIT \ 00364 REGS_64BIT 00365 00366 #define ALL_REGS \ 00367 REGS_8BIT \ 00368 REGS_16BIT \ 00369 REGS_32BIT \ 00370 REGS_64BIT \ 00371 REGS_MMX \ 00372 REGS_XMM \ 00373 REGS_YMM \ 00374 REGS_ZMM \ 00375 REGS_MASKS \ 00376 REGS_SEGMENT \ 00377 REGS_DEBUG \ 00378 REGS_CONTROL \ 00379 ENTRY(RIP) 00380 00381 /// \brief All possible values of the base field for effective-address 00382 /// computations, a.k.a. the Mod and R/M fields of the ModR/M byte. 00383 /// We distinguish between bases (EA_BASE_*) and registers that just happen 00384 /// to be referred to when Mod == 0b11 (EA_REG_*). 00385 enum EABase { 00386 EA_BASE_NONE, 00387 #define ENTRY(x) EA_BASE_##x, 00388 ALL_EA_BASES 00389 #undef ENTRY 00390 #define ENTRY(x) EA_REG_##x, 00391 ALL_REGS 00392 #undef ENTRY 00393 EA_max 00394 }; 00395 00396 /// \brief All possible values of the SIB index field. 00397 /// borrows entries from ALL_EA_BASES with the special case that 00398 /// sib is synonymous with NONE. 00399 /// Vector SIB: index can be XMM or YMM. 00400 enum SIBIndex { 00401 SIB_INDEX_NONE, 00402 #define ENTRY(x) SIB_INDEX_##x, 00403 ALL_EA_BASES 00404 REGS_XMM 00405 REGS_YMM 00406 REGS_ZMM 00407 #undef ENTRY 00408 SIB_INDEX_max 00409 }; 00410 00411 /// \brief All possible values of the SIB base field. 00412 enum SIBBase { 00413 SIB_BASE_NONE, 00414 #define ENTRY(x) SIB_BASE_##x, 00415 ALL_SIB_BASES 00416 #undef ENTRY 00417 SIB_BASE_max 00418 }; 00419 00420 /// \brief Possible displacement types for effective-address computations. 00421 typedef enum { 00422 EA_DISP_NONE, 00423 EA_DISP_8, 00424 EA_DISP_16, 00425 EA_DISP_32 00426 } EADisplacement; 00427 00428 /// \brief All possible values of the reg field in the ModR/M byte. 00429 enum Reg { 00430 #define ENTRY(x) MODRM_REG_##x, 00431 ALL_REGS 00432 #undef ENTRY 00433 MODRM_REG_max 00434 }; 00435 00436 /// \brief All possible segment overrides. 00437 enum SegmentOverride { 00438 SEG_OVERRIDE_NONE, 00439 SEG_OVERRIDE_CS, 00440 SEG_OVERRIDE_SS, 00441 SEG_OVERRIDE_DS, 00442 SEG_OVERRIDE_ES, 00443 SEG_OVERRIDE_FS, 00444 SEG_OVERRIDE_GS, 00445 SEG_OVERRIDE_max 00446 }; 00447 00448 /// \brief Possible values for the VEX.m-mmmm field 00449 enum VEXLeadingOpcodeByte { 00450 VEX_LOB_0F = 0x1, 00451 VEX_LOB_0F38 = 0x2, 00452 VEX_LOB_0F3A = 0x3 00453 }; 00454 00455 enum XOPMapSelect { 00456 XOP_MAP_SELECT_8 = 0x8, 00457 XOP_MAP_SELECT_9 = 0x9, 00458 XOP_MAP_SELECT_A = 0xA 00459 }; 00460 00461 /// \brief Possible values for the VEX.pp/EVEX.pp field 00462 enum VEXPrefixCode { 00463 VEX_PREFIX_NONE = 0x0, 00464 VEX_PREFIX_66 = 0x1, 00465 VEX_PREFIX_F3 = 0x2, 00466 VEX_PREFIX_F2 = 0x3 00467 }; 00468 00469 enum VectorExtensionType { 00470 TYPE_NO_VEX_XOP = 0x0, 00471 TYPE_VEX_2B = 0x1, 00472 TYPE_VEX_3B = 0x2, 00473 TYPE_EVEX = 0x3, 00474 TYPE_XOP = 0x4 00475 }; 00476 00477 /// \brief Type for the byte reader that the consumer must provide to 00478 /// the decoder. Reads a single byte from the instruction's address space. 00479 /// \param arg A baton that the consumer can associate with any internal 00480 /// state that it needs. 00481 /// \param byte A pointer to a single byte in memory that should be set to 00482 /// contain the value at address. 00483 /// \param address The address in the instruction's address space that should 00484 /// be read from. 00485 /// \return -1 if the byte cannot be read for any reason; 0 otherwise. 00486 typedef int (*byteReader_t)(const void *arg, uint8_t *byte, uint64_t address); 00487 00488 /// \brief Type for the logging function that the consumer can provide to 00489 /// get debugging output from the decoder. 00490 /// \param arg A baton that the consumer can associate with any internal 00491 /// state that it needs. 00492 /// \param log A string that contains the message. Will be reused after 00493 /// the logger returns. 00494 typedef void (*dlog_t)(void *arg, const char *log); 00495 00496 /// The specification for how to extract and interpret a full instruction and 00497 /// its operands. 00498 struct InstructionSpecifier { 00499 uint16_t operands; 00500 }; 00501 00502 /// The x86 internal instruction, which is produced by the decoder. 00503 struct InternalInstruction { 00504 // Reader interface (C) 00505 byteReader_t reader; 00506 // Opaque value passed to the reader 00507 const void* readerArg; 00508 // The address of the next byte to read via the reader 00509 uint64_t readerCursor; 00510 00511 // Logger interface (C) 00512 dlog_t dlog; 00513 // Opaque value passed to the logger 00514 void* dlogArg; 00515 00516 // General instruction information 00517 00518 // The mode to disassemble for (64-bit, protected, real) 00519 DisassemblerMode mode; 00520 // The start of the instruction, usable with the reader 00521 uint64_t startLocation; 00522 // The length of the instruction, in bytes 00523 size_t length; 00524 00525 // Prefix state 00526 00527 // 1 if the prefix byte corresponding to the entry is present; 0 if not 00528 uint8_t prefixPresent[0x100]; 00529 // contains the location (for use with the reader) of the prefix byte 00530 uint64_t prefixLocations[0x100]; 00531 // The value of the vector extension prefix(EVEX/VEX/XOP), if present 00532 uint8_t vectorExtensionPrefix[4]; 00533 // The type of the vector extension prefix 00534 VectorExtensionType vectorExtensionType; 00535 // The value of the REX prefix, if present 00536 uint8_t rexPrefix; 00537 // The location where a mandatory prefix would have to be (i.e., right before 00538 // the opcode, or right before the REX prefix if one is present). 00539 uint64_t necessaryPrefixLocation; 00540 // The segment override type 00541 SegmentOverride segmentOverride; 00542 // 1 if the prefix byte, 0xf2 or 0xf3 is xacquire or xrelease 00543 bool xAcquireRelease; 00544 00545 // Sizes of various critical pieces of data, in bytes 00546 uint8_t registerSize; 00547 uint8_t addressSize; 00548 uint8_t displacementSize; 00549 uint8_t immediateSize; 00550 00551 // Offsets from the start of the instruction to the pieces of data, which is 00552 // needed to find relocation entries for adding symbolic operands. 00553 uint8_t displacementOffset; 00554 uint8_t immediateOffset; 00555 00556 // opcode state 00557 00558 // The last byte of the opcode, not counting any ModR/M extension 00559 uint8_t opcode; 00560 // The ModR/M byte of the instruction, if it is an opcode extension 00561 uint8_t modRMExtension; 00562 00563 // decode state 00564 00565 // The type of opcode, used for indexing into the array of decode tables 00566 OpcodeType opcodeType; 00567 // The instruction ID, extracted from the decode table 00568 uint16_t instructionID; 00569 // The specifier for the instruction, from the instruction info table 00570 const InstructionSpecifier *spec; 00571 00572 // state for additional bytes, consumed during operand decode. Pattern: 00573 // consumed___ indicates that the byte was already consumed and does not 00574 // need to be consumed again. 00575 00576 // The VEX.vvvv field, which contains a third register operand for some AVX 00577 // instructions. 00578 Reg vvvv; 00579 00580 // The writemask for AVX-512 instructions which is contained in EVEX.aaa 00581 Reg writemask; 00582 00583 // The ModR/M byte, which contains most register operands and some portion of 00584 // all memory operands. 00585 bool consumedModRM; 00586 uint8_t modRM; 00587 00588 // The SIB byte, used for more complex 32- or 64-bit memory operands 00589 bool consumedSIB; 00590 uint8_t sib; 00591 00592 // The displacement, used for memory operands 00593 bool consumedDisplacement; 00594 int32_t displacement; 00595 00596 // Immediates. There can be two in some cases 00597 uint8_t numImmediatesConsumed; 00598 uint8_t numImmediatesTranslated; 00599 uint64_t immediates[2]; 00600 00601 // A register or immediate operand encoded into the opcode 00602 Reg opcodeRegister; 00603 00604 // Portions of the ModR/M byte 00605 00606 // These fields determine the allowable values for the ModR/M fields, which 00607 // depend on operand and address widths. 00608 EABase eaBaseBase; 00609 EABase eaRegBase; 00610 Reg regBase; 00611 00612 // The Mod and R/M fields can encode a base for an effective address, or a 00613 // register. These are separated into two fields here. 00614 EABase eaBase; 00615 EADisplacement eaDisplacement; 00616 // The reg field always encodes a register 00617 Reg reg; 00618 00619 // SIB state 00620 SIBIndex sibIndex; 00621 uint8_t sibScale; 00622 SIBBase sibBase; 00623 00624 ArrayRef<OperandSpecifier> operands; 00625 }; 00626 00627 /// \brief Decode one instruction and store the decoding results in 00628 /// a buffer provided by the consumer. 00629 /// \param insn The buffer to store the instruction in. Allocated by the 00630 /// consumer. 00631 /// \param reader The byteReader_t for the bytes to be read. 00632 /// \param readerArg An argument to pass to the reader for storing context 00633 /// specific to the consumer. May be NULL. 00634 /// \param logger The dlog_t to be used in printing status messages from the 00635 /// disassembler. May be NULL. 00636 /// \param loggerArg An argument to pass to the logger for storing context 00637 /// specific to the logger. May be NULL. 00638 /// \param startLoc The address (in the reader's address space) of the first 00639 /// byte in the instruction. 00640 /// \param mode The mode (16-bit, 32-bit, 64-bit) to decode in. 00641 /// \return Nonzero if there was an error during decode, 0 otherwise. 00642 int decodeInstruction(InternalInstruction *insn, 00643 byteReader_t reader, 00644 const void *readerArg, 00645 dlog_t logger, 00646 void *loggerArg, 00647 const void *miiArg, 00648 uint64_t startLoc, 00649 DisassemblerMode mode); 00650 00651 /// \brief Print a message to debugs() 00652 /// \param file The name of the file printing the debug message. 00653 /// \param line The line number that printed the debug message. 00654 /// \param s The message to print. 00655 void Debug(const char *file, unsigned line, const char *s); 00656 00657 const char *GetInstrName(unsigned Opcode, const void *mii); 00658 00659 } // namespace X86Disassembler 00660 } // namespace llvm 00661 00662 #endif