00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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"
00047
00048
00049
00050
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];
00064
00066 xed_uint8_t _operand_order[XED_ENCODE_ORDER_MAX_OPERANDS];
00067
00068 xed_uint8_t _decoded_length;
00069
00070 xed_uint8_t _n_operand_order;
00071
00075 const xed_inst_t* _inst;
00076
00077
00078 union {
00079 xed_uint8_t* _enc;
00080 const xed_uint8_t* _dec;
00081 } _byte_array;
00082
00083
00084
00085 union {
00086
00087
00088
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 }
00160
00161
00165
00167
00168
00169
00170 static XED_INLINE xed_bool_t xed_decoded_inst_valid(const xed_decoded_inst_t* p ) {
00171 return STATIC_CAST(xed_bool_t,(p->_inst != 0));
00172 }
00175 static XED_INLINE const xed_inst_t* xed_decoded_inst_inst( const xed_decoded_inst_t* p) {
00176 return p->_inst;
00177 }
00178
00179
00182 static XED_INLINE xed_category_enum_t xed_decoded_inst_get_category(const xed_decoded_inst_t* p) {
00183 xed_assert(p->_inst != 0);
00184 return xed_inst_category(p->_inst);
00185 }
00188 static XED_INLINE xed_extension_enum_t xed_decoded_inst_get_extension( const xed_decoded_inst_t* p) {
00189 xed_assert(p->_inst != 0);
00190 return xed_inst_extension(p->_inst);
00191 }
00194 static XED_INLINE xed_iclass_enum_t xed_decoded_inst_get_iclass( const xed_decoded_inst_t* p){
00195 xed_assert(p->_inst != 0);
00196 return xed_inst_iclass(p->_inst);
00197 }
00198
00201 XED_DLL_EXPORT xed_uint32_t xed_decoded_inst_get_attribute(const xed_decoded_inst_t* p, xed_attribute_enum_t attr);
00202
00205 XED_DLL_EXPORT xed_uint32_t xed_decoded_inst_get_attributes(const xed_decoded_inst_t* p);
00207
00208
00210
00211
00214 static XED_INLINE xed_iform_enum_t xed_decoded_inst_get_iform_enum(const xed_decoded_inst_t* p) {
00215 xed_assert(p->_inst != 0);
00216 return xed_inst_iform_enum(p->_inst);
00217 }
00218
00224 static XED_INLINE unsigned int xed_decoded_inst_get_iform_enum_dispatch(const xed_decoded_inst_t* p) {
00225 xed_assert(p->_inst != 0);
00226 return xed_inst_iform_enum(p->_inst) - xed_iform_first_per_iclass(xed_inst_iclass(p->_inst));
00227 }
00229
00230
00231
00233
00234
00235
00236 XED_DLL_EXPORT unsigned int xed_decoded_inst_operand_length(const xed_decoded_inst_t* p,
00237 unsigned int operand_index);
00240 static XED_INLINE unsigned int xed_decoded_inst_noperands(const xed_decoded_inst_t* p) {
00241 unsigned int noperands = xed_inst_noperands(xed_decoded_inst_inst(p));
00242 return noperands;
00243 }
00245
00247
00248
00249
00250 XED_DLL_EXPORT void xed_decoded_inst_dump(const xed_decoded_inst_t* p, char* buf, int buflen);
00251
00260 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format(const xed_decoded_inst_t* p,
00261 char* buf,
00262 int buflen,
00263 xed_uint64_t runtime_address);
00273 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format_context(const xed_decoded_inst_t* p,
00274 char* buf,
00275 int buflen,
00276 xed_uint64_t runtime_address,
00277 void* context);
00278
00291 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format(const xed_decoded_inst_t* p,
00292 char* buf,
00293 int buflen,
00294 xed_uint64_t runtime_address);
00295
00308 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format_context(const xed_decoded_inst_t* p,
00309 char* buf,
00310 int buflen,
00311 xed_uint64_t runtime_address,
00312 void* context);
00313
00320 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_xed_format(const xed_decoded_inst_t* p,
00321 char* buf,
00322 int buflen, xed_uint64_t runtime_address) ;
00324
00326
00327
00328 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_seg_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00330 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_base_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00331 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_index_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00333 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_scale(const xed_decoded_inst_t* p, unsigned int mem_idx);
00335 XED_DLL_EXPORT xed_int64_t xed_decoded_inst_get_memory_displacement(const xed_decoded_inst_t* p, unsigned int mem_idx);
00338 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_memory_displacement_width(const xed_decoded_inst_t* p, unsigned int mem_idx);
00341 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_memory_displacement_width_bits(const xed_decoded_inst_t* p, unsigned int mem_idx);
00343 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_branch_displacement(const xed_decoded_inst_t* p);
00346 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_branch_displacement_width(const xed_decoded_inst_t* p);
00349 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_branch_displacement_width_bits(const xed_decoded_inst_t* p);
00351 XED_DLL_EXPORT xed_uint64_t xed_decoded_inst_get_unsigned_immediate(const xed_decoded_inst_t* p);
00354 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_is_signed(const xed_decoded_inst_t* p);
00357 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width(const xed_decoded_inst_t* p);
00360 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width_bits(const xed_decoded_inst_t* p);
00362 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_signed_immediate(const xed_decoded_inst_t* p);
00365 static XED_INLINE xed_uint8_t xed_decoded_inst_get_second_immediate(const xed_decoded_inst_t* p) {
00366 return STATIC_CAST(xed_uint8_t,p->_operands[XED_OPERAND_UIMM1]);
00367 }
00368
00371 static XED_INLINE xed_reg_enum_t xed_decoded_inst_get_reg(const xed_decoded_inst_t* p,
00372 xed_operand_enum_t reg_operand) {
00373 return STATIC_CAST(xed_reg_enum_t,p->_operands[reg_operand]);
00374 }
00375
00376
00377
00379 XED_DLL_EXPORT const xed_simple_flag_t* xed_decoded_inst_get_rflags_info( const xed_decoded_inst_t* p );
00381 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_uses_rflags(const xed_decoded_inst_t* p);
00383 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_number_of_memory_operands(const xed_decoded_inst_t* p);
00385 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_read(const xed_decoded_inst_t* p, unsigned int mem_idx);
00387 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written(const xed_decoded_inst_t* p, unsigned int mem_idx);
00389 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written_only(const xed_decoded_inst_t* p, unsigned int mem_idx);
00391 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_conditionally_writes_registers(const xed_decoded_inst_t* p);
00393 XED_DLL_EXPORT unsigned int xed_decoded_inst_get_memory_operand_length(const xed_decoded_inst_t* p,
00394 unsigned int memop_idx);
00395
00396
00399 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_is_prefetch(const xed_decoded_inst_t* p);
00401
00402
00404
00405
00407 XED_DLL_EXPORT void xed_decoded_inst_set_scale(xed_decoded_inst_t* p, xed_uint_t scale);
00410 XED_DLL_EXPORT void xed_decoded_inst_set_memory_displacement(xed_decoded_inst_t* p, xed_int64_t disp, xed_uint_t length_bytes);
00413 XED_DLL_EXPORT void xed_decoded_inst_set_branch_displacement(xed_decoded_inst_t* p, xed_int32_t disp, xed_uint_t length_bytes);
00416 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_signed(xed_decoded_inst_t* p, xed_int32_t x, xed_uint_t length_bytes);
00419 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_unsigned(xed_decoded_inst_t* p, xed_uint64_t x, xed_uint_t length_bytes);
00420
00421
00424 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);
00427 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);
00430 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);
00433 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);
00434
00436
00438
00439
00440
00441 static XED_INLINE xed_uint64_t xed_decoded_inst_get_user_data(xed_decoded_inst_t* p) {
00442 return p->u.user_data;
00443 }
00446 static XED_INLINE void xed_decoded_inst_set_user_data(xed_decoded_inst_t* p, xed_uint64_t new_value) {
00447 p->u.user_data = new_value;
00448 }
00450 #endif
00451
00452
00453