Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / misc / decoder_test / XED2 / include / xed / xed-encode.h
1 /*BEGIN_LEGAL 
2 Intel Open Source License 
3
4 Copyright (c) 2002-2007 Intel Corporation 
5 All rights reserved. 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9
10 Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.  Redistributions
12 in binary form must reproduce the above copyright notice, this list of
13 conditions and the following disclaimer in the documentation and/or
14 other materials provided with the distribution.  Neither the name of
15 the Intel Corporation nor the names of its contributors may be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
18  
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 END_LEGAL */
31 /// @file xed-encode.h
32 /// @author Mark Charney   <mark.charney@intel.com> 
33
34
35 #ifndef _XED_ENCODE_H_
36 # define _XED_ENCODE_H_
37 #include "xed-common-hdrs.h"
38 #include "xed-types.h"
39 #include "xed-error-enum.h"
40 #include "xed-operand-values-interface.h"
41 #include "xed-operand-width-enum.h"
42 #include "xed-encoder-iforms.h" //generated
43 #include "xed-encoder-gen-defs.h" //generated
44
45 // we now (mostly) share the decode data structure
46 #include "xed-decoded-inst.h" 
47
48
49 // establish a type equivalence for the xed_encoder_request_t and the corresponding xed_decoded_inst_t.
50
51 /// @ingroup ENC
52 typedef struct  xed_decoded_inst_s xed_encoder_request_s; 
53 /// @ingroup ENC
54 typedef xed_decoded_inst_t xed_encoder_request_t; 
55
56
57 /// @ingroup ENC
58 XED_DLL_EXPORT xed_iclass_enum_t 
59 xed_encoder_request_get_iclass( const xed_encoder_request_t* p);
60
61 /////////////////////////////////////////////////////////
62 // set functions
63
64 /// @ingroup ENC
65 XED_DLL_EXPORT void  
66 xed_encoder_request_set_iclass( xed_encoder_request_t* p, 
67                                 xed_iclass_enum_t iclass);
68
69 /// @name Prefixes
70 //@{
71 /// @ingroup ENC
72 /// For locked (atomic read-modify-write) memops requests.
73 XED_DLL_EXPORT void xed_encoder_request_set_lock(xed_encoder_request_t* p);
74 /// @ingroup ENC
75 /// for REP(F3) and REPNE(F2) prefixe on string ops
76 XED_DLL_EXPORT void xed_encoder_request_set_repne(xed_encoder_request_t* p);
77 /// @ingroup ENC
78 /// for REP(F3) and REPNE(F2) prefixe on string ops
79 XED_DLL_EXPORT void xed_encoder_request_set_rep(xed_encoder_request_t* p);
80 //@}
81
82 /// @name Primary Encode Functions
83 //@{
84 /// @ingroup ENC
85 XED_DLL_EXPORT void  xed_encoder_request_set_effective_operand_width( xed_encoder_request_t* p, 
86                                                                       xed_uint_t width_bits);
87 /// @ingroup ENC
88 XED_DLL_EXPORT void  xed_encoder_request_set_effective_address_size( xed_encoder_request_t* p, 
89                                                                      xed_uint_t width_bits);
90 /*! @ingroup ENC
91  * Set the operands array element indexed by operand to the actual register name reg.
92  *
93  * @param[in] p                xed_encoder_request_t
94  * @param[in] operand          indicates which register operand storage field to use
95  * @param[in] reg              the actual register represented (EAX, etc.)  to store.
96  */
97 XED_DLL_EXPORT void xed_encoder_request_set_reg(xed_encoder_request_t* p,
98                                                 xed_operand_enum_t operand, 
99                                                 xed_reg_enum_t reg);
100 //@}
101
102 /// @name Operand Order
103 //@{
104 /*! @ingroup ENC
105  * Specify the name as the n'th operand in the operand order. 
106  *
107  * The complication of this function is that the register operand names are
108  * specific to the position of the operand (REG0, REG1, REG2...). One can
109  * use this function for registers or one can use the
110  * xed_encoder_request_set_operand_name_reg() which takes integers instead
111  * of operand names.
112  *
113  * @param[in] p                #xed_encoder_request_t
114  * @param[in] operand_index    xed_uint_t representing n'th operand position
115  * @param[in] name             #xed_operand_enum_t operand name.
116  */
117 XED_DLL_EXPORT void xed_encoder_request_set_operand_order(xed_encoder_request_t* p, 
118                                                           xed_uint_t operand_index, 
119                                                           xed_operand_enum_t name);
120
121 /*! @ingroup ENC
122  * Retreive the name of the n'th operand in the operand order. 
123  *
124  * @param[in] p                #xed_encoder_request_t
125  * @param[in] operand_index    xed_uint_t representing n'th operand position
126  * @return The #xed_operand_enum_t operand name.
127  */
128 XED_DLL_EXPORT xed_operand_enum_t xed_encoder_request_get_operand_order(xed_encoder_request_t* p, 
129                                                                         xed_uint_t operand_index);
130                                                                         
131
132 /// @ingroup ENC
133 /// Retreive the number of entries in the encoder operand order array
134 /// @return The number of entries in the encoder operand order array
135 static XED_INLINE 
136 xed_uint_t xed_encoder_request_operand_order_entries(xed_encoder_request_t* p) {
137     return  p->_n_operand_order;
138 }
139
140 //@}
141
142
143 /// @name branches and far pointers
144 //@{
145 /// @ingroup ENC
146 XED_DLL_EXPORT void xed_encoder_request_set_relbr(xed_encoder_request_t* p);
147 /// @ingroup ENC
148 XED_DLL_EXPORT void xed_encoder_request_set_branch_displacement(xed_encoder_request_t* p,
149                                                                 xed_int32_t brdisp,
150                                                                 xed_uint_t nbytes);
151 /// @ingroup ENC
152 XED_DLL_EXPORT void xed_encoder_request_set_ptr(xed_encoder_request_t* p);
153 //@}
154
155
156 /// @name Immediates
157 //@{
158 /// @ingroup ENC
159 /// Set the uimm0 using a BYTE  width.
160 XED_DLL_EXPORT void xed_encoder_request_set_uimm0(xed_encoder_request_t* p,
161                                                   xed_uint64_t uimm,
162                                                   xed_uint_t nbytes);
163 /// @ingroup ENC
164 /// Set the uimm0 using a BIT  width.
165 XED_DLL_EXPORT void xed_encoder_request_set_uimm0_bits(xed_encoder_request_t* p,
166                                                        xed_uint64_t uimm,
167                                                        xed_uint_t nbits);
168 /// @ingroup ENC
169 XED_DLL_EXPORT void xed_encoder_request_set_uimm1(xed_encoder_request_t* p,
170                                                   xed_uint8_t uimm);
171 /// @ingroup ENC
172 /// same storage as uimm0
173 XED_DLL_EXPORT void xed_encoder_request_set_simm(xed_encoder_request_t* p,
174                                                  xed_int32_t simm,
175                                                  xed_uint_t nbytes);
176 //@}
177
178 /// @name Memory
179 //@{
180 /// @ingroup ENC
181 XED_DLL_EXPORT void xed_encoder_request_set_memory_displacement(xed_encoder_request_t* p,
182                                                                 xed_int64_t memdisp,
183                                                                 xed_uint_t nbytes);
184
185 /// @ingroup ENC
186 XED_DLL_EXPORT void xed_encoder_request_set_agen(xed_encoder_request_t* p);
187 /// @ingroup ENC
188 XED_DLL_EXPORT void xed_encoder_request_set_mem0(xed_encoder_request_t* p);
189 /// @ingroup ENC
190 XED_DLL_EXPORT void xed_encoder_request_set_mem1(xed_encoder_request_t* p);
191 /// @ingroup ENC
192 XED_DLL_EXPORT void xed_encoder_request_set_memory_operand_length(xed_encoder_request_t* p,
193                                                                   xed_uint_t nbytes);
194 /// @ingroup ENC
195 XED_DLL_EXPORT void xed_encoder_request_set_seg0(xed_encoder_request_t* p,
196                                   xed_reg_enum_t seg_reg);
197 /// @ingroup ENC
198 XED_DLL_EXPORT void xed_encoder_request_set_seg1(xed_encoder_request_t* p,
199                                   xed_reg_enum_t seg_reg);
200 /// @ingroup ENC
201 XED_DLL_EXPORT void xed_encoder_request_set_base0(xed_encoder_request_t* p,
202                                    xed_reg_enum_t base_reg);
203 /// @ingroup ENC
204 XED_DLL_EXPORT void xed_encoder_request_set_base1(xed_encoder_request_t* p,
205                                    xed_reg_enum_t base_reg) ;
206 /// @ingroup ENC
207 XED_DLL_EXPORT void xed_encoder_request_set_index(xed_encoder_request_t* p,
208                                    xed_reg_enum_t index_reg);
209 /// @ingroup ENC
210 XED_DLL_EXPORT void xed_encoder_request_set_scale(xed_encoder_request_t* p,
211                                    xed_uint_t scale);
212 //@}
213
214 //////////////////////////////////////////////
215 /// @ingroup ENC
216 XED_DLL_EXPORT const xed_operand_values_t* xed_encoder_request_operands_const(const xed_encoder_request_t* p);
217 /// @ingroup ENC
218 XED_DLL_EXPORT xed_operand_values_t* xed_encoder_request_operands(xed_encoder_request_t* p);
219
220 /// @name Initialization
221 //@{
222 /*! @ingroup ENC
223  * clear the operand order array
224  * @param[in] p                xed_encoder_request_t
225  */
226 XED_DLL_EXPORT void xed_encoder_request_zero_operand_order(xed_encoder_request_t* p);
227
228 /// @ingroup ENC
229 XED_DLL_EXPORT void  xed_encoder_request_zero_set_mode(xed_encoder_request_t* p,
230                                                        const xed_state_t* dstate);
231 /// @ingroup ENC
232 XED_DLL_EXPORT void  xed_encoder_request_zero(xed_encoder_request_t* p) ;
233 //@}
234
235 struct xed_decoded_inst_s; //fwd decl
236 /// @ingroup ENC
237 /// Converts an decoder request to a valid encoder request.
238 XED_DLL_EXPORT void  xed_encoder_request_init_from_decode(struct xed_decoded_inst_s* d);
239
240 void
241 xed_encoder_request_encode_emit(xed_encoder_request_t* q,
242                                 const unsigned int bits,
243                                 const xed_uint64_t value);
244     
245 xed_bool_t
246 xed_encoder_request__memop_compatible(const xed_encoder_request_t* p,
247                                       xed_operand_width_enum_t operand_width);
248
249 /// @name String Printing
250 //@{
251 /// @ingroup ENC        
252 XED_DLL_EXPORT void xed_encode_request_print(const xed_encoder_request_t* p, 
253                                              char* buf, xed_uint_t buflen);
254 //@}
255
256 // Type signature for an encode function
257 typedef xed_uint_t (*xed_encode_function_pointer_t)(xed_encoder_request_t* enc_req);
258
259
260 /// @name Encoding
261 //@{
262 ///   This is the main interface to the encoder. The array should be
263 ///   at most 15 bytes long. The ilen parameter should indiciate
264 ///   this length. If the array is too short, the encoder may fail to
265 ///   encode the request.  Failure is indicated by a return value of
266 ///   type #xed_error_enum_t that is not equal to
267 ///   #XED_ERROR_NONE. Otherwise, #XED_ERROR_NONE is returned and the
268 ///   length of the encoded instruction is returned in olen.
269 ///
270 /// @param r encoder request description (#xed_encoder_request_t), includes mode info
271 /// @param array the encoded instruction bytes are stored here
272 /// @param ilen the input length of array.
273 /// @param olen the actual  length of array used for encoding
274 /// @return success/failure as a #xed_error_enum_t
275 /// @ingroup ENC
276 XED_DLL_EXPORT xed_error_enum_t
277 xed_encode(xed_encoder_request_t* r,
278            xed_uint8_t* array, 
279            const unsigned int ilen,
280            unsigned int* olen);
281
282 /// This function will attempt to encode a NOP of exactly ilen
283 /// bytes. If such a NOP is not encodeable, then false will be returned.
284 ///
285 /// @param array the encoded instruction bytes are stored here
286 /// @param  ilen the input length array.
287 /// @return success/failure as a #xed_error_enum_t
288 /// @ingroup ENC
289 XED_DLL_EXPORT xed_error_enum_t
290 xed_encode_nop(xed_uint8_t* array, 
291                const unsigned int ilen);
292 //@}
293
294 #endif
295 ////////////////////////////////////////////////////////////////////////////
296 //Local Variables:
297 //pref: "../../xed-encode.c"
298 //End: