xed-decoded-inst.h

Go to the documentation of this file.
00001 /*BEGIN_LEGAL 
00002 Intel Open Source License 
00003 
00004 Copyright (c) 2002-2009 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 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 xed_decoded_inst_get_attribute(const xed_decoded_inst_t* p, xed_attribute_enum_t attr);
00151 
00154 XED_DLL_EXPORT xed_uint64_t xed_decoded_inst_get_attributes(const xed_decoded_inst_t* p);
00156 
00157 
00159 
00160 
00161 
00162 static XED_INLINE const xed_operand_values_t* 
00163 xed_decoded_inst_operands_const(const xed_decoded_inst_t* p) {
00164     return STATIC_CAST(xed_operand_values_t*,p->_operands);
00165 }
00168 static XED_INLINE xed_operand_values_t* 
00169 xed_decoded_inst_operands(xed_decoded_inst_t* p) {
00170     return STATIC_CAST(xed_operand_values_t*,p->_operands);
00171 }
00172 
00175 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_length_bits(const xed_decoded_inst_t* p, 
00176                                                                   unsigned int operand_index);
00177 
00178 
00182 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_length(const xed_decoded_inst_t* p, 
00183                                                              unsigned int operand_index);
00184 
00185 
00188 static XED_INLINE unsigned int  xed_decoded_inst_noperands(const xed_decoded_inst_t* p) {
00189     unsigned int noperands = xed_inst_noperands(xed_decoded_inst_inst(p));
00190     return noperands;
00191 }
00192 
00193 
00196 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_elements(const xed_decoded_inst_t* p, 
00197                                                                unsigned int operand_index);
00198 
00201 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_element_size_bits(const xed_decoded_inst_t* p, 
00202                                                                         unsigned int operand_index);
00203 
00206 XED_DLL_EXPORT xed_operand_element_type_enum_t  xed_decoded_inst_operand_element_type(const xed_decoded_inst_t* p, 
00207                                                                                       unsigned int operand_index);
00208 
00209 
00211 
00213 
00214 
00215 
00216 XED_DLL_EXPORT void  xed_decoded_inst_zero_set_mode(xed_decoded_inst_t* p, const xed_state_t* dstate);
00219 XED_DLL_EXPORT void  xed_decoded_inst_zero_keep_mode(xed_decoded_inst_t* p);
00222 XED_DLL_EXPORT void  xed_decoded_inst_zero(xed_decoded_inst_t* p);
00223 
00228 static XED_INLINE void  xed_decoded_inst_set_mode(xed_decoded_inst_t* p,
00229                                                   xed_machine_mode_enum_t mmode,
00230                                                   xed_address_width_enum_t stack_addr_width) {
00231     xed_state_t dstate;
00232     dstate.mmode = mmode;
00233     dstate.stack_addr_width = stack_addr_width;
00234     xed_operand_values_set_mode(p->_operands, &dstate);
00235 }
00236 
00237 
00238 
00241 XED_DLL_EXPORT void  xed_decoded_inst_zero_keep_mode_from_operands(xed_decoded_inst_t* p,
00242                                                                    const xed_operand_values_t* operands);
00243 // Set an arbitrary field
00245 XED_DLL_EXPORT void xed_decoded_inst_set_operand_storage_field(xed_decoded_inst_t* p,
00246                                                                xed_operand_enum_t operand_name,  
00247                                                                xed_uint32_t value);
00248 
00250 
00252 
00253 
00254 
00255 static XED_INLINE xed_uint_t
00256 xed_decoded_inst_get_length(const xed_decoded_inst_t* p) {  
00257     return p->_decoded_length;
00258 }
00259 
00260 
00262 
00264 
00265 
00266 
00267 
00268 static XED_INLINE xed_uint_t xed_decoded_inst_get_machine_mode_bits(const xed_decoded_inst_t* p) {
00269     if (p->_operands[XED_OPERAND_MODE] == 2) return 64;
00270     if (p->_operands[XED_OPERAND_MODE] == 1) return 32;
00271     return 16;
00272 }
00276 static XED_INLINE xed_uint_t xed_decoded_inst_get_stack_address_mode_bits(const xed_decoded_inst_t* p) {
00277     if (p->_operands[XED_OPERAND_SMODE] == 2) return 64;
00278     if (p->_operands[XED_OPERAND_SMODE] == 1) return 32;
00279     return 16;
00280 }
00281 
00287 XED_DLL_EXPORT xed_uint32_t xed_decoded_inst_get_operand_width(const xed_decoded_inst_t* p);
00288 
00291 static XED_INLINE xed_chip_enum_t xed_decoded_inst_get_input_chip(const xed_decoded_inst_t* p) {
00292     return STATIC_CAST(xed_chip_enum_t,p->_operands[XED_OPERAND_CHIP]);
00293 }
00294 
00297 static XED_INLINE void xed_decoded_inst_set_input_chip(xed_decoded_inst_t* p,  xed_chip_enum_t chip) {
00298     p->_operands[XED_OPERAND_CHIP] = chip;
00299 }
00300 
00301 
00304 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_valid_for_chip(xed_decoded_inst_t* p, 
00305                                                           xed_chip_enum_t chip);
00306 
00308 
00309 
00310 
00311 
00313 
00314 
00317 static XED_INLINE xed_iform_enum_t xed_decoded_inst_get_iform_enum(const xed_decoded_inst_t* p) {
00318     xed_assert(p->_inst != 0);
00319     return xed_inst_iform_enum(p->_inst);
00320 }
00321 
00327 static XED_INLINE unsigned int xed_decoded_inst_get_iform_enum_dispatch(const xed_decoded_inst_t* p) {
00328     xed_assert(p->_inst != 0);
00329     return xed_inst_iform_enum(p->_inst) - xed_iform_first_per_iclass(xed_inst_iclass(p->_inst));
00330 }
00332 
00333 
00334 
00335 
00337 
00338 
00339 
00340 XED_DLL_EXPORT void xed_decoded_inst_dump(const xed_decoded_inst_t* p, char* buf,  int buflen);
00341 
00350 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format(const xed_decoded_inst_t* p, 
00351                                                              char* buf, 
00352                                                              int buflen, 
00353                                                              xed_uint64_t runtime_address);
00363 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format_context(const xed_decoded_inst_t* p, 
00364                                                                      char* buf, 
00365                                                                      int buflen, 
00366                                                                      xed_uint64_t runtime_address,
00367                                                                      void* context);
00368 
00381 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format(const xed_decoded_inst_t* p, 
00382                                                            char* buf, 
00383                                                            int buflen, 
00384                                                            xed_uint64_t runtime_address);
00385 
00398 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format_context(const xed_decoded_inst_t* p, 
00399                                                                    char* buf, 
00400                                                                    int buflen, 
00401                                                                    xed_uint64_t runtime_address,
00402                                                                    void* context);
00403 
00411 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_xed_format(const xed_decoded_inst_t* p,
00412                                                            char* buf, 
00413                                                            int buflen, 
00414                                                            xed_uint64_t runtime_address) ;
00416 
00418 
00419 
00420 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_seg_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00422 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_base_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00423 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_index_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00425 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_scale(const xed_decoded_inst_t* p, unsigned int mem_idx);
00427 XED_DLL_EXPORT xed_int64_t xed_decoded_inst_get_memory_displacement(const xed_decoded_inst_t* p, unsigned int mem_idx);
00430 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_memory_displacement_width(const xed_decoded_inst_t* p, unsigned int mem_idx);
00433 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_memory_displacement_width_bits(const xed_decoded_inst_t* p, unsigned int mem_idx);
00435 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_branch_displacement(const xed_decoded_inst_t* p);
00438 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_branch_displacement_width(const xed_decoded_inst_t* p);
00441 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_branch_displacement_width_bits(const xed_decoded_inst_t* p);
00443 XED_DLL_EXPORT xed_uint64_t xed_decoded_inst_get_unsigned_immediate(const xed_decoded_inst_t* p); 
00446 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_is_signed(const xed_decoded_inst_t* p);
00449 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width(const xed_decoded_inst_t* p);
00452 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width_bits(const xed_decoded_inst_t* p);
00454 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_signed_immediate(const xed_decoded_inst_t* p);
00457 static XED_INLINE xed_uint8_t xed_decoded_inst_get_second_immediate(const xed_decoded_inst_t* p) {
00458     return STATIC_CAST(xed_uint8_t,p->_operands[XED_OPERAND_UIMM1]);
00459 }
00460 
00463 static XED_INLINE xed_reg_enum_t xed_decoded_inst_get_reg(const xed_decoded_inst_t* p, 
00464                                                           xed_operand_enum_t reg_operand) {
00465     return STATIC_CAST(xed_reg_enum_t,p->_operands[reg_operand]);
00466 }
00467 
00468 
00472 XED_DLL_EXPORT const xed_simple_flag_t* xed_decoded_inst_get_rflags_info( const xed_decoded_inst_t* p );
00473 
00480 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_uses_rflags(const xed_decoded_inst_t* p);
00482 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_number_of_memory_operands(const xed_decoded_inst_t* p);
00484 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_read(const xed_decoded_inst_t* p, unsigned int mem_idx);
00486 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written(const xed_decoded_inst_t* p, unsigned int mem_idx);
00488 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written_only(const xed_decoded_inst_t* p, unsigned int mem_idx);
00490 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_conditionally_writes_registers(const xed_decoded_inst_t* p);
00492 XED_DLL_EXPORT unsigned int  xed_decoded_inst_get_memory_operand_length(const xed_decoded_inst_t* p, 
00493                                                                         unsigned int memop_idx);
00494 
00495 
00498 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_is_prefetch(const xed_decoded_inst_t* p);
00500 
00501                   
00503 
00504 // Modifying decoded instructions before re-encoding    
00506 XED_DLL_EXPORT void xed_decoded_inst_set_scale(xed_decoded_inst_t* p, xed_uint_t scale);
00509 XED_DLL_EXPORT void xed_decoded_inst_set_memory_displacement(xed_decoded_inst_t* p, xed_int64_t disp, xed_uint_t length_bytes);
00512 XED_DLL_EXPORT void xed_decoded_inst_set_branch_displacement(xed_decoded_inst_t* p, xed_int32_t disp, xed_uint_t length_bytes);
00515 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_signed(xed_decoded_inst_t* p, xed_int32_t x, xed_uint_t length_bytes);
00518 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_unsigned(xed_decoded_inst_t* p, xed_uint64_t x, xed_uint_t length_bytes);
00519 
00520 
00523 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);
00526 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);
00529 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);
00532 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);
00533 
00535 
00537 
00538 
00539 
00540 static XED_INLINE  xed_uint64_t xed_decoded_inst_get_user_data(xed_decoded_inst_t* p) {
00541     return p->u.user_data;
00542 }
00545 static XED_INLINE  void xed_decoded_inst_set_user_data(xed_decoded_inst_t* p, xed_uint64_t new_value) {
00546     p->u.user_data = new_value;
00547 }
00548 
00549 
00550 
00552 #endif
00553 //Local Variables:
00554 //pref: "../../xed-decoded-inst.c"
00555 //End:
00556 

Generated on Tue Dec 15 03:23:59 2009 for XED2 by  doxygen 1.4.6