00001 /*BEGIN_LEGAL 00002 Copyright (c) 2004-2008, Intel Corp. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 00012 * Redistributions in binary form must reproduce the above 00013 copyright notice, this list of conditions and the following 00014 disclaimer in the documentation and/or other materials provided 00015 with the distribution. 00016 00017 * Neither the name of Intel Corporation nor the names of its 00018 contributors may be used to endorse or promote products derived 00019 from this software without specific prior written permission. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00024 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00025 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00027 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00028 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00029 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 END_LEGAL */ 00035 00036 #if !defined(_XED_INST_H_) 00037 # define _XED_INST_H_ 00038 00039 #include "xed-util.h" 00040 #include "xed-portability.h" 00041 #include "xed-category-enum.h" 00042 #include "xed-extension-enum.h" 00043 #include "xed-iclass-enum.h" 00044 #include "xed-operand-enum.h" 00045 #include "xed-operand-visibility-enum.h" 00046 #include "xed-operand-action-enum.h" 00047 #include "xed-operand-type-enum.h" 00048 #include "xed-nonterminal-enum.h" // a generated file 00049 #include "xed-operand-width-enum.h" // a generated file 00050 #include "xed-reg-enum.h" // a generated file 00051 #include "xed-attribute-enum.h" // a generated file 00052 #include "xed-iform-enum.h" // a generated file 00053 #include "xed-iform-map.h" 00054 00055 struct xed_decoded_inst_s; //fwd-decl 00056 00057 typedef void (*xed_operand_extractor_fn_t)(struct xed_decoded_inst_s* xds); 00058 //typedef xed_bool_t (*xed_instruction_fixed_bit_confirmer_fn_t)(struct xed_decoded_inst_s* xds); 00059 00060 00063 typedef struct XED_DLL_EXPORT xed_operand_s 00064 { 00065 xed_operand_enum_t _name; 00066 00067 xed_operand_visibility_enum_t _operand_visibility; 00068 00069 xed_operand_action_enum_t _rw; 00070 xed_operand_width_enum_t _oc2; 00071 00072 xed_operand_type_enum_t _type; 00073 union { 00074 xed_uint32_t _imm; 00075 xed_nonterminal_enum_t _nt; // for nt_lookup_fn's 00076 xed_reg_enum_t _reg; 00077 } _u; 00078 } xed_operand_t; 00079 00081 00082 00083 static XED_INLINE xed_operand_enum_t xed_operand_name(const xed_operand_t* p) { 00084 return p->_name; 00085 } 00086 00087 00089 static XED_INLINE xed_operand_visibility_enum_t xed_operand_operand_visibility( const xed_operand_t* p) { 00090 return p->_operand_visibility; 00091 } 00092 00093 00097 static XED_INLINE xed_operand_type_enum_t xed_operand_type(const xed_operand_t* p) { 00098 return p->_type; 00099 } 00100 00101 00103 static XED_INLINE xed_operand_width_enum_t xed_operand_width(const xed_operand_t* p) { 00104 return p->_oc2; 00105 } 00106 00108 static XED_INLINE 00109 xed_nonterminal_enum_t xed_operand_nonterminal_name(const xed_operand_t* p) { 00110 return p->_u._nt; 00111 } 00112 00122 static XED_INLINE xed_reg_enum_t xed_operand_reg(const xed_operand_t* p) { 00123 return p->_u._reg; 00124 } 00125 00126 00127 00138 static XED_INLINE xed_uint_t xed_operand_template_is_register(const xed_operand_t* p) { 00139 return p->_type == XED_OPERAND_TYPE_NT_LOOKUP_FN || p->_type == XED_OPERAND_TYPE_REG; 00140 } 00141 00145 static XED_INLINE xed_uint32_t xed_operand_imm(const xed_operand_t* p) { 00146 return p->_u._imm; 00147 } 00148 00154 XED_DLL_EXPORT void xed_operand_print(const xed_operand_t* p, char* buf, int buflen); 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 static XED_INLINE xed_uint_t xed_operand_is_register(xed_operand_enum_t name) { 00166 return name >= XED_OPERAND_REG0 && name <= XED_OPERAND_REG15; 00167 } 00173 static XED_INLINE xed_uint_t xed_operand_is_memory_addressing_register(xed_operand_enum_t name) { 00174 return ( name == XED_OPERAND_BASE0 || 00175 name == XED_OPERAND_INDEX || 00176 name == XED_OPERAND_SEG0 || 00177 name == XED_OPERAND_BASE1 || 00178 name == XED_OPERAND_SEG1 ); 00179 } 00180 00182 00184 00185 00186 00187 00188 static XED_INLINE xed_operand_action_enum_t xed_operand_rw(const xed_operand_t* p) { 00189 return p->_rw; 00190 } 00191 00194 XED_DLL_EXPORT xed_uint_t xed_operand_read(const xed_operand_t* p); 00197 XED_DLL_EXPORT xed_uint_t xed_operand_read_only(const xed_operand_t* p); 00200 XED_DLL_EXPORT xed_uint_t xed_operand_written(const xed_operand_t* p); 00203 XED_DLL_EXPORT xed_uint_t xed_operand_written_only(const xed_operand_t* p); 00206 XED_DLL_EXPORT xed_uint_t xed_operand_read_and_written(const xed_operand_t* p); 00209 XED_DLL_EXPORT xed_uint_t xed_operand_conditional_read(const xed_operand_t* p); 00212 XED_DLL_EXPORT xed_uint_t xed_operand_conditional_write(const xed_operand_t* p); 00214 00215 00216 #include "xed-gen-table-defs.h" 00217 XED_DLL_GLOBAL extern const xed_operand_t xed_operand[XED_MAX_OPERAND_TABLE_NODES]; 00218 00221 typedef struct XED_DLL_EXPORT xed_inst_s { 00222 xed_iform_enum_t _iform_enum; 00223 00224 //xed_instruction_fixed_bit_confirmer_fn_t _confirmer; 00225 00226 // number of operands in the operands array 00227 xed_uint8_t _noperands; 00228 00229 // index into the xed_operand[] array of xed_operand_t structures 00230 xed_uint32_t _operand_base; 00231 // bit vector of values from the xed_attribute_enum_t 00232 xed_uint32_t _attributes; 00233 00234 // rflags info -- index in to the 2 tables of flags information. 00235 // If _flag_complex is true, then the data are in the 00236 // xed_flags_complex_table[]. Otherwise, the data are in the 00237 // xed_flags_simple_table[]. 00238 xed_uint16_t _flag_info_index; 00239 xed_bool_t _flag_complex; 00240 00241 xed_uint8_t _cpl; // the nominal CPL for the instruction. 00242 } xed_inst_t; 00243 00245 00246 00247 00248 XED_DLL_EXPORT unsigned int xed_inst_cpl(const xed_inst_t* p) ; 00249 00250 00251 //These next few are not doxygen commented because I want people to use the higher 00252 //level interface in xed-decoded-inst.h. 00253 static XED_INLINE xed_iclass_enum_t xed_inst_iclass(const xed_inst_t* p) { 00254 return xed_iform_to_iclass(p->_iform_enum); 00255 } 00256 00257 static XED_INLINE xed_category_enum_t xed_inst_category(const xed_inst_t* p) { 00258 return xed_iform_to_category(p->_iform_enum); 00259 } 00260 00261 static XED_INLINE xed_extension_enum_t xed_inst_extension(const xed_inst_t* p) { 00262 return xed_iform_to_extension(p->_iform_enum); 00263 } 00264 00265 static XED_INLINE xed_iform_enum_t xed_inst_iform_enum(const xed_inst_t* p) { 00266 return p->_iform_enum; 00267 } 00268 00269 00272 static XED_INLINE unsigned int xed_inst_noperands(const xed_inst_t* p) { 00273 return p->_noperands; 00274 } 00275 00278 static XED_INLINE const xed_operand_t* xed_inst_operand(const xed_inst_t* p, unsigned int i) { 00279 xed_assert(i < p->_noperands); 00280 return &(xed_operand[p->_operand_base + i]); 00281 } 00282 00283 00284 00285 XED_DLL_EXPORT xed_uint32_t xed_inst_flag_info_index(const xed_inst_t* p); 00286 00288 00290 00291 00292 00293 static XED_INLINE xed_uint32_t xed_inst_get_attribute(const xed_inst_t* p, xed_attribute_enum_t attr) { 00294 if (p->_attributes & attr) 00295 return 1; 00296 return 0; 00297 } 00298 00301 static XED_INLINE xed_uint32_t xed_inst_get_attributes(const xed_inst_t* p) { 00302 return p->_attributes; 00303 } 00306 XED_DLL_EXPORT unsigned int xed_attribute_max(); 00307 00311 XED_DLL_EXPORT xed_attribute_enum_t xed_attribute(unsigned int i); 00312 00314 00315 #endif