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 / doc / html / group__CMDLINE.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>XED2: XED2 User Guide - Thu May 15 03:15:09 2008 </title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 <link href="tabs.css" rel="stylesheet" type="text/css">
6 </head><body>
7 <!-- Generated by Doxygen 1.4.6 -->
8 <div class="tabs">
9   <ul>
10     <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
11     <li><a href="modules.html"><span>Modules</span></a></li>
12     <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
13     <li><a href="files.html"><span>Files</span></a></li>
14     <li>
15       <form action="search.php" method="get">
16         <table cellspacing="0" cellpadding="0" border="0">
17           <tr>
18             <td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
19             <td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
20           </tr>
21         </table>
22       </form>
23     </li>
24   </ul></div>
25 <h1>XED command interface</h1>The command line tool called xed or xed.exe is built when you build the examples (<a class="el" href="group__EXAMPLES.html">Examples of using XED</a>) that come with XED. The xed-ex3 is just encode portion of the xed command line tool.<p>
26 This tool is useful for encoding and decoding or even decoding-then-re-encoding a single instruction or all the instructions in the text segment of an ELF binary (32 or 64b). For decoding, just jump to the examples.<p>
27 This section also explains a little language for writing the instructions for encode requests (-e option). I am constantly using this tool and updating it. The xed-ex3 (xed-ex3.exe) example is just the encoder portion of the xed command line tool.<p>
28 The SUPPRESSED operands emitted by the decoder are not used when encoding. They are ignored. They are not required to select an encoding.<p>
29 The syntax for encodable strings is as follows: <div class="fragment"><pre class="fragment">             Opcode[/width]   [operand [operand]]
30 </pre></div><p>
31 The width is a 8, 16, 32 or 64, indicating the effective operand width if it differs from the default. 8b operations generally require this. Or since most operations that default to 32b widths in 64b mode, it is required for 64b operation widths in 64b mode.<p>
32 The operand specifier is one of the following.<p>
33 <ul>
34 <li>A register name such as EAX or R8B, etc. Case does not matter.</li></ul>
35 <p>
36 <ul>
37 <li>An immediate specifier such as IMM(12ff) . Note: most shells require quotes because of the parens.</li></ul>
38 <p>
39 <ul>
40 <li>A displacement specifier such as DISP(0000001f) . Note: need the quotes.</li></ul>
41 <p>
42 <ul>
43 <li>A memory specifier that indicates the base register, index register, scale value, and displacement value. If one of the fields is not required, a - is necessary. The displacement is omittable. For example: MEM4(ESI,EAX,8,ff) or MEM4(EBX,-,-). The first one specifies that the memory address 4 bytes and should be ESI + EAX * 8 + 0xff. The second one specifies that EBX should be used to access 4 bytes of memory; note the displacement is omitted. A segment override can be specified as follows: MEM4(GS:EAX,-,-,-), by using a segment-name followed by a ":" before the base register. If there is no base register, you can use a "-", for example: MEM4(GS:-,-,11223344). One also needs to specify a memory operation width. This can be accomplished by indicating a number of bytes just after the MEM specifier. For example: MEM2(EAX,-,-) indicates a 2 byte memory operation.</li></ul>
44 <p>
45 <ul>
46 <li>An address generation specifer that has the same syntax as the above MEM() specifier, but is only used for LEA instructions. Example: AGEN(EAX,EBX,2,-)</li></ul>
47 <p>
48 Here is the help message:<p>
49 <div class="fragment"><pre class="fragment">% obj/xed -h
50 Usage: obj/xed [options]
51 One of the following is required:
52   -i input_file             (decode file)
53   -ide input_file           (decode/encode file)
54   -d hex-string             (decode one instruction)
55   -e instruction            (encode, must be last)
56   -de hex-string            (decode-then-encode)
57  
58 Optional arguments:
59   -v verbosity  (0=quiet, 1=errors, 2=useful-info, 3=trace, 5=very verbose)
60   -n number-of-instructions-to-decode (default 10,000, accepts K/M/G qualifiers)
61   -I            (Intel SYSV syntax for disassembly)
62   -A            (ATT SYSV syntax for disassembly)
63   -16           (for LEGACY_16 mode)
64   -32           (for LEGACY_32 mode, default)
65   -64           (for LONG_64 mode w/64b addressing)
66   -a32          (32b addressing, default, not in LONG_64 mode)
67   -a16          (16b addressing, not in LONG_64 mode)
68   -s32          (32b stack addressing, default, not in LONG_64 mode)
69   -s16          (16b stack addressing, not in LONG_64 mode)
70 </pre></div><p>
71 Here are a couple of examples:<p>
72 <div class="fragment"><pre class="fragment">% xed -d 0000
73 ADD INT_ALU BASE  Opcode: 00  MODRM: 00 Bytes: 2
74         Eb/EXPLICIT/RW Gb/EXPLICIT/R 
75         ADD EffWidth: 8b
76         MachineMode: LEGACY_32 AddrWidth: 32b StackAddrWidth: 32b
77         MEM/EXPLICIT/RW REG/AL(REG8)/EXPLICIT/R 
78         Read Write BASE= EAX(REG32) MemopLength = 1
79
80         rFLAGS: of-mod sf-mod zf-mod af-mod pf-mod cf-mod Read:  Written: of sf zf af pf cf             writes
81
82 % xed -e ADD EAX EBX
83 Encodable! 01d8
84
85 xed -e ADD EAX 'MEM4(ESP,EBX,4)'
86 Encodable! 03049c
87
88 % xed -d 6a00
89 PUSH INT_ALU BASE  Opcode: 6a  Immed: 00 Bytes: 2
90         Ib/EXPLICIT/R STACKPUSH/SUPPRESSED/R 
91         PUSH EffWidth: 32b
92         MachineMode: LEGACY_32 AddrWidth: 32b StackAddrWidth: 32b
93         MEM/SUPPRESSED/W REG/ESP(REG32)/SUPPRESSED/RW IMM/EXPLICIT/R 
94         Write SEG= SS BASE= ESP(REG32) MemopLength = 4
95         IMMED: 00
96
97         Does not use rFLAGS
98
99 % xed -e MOV EAX 'MEM4(SS:ESP,-,-)'
100 Encodable! 8b0424
101 </pre></div><p>
102 Or using the xed-ex3 example tool: <div class="fragment"><pre class="fragment">% obj/xed-ex3
103 Usage: obj/xed-ex3 [-16|-32|-64] [-a16|-a32] [-s16|-s32] encode-string
104 </pre></div><p>
105 The -16, -32 or -64 are for specifying the major mode of the machine. The -a16 and -a32 are for specifying 16 or 32 bit addressing. The default addressing mode in 64b mode is 64b addressing. The -s16 and -a32 are for specifying 16 or 32 bit stack addressing in 16 or 32 bit modes.<p>
106 <div class="fragment"><pre class="fragment">% obj/xed-ex3 -64 PUSH/64 RAX
107 Encode request:
108 PUSH Prefixes:  EffOpWidth: 64b EffAddrWidth: 64b
109         MachineMode: LONG_64 AddrWidth: 64b StackAddrWidth: 32b
110         REG/RAX(REG64)/EXPLICIT/RW 
111         MemopLength = 0
112
113 Encodable! 50
114
115 % obj/xed-ex3 MOV 'MEM4(EAX,-,-)<span class="charliteral">' '</span>IMM(11223344)'
116 Encode request:
117 MOV Prefixes:  EffOpWidth: 32b EffAddrWidth: 32b
118         MachineMode: LEGACY_32 AddrWidth: 32b StackAddrWidth: 32b
119         MEM0/EXPLICIT/RW IMM/EXPLICIT/RW 
120         TmpltIdx=0 BASE= EAX(REG32) MemopLength = 0
121         IMMED: 0x11223344 <span class="keywordtype">signed</span>: 1144201745 starts@byte: 1
122
123 Encodable! c70011223344
124 </pre></div><h2><a class="anchor" name="ENCODE_EXAMPLE">
125 An example of using the encoder</a></h2>
126 The encoder language file which is part of the xed command line tool shows how to build up instructions from scratch. The example uses a string to drive the creation of the instruction, but that is just an example. Look at the parse_encode_request function for the required pieces.<p>
127 <div class="fragment"><pre class="fragment"><span class="comment">/*BEGIN_LEGAL </span>
128 <span class="comment">Copyright (c) 2007, Intel Corp.</span>
129 <span class="comment">All rights reserved.</span>
130 <span class="comment"></span>
131 <span class="comment">Redistribution and use in source and binary forms, with or without</span>
132 <span class="comment">modification, are permitted provided that the following conditions are</span>
133 <span class="comment">met:</span>
134 <span class="comment"></span>
135 <span class="comment">    * Redistributions of source code must retain the above copyright</span>
136 <span class="comment">      notice, this list of conditions and the following disclaimer.</span>
137 <span class="comment"></span>
138 <span class="comment">    * Redistributions in binary form must reproduce the above</span>
139 <span class="comment">      copyright notice, this list of conditions and the following</span>
140 <span class="comment">      disclaimer in the documentation and/or other materials provided</span>
141 <span class="comment">      with the distribution.</span>
142 <span class="comment"></span>
143 <span class="comment">    * Neither the name of Intel Corporation nor the names of its</span>
144 <span class="comment">      contributors may be used to endorse or promote products derived</span>
145 <span class="comment">      from this software without specific prior written permission.</span>
146 <span class="comment"></span>
147 <span class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
148 <span class="comment">"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
149 <span class="comment">LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
150 <span class="comment">A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
151 <span class="comment">OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
152 <span class="comment">SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
153 <span class="comment">LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
154 <span class="comment">DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
155 <span class="comment">THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
156 <span class="comment">(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
157 <span class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
158 <span class="comment">END_LEGAL */</span>
159
160 <span class="comment">// This is an example of how to use the encoder from scratch in the context</span>
161 <span class="comment">// of parsing a string from the command line.  </span>
162
163
164 <span class="preprocessor">#include &lt;iostream&gt;</span>
165 <span class="preprocessor">#include &lt;iomanip&gt;</span>
166 <span class="preprocessor">#include &lt;vector&gt;</span>
167 <span class="preprocessor">#include &lt;sstream&gt;</span>
168 <span class="preprocessor">#include &lt;cassert&gt;</span>
169 <span class="keyword">extern</span> <span class="stringliteral">"C"</span> {
170 <span class="preprocessor">#include "<a class="code" href="xed-interface_8h.html">xed-interface.h</a>"</span>
171 <span class="preprocessor">#include "<a class="code" href="xed-portability_8h.html">xed-portability.h</a>"</span>
172 <span class="preprocessor">#include "xed-examples-util.h"</span>
173 }
174 <span class="preprocessor">#include "xed-enc-lang.H"</span>
175
176
177
178
179 <span class="keyword">using namespace </span>std;
180 <span class="keyword">static</span> <span class="keywordtype">char</span> xed_enc_lang_toupper(<span class="keywordtype">char</span> c) {
181     <span class="keywordflow">if</span> (c &gt;= <span class="charliteral">'a'</span> &amp;&amp; c &lt;= <span class="charliteral">'z'</span>)
182         <span class="keywordflow">return</span> c-<span class="charliteral">'a'</span>+<span class="charliteral">'A'</span>;
183     <span class="keywordflow">return</span> c;
184 }
185
186 <span class="keyword">static</span> string upcase(string s) {
187     string t = <span class="stringliteral">""</span>;
188     <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> len = static_cast&lt;xed_uint_t&gt;(s.size());
189     <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> i;
190     <span class="keywordflow">for</span>(i=0 ; i &lt; len ; i++ ) 
191         t = t + xed_enc_lang_toupper(s[i]);
192     <span class="keywordflow">return</span> t;
193 }
194
195 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>
196 xed_split_args(<span class="keyword">const</span> string&amp; sep, 
197                <span class="keyword">const</span> string&amp; input, 
198                vector&lt;string&gt;&amp; output_array)
199 {
200     <span class="comment">// returns the number of args</span>
201     <span class="comment">// rip off the separator characters and split the src string based on separators.</span>
202     
203     <span class="comment">// find the string between last_pos and pos. pos is after last_pos</span>
204     string::size_type last_pos = input.find_first_not_of(sep, 0);
205     string::size_type pos = input.find_first_of(sep, last_pos);  
206     <span class="keywordflow">if</span> (CLIENT_VERBOSE3)
207         printf(<span class="stringliteral">"input %s\tlast_pos "</span> <a class="code" href="xed-portability_8h.html#9091b96f5482bcfd24989443027cf922">XED_FMT_U</a> <span class="stringliteral">" pos "</span> <a class="code" href="xed-portability_8h.html#9091b96f5482bcfd24989443027cf922">XED_FMT_U</a> <span class="stringliteral">"\n"</span>, 
208                input.c_str() , <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a>,last_pos), <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a>,pos));
209     <span class="keywordtype">int</span> i=0;
210     <span class="keywordflow">while</span>( pos != string::npos &amp;&amp; last_pos != string::npos ) 
211     {
212         string a = input.substr(last_pos, pos-last_pos);
213         output_array.push_back(a); 
214         <span class="keywordflow">if</span> (CLIENT_VERBOSE3)
215             printf(<span class="stringliteral">"\t\tlast_pos "</span> XED_FMT_U <span class="stringliteral">" pos "</span> XED_FMT_U <span class="stringliteral">" i %d\n"</span>, 
216                    <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a>,last_pos),
217                    <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a>,pos),
218                    i);
219         last_pos = input.find_first_not_of(sep, pos);
220         pos = input.find_first_of(sep, last_pos);  
221         i++;
222     }
223     <span class="keywordflow">if</span> (last_pos != string::npos &amp;&amp; pos == string::npos)
224     {
225         <span class="keywordflow">if</span> (CLIENT_VERBOSE3)
226             printf(<span class="stringliteral">"\t\tGetting last substring at "</span> XED_FMT_U <span class="stringliteral">"\n"</span>, <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a>,last_pos));
227         string a = input.substr(last_pos); <span class="comment">// get the rest of the string</span>
228         output_array.push_back(a);
229         i++;
230     }
231     <span class="keywordflow">if</span> (CLIENT_VERBOSE3)
232         printf(<span class="stringliteral">"\t returning %d\n"</span>,i);
233     <span class="keywordflow">return</span> i;
234 }
235
236 vector&lt;string&gt; 
237 tokenize(<span class="keyword">const</span> string&amp; s,
238          <span class="keyword">const</span> string&amp; delimiter) {
239     vector&lt;string&gt; v;
240     (void) xed_split_args(delimiter, s, v);
241     <span class="keywordflow">return</span> v;
242 }
243
244
245 <span class="keywordtype">void</span> slash_split(<span class="keyword">const</span> string&amp; src,
246                  string&amp; first, <span class="comment">// output</span>
247                  string&amp;  second) <span class="comment">//output</span>
248 {
249   string::size_type p = src.find(<span class="stringliteral">"/"</span>);
250   <span class="keywordflow">if</span> (p == string::npos) {
251     first = src;
252     second = <span class="stringliteral">""</span>;
253   }
254   <span class="keywordflow">else</span> {
255     first = src.substr(0,p);
256     second = src.substr(p+1);
257   }
258 }
259
260 <span class="keyword">class </span>immed_parser_t {
261   <span class="keyword">public</span>:
262     <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> valid;
263     string immed;
264     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> width_bits;
265     xed_uint64_t immed_val;
266     string tok0;
267
268     immed_parser_t(<span class="keyword">const</span> string&amp; s, 
269                    <span class="keyword">const</span> string&amp; arg_tok0) <span class="comment">//CONS</span>
270         : valid(false),
271           tok0(arg_tok0)
272     {
273         vector&lt;string&gt; vs = tokenize(s,<span class="stringliteral">"(),"</span>);
274         <span class="keywordflow">if</span> (vs.size() == 2) {
275             <span class="keywordflow">if</span> (vs[0] == tok0) {
276                 string immed_str = vs[1];
277                 immed_val = convert_ascii_hex_to_int(immed_str.c_str());
278                 width_bits = static_cast&lt;unsigned int&gt;(immed_str.size()*4); <span class="comment">// nibbles to bits</span>
279                 valid = <span class="keyword">true</span>;
280             }
281         }
282     }
283
284     <span class="keywordtype">void</span>
285     print(ostream&amp; o)<span class="keyword"> const </span>{
286         o &lt;&lt; tok0 
287           &lt;&lt; <span class="stringliteral">"("</span> ;
288         <span class="keywordflow">if</span> (valid) 
289             o &lt;&lt; hex &lt;&lt; immed_val &lt;&lt; dec;
290         <span class="keywordflow">else</span> 
291             o &lt;&lt; <span class="stringliteral">"???"</span>;
292         o &lt;&lt; <span class="stringliteral">")"</span>;
293     }
294
295 };
296
297 ostream&amp; operator&lt;&lt;(ostream&amp; o, <span class="keyword">const</span> immed_parser_t&amp; x) 
298 {
299     x.print(o);
300     <span class="keywordflow">return</span> o;
301 }
302
303
304 <span class="keyword">class </span>seg_parser_t
305 {
306   <span class="keyword">public</span>:
307     <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> valid;
308     <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> segment_reg;
309     string segment;
310
311     seg_parser_t(<span class="keyword">const</span> string&amp; s) <span class="comment">// CONS</span>
312         : valid(false),
313           segment_reg(<a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>)
314     {
315         vector&lt;string&gt; vs = tokenize(s,<span class="stringliteral">"(),"</span>);
316         <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> ntokens = static_cast&lt;xed_uint_t&gt;(vs.size());
317         cerr &lt;&lt; <span class="stringliteral">"ntokens "</span> &lt;&lt; ntokens &lt;&lt; <span class="stringliteral">": "</span> ;
318         <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0;i&lt;ntokens;i++) cerr  &lt;&lt; <span class="charliteral">'['</span> &lt;&lt; vs[i] &lt;&lt; <span class="stringliteral">"] "</span>;
319         cerr &lt;&lt; endl;
320         <span class="keywordflow">if</span> (ntokens == 2 &amp;&amp; vs[0] == <span class="stringliteral">"SEG"</span>) {
321             segment = vs[1];
322             segment_reg = <a class="code" href="xed-reg-enum_8h.html#48dc3d086b469ae580ca47917043c2fd">str2xed_reg_enum_t</a>(segment.c_str());
323             <span class="keywordflow">if</span> (segment_reg != <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a> &amp;&amp; <a class="code" href="group__REGINTFC.html#g9003309edac48c9c1dfca2187497c613">xed_reg_class</a>(segment_reg) == <a class="code" href="xed-reg-class-enum_8h.html#8ac6bf3f9f78208385c46ea25324ea76b02b323ba71ce251bca0ac4206b7d028">XED_REG_CLASS_SR</a>) {
324                 valid=<span class="keyword">true</span>;
325             }
326         }
327     }
328
329 };
330
331 <span class="keyword">class </span>mem_bis_parser_t 
332 {
333     <span class="comment">// parse: MEM[length]([segment:]base,index,scale[,displacement])</span>
334     <span class="comment">// parse: AGEN(base,index,scale[,displacement])</span>
335     <span class="comment">// The displacement is optional</span>
336     <span class="comment">// The length of the memop is usually optional </span>
337     <span class="comment">//   but required for x87 ops, for example.</span>
338   <span class="keyword">public</span>:
339     <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> valid;
340     <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> mem;
341
342     <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> agen;
343     <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> disp_valid;
344     string segment;
345     string base;
346     string index;
347     string scale;
348     string disp; <span class="comment">//displacement</span>
349     <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> segment_reg;
350     <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> base_reg;
351     <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> index_reg;
352     xed_uint8_t scale_val;
353
354
355     xed_int64_t disp_val;
356     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> disp_width_bits;
357
358     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mem_len;
359
360     <span class="keywordtype">void</span>
361     print(ostream&amp; o)<span class="keyword"> const </span>{
362         <span class="keywordflow">if</span> (agen) 
363             o &lt;&lt; <span class="stringliteral">"AGEN"</span>; 
364         <span class="keywordflow">if</span> (mem) 
365             o &lt;&lt; <span class="stringliteral">"MEM"</span>; 
366         <span class="keywordflow">if</span> (mem_len) 
367             o &lt;&lt; setw(1) &lt;&lt; mem_len;
368         o &lt;&lt; <span class="stringliteral">"("</span>;
369         <span class="keywordflow">if</span> (segment_reg != <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>)
370             o &lt;&lt; segment_reg &lt;&lt; <span class="stringliteral">":"</span>;
371         o &lt;&lt; base_reg;
372         o &lt;&lt; <span class="stringliteral">","</span> &lt;&lt; index_reg 
373           &lt;&lt; <span class="stringliteral">","</span> 
374           &lt;&lt; (<span class="keywordtype">unsigned</span> int) scale_val;
375         <span class="keywordflow">if</span> (disp_valid) 
376             o &lt;&lt;  <span class="stringliteral">","</span> &lt;&lt; disp;
377         o &lt;&lt; <span class="stringliteral">")"</span>;
378      
379     }
380   
381     mem_bis_parser_t(<span class="keyword">const</span> string&amp; s) <span class="comment">//CONS</span>
382         : valid(false),
383           disp_valid(false),
384           base(<span class="stringliteral">"INVALID"</span>),
385           index(<span class="stringliteral">"INVALID"</span>),
386           scale(<span class="stringliteral">"1"</span>),
387           segment_reg(<a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>),
388           base_reg(<a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>),
389           index_reg(<a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>),
390           disp_val(0),
391           disp_width_bits(0),
392           mem_len(0)
393     {
394
395         mem = <span class="keyword">false</span>;
396         agen = <span class="keyword">false</span>;
397         vector&lt;string&gt; vs = tokenize(s,<span class="stringliteral">"(),"</span>);
398         <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> ntokens = static_cast&lt;xed_uint_t&gt;(vs.size());
399         <span class="keywordflow">if</span> (ntokens &gt;= 2 &amp;&amp; ntokens &lt;= 5) {
400             <span class="keywordflow">if</span> (vs[0] == <span class="stringliteral">"AGEN"</span>) {
401                 agen = <span class="keyword">true</span>;
402             }
403             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (vs[0].substr(0,3) == <span class="stringliteral">"MEM"</span>) {
404                 mem = <span class="keyword">true</span>;
405                 <span class="keywordflow">if</span> (vs[0].size() &gt; 3) {
406                     string len = vs[0].substr(3);
407                     mem_len = strtol(len.c_str(),0,0);
408                     <span class="comment">//printf("mem_len  = " XED_FMT_U "\n", mem_len);</span>
409                 }
410             }
411             <span class="keywordflow">else</span>             {
412                 <span class="keywordflow">return</span>;
413             }
414
415             segment = <span class="stringliteral">"INVALID"</span>;
416             string seg_and_base = upcase(vs[1]);
417             vector&lt;string&gt; sb = tokenize(seg_and_base,<span class="stringliteral">":"</span>);
418             <span class="keywordtype">int</span> seg_and_base_tokens = <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<span class="keywordtype">int</span>,sb.size());
419             <span class="keywordflow">if</span> (seg_and_base_tokens == 1) {
420                 segment = <span class="stringliteral">"INVALID"</span>;
421                 base = sb[0];
422             }
423             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (seg_and_base_tokens == 2) {
424                 <span class="keywordflow">if</span> (agen) {
425                     xedex_derror(<span class="stringliteral">"AGENs cannot have segment overrides"</span>);
426                 }
427                 segment = sb[0];
428                 base = sb[1];
429             }
430             <span class="keywordflow">else</span>            {
431                 printf(<span class="stringliteral">"seg_and_base_tokens = %d\n"</span>,seg_and_base_tokens);
432                 xedex_derror(<span class="stringliteral">"Bad segment-and-base specifier."</span>);
433             }
434
435             <span class="keywordflow">if</span> (base == <span class="stringliteral">"-"</span> || base == <span class="stringliteral">"NA"</span>) {
436                 base = <span class="stringliteral">"INVALID"</span>;
437             }
438             <span class="keywordflow">if</span> (ntokens &gt; 2) {
439                 index = upcase(vs[2]);
440                 <span class="keywordflow">if</span> (index == <span class="stringliteral">"-"</span> || index == <span class="stringliteral">"NA"</span>) {
441                     index = <span class="stringliteral">"INVALID"</span>;
442                 }
443             }
444
445             <span class="keywordflow">if</span> (ntokens &gt; 3) {
446                 scale = vs[3];
447                 <span class="keywordflow">if</span> (scale == <span class="stringliteral">"-"</span> || scale == <span class="stringliteral">"NA"</span>) {
448                     scale = <span class="stringliteral">"1"</span>;
449                 }
450             }
451             <span class="keywordflow">if</span> (scale == <span class="stringliteral">"1"</span> || scale == <span class="stringliteral">"2"</span> || scale == <span class="stringliteral">"4"</span> || scale == <span class="stringliteral">"8"</span>) {
452                 valid=<span class="keyword">true</span>;
453                 scale_val = <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(xed_uint8_t,strtol(scale.c_str(), 0, 10));
454                 segment_reg = <a class="code" href="xed-reg-enum_8h.html#48dc3d086b469ae580ca47917043c2fd">str2xed_reg_enum_t</a>(segment.c_str());
455                 base_reg = <a class="code" href="xed-reg-enum_8h.html#48dc3d086b469ae580ca47917043c2fd">str2xed_reg_enum_t</a>(base.c_str());
456                 index_reg = <a class="code" href="xed-reg-enum_8h.html#48dc3d086b469ae580ca47917043c2fd">str2xed_reg_enum_t</a>(index.c_str());
457
458                 <span class="comment">// look for a displacement</span>
459                 <span class="keywordflow">if</span> (ntokens == 5 &amp;&amp; vs[4] != <span class="stringliteral">"-"</span>) {
460                     disp = vs[4];
461                     disp_valid = <span class="keyword">true</span>;
462                     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nibbles = <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<span class="keywordtype">int</span>,disp.size());
463                     <span class="keywordflow">if</span> (nibbles &amp; 1) {
464                         <span class="comment">// ensure an even number of nibbles</span>
465                         string zero(<span class="stringliteral">"0"</span>);
466                         disp = zero + disp;
467                         nibbles++;
468                     }
469                     disp_val = convert_ascii_hex_to_int(disp.c_str());
470                     disp_width_bits = nibbles*4; <span class="comment">// nibbles to bits</span>
471                 }
472             }
473
474         }
475     
476     }
477 };
478
479 ostream&amp; operator&lt;&lt;(ostream&amp; o, <span class="keyword">const</span> mem_bis_parser_t&amp; x) {
480   x.print(o);
481   <span class="keywordflow">return</span> o;
482 }
483
484 <a class="code" href="group__ENC.html#g6f914541ddfa1ffe609acebff72d0b5f">xed_encoder_request_t</a> parse_encode_request(ascii_encode_request_t&amp; areq) {
485     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
486     <a class="code" href="group__ENC.html#g6f914541ddfa1ffe609acebff72d0b5f">xed_encoder_request_t</a> req;
487     <a class="code" href="group__ENC.html#g8a379853ad688ff61de9e73862617e40">xed_encoder_request_zero_set_mode</a>(&amp;req,&amp;(areq.dstate)); <span class="comment">// calls xed_encoder_request_zero()</span>
488
489     <span class="comment">/* This is the important function here. This encodes an instruction from scratch.</span>
490 <span class="comment">       </span>
491 <span class="comment">    You must set:</span>
492 <span class="comment">    the machine mode (machine width, addressing widths)</span>
493 <span class="comment">    the effective operand width</span>
494 <span class="comment">    the iclass</span>
495 <span class="comment">    for some instructions you need to specify prefixes (like REP or LOCK).</span>
496 <span class="comment">    the operands:</span>
497 <span class="comment">           operand kind (XED_OPERAND_{AGEN,MEM0,MEM1,IMM0,IMM1,RELBR,PTR,REG0...REG15}</span>
498 <span class="comment">           operand order </span>
499 <span class="comment">                    xed_encoder_request_set_operand_order(&amp;req,operand_index, XED_OPERAND_*);</span>
500 <span class="comment">                    where the operand_index is a sequential index starting at zero.</span>
501 <span class="comment"></span>
502 <span class="comment">           operand details </span>
503 <span class="comment">                     FOR MEMOPS: base,segment,index,scale,displacement for memops, </span>
504 <span class="comment">                  FOR REGISTERS: register name</span>
505 <span class="comment">                 FOR IMMEDIATES: immediate values</span>
506 <span class="comment">       </span>
507 <span class="comment">     */</span>
508     
509
510     <span class="keywordflow">switch</span>(<a class="code" href="group__INIT.html#g8b1fc00b95c50fd54959889d72dc569a">xed_state_get_machine_mode</a>(&amp;(areq.dstate))) {
511         <span class="comment">// set the default width.</span>
512       <span class="keywordflow">case</span> <a class="code" href="xed-machine-mode-enum_8h.html#754db9d73c5365644094cd161fe570a7708dc25876ca1910c387c0a4f2f066cb">XED_MACHINE_MODE_LONG_64</a>:
513         <a class="code" href="group__ENC.html#g53b937905ca110c4dd4b20e5695d8937">xed_encoder_request_set_effective_operand_width</a>(&amp;req, 32);
514         <a class="code" href="group__ENC.html#gb416edcadb0d2b59fb62cfcd93991c3d">xed_encoder_request_set_effective_address_size</a>(&amp;req, 64);
515         <span class="keywordflow">break</span>;
516
517       <span class="keywordflow">case</span> <a class="code" href="xed-machine-mode-enum_8h.html#754db9d73c5365644094cd161fe570a7a96a9d517621e28100e179eff7c92458">XED_MACHINE_MODE_LEGACY_32</a>:
518       <span class="keywordflow">case</span> <a class="code" href="xed-machine-mode-enum_8h.html#754db9d73c5365644094cd161fe570a71f0b512a8836f22da0b51bee9c656cd2">XED_MACHINE_MODE_LONG_COMPAT_32</a>:
519         <a class="code" href="group__ENC.html#g53b937905ca110c4dd4b20e5695d8937">xed_encoder_request_set_effective_operand_width</a>(&amp;req, 32);
520         <a class="code" href="group__ENC.html#gb416edcadb0d2b59fb62cfcd93991c3d">xed_encoder_request_set_effective_address_size</a>(&amp;req, 32);
521         <span class="keywordflow">break</span>;
522
523       <span class="keywordflow">case</span> <a class="code" href="xed-machine-mode-enum_8h.html#754db9d73c5365644094cd161fe570a7389547057da410225afe20064b3a4c0e">XED_MACHINE_MODE_LEGACY_16</a>:
524       <span class="keywordflow">case</span> <a class="code" href="xed-machine-mode-enum_8h.html#754db9d73c5365644094cd161fe570a74cfc0a828f9fce37f07d0764d49a0976">XED_MACHINE_MODE_LONG_COMPAT_16</a>:
525         <a class="code" href="group__ENC.html#g53b937905ca110c4dd4b20e5695d8937">xed_encoder_request_set_effective_operand_width</a>(&amp;req, 16);
526         <a class="code" href="group__ENC.html#gb416edcadb0d2b59fb62cfcd93991c3d">xed_encoder_request_set_effective_address_size</a>(&amp;req, 16);
527         <span class="keywordflow">break</span>;
528
529       <span class="keywordflow">default</span>:
530         assert(0);
531     }
532
533     <span class="comment">//FIXME: allow changing the effective address size from the above defaults.</span>
534
535     vector&lt;string&gt; tokens = tokenize(areq.command,<span class="stringliteral">" "</span>);
536     <span class="comment">// first token has the operand and our temporary hack for the immediate</span>
537
538     string first, second;
539     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> token_index = 0;
540
541     <span class="keywordflow">while</span>(token_index &lt; tokens.size()) {
542         slash_split(tokens[token_index], first, second);
543         <span class="keywordflow">if</span> (CLIENT_VERBOSE3)
544             printf( <span class="stringliteral">"[%s][%s][%s]\n"</span>, tokens[0].c_str(), first.c_str(), second.c_str());
545
546         <span class="keywordflow">if</span> (token_index == 0 &amp;&amp; first == <span class="stringliteral">"REP"</span>) {
547             <a class="code" href="group__ENC.html#g71d03e9d694f56fc362974f2d81e5464">xed_encoder_request_set_rep</a>(&amp;req);
548             token_index++;
549             <span class="keywordflow">continue</span>;
550         }
551         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (token_index == 0 &amp;&amp; first == <span class="stringliteral">"REPNE"</span>) {
552             <a class="code" href="group__ENC.html#gf651a483ec90cbf4495f87b114facc0b">xed_encoder_request_set_repne</a>(&amp;req);
553             token_index++;
554             <span class="keywordflow">continue</span>;
555         }
556   
557         token_index++;
558         <span class="keywordflow">break</span>;
559     }
560
561     <span class="comment">// we can attempt to override the mode </span>
562     <span class="keywordflow">if</span> (second == <span class="stringliteral">"8"</span>) 
563         <a class="code" href="group__ENC.html#g53b937905ca110c4dd4b20e5695d8937">xed_encoder_request_set_effective_operand_width</a>(&amp;req, 8);
564     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (second == <span class="stringliteral">"16"</span>) 
565         <a class="code" href="group__ENC.html#g53b937905ca110c4dd4b20e5695d8937">xed_encoder_request_set_effective_operand_width</a>(&amp;req, 16);
566     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (second == <span class="stringliteral">"32"</span>) 
567         <a class="code" href="group__ENC.html#g53b937905ca110c4dd4b20e5695d8937">xed_encoder_request_set_effective_operand_width</a>(&amp;req, 32);
568     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (second == <span class="stringliteral">"64"</span>) 
569         <a class="code" href="group__ENC.html#g53b937905ca110c4dd4b20e5695d8937">xed_encoder_request_set_effective_operand_width</a>(&amp;req, 64);
570
571     first = upcase(first);
572     <a class="code" href="xed-iclass-enum_8h.html#d318511ae9cc50f102251b3c91a1ab9f">xed_iclass_enum_t</a> iclass =  <a class="code" href="xed-iclass-enum_8h.html#c4b76adf6ede75bbc5754866187fcfa2">str2xed_iclass_enum_t</a>(first.c_str());
573     <span class="keywordflow">if</span> (iclass == <a class="code" href="xed-iclass-enum_8h.html#d318511ae9cc50f102251b3c91a1ab9f2c77d475f97998fe763062db09fd15de">XED_ICLASS_INVALID</a>) {
574         ostringstream os;
575         os &lt;&lt; <span class="stringliteral">"Bad instruction name: "</span> &lt;&lt; first;
576         xedex_derror(os.str().c_str());
577     }
578     <a class="code" href="group__ENC.html#gff030e16b97deae21b1f7613684c54c7">xed_encoder_request_set_iclass</a>(&amp;req, iclass );
579
580     <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> memop = 0;
581     <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> regnum = 0;
582     <span class="comment">// put the operands in the request. Loop through tokens </span>
583     <span class="comment">// (skip the opcode iclass, handled above)</span>
584     <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> operand_index = 0;
585     <span class="keywordflow">for</span>( i=token_index; i &lt; tokens.size(); i++, operand_index++ ) {
586         string str_res_reg, second_x;
587         slash_split(tokens[i], str_res_reg, second_x);
588         str_res_reg = upcase(str_res_reg);
589         <span class="comment">// prune the AGEN or MEM(base,index,scale[,displacement]) text from str_res_reg</span>
590         <span class="comment">// FIXME: add MEM(immed) for the OC1_A and OC1_O types????</span>
591         mem_bis_parser_t mem_bis(str_res_reg);
592         <span class="keywordflow">if</span> (mem_bis.valid) {
593             <span class="keywordflow">if</span> (mem_bis.mem) {
594                 <span class="keywordflow">if</span> (memop == 0) {
595                     <span class="comment">// Tell XED that we have a memory operand</span>
596                     <a class="code" href="group__ENC.html#g7b4e446882bcc615e917132f3fbb16b3">xed_encoder_request_set_mem0</a>(&amp;req);
597                     <span class="comment">// Tell XED that the mem0 operand is the next operand:</span>
598                     <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req,operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a17757f8f75fb149d6a9ceff628403994">XED_OPERAND_MEM0</a>);
599                 }
600                 <span class="keywordflow">else</span> {
601                     <a class="code" href="group__ENC.html#gfe70e5db7dc59e9880f2db3ec7e71d9d">xed_encoder_request_set_mem1</a>(&amp;req);
602                     <span class="comment">// Tell XED that the mem1 operand is the next operand:</span>
603                     <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req,operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011abe26987877ba7bfe6b67c7106fd77286">XED_OPERAND_MEM1</a>);
604                 }
605                 memop++;
606             }
607             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mem_bis.agen) {
608                 <span class="comment">// Tell XED we have an AGEN</span>
609                 <a class="code" href="group__ENC.html#gac846d407fd6537461a6efaccff7609d">xed_encoder_request_set_agen</a>(&amp;req);
610                 <span class="comment">// The AGEN is the next operand</span>
611                 <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req,operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a3ce839ecfbe4f991f6c46b7cb767a703">XED_OPERAND_AGEN</a>);
612             }
613             <span class="keywordflow">else</span> 
614                 assert(mem_bis.agen || mem_bis.mem);
615
616             <a class="code" href="xed-reg-class-enum_8h.html#8ac6bf3f9f78208385c46ea25324ea76">xed_reg_class_enum_t</a> rc = <a class="code" href="group__REGINTFC.html#g46208c55a69fb76e42f1b5755aa4923e">xed_gpr_reg_class</a>(mem_bis.base_reg);
617             <a class="code" href="xed-reg-class-enum_8h.html#8ac6bf3f9f78208385c46ea25324ea76">xed_reg_class_enum_t</a> rci = <a class="code" href="group__REGINTFC.html#g46208c55a69fb76e42f1b5755aa4923e">xed_gpr_reg_class</a>(mem_bis.index_reg);
618             <span class="keywordflow">if</span> (mem_bis.base_reg != <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a> &amp;&amp; mem_bis.index_reg != <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>) 
619                 <span class="keywordflow">if</span> (rc != rci) {
620                     ostringstream os;
621                     os &lt;&lt; <span class="stringliteral">"The base and index regs do not agree on the address size"</span> &lt;&lt; endl;
622                     xedex_derror(os.str().c_str()); <span class="comment">// dies</span>
623                 }
624             
625             <span class="keywordflow">if</span> (rc == <a class="code" href="xed-reg-class-enum_8h.html#8ac6bf3f9f78208385c46ea25324ea76aca8356f5ea67683de3d49fb3de4583f">XED_REG_CLASS_GPR32</a> || rci == <a class="code" href="xed-reg-class-enum_8h.html#8ac6bf3f9f78208385c46ea25324ea76aca8356f5ea67683de3d49fb3de4583f">XED_REG_CLASS_GPR32</a>) 
626                 <a class="code" href="group__ENC.html#gb416edcadb0d2b59fb62cfcd93991c3d">xed_encoder_request_set_effective_address_size</a>(&amp;req, 32);
627
628             <span class="comment">// fill in the memory fields</span>
629             <a class="code" href="group__ENC.html#g9002c58e013af93550df7bd9b37e13ed">xed_encoder_request_set_base0</a>(&amp;req, mem_bis.base_reg);
630             <a class="code" href="group__ENC.html#gd436ed3d253f15e11f4c943e0308db06">xed_encoder_request_set_index</a>(&amp;req, mem_bis.index_reg);
631             <a class="code" href="group__ENC.html#gca791f284c852c6ae4c071ba5751d257">xed_encoder_request_set_scale</a>(&amp;req, mem_bis.scale_val);
632             <a class="code" href="group__ENC.html#g72a43d42aa1c15bba69bcab84439471a">xed_encoder_request_set_seg0</a>(&amp;req, mem_bis.segment_reg);
633
634             <span class="keywordflow">if</span> (mem_bis.mem_len) 
635                 <a class="code" href="group__ENC.html#g03790a14a625c544edcbda559e359f14">xed_encoder_request_set_memory_operand_length</a>(&amp;req, mem_bis.mem_len ); <span class="comment">// BYTES</span>
636             <span class="keywordflow">if</span> (mem_bis.disp_valid)
637                 <a class="code" href="group__ENC.html#gf745dfb40af1361b8a9b9f1ecb4f0228">xed_encoder_request_set_memory_displacement</a>(&amp;req,
638                                                             mem_bis.disp_val,
639                                                             mem_bis.disp_width_bits/8);
640             <span class="keywordflow">continue</span>;
641         }
642
643         seg_parser_t seg_parser(str_res_reg);
644         <span class="keywordflow">if</span> (seg_parser.valid) {
645             printf(<span class="stringliteral">"Setting segment to %s\n"</span>, <a class="code" href="xed-reg-enum_8h.html#2219331ccd4d809d431e81fe5e857e95">xed_reg_enum_t2str</a>(seg_parser.segment_reg));
646             <a class="code" href="group__ENC.html#g72a43d42aa1c15bba69bcab84439471a">xed_encoder_request_set_seg0</a>(&amp;req, seg_parser.segment_reg);
647             <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req, operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a2c3c0c5a73438245c6d52fc0f1e4ea1d">XED_OPERAND_SEG0</a>);
648             <span class="keywordflow">continue</span>;
649         }
650
651         immed_parser_t imm(str_res_reg, <span class="stringliteral">"IMM"</span>);
652         <span class="keywordflow">if</span> (imm.valid) {
653             <span class="keywordflow">if</span> (CLIENT_VERBOSE3) 
654                 printf(<span class="stringliteral">"Setting immediate value to "</span> <a class="code" href="xed-portability_8h.html#99b93e37a937348afa3e458fb1e04fb1">XED_FMT_LX</a> <span class="stringliteral">"\n"</span>, imm.immed_val);
655             <a class="code" href="group__ENC.html#g5dcaec413dfefdd6ca2ad179e5a181c9">xed_encoder_request_set_uimm0_bits</a>(&amp;req, 
656                                                imm.immed_val,
657                                                imm.width_bits);
658             <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req,operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a7cfee5454147cd3ea586172facd26f30">XED_OPERAND_IMM0</a>);
659             <span class="keywordflow">continue</span>;
660         }
661         immed_parser_t simm(str_res_reg, <span class="stringliteral">"SIMM"</span>);
662         <span class="keywordflow">if</span> (simm.valid) {
663             <span class="keywordflow">if</span> (CLIENT_VERBOSE3) 
664                 printf(<span class="stringliteral">"Setting immediate value to "</span> <a class="code" href="xed-portability_8h.html#99b93e37a937348afa3e458fb1e04fb1">XED_FMT_LX</a> <span class="stringliteral">"\n"</span>, simm.immed_val);
665             <a class="code" href="group__ENC.html#gf2477dc50a13ec112d7cf3f3fa5c9178">xed_encoder_request_set_simm</a>(&amp;req, 
666                                          <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(xed_int32_t,simm.immed_val),
667                                          simm.width_bits/8); <span class="comment">//FIXME</span>
668             <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req,operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a7cfee5454147cd3ea586172facd26f30">XED_OPERAND_IMM0</a>);
669             <span class="keywordflow">continue</span>;
670         }
671         immed_parser_t imm2(str_res_reg, <span class="stringliteral">"IMM2"</span>);
672         <span class="keywordflow">if</span> (imm2.valid) {
673             <span class="keywordflow">if</span> (imm2.width_bits != 8)
674                 xedex_derror(<span class="stringliteral">"2nd immediate must be just 1 byte long"</span>);
675             <a class="code" href="group__ENC.html#g4edd1347ebaceee3811584123b4daa9b">xed_encoder_request_set_uimm1</a>(&amp;req, imm2.immed_val);
676             <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req,operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011aecf4b40f8ec183182501a80b93b5b4dc">XED_OPERAND_IMM1</a>);
677             <span class="keywordflow">continue</span>;
678         }
679
680         immed_parser_t disp(str_res_reg, <span class="stringliteral">"BRDISP"</span>);
681         <span class="keywordflow">if</span> (disp.valid) {
682             <span class="keywordflow">if</span> (CLIENT_VERBOSE3) 
683                 printf(<span class="stringliteral">"Setting  displacement value to "</span> <a class="code" href="xed-portability_8h.html#99b93e37a937348afa3e458fb1e04fb1">XED_FMT_LX</a> <span class="stringliteral">"\n"</span>, disp.immed_val);
684             <a class="code" href="group__ENC.html#g3594acbdb2001a816da28b7554b2ae4c">xed_encoder_request_set_branch_displacement</a>(&amp;req,
685                                                         <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(xed_uint32_t,disp.immed_val),
686                                                         disp.width_bits/8); <span class="comment">//FIXME</span>
687             <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req,operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a6f36302cd147e020b2662b75fa314c17">XED_OPERAND_RELBR</a>);
688             <a class="code" href="group__ENC.html#gd447fb779e58b7eaae0dd54e51af6066">xed_encoder_request_set_relbr</a>(&amp;req);
689             <span class="keywordflow">continue</span>;
690         }
691
692         immed_parser_t ptr_disp(str_res_reg, <span class="stringliteral">"PTR"</span>);
693         <span class="keywordflow">if</span> (ptr_disp.valid) {
694             <span class="keywordflow">if</span> (CLIENT_VERBOSE3) 
695                 printf(<span class="stringliteral">"Setting pointer displacement value to "</span> <a class="code" href="xed-portability_8h.html#99b93e37a937348afa3e458fb1e04fb1">XED_FMT_LX</a> <span class="stringliteral">"\n"</span>, ptr_disp.immed_val);
696             <a class="code" href="group__ENC.html#g3594acbdb2001a816da28b7554b2ae4c">xed_encoder_request_set_branch_displacement</a>(&amp;req,
697                                                         <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(xed_uint32_t,ptr_disp.immed_val),
698                                                         ptr_disp.width_bits/8); <span class="comment">//FIXME</span>
699             <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req,operand_index, <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011af84141b5908fd0d494f446a66f3eeef3">XED_OPERAND_PTR</a>);
700             <a class="code" href="group__ENC.html#g7be1c7da28a5d88f485f7e80b67959b4">xed_encoder_request_set_ptr</a>(&amp;req);
701             <span class="keywordflow">continue</span>;
702         }
703
704         <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> reg = <a class="code" href="xed-reg-enum_8h.html#48dc3d086b469ae580ca47917043c2fd">str2xed_reg_enum_t</a>(str_res_reg.c_str());
705         <span class="keywordflow">if</span> (reg == <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>) {
706             ostringstream os;
707             os &lt;&lt; <span class="stringliteral">"Bad register name: "</span> &lt;&lt; str_res_reg &lt;&lt; <span class="stringliteral">" on operand "</span> &lt;&lt; i;
708             xedex_derror(os.str().c_str()); <span class="comment">// dies</span>
709         }
710         <span class="comment">// The registers operands aer numbered starting from the first one</span>
711         <span class="comment">// as XED_OPERAND_REG0. We incremenet regnum (below) every time we add a</span>
712         <span class="comment">// register operands.</span>
713         <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a">xed_operand_enum_t</a> r = <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a">xed_operand_enum_t</a>,<a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a4a8a5c45ea6041f25d7b98e3892bb389">XED_OPERAND_REG0</a> + regnum);
714         <span class="comment">// store the register identifer in the operand storage field</span>
715         <a class="code" href="group__ENC.html#gba22ae36cab0f632d5461830cc9a3133">xed_encoder_request_set_reg</a>(&amp;req, r, reg);
716         <span class="comment">// store the operand storage field name in the encode-order array</span>
717         <a class="code" href="group__ENC.html#g1e46ce602263f0de591b3ebc268cc12e">xed_encoder_request_set_operand_order</a>(&amp;req, operand_index, r);
718         regnum++;
719     } <span class="comment">// for loop</span>
720
721     <span class="keywordflow">return</span> req;
722 }
723 </pre></div> 
724 <p>
725 <table border="0" cellpadding="0" cellspacing="0">
726 <tr><td></td></tr>
727 </table>
728 <hr size="1"><address style="align: right;"><small>Generated on Thu May 15 03:15:09 2008 for XED2 by&nbsp;
729 <a href="http://www.doxygen.org/index.html">
730 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>
731 </body>
732 </html>