00001 /*BEGIN_LEGAL 00002 Intel Open Source License 00003 00004 Copyright (c) 2002-2011 Intel Corporation. All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are 00008 met: 00009 00010 Redistributions of source code must retain the above copyright notice, 00011 this list of conditions and the following disclaimer. Redistributions 00012 in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or 00014 other materials provided with the distribution. Neither the name of 00015 the Intel Corporation nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without 00017 specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 00023 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00026 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00027 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00029 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 END_LEGAL */ 00033 00034 #if !defined(_XED_INST_H_) 00035 # define _XED_INST_H_ 00036 00037 #include "xed-util.h" 00038 #include "xed-portability.h" 00039 #include "xed-category-enum.h" // generated 00040 #include "xed-extension-enum.h" //generated 00041 #include "xed-iclass-enum.h" //generated 00042 #include "xed-operand-enum.h" // generated 00043 #include "xed-operand-visibility-enum.h" //generated 00044 #include "xed-operand-action-enum.h" // generated 00045 #include "xed-operand-convert-enum.h" // generated 00046 #include "xed-operand-type-enum.h" // generated 00047 #include "xed-nonterminal-enum.h" // a generated file 00048 #include "xed-operand-width-enum.h" // a generated file 00049 #include "xed-operand-element-xtype-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-exception-enum.h" // a generated file 00053 #include "xed-iform-enum.h" // a generated file 00054 #include "xed-iform-map.h" 00055 #include "xed-attributes.h" 00056 00057 struct xed_decoded_inst_s; //fwd-decl 00058 00059 typedef void (*xed_operand_extractor_fn_t)(struct xed_decoded_inst_s* xds); 00060 //typedef xed_bool_t (*xed_instruction_fixed_bit_confirmer_fn_t)(struct xed_decoded_inst_s* xds); 00061 00062 00067 typedef struct XED_DLL_EXPORT xed_operand_s 00068 { 00069 xed_operand_enum_t _name; 00070 xed_operand_visibility_enum_t _operand_visibility; // implicit, explicit, suppressed 00071 xed_operand_action_enum_t _rw; // read or written 00072 xed_operand_width_enum_t _oc2; // width code, could be invalid (then use register name) 00073 xed_operand_type_enum_t _type; // IMM, IMM_CONST, NT_LOOKUP_FN, REG, ERROR 00074 xed_operand_element_xtype_enum_t _xtype; // xed data type: u32, f32, etc. 00075 xed_uint8_t _cvt_idx; // decoration index 00076 union { 00077 xed_uint32_t _imm; // value for some constant immediates 00078 xed_nonterminal_enum_t _nt; // for nt_lookup_fn's 00079 xed_reg_enum_t _reg; // register name 00080 } _u; 00081 } xed_operand_t; 00082 00084 00085 00086 static XED_INLINE xed_operand_enum_t xed_operand_name(const xed_operand_t* p) { 00087 return p->_name; 00088 } 00089 00090 00092 static XED_INLINE xed_operand_visibility_enum_t 00093 xed_operand_operand_visibility( const xed_operand_t* p) { 00094 return p->_operand_visibility; 00095 } 00096 00097 00101 static XED_INLINE xed_operand_type_enum_t xed_operand_type(const xed_operand_t* p) { 00102 return p->_type; 00103 } 00104 00108 static XED_INLINE xed_operand_element_xtype_enum_t xed_operand_xtype(const xed_operand_t* p) { 00109 return p->_xtype; 00110 } 00111 00112 00114 static XED_INLINE xed_operand_width_enum_t xed_operand_width(const xed_operand_t* p) { 00115 return p->_oc2; 00116 } 00117 00119 static XED_INLINE 00120 xed_nonterminal_enum_t xed_operand_nonterminal_name(const xed_operand_t* p) { 00121 return p->_u._nt; 00122 } 00123 00133 static XED_INLINE xed_reg_enum_t xed_operand_reg(const xed_operand_t* p) { 00134 return p->_u._reg; 00135 } 00136 00137 00138 00149 static XED_INLINE xed_uint_t xed_operand_template_is_register(const xed_operand_t* p) { 00150 return p->_type == XED_OPERAND_TYPE_NT_LOOKUP_FN || p->_type == XED_OPERAND_TYPE_REG; 00151 } 00152 00156 static XED_INLINE xed_uint32_t xed_operand_imm(const xed_operand_t* p) { 00157 return p->_u._imm; 00158 } 00159 00165 XED_DLL_EXPORT void xed_operand_print(const xed_operand_t* p, char* buf, int buflen); 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 static XED_INLINE xed_uint_t xed_operand_is_register(xed_operand_enum_t name) { 00177 return name >= XED_OPERAND_REG0 && name <= XED_OPERAND_REG15; 00178 } 00184 static XED_INLINE xed_uint_t xed_operand_is_memory_addressing_register(xed_operand_enum_t name) { 00185 return ( name == XED_OPERAND_BASE0 || 00186 name == XED_OPERAND_INDEX || 00187 name == XED_OPERAND_SEG0 || 00188 name == XED_OPERAND_BASE1 || 00189 name == XED_OPERAND_SEG1 ); 00190 } 00191 00193 00195 00196 00197 00198 00199 static XED_INLINE xed_operand_action_enum_t xed_operand_rw(const xed_operand_t* p) { 00200 return p->_rw; 00201 } 00202 00205 XED_DLL_EXPORT xed_uint_t xed_operand_read(const xed_operand_t* p); 00208 XED_DLL_EXPORT xed_uint_t xed_operand_read_only(const xed_operand_t* p); 00211 XED_DLL_EXPORT xed_uint_t xed_operand_written(const xed_operand_t* p); 00214 XED_DLL_EXPORT xed_uint_t xed_operand_written_only(const xed_operand_t* p); 00217 XED_DLL_EXPORT xed_uint_t xed_operand_read_and_written(const xed_operand_t* p); 00220 XED_DLL_EXPORT xed_uint_t xed_operand_conditional_read(const xed_operand_t* p); 00223 XED_DLL_EXPORT xed_uint_t xed_operand_conditional_write(const xed_operand_t* p); 00225 00226 00227 #include "xed-gen-table-defs.h" 00228 XED_DLL_GLOBAL extern const xed_operand_t 00229 xed_operand[XED_MAX_OPERAND_TABLE_NODES]; 00230 00231 XED_DLL_GLOBAL extern const xed_uint16_t 00232 xed_operand_sequences[XED_MAX_OPERAND_SEQUENCES]; 00233 00238 typedef struct XED_DLL_EXPORT xed_inst_s { 00239 00240 00241 // rflags info -- index in to the 2 tables of flags information. 00242 // If _flag_complex is true, then the data are in the 00243 // xed_flags_complex_table[]. Otherwise, the data are in the 00244 // xed_flags_simple_table[]. 00245 00246 //xed_instruction_fixed_bit_confirmer_fn_t _confirmer; 00247 00248 // number of operands in the operands array 00249 xed_uint8_t _noperands; 00250 xed_uint8_t _cpl; // the nominal CPL for the instruction. 00251 xed_uint16_t _flag_info_index; 00252 00253 xed_iform_enum_t _iform_enum; 00254 // index into the xed_operand[] array of xed_operand_t structures 00255 xed_uint16_t _operand_base; 00256 xed_uint16_t _flag_complex; /* 1/0 valued, bool type */ 00257 00258 // index to table of xed_attributes_t structures 00259 xed_uint16_t _attributes; 00260 xed_exception_enum_t _exceptions; 00261 } xed_inst_t; 00262 00264 00265 00266 00267 00268 00269 00270 00271 XED_DLL_EXPORT unsigned int xed_inst_cpl(const xed_inst_t* p) ; 00272 00273 00274 //These next few are not doxygen commented because I want people to use the higher 00275 //level interface in xed-decoded-inst.h. 00276 static XED_INLINE xed_iclass_enum_t xed_inst_iclass(const xed_inst_t* p) { 00277 return xed_iform_to_iclass(p->_iform_enum); 00278 } 00279 00280 static XED_INLINE xed_category_enum_t xed_inst_category(const xed_inst_t* p) { 00281 return xed_iform_to_category(p->_iform_enum); 00282 } 00283 00284 static XED_INLINE xed_extension_enum_t xed_inst_extension(const xed_inst_t* p) { 00285 return xed_iform_to_extension(p->_iform_enum); 00286 } 00287 static XED_INLINE xed_isa_set_enum_t xed_inst_isa_set(const xed_inst_t* p) { 00288 return xed_iform_to_isa_set(p->_iform_enum); 00289 } 00290 00291 static XED_INLINE xed_iform_enum_t xed_inst_iform_enum(const xed_inst_t* p) { 00292 return p->_iform_enum; 00293 } 00294 00295 00298 static XED_INLINE unsigned int xed_inst_noperands(const xed_inst_t* p) { 00299 return p->_noperands; 00300 } 00301 00304 static XED_INLINE const xed_operand_t* 00305 xed_inst_operand(const xed_inst_t* p, unsigned int i) { 00306 xed_assert(i < p->_noperands); 00307 return &(xed_operand[xed_operand_sequences[p->_operand_base + i]]); 00308 } 00309 00310 00311 00312 XED_DLL_EXPORT xed_uint32_t xed_inst_flag_info_index(const xed_inst_t* p); 00313 00315 00317 00318 00319 00320 XED_DLL_EXPORT xed_uint32_t 00321 xed_inst_get_attribute(const xed_inst_t* p, 00322 xed_attribute_enum_t attr); 00323 00326 XED_DLL_EXPORT xed_attributes_t 00327 xed_inst_get_attributes(const xed_inst_t* p); 00328 00329 00332 XED_DLL_EXPORT unsigned int xed_attribute_max(void); 00333 00337 XED_DLL_EXPORT xed_attribute_enum_t xed_attribute(unsigned int i); 00338 00340 00342 00343 00344 00345 00346 static XED_INLINE xed_exception_enum_t xed_inst_exception(const xed_inst_t* p) { 00347 return p->_exceptions; 00348 } 00349 00351 00352 00353 XED_DLL_EXPORT const xed_inst_t* xed_inst_table_base(void); 00354 00355 #endif