]> andersk Git - udis86.git/blob - libudis86/decode.h
Use the public http URI to docbook.xsl.
[udis86.git] / libudis86 / decode.h
1 /* udis86 - libudis86/decode.h
2  *
3  * Copyright (c) 2002-2009 Vivek Thampi
4  * All rights reserved.
5  * 
6  * Redistribution and use in source and binary forms, with or without modification, 
7  * are permitted provided that the following conditions are met:
8  * 
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.
14  * 
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.
25  */
26 #ifndef UD_DECODE_H
27 #define UD_DECODE_H
28
29 #define MAX_INSN_LENGTH 15
30
31 /* register classes */
32 #define T_NONE  0
33 #define T_GPR   1
34 #define T_MMX   2
35 #define T_CRG   3
36 #define T_DBG   4
37 #define T_SEG   5
38 #define T_XMM   6
39
40 /* itab prefix bits */
41 #define P_none          ( 0 )
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 )
68
69 /* rex prefix bits */
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 ) | \
77                           ( P_REXB(n) << 0 ) )
78
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 )
83
84 /* modrm bits */
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 )
89
90 /* operand type constants -- order is important! */
91
92 enum __attribute__((packed)) ud_operand_code {
93     OP_NONE,
94
95     OP_A,      OP_E,      OP_M,       OP_G,       
96     OP_I,
97
98     OP_AL,     OP_CL,     OP_DL,      OP_BL,
99     OP_AH,     OP_CH,     OP_DH,      OP_BH,
100
101     OP_ALr8b,  OP_CLr9b,  OP_DLr10b,  OP_BLr11b,
102     OP_AHr12b, OP_CHr13b, OP_DHr14b,  OP_BHr15b,
103
104     OP_AX,     OP_CX,     OP_DX,      OP_BX,
105     OP_SI,     OP_DI,     OP_SP,      OP_BP,
106
107     OP_rAX,    OP_rCX,    OP_rDX,     OP_rBX,  
108     OP_rSP,    OP_rBP,    OP_rSI,     OP_rDI,
109
110     OP_rAXr8,  OP_rCXr9,  OP_rDXr10,  OP_rBXr11,  
111     OP_rSPr12, OP_rBPr13, OP_rSIr14,  OP_rDIr15,
112
113     OP_eAX,    OP_eCX,    OP_eDX,     OP_eBX,
114     OP_eSP,    OP_eBP,    OP_eSI,     OP_eDI,
115
116     OP_ES,     OP_CS,     OP_SS,      OP_DS,  
117     OP_FS,     OP_GS,
118
119     OP_ST0,    OP_ST1,    OP_ST2,     OP_ST3,
120     OP_ST4,    OP_ST5,    OP_ST6,     OP_ST7,
121
122     OP_J,      OP_S,      OP_O,          
123     OP_I1,     OP_I3, 
124
125     OP_V,      OP_W,      OP_Q,       OP_P, 
126
127     OP_R,      OP_C,  OP_D,       OP_VR,  OP_PR
128 };
129
130
131 /* operand size constants */
132
133 enum __attribute__((packed)) ud_operand_size {
134     SZ_NA  = 0,
135     SZ_Z   = 1,
136     SZ_V   = 2,
137     SZ_P   = 3,
138     SZ_WP  = 4,
139     SZ_DP  = 5,
140     SZ_MDQ = 6,
141     SZ_RDQ = 7,
142
143     /* the following values are used as is,
144      * and thus hard-coded. changing them 
145      * will break internals 
146      */
147     SZ_B   = 8,
148     SZ_W   = 16,
149     SZ_D   = 32,
150     SZ_Q   = 64,
151     SZ_T   = 80,
152     SZ_O   = 128,
153 };
154
155
156 /* A single operand of an entry in the instruction table. 
157  * (internal use only)
158  */
159 struct ud_itab_entry_operand 
160 {
161   enum ud_operand_code type;
162   enum ud_operand_size size;
163 };
164
165
166 /* A single entry in an instruction table. 
167  *(internal use only)
168  */
169 struct ud_itab_entry 
170 {
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;
175   uint32_t                      prefix;
176 };
177
178 extern const char * ud_lookup_mnemonic( enum ud_mnemonic_code c );
179
180 #endif /* UD_DECODE_H */
181
182 /* vim:cindent
183  * vim:expandtab
184  * vim:ts=4
185  * vim:sw=4
186  */
This page took 0.043038 seconds and 5 git commands to generate.