xed-decoded-inst.h

Go to the documentation of this file.
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_DECODER_STATE_H_)
00035 # define _XED_DECODER_STATE_H_
00036 #include "xed-common-hdrs.h"
00037 #include "xed-common-defs.h"
00038 #include "xed-portability.h"
00039 #include "xed-util.h"
00040 #include "xed-types.h"
00041 #include "xed-operand-values-interface.h" 
00042 #include "xed-inst.h"
00043 #include "xed-flags.h"
00044 #if defined(XED_ENCODER)
00045 # include "xed-encoder-gen-defs.h" //generated
00046 #endif
00047 #include "xed-chip-enum.h" //generated
00048 #include "xed-operand-element-type-enum.h" // a generated file
00049 
00050 
00051 // fwd-decl xed_simple_flag_t;
00052 // fwd-decl xed_inst_t;
00053 
00054 
00055 struct xed_encoder_vars_s;
00056 struct xed_decoder_vars_s;
00057 
00063 typedef struct XED_DLL_EXPORT xed_decoded_inst_s  {
00065     xed_operand_values_t _operands[XED_OPERAND_LAST]; // FIXME: can further squeeze down 16b units
00066 
00067 #if defined(XED_ENCODER)
00068 
00069     xed_uint8_t _operand_order[XED_ENCODE_ORDER_MAX_OPERANDS];
00070 #endif
00071 
00072     xed_uint8_t _decoded_length;
00074     xed_uint8_t _n_operand_order; 
00075 
00079     const xed_inst_t* _inst;
00080 
00081     // decoder does not change it, encoder does    
00082     union {
00083         xed_uint8_t* _enc;
00084         const xed_uint8_t* _dec;
00085     } _byte_array; 
00086 
00087     // These are stack allocated by xed_encode() or xed_decode(). These are
00088     // per-encode or per-decode transitory data.
00089     union {
00090 
00091         /* user_data is available as a user data storage field after
00092          * decoding. It does not live across re-encodes or re-decodes. */
00093         xed_uint64_t user_data; 
00094         struct xed_decoder_vars_s* dv;
00095 #if defined(XED_ENCODER)
00096         struct xed_encoder_vars_s* ev;
00097 #endif
00098     } u;
00099 
00100 
00101     
00102 } xed_decoded_inst_t;
00103 
00104 
00108 
00110 
00111 
00112 
00113 static XED_INLINE xed_bool_t xed_decoded_inst_valid(const xed_decoded_inst_t* p ) {
00114     return XED_STATIC_CAST(xed_bool_t,(p->_inst != 0));
00115 }
00118 static XED_INLINE const xed_inst_t* xed_decoded_inst_inst( const xed_decoded_inst_t* p) {
00119     return p->_inst;
00120 }
00121 
00122 
00125 static XED_INLINE xed_category_enum_t xed_decoded_inst_get_category(const xed_decoded_inst_t* p) {
00126     xed_assert(p->_inst != 0);
00127     return xed_inst_category(p->_inst);
00128 }
00131 static XED_INLINE xed_extension_enum_t xed_decoded_inst_get_extension( const xed_decoded_inst_t* p) {
00132     xed_assert(p->_inst != 0);
00133     return xed_inst_extension(p->_inst);
00134 }
00137 static XED_INLINE xed_isa_set_enum_t xed_decoded_inst_get_isa_set( const xed_decoded_inst_t* p) {
00138     xed_assert(p->_inst != 0);
00139     return xed_inst_isa_set(p->_inst);
00140 }
00143 static XED_INLINE xed_iclass_enum_t xed_decoded_inst_get_iclass( const xed_decoded_inst_t* p){
00144     xed_assert(p->_inst != 0);
00145     return xed_inst_iclass(p->_inst);
00146 }
00147 
00150 XED_DLL_EXPORT xed_uint32_t
00151 xed_decoded_inst_get_attribute(const xed_decoded_inst_t* p,
00152                                xed_attribute_enum_t attr);
00153 
00156 XED_DLL_EXPORT xed_attributes_t
00157 xed_decoded_inst_get_attributes(const xed_decoded_inst_t* p);
00159 
00160 
00162 
00163 
00164 
00165 static XED_INLINE const xed_operand_values_t* 
00166 xed_decoded_inst_operands_const(const xed_decoded_inst_t* p) {
00167     return XED_STATIC_CAST(xed_operand_values_t*,p->_operands);
00168 }
00171 static XED_INLINE xed_operand_values_t* 
00172 xed_decoded_inst_operands(xed_decoded_inst_t* p) {
00173     return XED_STATIC_CAST(xed_operand_values_t*,p->_operands);
00174 }
00175 
00178 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_length_bits(const xed_decoded_inst_t* p, 
00179                                                                   unsigned int operand_index);
00180 
00181 
00185 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_length(const xed_decoded_inst_t* p, 
00186                                                              unsigned int operand_index);
00187 
00188 
00191 static XED_INLINE unsigned int  xed_decoded_inst_noperands(const xed_decoded_inst_t* p) {
00192     unsigned int noperands = xed_inst_noperands(xed_decoded_inst_inst(p));
00193     return noperands;
00194 }
00195 
00196 
00199 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_elements(const xed_decoded_inst_t* p, 
00200                                                                unsigned int operand_index);
00201 
00204 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_element_size_bits(const xed_decoded_inst_t* p, 
00205                                                                         unsigned int operand_index);
00206 
00209 XED_DLL_EXPORT xed_operand_element_type_enum_t  xed_decoded_inst_operand_element_type(const xed_decoded_inst_t* p, 
00210                                                                                       unsigned int operand_index);
00211 
00212 
00214 
00216 
00217 
00218 
00219 XED_DLL_EXPORT void  xed_decoded_inst_zero_set_mode(xed_decoded_inst_t* p, const xed_state_t* dstate);
00222 XED_DLL_EXPORT void  xed_decoded_inst_zero_keep_mode(xed_decoded_inst_t* p);
00225 XED_DLL_EXPORT void  xed_decoded_inst_zero(xed_decoded_inst_t* p);
00226 
00231 static XED_INLINE void  xed_decoded_inst_set_mode(xed_decoded_inst_t* p,
00232                                                   xed_machine_mode_enum_t mmode,
00233                                                   xed_address_width_enum_t stack_addr_width) {
00234     xed_state_t dstate;
00235     dstate.mmode = mmode;
00236     dstate.stack_addr_width = stack_addr_width;
00237     xed_operand_values_set_mode(p->_operands, &dstate);
00238 }
00239 
00240 
00241 
00244 XED_DLL_EXPORT void  xed_decoded_inst_zero_keep_mode_from_operands(xed_decoded_inst_t* p,
00245                                                                    const xed_operand_values_t* operands);
00246 // Set an arbitrary field
00248 XED_DLL_EXPORT void xed_decoded_inst_set_operand_storage_field(xed_decoded_inst_t* p,
00249                                                                xed_operand_enum_t operand_name,  
00250                                                                xed_uint32_t value);
00251 
00253 
00255 
00256 
00257 
00258 static XED_INLINE xed_uint_t
00259 xed_decoded_inst_get_length(const xed_decoded_inst_t* p) {  
00260     return p->_decoded_length;
00261 }
00262 
00263 
00265 
00267 
00268 
00269 
00270 
00271 static XED_INLINE xed_uint_t xed_decoded_inst_get_machine_mode_bits(const xed_decoded_inst_t* p) {
00272     if (p->_operands[XED_OPERAND_MODE] == 2) return 64;
00273     if (p->_operands[XED_OPERAND_MODE] == 1) return 32;
00274     return 16;
00275 }
00279 static XED_INLINE xed_uint_t xed_decoded_inst_get_stack_address_mode_bits(const xed_decoded_inst_t* p) {
00280     if (p->_operands[XED_OPERAND_SMODE] == 2) return 64;
00281     if (p->_operands[XED_OPERAND_SMODE] == 1) return 32;
00282     return 16;
00283 }
00284 
00290 XED_DLL_EXPORT xed_uint32_t xed_decoded_inst_get_operand_width(const xed_decoded_inst_t* p);
00291 
00294 static XED_INLINE xed_chip_enum_t xed_decoded_inst_get_input_chip(const xed_decoded_inst_t* p) {
00295     return XED_STATIC_CAST(xed_chip_enum_t,p->_operands[XED_OPERAND_CHIP]);
00296 }
00297 
00300 static XED_INLINE void xed_decoded_inst_set_input_chip(xed_decoded_inst_t* p,  xed_chip_enum_t chip) {
00301     p->_operands[XED_OPERAND_CHIP] = chip;
00302 }
00303 
00304 
00307 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_valid_for_chip(xed_decoded_inst_t* p, 
00308                                                           xed_chip_enum_t chip);
00309 
00311 
00312 
00313 
00314 
00316 
00317 
00320 static XED_INLINE xed_iform_enum_t xed_decoded_inst_get_iform_enum(const xed_decoded_inst_t* p) {
00321     xed_assert(p->_inst != 0);
00322     return xed_inst_iform_enum(p->_inst);
00323 }
00324 
00330 static XED_INLINE unsigned int xed_decoded_inst_get_iform_enum_dispatch(const xed_decoded_inst_t* p) {
00331     xed_assert(p->_inst != 0);
00332     return xed_inst_iform_enum(p->_inst) - xed_iform_first_per_iclass(xed_inst_iclass(p->_inst));
00333 }
00335 
00336 
00337 
00338 
00340 
00341 
00342 
00343 XED_DLL_EXPORT void xed_decoded_inst_dump(const xed_decoded_inst_t* p, char* buf,  int buflen);
00344 
00353 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format(const xed_decoded_inst_t* p, 
00354                                                              char* buf, 
00355                                                              int buflen, 
00356                                                              xed_uint64_t runtime_address);
00366 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format_context(const xed_decoded_inst_t* p, 
00367                                                                      char* buf, 
00368                                                                      int buflen, 
00369                                                                      xed_uint64_t runtime_address,
00370                                                                      void* context);
00371 
00384 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format(const xed_decoded_inst_t* p, 
00385                                                            char* buf, 
00386                                                            int buflen, 
00387                                                            xed_uint64_t runtime_address);
00388 
00401 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format_context(const xed_decoded_inst_t* p, 
00402                                                                    char* buf, 
00403                                                                    int buflen, 
00404                                                                    xed_uint64_t runtime_address,
00405                                                                    void* context);
00406 
00414 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_xed_format(const xed_decoded_inst_t* p,
00415                                                            char* buf, 
00416                                                            int buflen, 
00417                                                            xed_uint64_t runtime_address) ;
00419 
00421 
00422 
00423 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_seg_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00425 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_base_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00426 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_index_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00428 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_scale(const xed_decoded_inst_t* p, unsigned int mem_idx);
00430 XED_DLL_EXPORT xed_int64_t xed_decoded_inst_get_memory_displacement(const xed_decoded_inst_t* p, unsigned int mem_idx);
00433 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_memory_displacement_width(const xed_decoded_inst_t* p, unsigned int mem_idx);
00436 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_memory_displacement_width_bits(const xed_decoded_inst_t* p, unsigned int mem_idx);
00438 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_branch_displacement(const xed_decoded_inst_t* p);
00441 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_branch_displacement_width(const xed_decoded_inst_t* p);
00444 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_branch_displacement_width_bits(const xed_decoded_inst_t* p);
00446 XED_DLL_EXPORT xed_uint64_t xed_decoded_inst_get_unsigned_immediate(const xed_decoded_inst_t* p); 
00449 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_is_signed(const xed_decoded_inst_t* p);
00452 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width(const xed_decoded_inst_t* p);
00455 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width_bits(const xed_decoded_inst_t* p);
00457 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_signed_immediate(const xed_decoded_inst_t* p);
00460 static XED_INLINE xed_uint8_t xed_decoded_inst_get_second_immediate(const xed_decoded_inst_t* p) {
00461     return XED_STATIC_CAST(xed_uint8_t,p->_operands[XED_OPERAND_UIMM1]);
00462 }
00463 
00466 static XED_INLINE xed_reg_enum_t xed_decoded_inst_get_reg(const xed_decoded_inst_t* p, 
00467                                                           xed_operand_enum_t reg_operand) {
00468     return XED_STATIC_CAST(xed_reg_enum_t,p->_operands[reg_operand]);
00469 }
00470 
00471 
00475 XED_DLL_EXPORT const xed_simple_flag_t* xed_decoded_inst_get_rflags_info( const xed_decoded_inst_t* p );
00476 
00483 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_uses_rflags(const xed_decoded_inst_t* p);
00485 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_number_of_memory_operands(const xed_decoded_inst_t* p);
00487 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_read(const xed_decoded_inst_t* p, unsigned int mem_idx);
00489 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written(const xed_decoded_inst_t* p, unsigned int mem_idx);
00491 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written_only(const xed_decoded_inst_t* p, unsigned int mem_idx);
00493 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_conditionally_writes_registers(const xed_decoded_inst_t* p);
00495 XED_DLL_EXPORT unsigned int  xed_decoded_inst_get_memory_operand_length(const xed_decoded_inst_t* p, 
00496                                                                         unsigned int memop_idx);
00497 
00501 // 67 prefixes if present.
00502 
00504 XED_DLL_EXPORT unsigned int 
00505 xed_decoded_inst_get_memop_address_width(const xed_decoded_inst_t* p,
00506                                          xed_uint_t memop_idx);
00507 
00508 
00509 
00512 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_is_prefetch(const xed_decoded_inst_t* p);
00514 
00515                   
00517 
00518 // Modifying decoded instructions before re-encoding    
00520 XED_DLL_EXPORT void xed_decoded_inst_set_scale(xed_decoded_inst_t* p, xed_uint_t scale);
00523 XED_DLL_EXPORT void xed_decoded_inst_set_memory_displacement(xed_decoded_inst_t* p, xed_int64_t disp, xed_uint_t length_bytes);
00526 XED_DLL_EXPORT void xed_decoded_inst_set_branch_displacement(xed_decoded_inst_t* p, xed_int32_t disp, xed_uint_t length_bytes);
00529 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_signed(xed_decoded_inst_t* p, xed_int32_t x, xed_uint_t length_bytes);
00532 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_unsigned(xed_decoded_inst_t* p, xed_uint64_t x, xed_uint_t length_bytes);
00533 
00534 
00537 XED_DLL_EXPORT void xed_decoded_inst_set_memory_displacement_bits(xed_decoded_inst_t* p, xed_int64_t disp, xed_uint_t length_bits);
00540 XED_DLL_EXPORT void xed_decoded_inst_set_branch_displacement_bits(xed_decoded_inst_t* p, xed_int32_t disp, xed_uint_t length_bits);
00543 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_signed_bits(xed_decoded_inst_t* p, xed_int32_t x, xed_uint_t length_bits);
00546 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_unsigned_bits(xed_decoded_inst_t* p, xed_uint64_t x, xed_uint_t length_bits);
00547 
00549 
00551 
00552 
00553 
00554 static XED_INLINE  xed_uint64_t xed_decoded_inst_get_user_data(xed_decoded_inst_t* p) {
00555     return p->u.user_data;
00556 }
00559 static XED_INLINE  void xed_decoded_inst_set_user_data(xed_decoded_inst_t* p, xed_uint64_t new_value) {
00560     p->u.user_data = new_value;
00561 }
00562 
00563 
00564 
00566 #endif
00567 //Local Variables:
00568 //pref: "../../xed-decoded-inst.c"
00569 //End:
00570 

Generated on Tue Nov 22 12:27:07 2011 for XED2 by  doxygen 1.4.6