xed-ild.h

Go to the documentation of this file.
00001 /*BEGIN_LEGAL 
00002 Intel Open Source License 
00003 
00004 Copyright (c) 2002-2012 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 */
00031 
00034     
00035 #if !defined(_XED_ILD_H_)
00036 # define _XED_ILD_H_
00037 #include "xed-common-hdrs.h"
00038 #include "xed-common-defs.h"
00039 #include "xed-portability.h"
00040 #include "xed-types.h"
00041 
00042 #if defined(XED_ILD)
00043     
00044     /**********************************************************************/
00045     /*                                                                    */
00046     /* THIS CODE IS INCOMPLETE, EXPERIMENTAL AND SUBJECT TO CHANGE AT     */
00047     /* ANY TIME! DO NOT USE THIS CODE YET!                                */
00048     /*                                                                    */
00049     /**********************************************************************/
00050 
00051 /* ILD-related defines:
00052  *
00053  * XED_ILD - for building ILD module 
00054  * XED_ILD_CHECK  for using ILD module in decoding and checking 
00055  *                results against regular decode
00056  * XED_ILD_ONLY - for using only ILD for length decoding, without
00057  *                regular decoding. This is for performance measurements.
00058  */
00059 
00060 XED_INLINE static xed_uint_t xed_modrm_mod(xed_uint8_t m) { return m>>6; }
00061 XED_INLINE static xed_uint_t xed_modrm_reg(xed_uint8_t m) { return (m>>3)&7; }
00062 XED_INLINE static xed_uint_t xed_modrm_rm(xed_uint8_t m) { return m&7; }
00063 XED_INLINE static xed_uint_t xed_sib_scale(xed_uint8_t m) { return m>>6; }
00064 XED_INLINE static xed_uint_t xed_sib_index(xed_uint8_t m) { return (m>>3)&7; }
00065 XED_INLINE static xed_uint_t xed_sib_base(xed_uint8_t m) { return m&7; }
00066 XED_INLINE static xed_uint_t bits2bytes(xed_uint_t bits) { return bits>>3; }
00067 
00068 /*
00069  * To allow the ILD to record information for nonpublic extensions, we
00070  * allow adding fields to the xed_ild_extended_t at compile time by
00071  * generating xed-ild-extension.h that defines
00072  * xed_ild_extended_t type.  The implication of this model, is that
00073  * downstream extension models must be supersets of all the extensions that
00074  * they compose with. FIXME: cook up a way to synthesize/generate the
00075  * xed-ild-extension.h file and type definition from all the fields in
00076  * relevant models at compile time.
00077  */
00078 
00079 #include "xed-ild-extension.h"
00080 
00081 
00082 typedef enum {
00083     XED_ILD_MAP0=0,
00084     XED_ILD_MAP1=1,
00085     XED_ILD_MAP2=2,
00086     XED_ILD_MAP3=3,
00087     XED_ILD_MAPAMD,
00088     XED_ILD_INVALID_MAP=0xFF
00089 } xed_ild_map_enum_t;
00090 
00091 #define ILD_ITEXT_MAX_BYTES 15
00092 
00093 #define XED_GRAMMAR_MODE_64 2
00094 #define XED_GRAMMAR_MODE_32 1
00095 #define XED_GRAMMAR_MODE_16 0
00096 
00097 typedef struct  {
00098     /* init/configuration variables */
00099     xed_bits_t mmode;  /* machine mode in XED GRAMMAR format: 0/1/2 */
00100     const xed_uint8_t* itext;
00101     xed_uint_t  max_bytes; 
00102     xed_uint_t out_of_bytes; /* 1 if max_bytes bound was reached while
00103                               * scanning itext 
00104                               */
00105 
00106     /* observed variables */
00107     xed_uint_t  length;    /* the observed length */
00108     
00109     /* to get the count of real legacy prefixes, subtract the number of rex
00110        prefixes from nprefixes.  There is only one rex prefix that is used;
00111        but any rex-s that are mixed-in with the legacy prefixes are
00112        ignored! We must count them. */
00113     xed_uint_t  nprefixes; /* count of legacy and rex prefixes */
00114     xed_uint_t  nrexes;    /* count of rex prefixes */
00115     
00116     xed_uint_t  nseg_prefexies; /* count of segment prefixes */
00117 
00118     
00119     xed_uint8_t found; /* NDY - found a valid inst */
00120     xed_uint8_t osz;  /* if 66 was observed */
00121     xed_uint8_t asz;  /* if 67 was observed */
00122     xed_uint8_t seg;  /* the last seg prefix */
00123     xed_uint8_t lock; /* 1 or 0 */
00124     xed_uint8_t f2;  /* 1 or 0 */
00125     xed_uint8_t f3;  /* 1 or 0 */
00126     xed_uint8_t last_f2f3; /* f2 or f3 */
00127     xed_uint8_t first_f2f3;  /* f2 or f3 */
00128     xed_uint8_t rex; /* rex value */
00129     xed_uint8_t vex; /* c4 or c5 */
00130     xed_uint8_t nominal_opcode;
00131     xed_uint8_t nominal_opcode_position; /* 0 is first ... */
00132 
00133      /* required for sib processing */
00134     xed_uint8_t modrm; /* value of byte if has_modrm is nonzero*/
00135     
00136     xed_ild_map_enum_t map; 
00137     xed_uint8_t amd3dnow; /* 1 or 0 */
00138     xed_uint8_t rex_w;
00139     xed_uint8_t rex_r;
00140     xed_uint8_t rex_x;
00141     xed_uint8_t rex_b;
00142     xed_uint8_t vex_l;
00143     xed_uint8_t vex_pp;
00144     xed_uint8_t vex_w;
00145 
00146     /* decode-time derived variables */
00147     xed_bool_t has_modrm;
00148     xed_bool_t has_sib;
00149     xed_uint8_t imm_bytes;   /* 0=none, else 1,2,4,8 */
00150     /*has_imm1 is for AMD's double immediate insstructions */
00151     xed_uint8_t imm1_bytes;   /* 0=none, else 1,2 */
00152     xed_uint8_t disp_bytes;  /* 0=none, else 1,2,4,8 */
00153 
00154     /* position of the back-end bytes */
00155     xed_uint8_t pos_modrm;
00156     xed_uint8_t pos_sib;
00157     xed_uint8_t pos_imm;
00158     xed_uint8_t pos_imm1; //for AMD's second immediate
00159     xed_uint8_t pos_disp;
00160 
00161     xed_ild_extended_t ext;
00162 } xed_ild_t;
00163 
00164 XED_DLL_EXPORT void xed_ild_init(xed_ild_t* x,
00165                                  xed_machine_mode_enum_t mmode,
00166                                  const xed_uint8_t* itext,
00167                                  const xed_uint_t  max_bytes);
00168 
00169 
00171 void xed_ild_init_decoder(void);
00172 
00180 XED_DLL_EXPORT xed_uint_t
00181 xed_instruction_length_decode(xed_ild_t* ild);
00182 
00183 
00184 
00185 
00192 XED_DLL_EXPORT 
00193 xed_bits_t xed_ild_cvt_mode(xed_machine_mode_enum_t mmode);
00194 
00195 #endif
00196 
00197 #endif

Generated on Wed Aug 8 00:23:22 2012 for XED2 by  doxygen 1.4.6