xed-decoded-inst.h

Go to the documentation of this file.
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_DECODER_STATE_H_)
00037 # define _XED_DECODER_STATE_H_
00038 #include "xed-common-hdrs.h"
00039 #include "xed-common-defs.h"
00040 #include "xed-portability.h"
00041 #include "xed-util.h"
00042 #include "xed-types.h"
00043 #include "xed-operand-values-interface.h" 
00044 #include "xed-inst.h"
00045 #include "xed-flags.h"
00046 #include "xed-encoder-gen-defs.h" //generated
00047 
00048 
00049 // fwd-decl xed_simple_flag_t;
00050 // fwd-decl xed_inst_t;
00051 
00052 
00053 struct xed_encoder_vars_s;
00054 struct xed_decoder_vars_s;
00055 
00061 typedef struct XED_DLL_EXPORT xed_decoded_inst_s  {
00063     xed_operand_values_t _operands[XED_OPERAND_LAST]; // FIXME: can further squeeze down 16b units
00064 
00066     xed_uint8_t _operand_order[XED_ENCODE_ORDER_MAX_OPERANDS];
00067 
00068     xed_uint8_t _decoded_length;
00069     // Length of the _operand_order[] array.
00070     xed_uint8_t _n_operand_order; 
00071 
00075     const xed_inst_t* _inst;
00076 
00077     // decoder does not change it, encoder does    
00078     union {
00079         xed_uint8_t* _enc;
00080         const xed_uint8_t* _dec;
00081     } _byte_array; 
00082 
00083     // These are stack allocated by xed_encode() or xed_decode(). These are
00084     // per-encode or per-decode transitory data.
00085     union {
00086 
00087         /* user_data is available as a user data storage field after
00088          * decoding. It does not live across re-encodes or re-decodes. */
00089         xed_uint64_t user_data; 
00090         struct xed_decoder_vars_s* dv;
00091         struct xed_encoder_vars_s* ev;
00092     } u;
00093 
00094 
00095     
00096 } xed_decoded_inst_t;
00097 
00098 
00099 
00101 
00102 
00103 
00104 static XED_INLINE const xed_operand_values_t* 
00105 xed_decoded_inst_operands_const(const xed_decoded_inst_t* p) {
00106     return STATIC_CAST(xed_operand_values_t*,p->_operands);
00107 }
00110 static XED_INLINE xed_operand_values_t* 
00111 xed_decoded_inst_operands(xed_decoded_inst_t* p) {
00112     return STATIC_CAST(xed_operand_values_t*,p->_operands);
00113 }
00115 
00117 
00118 
00119 
00120 XED_DLL_EXPORT void  xed_decoded_inst_zero_set_mode(xed_decoded_inst_t* p, const xed_state_t* dstate);
00123 XED_DLL_EXPORT void  xed_decoded_inst_zero_keep_mode(xed_decoded_inst_t* p);
00126 XED_DLL_EXPORT void  xed_decoded_inst_zero(xed_decoded_inst_t* p);
00129 XED_DLL_EXPORT void  xed_decoded_inst_zero_keep_mode_from_operands(xed_decoded_inst_t* p,
00130                                                                    const xed_operand_values_t* operands);
00132 
00134 
00135 
00136 
00137 static XED_INLINE xed_uint_t
00138 xed_decoded_inst_get_length(const xed_decoded_inst_t* p) {  
00139     return p->_decoded_length;
00140 }
00141 
00142 
00144 
00146 
00147 
00148 static XED_INLINE xed_uint_t xed_decoded_inst_get_mode(const xed_decoded_inst_t* p) {
00149     return p->_operands[XED_OPERAND_MODE];
00150 }
00152 static XED_INLINE xed_uint_t xed_decoded_inst_get_address_mode(const xed_decoded_inst_t* p) {
00153     return p->_operands[XED_OPERAND_AMODE];
00154 }
00156 static XED_INLINE xed_uint_t xed_decoded_inst_get_stack_address_mode(const xed_decoded_inst_t* p) {
00157     return p->_operands[XED_OPERAND_SMODE];
00158 }
00159 
00165 XED_DLL_EXPORT xed_uint32_t xed_decoded_inst_get_operand_width(const xed_decoded_inst_t* p);
00167 
00168 
00172 
00174 
00175 
00176 
00177 static XED_INLINE xed_bool_t xed_decoded_inst_valid(const xed_decoded_inst_t* p ) {
00178     return STATIC_CAST(xed_bool_t,(p->_inst != 0));
00179 }
00182 static XED_INLINE const xed_inst_t* xed_decoded_inst_inst( const xed_decoded_inst_t* p) {
00183     return p->_inst;
00184 }
00185 
00186 
00189 static XED_INLINE xed_category_enum_t xed_decoded_inst_get_category(const xed_decoded_inst_t* p) {
00190     xed_assert(p->_inst != 0);
00191     return xed_inst_category(p->_inst);
00192 }
00195 static XED_INLINE xed_extension_enum_t xed_decoded_inst_get_extension( const xed_decoded_inst_t* p) {
00196     xed_assert(p->_inst != 0);
00197     return xed_inst_extension(p->_inst);
00198 }
00201 static XED_INLINE xed_iclass_enum_t xed_decoded_inst_get_iclass( const xed_decoded_inst_t* p){
00202     xed_assert(p->_inst != 0);
00203     return xed_inst_iclass(p->_inst);
00204 }
00205 
00208 XED_DLL_EXPORT xed_uint32_t xed_decoded_inst_get_attribute(const xed_decoded_inst_t* p, xed_attribute_enum_t attr);
00209 
00212 XED_DLL_EXPORT xed_uint32_t xed_decoded_inst_get_attributes(const xed_decoded_inst_t* p);
00214 
00215 
00217 
00218 
00221 static XED_INLINE xed_iform_enum_t xed_decoded_inst_get_iform_enum(const xed_decoded_inst_t* p) {
00222     xed_assert(p->_inst != 0);
00223     return xed_inst_iform_enum(p->_inst);
00224 }
00225 
00231 static XED_INLINE unsigned int xed_decoded_inst_get_iform_enum_dispatch(const xed_decoded_inst_t* p) {
00232     xed_assert(p->_inst != 0);
00233     return xed_inst_iform_enum(p->_inst) - xed_iform_first_per_iclass(xed_inst_iclass(p->_inst));
00234 }
00236 
00237 
00238 
00240 
00241 
00244 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_length_bits(const xed_decoded_inst_t* p, 
00245                                                                   unsigned int operand_index);
00246 
00247 
00251 XED_DLL_EXPORT unsigned int  xed_decoded_inst_operand_length(const xed_decoded_inst_t* p, 
00252                                                              unsigned int operand_index);
00253 
00254 
00255 
00258 static XED_INLINE unsigned int  xed_decoded_inst_noperands(const xed_decoded_inst_t* p) {
00259     unsigned int noperands = xed_inst_noperands(xed_decoded_inst_inst(p));
00260     return noperands;
00261 }
00263 
00265 
00266 
00267 
00268 XED_DLL_EXPORT void xed_decoded_inst_dump(const xed_decoded_inst_t* p, char* buf,  int buflen);
00269 
00278 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format(const xed_decoded_inst_t* p, 
00279                                                              char* buf, 
00280                                                              int buflen, 
00281                                                              xed_uint64_t runtime_address);
00291 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format_context(const xed_decoded_inst_t* p, 
00292                                                                      char* buf, 
00293                                                                      int buflen, 
00294                                                                      xed_uint64_t runtime_address,
00295                                                                      void* context);
00296 
00309 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format(const xed_decoded_inst_t* p, 
00310                                                            char* buf, 
00311                                                            int buflen, 
00312                                                            xed_uint64_t runtime_address);
00313 
00326 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format_context(const xed_decoded_inst_t* p, 
00327                                                                    char* buf, 
00328                                                                    int buflen, 
00329                                                                    xed_uint64_t runtime_address,
00330                                                                    void* context);
00331 
00338 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_xed_format(const xed_decoded_inst_t* p,
00339                                                            char* buf, 
00340                                                            int buflen, xed_uint64_t runtime_address) ;
00342 
00344 
00345 
00346 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_seg_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00348 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_base_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00349 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_index_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00351 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_scale(const xed_decoded_inst_t* p, unsigned int mem_idx);
00353 XED_DLL_EXPORT xed_int64_t xed_decoded_inst_get_memory_displacement(const xed_decoded_inst_t* p, unsigned int mem_idx);
00356 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_memory_displacement_width(const xed_decoded_inst_t* p, unsigned int mem_idx);
00359 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_memory_displacement_width_bits(const xed_decoded_inst_t* p, unsigned int mem_idx);
00361 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_branch_displacement(const xed_decoded_inst_t* p);
00364 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_branch_displacement_width(const xed_decoded_inst_t* p);
00367 XED_DLL_EXPORT xed_uint_t  xed_decoded_inst_get_branch_displacement_width_bits(const xed_decoded_inst_t* p);
00369 XED_DLL_EXPORT xed_uint64_t xed_decoded_inst_get_unsigned_immediate(const xed_decoded_inst_t* p); 
00372 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_is_signed(const xed_decoded_inst_t* p);
00375 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width(const xed_decoded_inst_t* p);
00378 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width_bits(const xed_decoded_inst_t* p);
00380 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_signed_immediate(const xed_decoded_inst_t* p);
00383 static XED_INLINE xed_uint8_t xed_decoded_inst_get_second_immediate(const xed_decoded_inst_t* p) {
00384     return STATIC_CAST(xed_uint8_t,p->_operands[XED_OPERAND_UIMM1]);
00385 }
00386 
00389 static XED_INLINE xed_reg_enum_t xed_decoded_inst_get_reg(const xed_decoded_inst_t* p, 
00390                                                           xed_operand_enum_t reg_operand) {
00391     return STATIC_CAST(xed_reg_enum_t,p->_operands[reg_operand]);
00392 }
00393 
00394 
00395 
00397 XED_DLL_EXPORT const xed_simple_flag_t* xed_decoded_inst_get_rflags_info( const xed_decoded_inst_t* p );
00399 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_uses_rflags(const xed_decoded_inst_t* p);
00401 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_number_of_memory_operands(const xed_decoded_inst_t* p);
00403 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_read(const xed_decoded_inst_t* p, unsigned int mem_idx);
00405 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written(const xed_decoded_inst_t* p, unsigned int mem_idx);
00407 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written_only(const xed_decoded_inst_t* p, unsigned int mem_idx);
00409 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_conditionally_writes_registers(const xed_decoded_inst_t* p);
00411 XED_DLL_EXPORT unsigned int  xed_decoded_inst_get_memory_operand_length(const xed_decoded_inst_t* p, 
00412                                                                         unsigned int memop_idx);
00413 
00414 
00417 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_is_prefetch(const xed_decoded_inst_t* p);
00419 
00420                   
00422 
00423 // Modifying decoded instructions before re-encoding    
00425 XED_DLL_EXPORT void xed_decoded_inst_set_scale(xed_decoded_inst_t* p, xed_uint_t scale);
00428 XED_DLL_EXPORT void xed_decoded_inst_set_memory_displacement(xed_decoded_inst_t* p, xed_int64_t disp, xed_uint_t length_bytes);
00431 XED_DLL_EXPORT void xed_decoded_inst_set_branch_displacement(xed_decoded_inst_t* p, xed_int32_t disp, xed_uint_t length_bytes);
00434 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_signed(xed_decoded_inst_t* p, xed_int32_t x, xed_uint_t length_bytes);
00437 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_unsigned(xed_decoded_inst_t* p, xed_uint64_t x, xed_uint_t length_bytes);
00438 
00439 
00442 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);
00445 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);
00448 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);
00451 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);
00452 
00454 
00456 
00457 
00458 
00459 static XED_INLINE  xed_uint64_t xed_decoded_inst_get_user_data(xed_decoded_inst_t* p) {
00460     return p->u.user_data;
00461 }
00464 static XED_INLINE  void xed_decoded_inst_set_user_data(xed_decoded_inst_t* p, xed_uint64_t new_value) {
00465     p->u.user_data = new_value;
00466 }
00468 #endif
00469 //Local Variables:
00470 //pref: "../../xed-decoded-inst.c"
00471 //End:

Generated on Wed Dec 3 03:10:46 2008 for XED2 by  doxygen 1.4.6