Path: blob/master/libs/capstone/arch/X86/X86DisassemblerDecoderCommon.h
4389 views
/*===-- X86DisassemblerDecoderCommon.h - Disassembler decoder -----*- C -*-===*1*2* The LLVM Compiler Infrastructure3*4* This file is distributed under the University of Illinois Open Source5* License. See LICENSE.TXT for details.6*7*===----------------------------------------------------------------------===*8*9* This file is part of the X86 Disassembler.10* It contains common definitions used by both the disassembler and the table11* generator.12* Documentation for the disassembler can be found in X86Disassembler.h.13*14*===----------------------------------------------------------------------===*/1516/* Capstone Disassembly Engine */17/* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */1819/*20* This header file provides those definitions that need to be shared between21* the decoder and the table generator in a C-friendly manner.22*/2324#ifndef CS_X86_DISASSEMBLERDECODERCOMMON_H25#define CS_X86_DISASSEMBLERDECODERCOMMON_H2627#define INSTRUCTIONS_SYM x86DisassemblerInstrSpecifiers28#define CONTEXTS_SYM x86DisassemblerContexts29#define ONEBYTE_SYM x86DisassemblerOneByteOpcodes30#define TWOBYTE_SYM x86DisassemblerTwoByteOpcodes31#define THREEBYTE38_SYM x86DisassemblerThreeByte38Opcodes32#define THREEBYTE3A_SYM x86DisassemblerThreeByte3AOpcodes33#define XOP8_MAP_SYM x86DisassemblerXOP8Opcodes34#define XOP9_MAP_SYM x86DisassemblerXOP9Opcodes35#define XOPA_MAP_SYM x86DisassemblerXOPAOpcodes36#define THREEDNOW_MAP_SYM x86Disassembler3DNowOpcodes373839/*40* Attributes of an instruction that must be known before the opcode can be41* processed correctly. Most of these indicate the presence of particular42* prefixes, but ATTR_64BIT is simply an attribute of the decoding context.43*/44#define ATTRIBUTE_BITS \45ENUM_ENTRY(ATTR_NONE, 0x00) \46ENUM_ENTRY(ATTR_64BIT, (0x1 << 0)) \47ENUM_ENTRY(ATTR_XS, (0x1 << 1)) \48ENUM_ENTRY(ATTR_XD, (0x1 << 2)) \49ENUM_ENTRY(ATTR_REXW, (0x1 << 3)) \50ENUM_ENTRY(ATTR_OPSIZE, (0x1 << 4)) \51ENUM_ENTRY(ATTR_ADSIZE, (0x1 << 5)) \52ENUM_ENTRY(ATTR_VEX, (0x1 << 6)) \53ENUM_ENTRY(ATTR_VEXL, (0x1 << 7)) \54ENUM_ENTRY(ATTR_EVEX, (0x1 << 8)) \55ENUM_ENTRY(ATTR_EVEXL, (0x1 << 9)) \56ENUM_ENTRY(ATTR_EVEXL2, (0x1 << 10)) \57ENUM_ENTRY(ATTR_EVEXK, (0x1 << 11)) \58ENUM_ENTRY(ATTR_EVEXKZ, (0x1 << 12)) \59ENUM_ENTRY(ATTR_EVEXB, (0x1 << 13))6061#define ENUM_ENTRY(n, v) n = v,62enum attributeBits {63ATTRIBUTE_BITS64ATTR_max65};66#undef ENUM_ENTRY6768/*69* Combinations of the above attributes that are relevant to instruction70* decode. Although other combinations are possible, they can be reduced to71* these without affecting the ultimately decoded instruction.72*/7374// Class name Rank Rationale for rank assignment75#define INSTRUCTION_CONTEXTS \76ENUM_ENTRY(IC, 0, "says nothing about the instruction") \77ENUM_ENTRY(IC_64BIT, 1, "says the instruction applies in " \78"64-bit mode but no more") \79ENUM_ENTRY(IC_OPSIZE, 3, "requires an OPSIZE prefix, so " \80"operands change width") \81ENUM_ENTRY(IC_ADSIZE, 3, "requires an ADSIZE prefix, so " \82"operands change width") \83ENUM_ENTRY(IC_OPSIZE_ADSIZE, 4, "requires ADSIZE and OPSIZE prefixes") \84ENUM_ENTRY(IC_XD, 2, "may say something about the opcode " \85"but not the operands") \86ENUM_ENTRY(IC_XS, 2, "may say something about the opcode " \87"but not the operands") \88ENUM_ENTRY(IC_XD_OPSIZE, 3, "requires an OPSIZE prefix, so " \89"operands change width") \90ENUM_ENTRY(IC_XS_OPSIZE, 3, "requires an OPSIZE prefix, so " \91"operands change width") \92ENUM_ENTRY(IC_XD_ADSIZE, 3, "requires an ADSIZE prefix, so " \93"operands change width") \94ENUM_ENTRY(IC_XS_ADSIZE, 3, "requires an ADSIZE prefix, so " \95"operands change width") \96ENUM_ENTRY(IC_64BIT_REXW, 5, "requires a REX.W prefix, so operands "\97"change width; overrides IC_OPSIZE") \98ENUM_ENTRY(IC_64BIT_REXW_ADSIZE, 6, "requires a REX.W prefix and 0x67 " \99"prefix") \100ENUM_ENTRY(IC_64BIT_OPSIZE, 3, "Just as meaningful as IC_OPSIZE") \101ENUM_ENTRY(IC_64BIT_ADSIZE, 3, "Just as meaningful as IC_ADSIZE") \102ENUM_ENTRY(IC_64BIT_OPSIZE_ADSIZE, 4, "Just as meaningful as IC_OPSIZE/" \103"IC_ADSIZE") \104ENUM_ENTRY(IC_64BIT_XD, 6, "XD instructions are SSE; REX.W is " \105"secondary") \106ENUM_ENTRY(IC_64BIT_XS, 6, "Just as meaningful as IC_64BIT_XD") \107ENUM_ENTRY(IC_64BIT_XD_OPSIZE, 3, "Just as meaningful as IC_XD_OPSIZE") \108ENUM_ENTRY(IC_64BIT_XS_OPSIZE, 3, "Just as meaningful as IC_XS_OPSIZE") \109ENUM_ENTRY(IC_64BIT_XD_ADSIZE, 3, "Just as meaningful as IC_XD_ADSIZE") \110ENUM_ENTRY(IC_64BIT_XS_ADSIZE, 3, "Just as meaningful as IC_XS_ADSIZE") \111ENUM_ENTRY(IC_64BIT_REXW_XS, 7, "OPSIZE could mean a different " \112"opcode") \113ENUM_ENTRY(IC_64BIT_REXW_XD, 7, "Just as meaningful as " \114"IC_64BIT_REXW_XS") \115ENUM_ENTRY(IC_64BIT_REXW_OPSIZE, 8, "The Dynamic Duo! Prefer over all " \116"else because this changes most " \117"operands' meaning") \118ENUM_ENTRY(IC_VEX, 1, "requires a VEX prefix") \119ENUM_ENTRY(IC_VEX_XS, 2, "requires VEX and the XS prefix") \120ENUM_ENTRY(IC_VEX_XD, 2, "requires VEX and the XD prefix") \121ENUM_ENTRY(IC_VEX_OPSIZE, 2, "requires VEX and the OpSize prefix") \122ENUM_ENTRY(IC_VEX_W, 3, "requires VEX and the W prefix") \123ENUM_ENTRY(IC_VEX_W_XS, 4, "requires VEX, W, and XS prefix") \124ENUM_ENTRY(IC_VEX_W_XD, 4, "requires VEX, W, and XD prefix") \125ENUM_ENTRY(IC_VEX_W_OPSIZE, 4, "requires VEX, W, and OpSize") \126ENUM_ENTRY(IC_VEX_L, 3, "requires VEX and the L prefix") \127ENUM_ENTRY(IC_VEX_L_XS, 4, "requires VEX and the L and XS prefix")\128ENUM_ENTRY(IC_VEX_L_XD, 4, "requires VEX and the L and XD prefix")\129ENUM_ENTRY(IC_VEX_L_OPSIZE, 4, "requires VEX, L, and OpSize") \130ENUM_ENTRY(IC_VEX_L_W, 4, "requires VEX, L and W") \131ENUM_ENTRY(IC_VEX_L_W_XS, 5, "requires VEX, L, W and XS prefix") \132ENUM_ENTRY(IC_VEX_L_W_XD, 5, "requires VEX, L, W and XD prefix") \133ENUM_ENTRY(IC_VEX_L_W_OPSIZE, 5, "requires VEX, L, W and OpSize") \134ENUM_ENTRY(IC_EVEX, 1, "requires an EVEX prefix") \135ENUM_ENTRY(IC_EVEX_XS, 2, "requires EVEX and the XS prefix") \136ENUM_ENTRY(IC_EVEX_XD, 2, "requires EVEX and the XD prefix") \137ENUM_ENTRY(IC_EVEX_OPSIZE, 2, "requires EVEX and the OpSize prefix") \138ENUM_ENTRY(IC_EVEX_W, 3, "requires EVEX and the W prefix") \139ENUM_ENTRY(IC_EVEX_W_XS, 4, "requires EVEX, W, and XS prefix") \140ENUM_ENTRY(IC_EVEX_W_XD, 4, "requires EVEX, W, and XD prefix") \141ENUM_ENTRY(IC_EVEX_W_OPSIZE, 4, "requires EVEX, W, and OpSize") \142ENUM_ENTRY(IC_EVEX_L, 3, "requires EVEX and the L prefix") \143ENUM_ENTRY(IC_EVEX_L_XS, 4, "requires EVEX and the L and XS prefix")\144ENUM_ENTRY(IC_EVEX_L_XD, 4, "requires EVEX and the L and XD prefix")\145ENUM_ENTRY(IC_EVEX_L_OPSIZE, 4, "requires EVEX, L, and OpSize") \146ENUM_ENTRY(IC_EVEX_L_W, 3, "requires EVEX, L and W") \147ENUM_ENTRY(IC_EVEX_L_W_XS, 4, "requires EVEX, L, W and XS prefix") \148ENUM_ENTRY(IC_EVEX_L_W_XD, 4, "requires EVEX, L, W and XD prefix") \149ENUM_ENTRY(IC_EVEX_L_W_OPSIZE, 4, "requires EVEX, L, W and OpSize") \150ENUM_ENTRY(IC_EVEX_L2, 3, "requires EVEX and the L2 prefix") \151ENUM_ENTRY(IC_EVEX_L2_XS, 4, "requires EVEX and the L2 and XS prefix")\152ENUM_ENTRY(IC_EVEX_L2_XD, 4, "requires EVEX and the L2 and XD prefix")\153ENUM_ENTRY(IC_EVEX_L2_OPSIZE, 4, "requires EVEX, L2, and OpSize") \154ENUM_ENTRY(IC_EVEX_L2_W, 3, "requires EVEX, L2 and W") \155ENUM_ENTRY(IC_EVEX_L2_W_XS, 4, "requires EVEX, L2, W and XS prefix") \156ENUM_ENTRY(IC_EVEX_L2_W_XD, 4, "requires EVEX, L2, W and XD prefix") \157ENUM_ENTRY(IC_EVEX_L2_W_OPSIZE, 4, "requires EVEX, L2, W and OpSize") \158ENUM_ENTRY(IC_EVEX_K, 1, "requires an EVEX_K prefix") \159ENUM_ENTRY(IC_EVEX_XS_K, 2, "requires EVEX_K and the XS prefix") \160ENUM_ENTRY(IC_EVEX_XD_K, 2, "requires EVEX_K and the XD prefix") \161ENUM_ENTRY(IC_EVEX_OPSIZE_K, 2, "requires EVEX_K and the OpSize prefix") \162ENUM_ENTRY(IC_EVEX_W_K, 3, "requires EVEX_K and the W prefix") \163ENUM_ENTRY(IC_EVEX_W_XS_K, 4, "requires EVEX_K, W, and XS prefix") \164ENUM_ENTRY(IC_EVEX_W_XD_K, 4, "requires EVEX_K, W, and XD prefix") \165ENUM_ENTRY(IC_EVEX_W_OPSIZE_K, 4, "requires EVEX_K, W, and OpSize") \166ENUM_ENTRY(IC_EVEX_L_K, 3, "requires EVEX_K and the L prefix") \167ENUM_ENTRY(IC_EVEX_L_XS_K, 4, "requires EVEX_K and the L and XS prefix")\168ENUM_ENTRY(IC_EVEX_L_XD_K, 4, "requires EVEX_K and the L and XD prefix")\169ENUM_ENTRY(IC_EVEX_L_OPSIZE_K, 4, "requires EVEX_K, L, and OpSize") \170ENUM_ENTRY(IC_EVEX_L_W_K, 3, "requires EVEX_K, L and W") \171ENUM_ENTRY(IC_EVEX_L_W_XS_K, 4, "requires EVEX_K, L, W and XS prefix") \172ENUM_ENTRY(IC_EVEX_L_W_XD_K, 4, "requires EVEX_K, L, W and XD prefix") \173ENUM_ENTRY(IC_EVEX_L_W_OPSIZE_K, 4, "requires EVEX_K, L, W and OpSize") \174ENUM_ENTRY(IC_EVEX_L2_K, 3, "requires EVEX_K and the L2 prefix") \175ENUM_ENTRY(IC_EVEX_L2_XS_K, 4, "requires EVEX_K and the L2 and XS prefix")\176ENUM_ENTRY(IC_EVEX_L2_XD_K, 4, "requires EVEX_K and the L2 and XD prefix")\177ENUM_ENTRY(IC_EVEX_L2_OPSIZE_K, 4, "requires EVEX_K, L2, and OpSize") \178ENUM_ENTRY(IC_EVEX_L2_W_K, 3, "requires EVEX_K, L2 and W") \179ENUM_ENTRY(IC_EVEX_L2_W_XS_K, 4, "requires EVEX_K, L2, W and XS prefix") \180ENUM_ENTRY(IC_EVEX_L2_W_XD_K, 4, "requires EVEX_K, L2, W and XD prefix") \181ENUM_ENTRY(IC_EVEX_L2_W_OPSIZE_K, 4, "requires EVEX_K, L2, W and OpSize") \182ENUM_ENTRY(IC_EVEX_B, 1, "requires an EVEX_B prefix") \183ENUM_ENTRY(IC_EVEX_XS_B, 2, "requires EVEX_B and the XS prefix") \184ENUM_ENTRY(IC_EVEX_XD_B, 2, "requires EVEX_B and the XD prefix") \185ENUM_ENTRY(IC_EVEX_OPSIZE_B, 2, "requires EVEX_B and the OpSize prefix") \186ENUM_ENTRY(IC_EVEX_W_B, 3, "requires EVEX_B and the W prefix") \187ENUM_ENTRY(IC_EVEX_W_XS_B, 4, "requires EVEX_B, W, and XS prefix") \188ENUM_ENTRY(IC_EVEX_W_XD_B, 4, "requires EVEX_B, W, and XD prefix") \189ENUM_ENTRY(IC_EVEX_W_OPSIZE_B, 4, "requires EVEX_B, W, and OpSize") \190ENUM_ENTRY(IC_EVEX_L_B, 3, "requires EVEX_B and the L prefix") \191ENUM_ENTRY(IC_EVEX_L_XS_B, 4, "requires EVEX_B and the L and XS prefix")\192ENUM_ENTRY(IC_EVEX_L_XD_B, 4, "requires EVEX_B and the L and XD prefix")\193ENUM_ENTRY(IC_EVEX_L_OPSIZE_B, 4, "requires EVEX_B, L, and OpSize") \194ENUM_ENTRY(IC_EVEX_L_W_B, 3, "requires EVEX_B, L and W") \195ENUM_ENTRY(IC_EVEX_L_W_XS_B, 4, "requires EVEX_B, L, W and XS prefix") \196ENUM_ENTRY(IC_EVEX_L_W_XD_B, 4, "requires EVEX_B, L, W and XD prefix") \197ENUM_ENTRY(IC_EVEX_L_W_OPSIZE_B, 4, "requires EVEX_B, L, W and OpSize") \198ENUM_ENTRY(IC_EVEX_L2_B, 3, "requires EVEX_B and the L2 prefix") \199ENUM_ENTRY(IC_EVEX_L2_XS_B, 4, "requires EVEX_B and the L2 and XS prefix")\200ENUM_ENTRY(IC_EVEX_L2_XD_B, 4, "requires EVEX_B and the L2 and XD prefix")\201ENUM_ENTRY(IC_EVEX_L2_OPSIZE_B, 4, "requires EVEX_B, L2, and OpSize") \202ENUM_ENTRY(IC_EVEX_L2_W_B, 3, "requires EVEX_B, L2 and W") \203ENUM_ENTRY(IC_EVEX_L2_W_XS_B, 4, "requires EVEX_B, L2, W and XS prefix") \204ENUM_ENTRY(IC_EVEX_L2_W_XD_B, 4, "requires EVEX_B, L2, W and XD prefix") \205ENUM_ENTRY(IC_EVEX_L2_W_OPSIZE_B, 4, "requires EVEX_B, L2, W and OpSize") \206ENUM_ENTRY(IC_EVEX_K_B, 1, "requires EVEX_B and EVEX_K prefix") \207ENUM_ENTRY(IC_EVEX_XS_K_B, 2, "requires EVEX_B, EVEX_K and the XS prefix") \208ENUM_ENTRY(IC_EVEX_XD_K_B, 2, "requires EVEX_B, EVEX_K and the XD prefix") \209ENUM_ENTRY(IC_EVEX_OPSIZE_K_B, 2, "requires EVEX_B, EVEX_K and the OpSize prefix") \210ENUM_ENTRY(IC_EVEX_W_K_B, 3, "requires EVEX_B, EVEX_K and the W prefix") \211ENUM_ENTRY(IC_EVEX_W_XS_K_B, 4, "requires EVEX_B, EVEX_K, W, and XS prefix") \212ENUM_ENTRY(IC_EVEX_W_XD_K_B, 4, "requires EVEX_B, EVEX_K, W, and XD prefix") \213ENUM_ENTRY(IC_EVEX_W_OPSIZE_K_B, 4, "requires EVEX_B, EVEX_K, W, and OpSize") \214ENUM_ENTRY(IC_EVEX_L_K_B, 3, "requires EVEX_B, EVEX_K and the L prefix") \215ENUM_ENTRY(IC_EVEX_L_XS_K_B, 4, "requires EVEX_B, EVEX_K and the L and XS prefix")\216ENUM_ENTRY(IC_EVEX_L_XD_K_B, 4, "requires EVEX_B, EVEX_K and the L and XD prefix")\217ENUM_ENTRY(IC_EVEX_L_OPSIZE_K_B, 4, "requires EVEX_B, EVEX_K, L, and OpSize") \218ENUM_ENTRY(IC_EVEX_L_W_K_B, 3, "requires EVEX_B, EVEX_K, L and W") \219ENUM_ENTRY(IC_EVEX_L_W_XS_K_B, 4, "requires EVEX_B, EVEX_K, L, W and XS prefix") \220ENUM_ENTRY(IC_EVEX_L_W_XD_K_B, 4, "requires EVEX_B, EVEX_K, L, W and XD prefix") \221ENUM_ENTRY(IC_EVEX_L_W_OPSIZE_K_B,4, "requires EVEX_B, EVEX_K, L, W and OpSize") \222ENUM_ENTRY(IC_EVEX_L2_K_B, 3, "requires EVEX_B, EVEX_K and the L2 prefix") \223ENUM_ENTRY(IC_EVEX_L2_XS_K_B, 4, "requires EVEX_B, EVEX_K and the L2 and XS prefix")\224ENUM_ENTRY(IC_EVEX_L2_XD_K_B, 4, "requires EVEX_B, EVEX_K and the L2 and XD prefix")\225ENUM_ENTRY(IC_EVEX_L2_OPSIZE_K_B, 4, "requires EVEX_B, EVEX_K, L2, and OpSize") \226ENUM_ENTRY(IC_EVEX_L2_W_K_B, 3, "requires EVEX_B, EVEX_K, L2 and W") \227ENUM_ENTRY(IC_EVEX_L2_W_XS_K_B, 4, "requires EVEX_B, EVEX_K, L2, W and XS prefix") \228ENUM_ENTRY(IC_EVEX_L2_W_XD_K_B, 4, "requires EVEX_B, EVEX_K, L2, W and XD prefix") \229ENUM_ENTRY(IC_EVEX_L2_W_OPSIZE_K_B,4, "requires EVEX_B, EVEX_K, L2, W and OpSize") \230ENUM_ENTRY(IC_EVEX_KZ_B, 1, "requires EVEX_B and EVEX_KZ prefix") \231ENUM_ENTRY(IC_EVEX_XS_KZ_B, 2, "requires EVEX_B, EVEX_KZ and the XS prefix") \232ENUM_ENTRY(IC_EVEX_XD_KZ_B, 2, "requires EVEX_B, EVEX_KZ and the XD prefix") \233ENUM_ENTRY(IC_EVEX_OPSIZE_KZ_B, 2, "requires EVEX_B, EVEX_KZ and the OpSize prefix") \234ENUM_ENTRY(IC_EVEX_W_KZ_B, 3, "requires EVEX_B, EVEX_KZ and the W prefix") \235ENUM_ENTRY(IC_EVEX_W_XS_KZ_B, 4, "requires EVEX_B, EVEX_KZ, W, and XS prefix") \236ENUM_ENTRY(IC_EVEX_W_XD_KZ_B, 4, "requires EVEX_B, EVEX_KZ, W, and XD prefix") \237ENUM_ENTRY(IC_EVEX_W_OPSIZE_KZ_B, 4, "requires EVEX_B, EVEX_KZ, W, and OpSize") \238ENUM_ENTRY(IC_EVEX_L_KZ_B, 3, "requires EVEX_B, EVEX_KZ and the L prefix") \239ENUM_ENTRY(IC_EVEX_L_XS_KZ_B, 4, "requires EVEX_B, EVEX_KZ and the L and XS prefix")\240ENUM_ENTRY(IC_EVEX_L_XD_KZ_B, 4, "requires EVEX_B, EVEX_KZ and the L and XD prefix")\241ENUM_ENTRY(IC_EVEX_L_OPSIZE_KZ_B, 4, "requires EVEX_B, EVEX_KZ, L, and OpSize") \242ENUM_ENTRY(IC_EVEX_L_W_KZ_B, 3, "requires EVEX_B, EVEX_KZ, L and W") \243ENUM_ENTRY(IC_EVEX_L_W_XS_KZ_B, 4, "requires EVEX_B, EVEX_KZ, L, W and XS prefix") \244ENUM_ENTRY(IC_EVEX_L_W_XD_KZ_B, 4, "requires EVEX_B, EVEX_KZ, L, W and XD prefix") \245ENUM_ENTRY(IC_EVEX_L_W_OPSIZE_KZ_B, 4, "requires EVEX_B, EVEX_KZ, L, W and OpSize") \246ENUM_ENTRY(IC_EVEX_L2_KZ_B, 3, "requires EVEX_B, EVEX_KZ and the L2 prefix") \247ENUM_ENTRY(IC_EVEX_L2_XS_KZ_B, 4, "requires EVEX_B, EVEX_KZ and the L2 and XS prefix")\248ENUM_ENTRY(IC_EVEX_L2_XD_KZ_B, 4, "requires EVEX_B, EVEX_KZ and the L2 and XD prefix")\249ENUM_ENTRY(IC_EVEX_L2_OPSIZE_KZ_B, 4, "requires EVEX_B, EVEX_KZ, L2, and OpSize") \250ENUM_ENTRY(IC_EVEX_L2_W_KZ_B, 3, "requires EVEX_B, EVEX_KZ, L2 and W") \251ENUM_ENTRY(IC_EVEX_L2_W_XS_KZ_B, 4, "requires EVEX_B, EVEX_KZ, L2, W and XS prefix") \252ENUM_ENTRY(IC_EVEX_L2_W_XD_KZ_B, 4, "requires EVEX_B, EVEX_KZ, L2, W and XD prefix") \253ENUM_ENTRY(IC_EVEX_L2_W_OPSIZE_KZ_B, 4, "requires EVEX_B, EVEX_KZ, L2, W and OpSize") \254ENUM_ENTRY(IC_EVEX_KZ, 1, "requires an EVEX_KZ prefix") \255ENUM_ENTRY(IC_EVEX_XS_KZ, 2, "requires EVEX_KZ and the XS prefix") \256ENUM_ENTRY(IC_EVEX_XD_KZ, 2, "requires EVEX_KZ and the XD prefix") \257ENUM_ENTRY(IC_EVEX_OPSIZE_KZ, 2, "requires EVEX_KZ and the OpSize prefix") \258ENUM_ENTRY(IC_EVEX_W_KZ, 3, "requires EVEX_KZ and the W prefix") \259ENUM_ENTRY(IC_EVEX_W_XS_KZ, 4, "requires EVEX_KZ, W, and XS prefix") \260ENUM_ENTRY(IC_EVEX_W_XD_KZ, 4, "requires EVEX_KZ, W, and XD prefix") \261ENUM_ENTRY(IC_EVEX_W_OPSIZE_KZ, 4, "requires EVEX_KZ, W, and OpSize") \262ENUM_ENTRY(IC_EVEX_L_KZ, 3, "requires EVEX_KZ and the L prefix") \263ENUM_ENTRY(IC_EVEX_L_XS_KZ, 4, "requires EVEX_KZ and the L and XS prefix")\264ENUM_ENTRY(IC_EVEX_L_XD_KZ, 4, "requires EVEX_KZ and the L and XD prefix")\265ENUM_ENTRY(IC_EVEX_L_OPSIZE_KZ, 4, "requires EVEX_KZ, L, and OpSize") \266ENUM_ENTRY(IC_EVEX_L_W_KZ, 3, "requires EVEX_KZ, L and W") \267ENUM_ENTRY(IC_EVEX_L_W_XS_KZ, 4, "requires EVEX_KZ, L, W and XS prefix") \268ENUM_ENTRY(IC_EVEX_L_W_XD_KZ, 4, "requires EVEX_KZ, L, W and XD prefix") \269ENUM_ENTRY(IC_EVEX_L_W_OPSIZE_KZ, 4, "requires EVEX_KZ, L, W and OpSize") \270ENUM_ENTRY(IC_EVEX_L2_KZ, 3, "requires EVEX_KZ and the L2 prefix") \271ENUM_ENTRY(IC_EVEX_L2_XS_KZ, 4, "requires EVEX_KZ and the L2 and XS prefix")\272ENUM_ENTRY(IC_EVEX_L2_XD_KZ, 4, "requires EVEX_KZ and the L2 and XD prefix")\273ENUM_ENTRY(IC_EVEX_L2_OPSIZE_KZ, 4, "requires EVEX_KZ, L2, and OpSize") \274ENUM_ENTRY(IC_EVEX_L2_W_KZ, 3, "requires EVEX_KZ, L2 and W") \275ENUM_ENTRY(IC_EVEX_L2_W_XS_KZ, 4, "requires EVEX_KZ, L2, W and XS prefix") \276ENUM_ENTRY(IC_EVEX_L2_W_XD_KZ, 4, "requires EVEX_KZ, L2, W and XD prefix") \277ENUM_ENTRY(IC_EVEX_L2_W_OPSIZE_KZ, 4, "requires EVEX_KZ, L2, W and OpSize")278279#define ENUM_ENTRY(n, r, d) n,280typedef enum {281INSTRUCTION_CONTEXTS282IC_max283} InstructionContext;284#undef ENUM_ENTRY285286/*287* Opcode types, which determine which decode table to use, both in the Intel288* manual and also for the decoder.289*/290typedef enum {291ONEBYTE = 0,292TWOBYTE = 1,293THREEBYTE_38 = 2,294THREEBYTE_3A = 3,295XOP8_MAP = 4,296XOP9_MAP = 5,297XOPA_MAP = 6,298THREEDNOW_MAP = 7299} OpcodeType;300301/*302* The following structs are used for the hierarchical decode table. After303* determining the instruction's class (i.e., which IC_* constant applies to304* it), the decoder reads the opcode. Some instructions require specific305* values of the ModR/M byte, so the ModR/M byte indexes into the final table.306*307* If a ModR/M byte is not required, "required" is left unset, and the values308* for each instructionID are identical.309*/310311typedef uint16_t InstrUID;312313/*314* ModRMDecisionType - describes the type of ModR/M decision, allowing the315* consumer to determine the number of entries in it.316*317* MODRM_ONEENTRY - No matter what the value of the ModR/M byte is, the decoded318* instruction is the same.319* MODRM_SPLITRM - If the ModR/M byte is between 0x00 and 0xbf, the opcode320* corresponds to one instruction; otherwise, it corresponds to321* a different instruction.322* MODRM_SPLITMISC- If the ModR/M byte is between 0x00 and 0xbf, ModR/M byte323* divided by 8 is used to select instruction; otherwise, each324* value of the ModR/M byte could correspond to a different325* instruction.326* MODRM_SPLITREG - ModR/M byte divided by 8 is used to select instruction. This327corresponds to instructions that use reg field as opcode328* MODRM_FULL - Potentially, each value of the ModR/M byte could correspond329* to a different instruction.330*/331332#define MODRMTYPES \333ENUM_ENTRY(MODRM_ONEENTRY) \334ENUM_ENTRY(MODRM_SPLITRM) \335ENUM_ENTRY(MODRM_SPLITMISC) \336ENUM_ENTRY(MODRM_SPLITREG) \337ENUM_ENTRY(MODRM_FULL)338339#define ENUM_ENTRY(n) n,340typedef enum {341MODRMTYPES342MODRM_max343} ModRMDecisionType;344#undef ENUM_ENTRY345346#define CASE_ENCODING_RM \347case ENCODING_RM: \348case ENCODING_RM_CD2: \349case ENCODING_RM_CD4: \350case ENCODING_RM_CD8: \351case ENCODING_RM_CD16: \352case ENCODING_RM_CD32: \353case ENCODING_RM_CD64354355#define CASE_ENCODING_VSIB \356case ENCODING_VSIB: \357case ENCODING_VSIB_CD2: \358case ENCODING_VSIB_CD4: \359case ENCODING_VSIB_CD8: \360case ENCODING_VSIB_CD16: \361case ENCODING_VSIB_CD32: \362case ENCODING_VSIB_CD64363364// Physical encodings of instruction operands.365366#define ENCODINGS \367ENUM_ENTRY(ENCODING_NONE, "") \368ENUM_ENTRY(ENCODING_REG, "Register operand in ModR/M byte.") \369ENUM_ENTRY(ENCODING_RM, "R/M operand in ModR/M byte.") \370ENUM_ENTRY(ENCODING_RM_CD2, "R/M operand with CDisp scaling of 2") \371ENUM_ENTRY(ENCODING_RM_CD4, "R/M operand with CDisp scaling of 4") \372ENUM_ENTRY(ENCODING_RM_CD8, "R/M operand with CDisp scaling of 8") \373ENUM_ENTRY(ENCODING_RM_CD16,"R/M operand with CDisp scaling of 16") \374ENUM_ENTRY(ENCODING_RM_CD32,"R/M operand with CDisp scaling of 32") \375ENUM_ENTRY(ENCODING_RM_CD64,"R/M operand with CDisp scaling of 64") \376ENUM_ENTRY(ENCODING_VSIB, "VSIB operand in ModR/M byte.") \377ENUM_ENTRY(ENCODING_VSIB_CD2, "VSIB operand with CDisp scaling of 2") \378ENUM_ENTRY(ENCODING_VSIB_CD4, "VSIB operand with CDisp scaling of 4") \379ENUM_ENTRY(ENCODING_VSIB_CD8, "VSIB operand with CDisp scaling of 8") \380ENUM_ENTRY(ENCODING_VSIB_CD16,"VSIB operand with CDisp scaling of 16") \381ENUM_ENTRY(ENCODING_VSIB_CD32,"VSIB operand with CDisp scaling of 32") \382ENUM_ENTRY(ENCODING_VSIB_CD64,"VSIB operand with CDisp scaling of 64") \383ENUM_ENTRY(ENCODING_VVVV, "Register operand in VEX.vvvv byte.") \384ENUM_ENTRY(ENCODING_WRITEMASK, "Register operand in EVEX.aaa byte.") \385ENUM_ENTRY(ENCODING_IB, "1-byte immediate") \386ENUM_ENTRY(ENCODING_IW, "2-byte") \387ENUM_ENTRY(ENCODING_ID, "4-byte") \388ENUM_ENTRY(ENCODING_IO, "8-byte") \389ENUM_ENTRY(ENCODING_RB, "(AL..DIL, R8L..R15L) Register code added to " \390"the opcode byte") \391ENUM_ENTRY(ENCODING_RW, "(AX..DI, R8W..R15W)") \392ENUM_ENTRY(ENCODING_RD, "(EAX..EDI, R8D..R15D)") \393ENUM_ENTRY(ENCODING_RO, "(RAX..RDI, R8..R15)") \394ENUM_ENTRY(ENCODING_FP, "Position on floating-point stack in ModR/M " \395"byte.") \396ENUM_ENTRY(ENCODING_Iv, "Immediate of operand size") \397ENUM_ENTRY(ENCODING_Ia, "Immediate of address size") \398ENUM_ENTRY(ENCODING_IRC, "Immediate for static rounding control") \399ENUM_ENTRY(ENCODING_Rv, "Register code of operand size added to the " \400"opcode byte") \401ENUM_ENTRY(ENCODING_DUP, "Duplicate of another operand; ID is encoded " \402"in type") \403ENUM_ENTRY(ENCODING_SI, "Source index; encoded in OpSize/Adsize prefix") \404ENUM_ENTRY(ENCODING_DI, "Destination index; encoded in prefixes")405406#define ENUM_ENTRY(n, d) n,407typedef enum {408ENCODINGS409ENCODING_max410} OperandEncoding;411#undef ENUM_ENTRY412413/*414* Semantic interpretations of instruction operands.415*/416#define TYPES \417ENUM_ENTRY(TYPE_NONE, "") \418ENUM_ENTRY(TYPE_REL, "immediate address") \419ENUM_ENTRY(TYPE_R8, "1-byte register operand") \420ENUM_ENTRY(TYPE_R16, "2-byte") \421ENUM_ENTRY(TYPE_R32, "4-byte") \422ENUM_ENTRY(TYPE_R64, "8-byte") \423ENUM_ENTRY(TYPE_IMM, "immediate operand") \424ENUM_ENTRY(TYPE_IMM3, "1-byte immediate operand between 0 and 7") \425ENUM_ENTRY(TYPE_IMM5, "1-byte immediate operand between 0 and 31") \426ENUM_ENTRY(TYPE_AVX512ICC, "1-byte immediate operand for AVX512 icmp") \427ENUM_ENTRY(TYPE_UIMM8, "1-byte unsigned immediate operand") \428ENUM_ENTRY(TYPE_M, "Memory operand") \429ENUM_ENTRY(TYPE_MVSIBX, "Memory operand using XMM index") \430ENUM_ENTRY(TYPE_MVSIBY, "Memory operand using YMM index") \431ENUM_ENTRY(TYPE_MVSIBZ, "Memory operand using ZMM index") \432ENUM_ENTRY(TYPE_SRCIDX, "memory at source index") \433ENUM_ENTRY(TYPE_DSTIDX, "memory at destination index") \434ENUM_ENTRY(TYPE_MOFFS, "memory offset (relative to segment base)") \435ENUM_ENTRY(TYPE_ST, "Position on the floating-point stack") \436ENUM_ENTRY(TYPE_MM64, "8-byte MMX register") \437ENUM_ENTRY(TYPE_XMM, "16-byte") \438ENUM_ENTRY(TYPE_YMM, "32-byte") \439ENUM_ENTRY(TYPE_ZMM, "64-byte") \440ENUM_ENTRY(TYPE_VK, "mask register") \441ENUM_ENTRY(TYPE_SEGMENTREG, "Segment register operand") \442ENUM_ENTRY(TYPE_DEBUGREG, "Debug register operand") \443ENUM_ENTRY(TYPE_CONTROLREG, "Control register operand") \444ENUM_ENTRY(TYPE_BNDR, "MPX bounds register") \445\446ENUM_ENTRY(TYPE_Rv, "Register operand of operand size") \447ENUM_ENTRY(TYPE_RELv, "Immediate address of operand size") \448ENUM_ENTRY(TYPE_DUP0, "Duplicate of operand 0") \449ENUM_ENTRY(TYPE_DUP1, "operand 1") \450ENUM_ENTRY(TYPE_DUP2, "operand 2") \451ENUM_ENTRY(TYPE_DUP3, "operand 3") \452ENUM_ENTRY(TYPE_DUP4, "operand 4") \453454#define ENUM_ENTRY(n, d) n,455typedef enum {456TYPES457TYPE_max458} OperandType;459#undef ENUM_ENTRY460461/*462* The specification for how to extract and interpret one operand.463*/464typedef struct OperandSpecifier {465uint8_t encoding;466uint8_t type;467} OperandSpecifier;468469#define X86_MAX_OPERANDS 6470471/*472* Decoding mode for the Intel disassembler. 16-bit, 32-bit, and 64-bit mode473* are supported, and represent real mode, IA-32e, and IA-32e in 64-bit mode,474* respectively.475*/476typedef enum {477MODE_16BIT,478MODE_32BIT,479MODE_64BIT480} DisassemblerMode;481482#endif483484485