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.
32 #define MAX_INSN_LENGTH 15
34 /* itab prefix bits */
36 #define P_cast ( 1 << 0 )
37 #define P_CAST(n) ( ( n >> 0 ) & 1 )
38 #define P_rexb ( 1 << 1 )
39 #define P_REXB(n) ( ( n >> 1 ) & 1 )
40 #define P_inv64 ( 1 << 4 )
41 #define P_INV64(n) ( ( n >> 4 ) & 1 )
42 #define P_rexw ( 1 << 5 )
43 #define P_REXW(n) ( ( n >> 5 ) & 1 )
44 #define P_def64 ( 1 << 7 )
45 #define P_DEF64(n) ( ( n >> 7 ) & 1 )
46 #define P_rexr ( 1 << 8 )
47 #define P_REXR(n) ( ( n >> 8 ) & 1 )
48 #define P_oso ( 1 << 9 )
49 #define P_OSO(n) ( ( n >> 9 ) & 1 )
50 #define P_aso ( 1 << 10 )
51 #define P_ASO(n) ( ( n >> 10 ) & 1 )
52 #define P_rexx ( 1 << 11 )
53 #define P_REXX(n) ( ( n >> 11 ) & 1 )
54 #define P_ImpAddr ( 1 << 12 )
55 #define P_IMPADDR(n) ( ( n >> 12 ) & 1 )
56 #define P_seg ( 1 << 13 )
57 #define P_SEG(n) ( ( n >> 13 ) & 1 )
58 #define P_str ( 1 << 14 )
59 #define P_STR(n) ( ( n >> 14 ) & 1 )
60 #define P_strz ( 1 << 15 )
61 #define P_STR_ZF(n) ( ( n >> 15 ) & 1 )
63 /* operand type constants -- order is important! */
65 enum ud_operand_code
{
68 OP_A
, OP_E
, OP_M
, OP_G
,
71 OP_R0
, OP_R1
, OP_R2
, OP_R3
,
72 OP_R4
, OP_R5
, OP_R6
, OP_R7
,
76 OP_eAX
, OP_eCX
, OP_eDX
,
77 OP_rAX
, OP_rCX
, OP_rDX
,
79 OP_ES
, OP_CS
, OP_SS
, OP_DS
,
82 OP_ST0
, OP_ST1
, OP_ST2
, OP_ST3
,
83 OP_ST4
, OP_ST5
, OP_ST6
, OP_ST7
,
88 OP_V
, OP_W
, OP_Q
, OP_P
,
97 /* operand size constants */
99 enum ud_operand_size
{
105 /* the following values are used as is,
106 * and thus hard-coded. changing them
107 * will break internals
119 * complex size types, that encode sizes for operands
120 * of type MR (memory or register), for internal use
121 * only. Id space 256 and above.
123 SZ_BD
= (SZ_B
<< 8) | SZ_D
,
124 SZ_BV
= (SZ_B
<< 8) | SZ_V
,
125 SZ_WD
= (SZ_W
<< 8) | SZ_D
,
126 SZ_WV
= (SZ_W
<< 8) | SZ_V
,
127 SZ_WY
= (SZ_W
<< 8) | SZ_Y
,
128 SZ_DY
= (SZ_D
<< 8) | SZ_Y
,
129 SZ_WO
= (SZ_W
<< 8) | SZ_O
,
130 SZ_DO
= (SZ_D
<< 8) | SZ_O
,
131 SZ_QO
= (SZ_Q
<< 8) | SZ_O
,
136 /* resolve complex size type.
138 static inline enum ud_operand_size
139 Mx_mem_size(enum ud_operand_size size
)
141 return (size
>> 8) & 0xff;
144 static inline enum ud_operand_size
145 Mx_reg_size(enum ud_operand_size size
)
150 /* A single operand of an entry in the instruction table.
151 * (internal use only)
153 struct ud_itab_entry_operand
155 enum ud_operand_code type
;
156 enum ud_operand_size size
;
160 /* A single entry in an instruction table.
165 enum ud_mnemonic_code mnemonic
;
166 struct ud_itab_entry_operand operand1
;
167 struct ud_itab_entry_operand operand2
;
168 struct ud_itab_entry_operand operand3
;
172 struct ud_lookup_table_list_entry
{
173 const uint16_t *table
;
174 enum ud_table_type type
;
181 ud_opcode_field_sext(uint8_t primary_opcode
)
183 return (primary_opcode
& 0x02) != 0;
186 extern struct ud_itab_entry ud_itab
[];
187 extern struct ud_lookup_table_list_entry ud_lookup_table_list
[];
189 #endif /* UD_DECODE_H */