Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / misc / decoder_test / XED2 / include / xed / xed-inst.h
1 /*BEGIN_LEGAL 
2 Intel Open Source License 
3
4 Copyright (c) 2002-2007 Intel Corporation 
5 All rights reserved. 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9
10 Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.  Redistributions
12 in binary form must reproduce the above copyright notice, this list of
13 conditions and the following disclaimer in the documentation and/or
14 other materials provided with the distribution.  Neither the name of
15 the Intel Corporation nor the names of its contributors may be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
18  
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 END_LEGAL */
31 /// @file xed-inst.h
32 /// @author Mark Charney <mark.charney@intel.com>
33
34 #if !defined(_XED_INST_H_)
35 # define _XED_INST_H_
36
37 #include "xed-util.h"
38 #include "xed-portability.h"
39 #include "xed-category-enum.h"
40 #include "xed-extension-enum.h"
41 #include "xed-iclass-enum.h"
42 #include "xed-operand-enum.h"
43 #include "xed-operand-visibility-enum.h"
44 #include "xed-operand-action-enum.h"
45 #include "xed-operand-type-enum.h"
46 #include "xed-nonterminal-enum.h" // a generated file
47 #include "xed-operand-width-enum.h" // a generated file
48 #include "xed-reg-enum.h" // a generated file
49 #include "xed-attribute-enum.h" // a generated file
50 #include "xed-iform-enum.h" // a generated file
51 #include "xed-operand-bitvec.h" // a generated file
52
53
54 struct xed_decoded_inst_s; //fwd-decl
55
56 typedef void (*xed_operand_extractor_fn_t)(struct xed_decoded_inst_s* xds);
57 //typedef xed_bool_t (*xed_instruction_fixed_bit_confirmer_fn_t)(struct xed_decoded_inst_s* xds);
58
59
60 /// @ingroup DEC
61 /// Constant information about an individual generic operand, like an operand template, describing the operand properties. See @ref DEC for API information.
62 typedef struct XED_DLL_EXPORT xed_operand_s
63 {
64     xed_operand_enum_t _name;
65     
66     xed_operand_visibility_enum_t _operand_visibility;
67
68     xed_operand_action_enum_t _rw;
69     xed_operand_width_enum_t _oc2;
70
71     xed_operand_type_enum_t _type;
72     union {
73         xed_uint32_t               _imm; 
74         xed_nonterminal_enum_t _nt; // for nt_lookup_fn's
75         xed_reg_enum_t         _reg;
76     } _u;
77 }  xed_operand_t;    
78
79 /// @name xed_inst_t Template Operands Access
80 //@{ 
81 /// @ingroup DEC
82 static XED_INLINE xed_operand_enum_t xed_operand_name(const xed_operand_t* p)  { 
83     return p->_name; 
84 }
85
86
87 /// @ingroup DEC
88 static XED_INLINE xed_operand_visibility_enum_t  xed_operand_operand_visibility( const xed_operand_t* p) { 
89     return p->_operand_visibility; 
90 }
91
92
93 /// @ingroup DEC
94 /// @return The #xed_operand_type_enum_t of the operand template. 
95 /// This is probably not what you want.
96 static XED_INLINE xed_operand_type_enum_t xed_operand_type(const xed_operand_t* p)  {
97     return p->_type; 
98 }
99
100
101 /// @ingroup DEC
102 static XED_INLINE xed_operand_width_enum_t xed_operand_width(const xed_operand_t* p)  { 
103     return p->_oc2; 
104 }
105
106 /// @ingroup DEC
107 static XED_INLINE 
108 xed_nonterminal_enum_t xed_operand_nonterminal_name(const xed_operand_t* p)  { 
109     return p->_u._nt; 
110 }
111
112 /// @ingroup DEC
113 /// Careful with this one -- use #xed_decoded_inst_get_reg()! This one is
114 /// probably not what you think it is. It is only used for hard-coded
115 /// registers implicit in the instruction encoding. Most likely you want to
116 /// get the #xed_operand_enum_t and then look up the instruction using
117 /// #xed_decoded_inst_get_reg(). The hard-coded registers are also available
118 /// that way.
119 /// @param p  an operand template,  #xed_operand_t.
120 /// @return  the hard-wired (implicit or suppressed) registers, type #xed_reg_enum_t
121 static XED_INLINE xed_reg_enum_t xed_operand_reg(const xed_operand_t* p) {
122     return p->_u._reg;
123 }
124
125
126
127 /// @ingroup DEC
128 /// Careful with this one; See #xed_operand_is_register().
129 /// @param p  an operand template,  #xed_operand_t.
130 /// @return 1 if the operand template represents are register-type
131 /// operand. 
132 ///
133 ///  Related functions:
134 ///   Use #xed_decoded_inst_get_reg() to get the decoded name of /// the
135 ///   register, #xed_reg_enum_t. Use #xed_operand_is_register() to test
136 ///   #xed_operand_enum_t names.
137 static XED_INLINE xed_uint_t xed_operand_template_is_register(const xed_operand_t* p) {
138     return p->_type == XED_OPERAND_TYPE_NT_LOOKUP_FN || p->_type == XED_OPERAND_TYPE_REG;
139 }
140
141 /// @ingroup DEC
142 /// @param p  an operand template,  #xed_operand_t.
143 /// These operands represent branch displacements, memory displacements and various immediates
144 static XED_INLINE xed_uint32_t xed_operand_imm(const xed_operand_t* p) {
145     return p->_u._imm;
146 }
147
148 /// @ingroup DEC
149 /// Print the operand p into the buffer buf, of length buflen.
150 /// @param p  an operand template,  #xed_operand_t.
151 /// @param buf buffer that gets filled in
152 /// @param buflen maximum buffer length
153 XED_DLL_EXPORT void    xed_operand_print(const xed_operand_t* p, char* buf, int buflen);
154 //@}
155 /// @name xed_inst_t Template Operand Enum Name Classification
156 //@{
157 /// @ingroup DEC
158 /// Tests the enum for inclusion in XED_OPERAND_REG0 through XED_OPERAND_REG15.
159 /// @param name the operand name, type #xed_operand_enum_t
160 /// @return 1 if the operand name is REG0...REG15, 0 otherwise. 
161 ///
162 ///Note there are other registers for memory addressing; See
163 /// #xed_operand_is_memory_addressing_register .
164 static XED_INLINE xed_uint_t xed_operand_is_register(xed_operand_enum_t name) {
165     return name >= XED_OPERAND_REG0 && name <= XED_OPERAND_REG15;
166 }
167 /// @ingroup DEC
168 /// Tests the enum for inclusion in XED_OPERAND_{BASE0,BASE1,INDEX,SEG0,SEG1}
169 /// @param name the operand name, type #xed_operand_enum_t
170 /// @return 1 if the operand name is for a memory addressing register operand, 0
171 /// otherwise. See also #xed_operand_is_register .
172 static XED_INLINE xed_uint_t xed_operand_is_memory_addressing_register(xed_operand_enum_t name) {
173     return  ( name == XED_OPERAND_BASE0 || 
174               name == XED_OPERAND_INDEX ||
175               name == XED_OPERAND_SEG0  ||
176               name == XED_OPERAND_BASE1 || 
177               name == XED_OPERAND_SEG1 );
178 }
179
180 //@}
181
182 /// @name xed_inst_t Template Operand Read/Written
183 //@{ 
184 /// @ingroup DEC
185 /// Returns the raw R/W action. There are many cases for conditional reads
186 /// and writes.
187 static XED_INLINE xed_operand_action_enum_t xed_operand_rw(const xed_operand_t* p)  { 
188     return p->_rw; 
189 }
190
191 /// @ingroup DEC
192 /// If the operand is read, including conditional reads
193 XED_DLL_EXPORT xed_uint_t xed_operand_read(const xed_operand_t* p);
194 /// @ingroup DEC
195 /// If the operand is read-only, including conditional reads
196 XED_DLL_EXPORT xed_uint_t xed_operand_read_only(const xed_operand_t* p);
197 /// @ingroup DEC
198 /// If the operand is written, including conditional writes
199 XED_DLL_EXPORT xed_uint_t xed_operand_written(const xed_operand_t* p);
200 /// @ingroup DEC
201 /// If the operand is written-only, including conditional writes
202 XED_DLL_EXPORT xed_uint_t xed_operand_written_only(const xed_operand_t* p);
203 /// @ingroup DEC
204 /// If the operand is read-and-written, conditional reads and conditional writes
205 XED_DLL_EXPORT xed_uint_t xed_operand_read_and_written(const xed_operand_t* p);
206 /// @ingroup DEC
207 /// If the operand has a conditional read (may also write)
208 XED_DLL_EXPORT xed_uint_t xed_operand_conditional_read(const xed_operand_t* p);
209 /// @ingroup DEC
210 /// If the operand has a conditional write (may also read)
211 XED_DLL_EXPORT xed_uint_t xed_operand_conditional_write(const xed_operand_t* p);
212 //@}
213
214
215 #include "xed-gen-table-defs.h"
216 XED_DLL_GLOBAL extern const  xed_operand_t xed_operand[XED_MAX_OPERAND_TABLE_NODES];
217
218 /// @ingroup DEC
219 /// constant information about a decoded instruction form, including the pointer to the constant operand properties #xed_operand_t for this instruction form.
220 typedef struct XED_DLL_EXPORT xed_inst_s {
221     xed_iclass_enum_t _iclass;
222     xed_category_enum_t _category;
223     xed_extension_enum_t _extension;
224     xed_operand_bitvec_t _operand_bitvec;
225     // The instruction form for this iclass.  The iform is a zero-based dense sequence for each iclass.
226     xed_uint8_t _iform;
227     xed_iform_enum_t _iform_enum;
228
229     //xed_instruction_fixed_bit_confirmer_fn_t _confirmer;
230     
231     // number of operands in the operands array
232     xed_uint8_t _noperands; 
233
234     // index into the xed_operand[] array of xed_operand_t structures
235     xed_uint32_t _operand_base; 
236     // bit vector of values from the xed_attribute_enum_t
237     xed_uint32_t _attributes;
238
239     // rflags info -- index in to the 2 tables of flags information. 
240     // If _flag_complex is true, then the data are in the
241     // xed_flags_complex_table[]. Otherwise, the data are in the
242     // xed_flags_simple_table[].
243     xed_uint16_t _flag_info_index; 
244     xed_bool_t  _flag_complex;
245
246     xed_uint8_t _cpl;  // the nominal CPL for the instruction.
247 }  xed_inst_t;
248
249 /// @name xed_inst_t Template  Instruction Information
250 //@{ 
251 /// @ingroup DEC
252 /// Return the current privilege level (CPL).
253 XED_DLL_EXPORT unsigned int xed_inst_cpl(const xed_inst_t* p) ;
254
255
256 //These next few are not doxygen commented because I want people to use the higher
257 //level interface in xed-decoded-inst.h.
258 static XED_INLINE xed_iclass_enum_t xed_inst_iclass(const xed_inst_t* p) {
259     return p->_iclass;
260 }
261
262 static XED_INLINE xed_category_enum_t xed_inst_category(const xed_inst_t* p) {
263     return p->_category;
264 }
265
266 static XED_INLINE xed_extension_enum_t xed_inst_extension(const xed_inst_t* p) {
267     return p->_extension;
268 }
269
270 static XED_INLINE xed_uint_t xed_inst_iform(const xed_inst_t* p) {
271     return p->_iform;
272 }
273 static XED_INLINE xed_iform_enum_t xed_inst_iform_enum(const xed_inst_t* p) {
274     return p->_iform_enum;
275 }
276
277
278 ///@ingroup DEC
279 /// Number of instruction operands
280 static XED_INLINE unsigned int xed_inst_noperands(const xed_inst_t* p) {
281     return p->_noperands;
282 }
283
284 ///@ingroup DEC
285 /// Obtain a pointer to an individual operand
286 static XED_INLINE const xed_operand_t* xed_inst_operand(const xed_inst_t* p, unsigned int i)    {
287     xed_assert(i <  p->_noperands);
288     return &(xed_operand[p->_operand_base + i]);
289 }
290
291
292
293 XED_DLL_EXPORT xed_uint32_t xed_inst_flag_info_index(const xed_inst_t* p);
294
295 //@}
296
297 /// @name xed_inst_t Attribute  access
298 //@{
299 /// @ingroup DEC
300 /// Scan for the attribute attr and return 1 if it is found, 0 otherwise.
301 static XED_INLINE xed_uint32_t xed_inst_get_attribute(const xed_inst_t* p, xed_attribute_enum_t attr) {
302     if (p->_attributes & attr) 
303         return 1;
304     return 0;
305 }
306
307 /// @ingroup DEC
308 /// Return the attributes bit vector
309 static XED_INLINE xed_uint32_t xed_inst_get_attributes(const xed_inst_t* p) {
310     return p->_attributes;
311 }
312 /// @ingroup DEC
313 /// Return the maximum number of defined attributes, independent of any instruction.
314 XED_DLL_EXPORT unsigned int xed_attribute_max();
315
316 /// @ingroup DEC
317 /// Return the i'th global attribute in a linear sequence, independent of
318 /// any instruction. This is used for scanning and printing all attributes.
319 XED_DLL_EXPORT xed_attribute_enum_t xed_attribute(unsigned int i);
320
321 //@}
322
323 #endif