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
00209
00210
00213 static XED_INLINE xed_iform_enum_t xed_decoded_inst_get_iform_enum(const xed_decoded_inst_t* p) {
00214 xed_assert(p->_inst != 0);
00215 return xed_inst_iform_enum(p->_inst);
00216 }
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) & 0xFF;
00227 }
00228
00233 XED_DLL_EXPORT xed_uint32_t xed_iform_max_per_iclass(xed_iclass_enum_t iclass);
00234
00235 #define XED_MASK_IFORM(x) ((x) & 0xFF)
00236
00240 static XED_INLINE xed_uint_t xed_decoded_inst_get_old_iform( const xed_decoded_inst_t* p){
00241 xed_assert(p->_inst != 0);
00242 return xed_inst_iform(p->_inst);
00243 }
00244
00246
00247
00248
00250
00251
00252
00253 XED_DLL_EXPORT unsigned int xed_decoded_inst_operand_length(const xed_decoded_inst_t* p,
00254 unsigned int operand_index);
00257 static XED_INLINE unsigned int xed_decoded_inst_noperands(const xed_decoded_inst_t* p) {
00258 unsigned int noperands = xed_inst_noperands(xed_decoded_inst_inst(p));
00259 return noperands;
00260 }
00262
00264
00265
00266
00267 XED_DLL_EXPORT void xed_decoded_inst_dump(const xed_decoded_inst_t* p, char* buf, int buflen);
00268
00277 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format(const xed_decoded_inst_t* p,
00278 char* buf,
00279 int buflen,
00280 xed_uint64_t runtime_address);
00290 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_intel_format_context(const xed_decoded_inst_t* p,
00291 char* buf,
00292 int buflen,
00293 xed_uint64_t runtime_address,
00294 void* context);
00295
00308 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format(const xed_decoded_inst_t* p,
00309 char* buf,
00310 int buflen,
00311 xed_uint64_t runtime_address);
00312
00325 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_att_format_context(const xed_decoded_inst_t* p,
00326 char* buf,
00327 int buflen,
00328 xed_uint64_t runtime_address,
00329 void* context);
00330
00337 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_dump_xed_format(const xed_decoded_inst_t* p,
00338 char* buf,
00339 int buflen, xed_uint64_t runtime_address) ;
00341
00343
00344
00345 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_seg_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00347 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_base_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00348 XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_index_reg(const xed_decoded_inst_t* p, unsigned int mem_idx);
00350 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_scale(const xed_decoded_inst_t* p, unsigned int mem_idx);
00352 XED_DLL_EXPORT xed_int64_t xed_decoded_inst_get_memory_displacement(const xed_decoded_inst_t* p, unsigned int mem_idx);
00355 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_memory_displacement_width(const xed_decoded_inst_t* p, unsigned int mem_idx);
00358 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_memory_displacement_width_bits(const xed_decoded_inst_t* p, unsigned int mem_idx);
00360 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_branch_displacement(const xed_decoded_inst_t* p);
00363 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_branch_displacement_width(const xed_decoded_inst_t* p);
00366 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_branch_displacement_width_bits(const xed_decoded_inst_t* p);
00368 XED_DLL_EXPORT xed_uint64_t xed_decoded_inst_get_unsigned_immediate(const xed_decoded_inst_t* p);
00371 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_is_signed(const xed_decoded_inst_t* p);
00374 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width(const xed_decoded_inst_t* p);
00377 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_immediate_width_bits(const xed_decoded_inst_t* p);
00379 XED_DLL_EXPORT xed_int32_t xed_decoded_inst_get_signed_immediate(const xed_decoded_inst_t* p);
00382 static XED_INLINE xed_uint8_t xed_decoded_inst_get_second_immediate(const xed_decoded_inst_t* p) {
00383 return STATIC_CAST(xed_uint8_t,p->_operands[XED_OPERAND_UIMM1]);
00384 }
00385
00388 static XED_INLINE xed_reg_enum_t xed_decoded_inst_get_reg(const xed_decoded_inst_t* p,
00389 xed_operand_enum_t reg_operand) {
00390 return STATIC_CAST(xed_reg_enum_t,p->_operands[reg_operand]);
00391 }
00392
00393
00394
00396 XED_DLL_EXPORT const xed_simple_flag_t* xed_decoded_inst_get_rflags_info( const xed_decoded_inst_t* p );
00398 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_uses_rflags(const xed_decoded_inst_t* p);
00400 XED_DLL_EXPORT xed_uint_t xed_decoded_inst_number_of_memory_operands(const xed_decoded_inst_t* p);
00402 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_read(const xed_decoded_inst_t* p, unsigned int mem_idx);
00404 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written(const xed_decoded_inst_t* p, unsigned int mem_idx);
00406 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_mem_written_only(const xed_decoded_inst_t* p, unsigned int mem_idx);
00408 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_conditionally_writes_registers(const xed_decoded_inst_t* p);
00410 XED_DLL_EXPORT unsigned int xed_decoded_inst_get_memory_operand_length(const xed_decoded_inst_t* p,
00411 unsigned int memop_idx);
00412
00413
00416 XED_DLL_EXPORT xed_bool_t xed_decoded_inst_is_prefetch(const xed_decoded_inst_t* p);
00418
00419
00421
00422
00424 XED_DLL_EXPORT void xed_decoded_inst_set_scale(xed_decoded_inst_t* p, xed_uint_t scale);
00427 XED_DLL_EXPORT void xed_decoded_inst_set_memory_displacement(xed_decoded_inst_t* p, xed_int64_t disp, xed_uint_t length_bytes);
00430 XED_DLL_EXPORT void xed_decoded_inst_set_branch_displacement(xed_decoded_inst_t* p, xed_int32_t disp, xed_uint_t length_bytes);
00433 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_signed(xed_decoded_inst_t* p, xed_int32_t x, xed_uint_t length_bytes);
00436 XED_DLL_EXPORT void xed_decoded_inst_set_immediate_unsigned(xed_decoded_inst_t* p, xed_uint64_t x, xed_uint_t length_bytes);
00437
00438
00441 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);
00444 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);
00447 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);
00450 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);
00451
00453
00455
00456
00457
00458 static XED_INLINE xed_uint64_t xed_decoded_inst_get_user_data(xed_decoded_inst_t* p) {
00459 return p->u.user_data;
00460 }
00463 static XED_INLINE void xed_decoded_inst_set_user_data(xed_decoded_inst_t* p, xed_uint64_t new_value) {
00464 p->u.user_data = new_value;
00465 }
00467 #endif
00468
00469
00470