xed-decoded-inst-api.h

Go to the documentation of this file.
00001 /*BEGIN_LEGAL 
00002 Intel Open Source License 
00003 
00004 Copyright (c) 2002-2015 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_DECODED_INST_API_H_)
00035 # define _XED_DECODED_INST_API_H_
00036 
00037 #include "xed-decoded-inst.h"
00038 #include "xed-operand-accessors.h"
00039 #include "xed-state.h"
00040 #include "xed-operand-values-interface.h"
00041 #include "xed-print-info.h"
00042 
00046 
00048 
00049 
00050 
00051 static XED_INLINE xed_bool_t
00052 xed_decoded_inst_valid(const xed_decoded_inst_t* p ) {
00053     return XED_STATIC_CAST(xed_bool_t,(p->_inst != 0));
00054 }
00058 static XED_INLINE const xed_inst_t*
00059 xed_decoded_inst_inst( const xed_decoded_inst_t* p) {
00060     return p->_inst;
00061 }
00062 
00063 
00066 static XED_INLINE xed_category_enum_t
00067 xed_decoded_inst_get_category(const xed_decoded_inst_t* p) {
00068     xed_assert(p->_inst != 0);
00069     return xed_inst_category(p->_inst);
00070 }
00073 static XED_INLINE xed_extension_enum_t
00074 xed_decoded_inst_get_extension( const xed_decoded_inst_t* p) {
00075     xed_assert(p->_inst != 0);
00076     return xed_inst_extension(p->_inst);
00077 }
00080 static XED_INLINE xed_isa_set_enum_t
00081 xed_decoded_inst_get_isa_set(xed_decoded_inst_t const* const p) {
00082     xed_assert(p->_inst != 0);
00083     return xed_inst_isa_set(p->_inst);
00084 }
00087 static XED_INLINE xed_iclass_enum_t
00088 xed_decoded_inst_get_iclass( const xed_decoded_inst_t* p){
00089     xed_assert(p->_inst != 0);
00090     return xed_inst_iclass(p->_inst);
00091 }
00092 
00094 
00095 
00096 
00097 XED_DLL_EXPORT xed_uint32_t
00098 xed_decoded_inst_get_attribute(const xed_decoded_inst_t* p,
00099                                xed_attribute_enum_t attr);
00100 
00103 XED_DLL_EXPORT xed_attributes_t
00104 xed_decoded_inst_get_attributes(const xed_decoded_inst_t* p);
00106 
00109 XED_DLL_EXPORT xed_uint32_t
00110 xed_decoded_inst_is_xacquire(const xed_decoded_inst_t* p);
00111 
00114 XED_DLL_EXPORT xed_uint32_t
00115 xed_decoded_inst_is_xrelease(const xed_decoded_inst_t* p);
00116 
00119 XED_DLL_EXPORT xed_uint32_t
00120 xed_decoded_inst_has_mpx_prefix(const xed_decoded_inst_t* p);
00121 
00124 XED_DLL_EXPORT xed_uint8_t
00125 xed_decoded_inst_get_modrm(const xed_decoded_inst_t* p);
00126 
00130 XED_DLL_EXPORT xed_bool_t
00131 xed_decoded_inst_masked_vector_operation(xed_decoded_inst_t* p);
00132 
00139 XED_DLL_EXPORT xed_uint_t
00140 xed_decoded_inst_vector_length_bits(xed_decoded_inst_t const* const p);
00141 
00144 XED_DLL_EXPORT xed_uint_t
00145 xed_decoded_inst_get_nprefixes(xed_decoded_inst_t* p);
00146 
00148 
00149 
00151 
00152 
00153 
00154 static XED_INLINE const xed_operand_values_t* 
00155 xed_decoded_inst_operands_const(const xed_decoded_inst_t* p) {
00156     return p;
00157 }
00160 static XED_INLINE xed_operand_values_t* 
00161 xed_decoded_inst_operands(xed_decoded_inst_t* p) {
00162     return p;
00163 }
00164 
00167 XED_DLL_EXPORT unsigned int
00168 xed_decoded_inst_operand_length_bits(const xed_decoded_inst_t* p, 
00169                                      unsigned int operand_index);
00170 
00171 
00175 XED_DLL_EXPORT unsigned int
00176 xed_decoded_inst_operand_length(const xed_decoded_inst_t* p, 
00177                                 unsigned int operand_index);
00178 
00179 
00182 static XED_INLINE unsigned int
00183 xed_decoded_inst_noperands(const xed_decoded_inst_t* p) {
00184     unsigned int noperands = xed_inst_noperands(xed_decoded_inst_inst(p));
00185     return noperands;
00186 }
00187 
00188 
00191 XED_DLL_EXPORT unsigned int
00192 xed_decoded_inst_operand_elements(const xed_decoded_inst_t* p, 
00193                                   unsigned int operand_index);
00194 
00197 XED_DLL_EXPORT unsigned int
00198 xed_decoded_inst_operand_element_size_bits(const xed_decoded_inst_t* p, 
00199                                            unsigned int operand_index);
00200 
00204 XED_DLL_EXPORT xed_operand_element_type_enum_t
00205 xed_decoded_inst_operand_element_type(const xed_decoded_inst_t* p,
00206                                       unsigned int operand_index);
00207 
00214 XED_DLL_EXPORT xed_operand_action_enum_t
00215 xed_decoded_inst_operand_action(const xed_decoded_inst_t* p,
00216                                 unsigned int operand_index);
00217 
00219 
00221 
00222 
00223 
00224 XED_DLL_EXPORT xed_bool_t
00225 xed_decoded_inst_masking(const xed_decoded_inst_t* p);
00226 
00229 XED_DLL_EXPORT xed_bool_t
00230 xed_decoded_inst_merging(const xed_decoded_inst_t* p);
00231 
00234 XED_DLL_EXPORT xed_bool_t
00235 xed_decoded_inst_zeroing(const xed_decoded_inst_t* p);
00237 
00239 
00240 
00241 
00242 
00243 XED_DLL_EXPORT void
00244 xed_decoded_inst_zero_set_mode(xed_decoded_inst_t* p,
00245                                const xed_state_t* dstate);
00246 
00250 XED_DLL_EXPORT void  xed_decoded_inst_zero_keep_mode(xed_decoded_inst_t* p);
00251 
00252 
00255 XED_DLL_EXPORT void  xed_decoded_inst_zero(xed_decoded_inst_t* p);
00256 
00261 static XED_INLINE void
00262 xed_decoded_inst_set_mode(xed_decoded_inst_t* p,
00263                           xed_machine_mode_enum_t mmode,
00264                           xed_address_width_enum_t stack_addr_width)
00265 {
00266     xed_state_t dstate;
00267     dstate.mmode = mmode;
00268     dstate.stack_addr_width = stack_addr_width;
00269     xed_operand_values_set_mode(p, &dstate);
00270 }
00271 
00272 
00273 
00278 XED_DLL_EXPORT void
00279 xed_decoded_inst_zero_keep_mode_from_operands(
00280     xed_decoded_inst_t* p,
00281     const xed_operand_values_t* operands);
00282 
00284 
00285 
00286 
00287 static XED_INLINE xed_uint_t
00288 xed_decoded_inst_get_length(const xed_decoded_inst_t* p) {  
00289     return p->_decoded_length;
00290 }
00291 
00293 
00294 
00296 
00297 
00298 
00299 static XED_INLINE xed_uint8_t
00300 xed_decoded_inst_get_byte(const xed_decoded_inst_t* p, xed_uint_t byte_index)
00301 {
00303     xed_uint8_t out = p->_byte_array._dec[byte_index];
00304     return out;
00305 }
00306 
00308 
00310 
00311 
00312 
00313 
00314 static XED_INLINE xed_uint_t
00315 xed_decoded_inst_get_machine_mode_bits(const xed_decoded_inst_t* p) {
00316     xed_uint8_t mode = xed3_operand_get_mode(p);
00317     if (mode == 2) return 64;
00318     if (mode == 1) return 32;
00319     return 16;
00320 }
00324 static XED_INLINE xed_uint_t
00325 xed_decoded_inst_get_stack_address_mode_bits(const xed_decoded_inst_t* p) {
00326     xed_uint8_t smode = xed3_operand_get_smode(p);
00327     if (smode == 2) return 64;
00328     if (smode == 1) return 32;
00329     return 16;
00330 }
00331 
00337 XED_DLL_EXPORT xed_uint32_t
00338 xed_decoded_inst_get_operand_width(const xed_decoded_inst_t* p);
00339 
00343 static XED_INLINE xed_chip_enum_t
00344 xed_decoded_inst_get_input_chip(const xed_decoded_inst_t* p) {
00345     return xed3_operand_get_chip(p);
00346 }
00347 
00350 static XED_INLINE void
00351 xed_decoded_inst_set_input_chip(xed_decoded_inst_t* p,
00352                                 xed_chip_enum_t chip) {
00353     xed3_operand_set_chip(p,chip);
00354 }
00355 
00356 
00360 XED_DLL_EXPORT xed_bool_t
00361 xed_decoded_inst_valid_for_chip(xed_decoded_inst_t const* const p, 
00362                                 xed_chip_enum_t chip);
00363 
00365 
00366 
00367 
00368 
00370 
00371 
00374 static XED_INLINE xed_iform_enum_t
00375 xed_decoded_inst_get_iform_enum(const xed_decoded_inst_t* p) {
00376     xed_assert(p->_inst != 0);
00377     return xed_inst_iform_enum(p->_inst);
00378 }
00379 
00385 static XED_INLINE unsigned int
00386 xed_decoded_inst_get_iform_enum_dispatch(const xed_decoded_inst_t* p) {
00387     xed_assert(p->_inst != 0);
00388     return xed_inst_iform_enum(p->_inst) -
00389                 xed_iform_first_per_iclass(xed_inst_iclass(p->_inst));
00390 }
00392 
00393 
00394 
00395 
00397 
00398 
00399 
00400 
00401 XED_DLL_EXPORT void
00402 xed_decoded_inst_dump(const xed_decoded_inst_t* p, char* buf,  int buflen);
00403 
00404 
00405 
00414 XED_DLL_EXPORT xed_bool_t
00415 xed_decoded_inst_dump_xed_format(const xed_decoded_inst_t* p,
00416                                  char* buf, 
00417                                  int buflen, 
00418                                  xed_uint64_t runtime_address) ;
00419 
00420 
00433 XED_DLL_EXPORT xed_bool_t
00434 xed_format_context(xed_syntax_enum_t syntax,
00435                    const xed_decoded_inst_t* xedd,
00436                    char* out_buffer,
00437                    int  buffer_len,
00438                    xed_uint64_t runtime_instruction_address,
00439                    void* context,
00440                    xed_disassembly_callback_fn_t symbolic_callback);
00441 
00442 
00450 XED_DLL_EXPORT xed_bool_t
00451 xed_format_generic(xed_print_info_t* pi);
00452 
00454 
00456 
00457 
00458 XED_DLL_EXPORT xed_reg_enum_t
00459 xed_decoded_inst_get_seg_reg(const xed_decoded_inst_t* p,
00460                              unsigned int mem_idx);
00462 XED_DLL_EXPORT xed_reg_enum_t
00463 xed_decoded_inst_get_base_reg(const xed_decoded_inst_t* p,
00464                               unsigned int mem_idx);
00465 XED_DLL_EXPORT xed_reg_enum_t
00466 xed_decoded_inst_get_index_reg(const xed_decoded_inst_t* p,
00467                                unsigned int mem_idx);
00469 XED_DLL_EXPORT xed_uint_t
00470 xed_decoded_inst_get_scale(const xed_decoded_inst_t* p,
00471                            unsigned int mem_idx);
00473 XED_DLL_EXPORT xed_int64_t
00474 xed_decoded_inst_get_memory_displacement(const xed_decoded_inst_t* p,
00475                                          unsigned int mem_idx);
00478 XED_DLL_EXPORT xed_uint_t
00479 xed_decoded_inst_get_memory_displacement_width(const xed_decoded_inst_t* p,
00480                                                unsigned int mem_idx);
00483 XED_DLL_EXPORT xed_uint_t
00484 xed_decoded_inst_get_memory_displacement_width_bits(const xed_decoded_inst_t* p,
00485                                                     unsigned int mem_idx);
00487 XED_DLL_EXPORT xed_int32_t
00488 xed_decoded_inst_get_branch_displacement(const xed_decoded_inst_t* p);
00491 XED_DLL_EXPORT xed_uint_t
00492 xed_decoded_inst_get_branch_displacement_width(const xed_decoded_inst_t* p);
00495 XED_DLL_EXPORT xed_uint_t
00496 xed_decoded_inst_get_branch_displacement_width_bits(
00497     const xed_decoded_inst_t* p);
00499 XED_DLL_EXPORT xed_uint64_t
00500 xed_decoded_inst_get_unsigned_immediate(const xed_decoded_inst_t* p); 
00503 XED_DLL_EXPORT xed_uint_t
00504 xed_decoded_inst_get_immediate_is_signed(const xed_decoded_inst_t* p);
00507 XED_DLL_EXPORT xed_uint_t
00508 xed_decoded_inst_get_immediate_width(const xed_decoded_inst_t* p);
00511 XED_DLL_EXPORT xed_uint_t
00512 xed_decoded_inst_get_immediate_width_bits(const xed_decoded_inst_t* p);
00514 XED_DLL_EXPORT xed_int32_t
00515 xed_decoded_inst_get_signed_immediate(const xed_decoded_inst_t* p);
00518 static XED_INLINE xed_uint8_t
00519 xed_decoded_inst_get_second_immediate(const xed_decoded_inst_t* p) {
00520     return xed3_operand_get_uimm1(p);
00521 }
00522 
00526 XED_DLL_EXPORT xed_reg_enum_t
00527 xed_decoded_inst_get_reg(const xed_decoded_inst_t* p, 
00528                          xed_operand_enum_t reg_operand);
00529 
00530 
00534 XED_DLL_EXPORT const xed_simple_flag_t*
00535 xed_decoded_inst_get_rflags_info( const xed_decoded_inst_t* p );
00536 
00543 XED_DLL_EXPORT xed_bool_t
00544 xed_decoded_inst_uses_rflags(const xed_decoded_inst_t* p);
00545 
00547 XED_DLL_EXPORT xed_uint_t
00548 xed_decoded_inst_number_of_memory_operands(const xed_decoded_inst_t* p);
00550 XED_DLL_EXPORT xed_bool_t
00551 xed_decoded_inst_mem_read(const xed_decoded_inst_t* p, unsigned int mem_idx);
00553 XED_DLL_EXPORT xed_bool_t
00554 xed_decoded_inst_mem_written(const xed_decoded_inst_t* p, unsigned int mem_idx);
00556 XED_DLL_EXPORT xed_bool_t
00557 xed_decoded_inst_mem_written_only(const xed_decoded_inst_t* p,
00558                                   unsigned int mem_idx);
00560 XED_DLL_EXPORT xed_bool_t
00561 xed_decoded_inst_conditionally_writes_registers(const xed_decoded_inst_t* p);
00564 XED_DLL_EXPORT unsigned int
00565 xed_decoded_inst_get_memory_operand_length(const xed_decoded_inst_t* p, 
00566                                            unsigned int memop_idx);
00567 
00571 // 67 prefixes if present.
00573 XED_DLL_EXPORT unsigned int 
00574 xed_decoded_inst_get_memop_address_width(const xed_decoded_inst_t* p,
00575                                          xed_uint_t memop_idx);
00576 
00577 
00578 
00581 XED_DLL_EXPORT xed_bool_t
00582 xed_decoded_inst_is_prefetch(const xed_decoded_inst_t* p);
00584 
00585                   
00587 
00588 // Modifying decoded instructions before re-encoding    
00590 XED_DLL_EXPORT void
00591 xed_decoded_inst_set_scale(xed_decoded_inst_t* p, xed_uint_t scale);
00594 XED_DLL_EXPORT void
00595 xed_decoded_inst_set_memory_displacement(xed_decoded_inst_t* p,
00596                                          xed_int64_t disp,
00597                                          xed_uint_t length_bytes);
00600 XED_DLL_EXPORT void
00601 xed_decoded_inst_set_branch_displacement(xed_decoded_inst_t* p,
00602                                          xed_int32_t disp,
00603                                          xed_uint_t length_bytes);
00606 XED_DLL_EXPORT void
00607 xed_decoded_inst_set_immediate_signed(xed_decoded_inst_t* p,
00608                                       xed_int32_t x,
00609                                       xed_uint_t length_bytes);
00612 XED_DLL_EXPORT void
00613 xed_decoded_inst_set_immediate_unsigned(xed_decoded_inst_t* p,
00614                                         xed_uint64_t x,
00615                                         xed_uint_t length_bytes);
00616 
00617 
00620 XED_DLL_EXPORT void
00621 xed_decoded_inst_set_memory_displacement_bits(xed_decoded_inst_t* p,
00622                                               xed_int64_t disp,
00623                                               xed_uint_t length_bits);
00626 XED_DLL_EXPORT void
00627 xed_decoded_inst_set_branch_displacement_bits(xed_decoded_inst_t* p,
00628                                               xed_int32_t disp,
00629                                               xed_uint_t length_bits);
00632 XED_DLL_EXPORT void
00633 xed_decoded_inst_set_immediate_signed_bits(xed_decoded_inst_t* p,
00634                                            xed_int32_t x,
00635                                            xed_uint_t length_bits);
00638 XED_DLL_EXPORT void
00639 xed_decoded_inst_set_immediate_unsigned_bits(xed_decoded_inst_t* p,
00640                                              xed_uint64_t x,
00641                                              xed_uint_t length_bits);
00642 
00644 
00646 
00647 
00648 
00649 static XED_INLINE  xed_uint64_t
00650 xed_decoded_inst_get_user_data(xed_decoded_inst_t* p) {
00651     return p->u.user_data;
00652 }
00655 static XED_INLINE  void
00656 xed_decoded_inst_set_user_data(xed_decoded_inst_t* p,
00657                                xed_uint64_t new_value) {
00658     p->u.user_data = new_value;
00659 }
00660 
00661 
00662 
00663 
00665 #endif
00666 

Generated on Wed Jan 21 02:14:35 2015 for XED by  doxygen 1.4.6