00001 /*BEGIN_LEGAL 00002 Intel Open Source License 00003 00004 Copyright (c) 2002-2012 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 */ 00032 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 00123 XED_DLL_EXPORT xed_uint32_t xed_operand_width_bits(const xed_operand_t* p, 00124 const xed_uint32_t eosz); 00125 00127 static XED_INLINE 00128 xed_nonterminal_enum_t xed_operand_nonterminal_name(const xed_operand_t* p) { 00129 return p->_u._nt; 00130 } 00131 00141 static XED_INLINE xed_reg_enum_t xed_operand_reg(const xed_operand_t* p) { 00142 return p->_u._reg; 00143 } 00144 00145 00146 00157 static XED_INLINE xed_uint_t xed_operand_template_is_register(const xed_operand_t* p) { 00158 return p->_type == XED_OPERAND_TYPE_NT_LOOKUP_FN || p->_type == XED_OPERAND_TYPE_REG; 00159 } 00160 00164 static XED_INLINE xed_uint32_t xed_operand_imm(const xed_operand_t* p) { 00165 return p->_u._imm; 00166 } 00167 00173 XED_DLL_EXPORT void xed_operand_print(const xed_operand_t* p, char* buf, int buflen); 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 static XED_INLINE xed_uint_t xed_operand_is_register(xed_operand_enum_t name) { 00185 return name >= XED_OPERAND_REG0 && name <= XED_OPERAND_REG15; 00186 } 00192 static XED_INLINE xed_uint_t xed_operand_is_memory_addressing_register(xed_operand_enum_t name) { 00193 return ( name == XED_OPERAND_BASE0 || 00194 name == XED_OPERAND_INDEX || 00195 name == XED_OPERAND_SEG0 || 00196 name == XED_OPERAND_BASE1 || 00197 name == XED_OPERAND_SEG1 ); 00198 } 00199 00201 00203 00204 00205 00206 00207 static XED_INLINE xed_operand_action_enum_t xed_operand_rw(const xed_operand_t* p) { 00208 return p->_rw; 00209 } 00210 00213 XED_DLL_EXPORT xed_uint_t xed_operand_read(const xed_operand_t* p); 00216 XED_DLL_EXPORT xed_uint_t xed_operand_read_only(const xed_operand_t* p); 00219 XED_DLL_EXPORT xed_uint_t xed_operand_written(const xed_operand_t* p); 00222 XED_DLL_EXPORT xed_uint_t xed_operand_written_only(const xed_operand_t* p); 00225 XED_DLL_EXPORT xed_uint_t xed_operand_read_and_written(const xed_operand_t* p); 00228 XED_DLL_EXPORT xed_uint_t xed_operand_conditional_read(const xed_operand_t* p); 00231 XED_DLL_EXPORT xed_uint_t xed_operand_conditional_write(const xed_operand_t* p); 00233 00234 00235 #include "xed-gen-table-defs.h" 00236 XED_DLL_GLOBAL extern const xed_operand_t 00237 xed_operand[XED_MAX_OPERAND_TABLE_NODES]; 00238 00239 XED_DLL_GLOBAL extern const xed_uint16_t 00240 xed_operand_sequences[XED_MAX_OPERAND_SEQUENCES]; 00241 00246 typedef struct XED_DLL_EXPORT xed_inst_s { 00247 00248 00249 // rflags info -- index in to the 2 tables of flags information. 00250 // If _flag_complex is true, then the data are in the 00251 // xed_flags_complex_table[]. Otherwise, the data are in the 00252 // xed_flags_simple_table[]. 00253 00254 //xed_instruction_fixed_bit_confirmer_fn_t _confirmer; 00255 00256 // number of operands in the operands array 00257 xed_uint8_t _noperands; 00258 xed_uint8_t _cpl; // the nominal CPL for the instruction. 00259 xed_uint16_t _flag_info_index; 00260 00261 xed_iform_enum_t _iform_enum; 00262 // index into the xed_operand[] array of xed_operand_t structures 00263 xed_uint16_t _operand_base; 00264 xed_uint16_t _flag_complex; /* 1/0 valued, bool type */ 00265 00266 // index to table of xed_attributes_t structures 00267 xed_uint16_t _attributes; 00268 xed_exception_enum_t _exceptions; 00269 } xed_inst_t; 00270 00272 00273 00274 00275 00276 00277 00278 00279 XED_DLL_EXPORT unsigned int xed_inst_cpl(const xed_inst_t* p) ; 00280 00281 00282 //These next few are not doxygen commented because I want people to use the higher 00283 //level interface in xed-decoded-inst.h. 00284 static XED_INLINE xed_iclass_enum_t xed_inst_iclass(const xed_inst_t* p) { 00285 return xed_iform_to_iclass(p->_iform_enum); 00286 } 00287 00288 static XED_INLINE xed_category_enum_t xed_inst_category(const xed_inst_t* p) { 00289 return xed_iform_to_category(p->_iform_enum); 00290 } 00291 00292 static XED_INLINE xed_extension_enum_t xed_inst_extension(const xed_inst_t* p) { 00293 return xed_iform_to_extension(p->_iform_enum); 00294 } 00295 static XED_INLINE xed_isa_set_enum_t xed_inst_isa_set(const xed_inst_t* p) { 00296 return xed_iform_to_isa_set(p->_iform_enum); 00297 } 00298 00299 static XED_INLINE xed_iform_enum_t xed_inst_iform_enum(const xed_inst_t* p) { 00300 return p->_iform_enum; 00301 } 00302 00303 00306 static XED_INLINE unsigned int xed_inst_noperands(const xed_inst_t* p) { 00307 return p->_noperands; 00308 } 00309 00312 static XED_INLINE const xed_operand_t* 00313 xed_inst_operand(const xed_inst_t* p, unsigned int i) { 00314 xed_assert(i < p->_noperands); 00315 return &(xed_operand[xed_operand_sequences[p->_operand_base + i]]); 00316 } 00317 00318 00319 00320 XED_DLL_EXPORT xed_uint32_t xed_inst_flag_info_index(const xed_inst_t* p); 00321 00323 00325 00326 00327 00328 XED_DLL_EXPORT xed_uint32_t 00329 xed_inst_get_attribute(const xed_inst_t* p, 00330 xed_attribute_enum_t attr); 00331 00334 XED_DLL_EXPORT xed_attributes_t 00335 xed_inst_get_attributes(const xed_inst_t* p); 00336 00337 00340 XED_DLL_EXPORT unsigned int xed_attribute_max(void); 00341 00345 XED_DLL_EXPORT xed_attribute_enum_t xed_attribute(unsigned int i); 00346 00348 00350 00351 00352 00353 00354 static XED_INLINE xed_exception_enum_t xed_inst_exception(const xed_inst_t* p) { 00355 return p->_exceptions; 00356 } 00357 00359 00360 00361 XED_DLL_EXPORT const xed_inst_t* xed_inst_table_base(void); 00362 00363 #endif