1 /* udis86 - libudis86/decode.h
3 * Copyright (c) 2002-2009 Vivek Thampi
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #define MAX_INSN_LENGTH 15
31 /* register classes */
40 /* itab prefix bits */
42 #define P_c1 ( 1 << 0 )
43 #define P_C1(n) ( ( n >> 0 ) & 1 )
44 #define P_rexb ( 1 << 1 )
45 #define P_REXB(n) ( ( n >> 1 ) & 1 )
46 #define P_depM ( 1 << 2 )
47 #define P_DEPM(n) ( ( n >> 2 ) & 1 )
48 #define P_c3 ( 1 << 3 )
49 #define P_C3(n) ( ( n >> 3 ) & 1 )
50 #define P_inv64 ( 1 << 4 )
51 #define P_INV64(n) ( ( n >> 4 ) & 1 )
52 #define P_rexw ( 1 << 5 )
53 #define P_REXW(n) ( ( n >> 5 ) & 1 )
54 #define P_c2 ( 1 << 6 )
55 #define P_C2(n) ( ( n >> 6 ) & 1 )
56 #define P_def64 ( 1 << 7 )
57 #define P_DEF64(n) ( ( n >> 7 ) & 1 )
58 #define P_rexr ( 1 << 8 )
59 #define P_REXR(n) ( ( n >> 8 ) & 1 )
60 #define P_oso ( 1 << 9 )
61 #define P_OSO(n) ( ( n >> 9 ) & 1 )
62 #define P_aso ( 1 << 10 )
63 #define P_ASO(n) ( ( n >> 10 ) & 1 )
64 #define P_rexx ( 1 << 11 )
65 #define P_REXX(n) ( ( n >> 11 ) & 1 )
66 #define P_ImpAddr ( 1 << 12 )
67 #define P_IMPADDR(n) ( ( n >> 12 ) & 1 )
70 #define REX_W(r) ( ( 0xF & ( r ) ) >> 3 )
71 #define REX_R(r) ( ( 0x7 & ( r ) ) >> 2 )
72 #define REX_X(r) ( ( 0x3 & ( r ) ) >> 1 )
73 #define REX_B(r) ( ( 0x1 & ( r ) ) >> 0 )
74 #define REX_PFX_MASK(n) ( ( P_REXW(n) << 3 ) | \
75 ( P_REXR(n) << 2 ) | \
76 ( P_REXX(n) << 1 ) | \
79 /* scable-index-base bits */
80 #define SIB_S(b) ( ( b ) >> 6 )
81 #define SIB_I(b) ( ( ( b ) >> 3 ) & 7 )
82 #define SIB_B(b) ( ( b ) & 7 )
85 #define MODRM_REG(b) ( ( ( b ) >> 3 ) & 7 )
86 #define MODRM_NNN(b) ( ( ( b ) >> 3 ) & 7 )
87 #define MODRM_MOD(b) ( ( ( b ) >> 6 ) & 3 )
88 #define MODRM_RM(b) ( ( b ) & 7 )
90 /* operand type constants -- order is important! */
92 enum __attribute__((packed)) ud_operand_code {
95 OP_A, OP_E, OP_M, OP_G,
98 OP_AL, OP_CL, OP_DL, OP_BL,
99 OP_AH, OP_CH, OP_DH, OP_BH,
101 OP_ALr8b, OP_CLr9b, OP_DLr10b, OP_BLr11b,
102 OP_AHr12b, OP_CHr13b, OP_DHr14b, OP_BHr15b,
104 OP_AX, OP_CX, OP_DX, OP_BX,
105 OP_SI, OP_DI, OP_SP, OP_BP,
107 OP_rAX, OP_rCX, OP_rDX, OP_rBX,
108 OP_rSP, OP_rBP, OP_rSI, OP_rDI,
110 OP_rAXr8, OP_rCXr9, OP_rDXr10, OP_rBXr11,
111 OP_rSPr12, OP_rBPr13, OP_rSIr14, OP_rDIr15,
113 OP_eAX, OP_eCX, OP_eDX, OP_eBX,
114 OP_eSP, OP_eBP, OP_eSI, OP_eDI,
116 OP_ES, OP_CS, OP_SS, OP_DS,
119 OP_ST0, OP_ST1, OP_ST2, OP_ST3,
120 OP_ST4, OP_ST5, OP_ST6, OP_ST7,
125 OP_V, OP_W, OP_Q, OP_P,
127 OP_R, OP_C, OP_D, OP_VR, OP_PR
131 /* operand size constants */
133 enum __attribute__((packed)) ud_operand_size {
143 /* the following values are used as is,
144 * and thus hard-coded. changing them
145 * will break internals
156 /* A single operand of an entry in the instruction table.
157 * (internal use only)
159 struct ud_itab_entry_operand
161 enum ud_operand_code type;
162 enum ud_operand_size size;
166 /* A single entry in an instruction table.
171 enum ud_mnemonic_code mnemonic;
172 struct ud_itab_entry_operand operand1;
173 struct ud_itab_entry_operand operand2;
174 struct ud_itab_entry_operand operand3;
178 extern const char * ud_lookup_mnemonic( enum ud_mnemonic_code c );
180 #endif /* UD_DECODE_H */