2 Intel Open Source License
4 Copyright (c) 2002-2007 Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
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.
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.
32 /// @author Mark Charney <mark.charney@intel.com>
34 #if !defined(_XED_INST_H_)
37 #include <xed/xed-util.h>
38 #include <xed/xed-portability.h>
39 #include <xed/xed-category-enum.h>
40 #include <xed/xed-extension-enum.h>
41 #include <xed/xed-iclass-enum.h>
42 #include <xed/xed-operand-enum.h>
43 #include <xed/xed-operand-visibility-enum.h>
44 #include <xed/xed-operand-action-enum.h>
45 #include <xed/xed-operand-type-enum.h>
46 #include <xed/xed-nonterminal-enum.h> // a generated file
47 #include <xed/xed-operand-width-enum.h> // a generated file
48 #include <xed/xed-reg-enum.h> // a generated file
49 #include <xed/xed-attribute-enum.h> // a generated file
50 #include <xed/xed-iform-enum.h> // a generated file
51 #include <xed/xed-operand-bitvec.h> // a generated file
54 struct xed_decoded_inst_s; //fwd-decl
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);
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
64 xed_operand_enum_t _name;
66 xed_operand_visibility_enum_t _operand_visibility;
68 xed_operand_action_enum_t _rw;
69 xed_operand_width_enum_t _oc2;
71 xed_operand_type_enum_t _type;
74 xed_nonterminal_enum_t _nt; // for nt_lookup_fn's
79 /// @name xed_inst_t Template Operands Access
82 static XED_INLINE xed_operand_enum_t xed_operand_name(const xed_operand_t* p) {
88 static XED_INLINE xed_operand_visibility_enum_t xed_operand_operand_visibility( const xed_operand_t* p) {
89 return p->_operand_visibility;
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) {
102 static XED_INLINE xed_operand_width_enum_t xed_operand_width(const xed_operand_t* p) {
108 xed_nonterminal_enum_t xed_operand_nonterminal_name(const xed_operand_t* p) {
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
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) {
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
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;
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) {
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);
155 /// @name xed_inst_t Template Operand Enum Name Classification
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.
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;
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 );
182 /// @name xed_inst_t Template Operand Read/Written
185 /// Returns the raw R/W action. There are many cases for conditional reads
187 static XED_INLINE xed_operand_action_enum_t xed_operand_rw(const xed_operand_t* p) {
192 /// If the operand is read, including conditional reads
193 XED_DLL_EXPORT xed_uint_t xed_operand_read(const xed_operand_t* p);
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);
198 /// If the operand is written, including conditional writes
199 XED_DLL_EXPORT xed_uint_t xed_operand_written(const xed_operand_t* p);
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);
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);
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);
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);
215 #include <xed/xed-gen-table-defs.h>
216 XED_DLL_GLOBAL extern const xed_operand_t xed_operand[XED_MAX_OPERAND_TABLE_NODES];
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.
227 xed_iform_enum_t _iform_enum;
229 //xed_instruction_fixed_bit_confirmer_fn_t _confirmer;
231 // number of operands in the operands array
232 xed_uint8_t _noperands;
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;
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;
246 xed_uint8_t _cpl; // the nominal CPL for the instruction.
249 /// @name xed_inst_t Template Instruction Information
252 /// Return the current privilege level (CPL).
253 XED_DLL_EXPORT unsigned int xed_inst_cpl(const xed_inst_t* p) ;
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) {
262 static XED_INLINE xed_category_enum_t xed_inst_category(const xed_inst_t* p) {
266 static XED_INLINE xed_extension_enum_t xed_inst_extension(const xed_inst_t* p) {
267 return p->_extension;
270 static XED_INLINE xed_uint_t xed_inst_iform(const xed_inst_t* p) {
273 static XED_INLINE xed_iform_enum_t xed_inst_iform_enum(const xed_inst_t* p) {
274 return p->_iform_enum;
279 /// Number of instruction operands
280 static XED_INLINE unsigned int xed_inst_noperands(const xed_inst_t* p) {
281 return p->_noperands;
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]);
293 XED_DLL_EXPORT xed_uint32_t xed_inst_flag_info_index(const xed_inst_t* p);
297 /// @name xed_inst_t Attribute access
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)
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;
313 /// Return the maximum number of defined attributes, independent of any instruction.
314 XED_DLL_EXPORT unsigned int xed_attribute_max();
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);