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">
7 <!-- Generated by Doxygen 1.4.6 -->
10 <li><a href="main.html"><span>Main Page</span></a></li>
11 <li><a href="modules.html"><span>Modules</span></a></li>
12 <li><a href="classes.html"><span>Data Structures</span></a></li>
13 <li><a href="files.html"><span>Files</span></a></li>
15 <form action="search.php" method="get">
16 <table cellspacing="0" cellpadding="0" border="0">
18 <td><label> <u>S</u>earch for </label></td>
19 <td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
25 <h1>Small Examples of using XED</h1>Here is a minimal example of using XED from the file examples/xed-min.cpp.<p>
26 <div class="fragment"><pre class="fragment"><span class="comment">/*BEGIN_LEGAL </span>
27 <span class="comment">Copyright (c) 2007, Intel Corp.</span>
28 <span class="comment">All rights reserved.</span>
29 <span class="comment"></span>
30 <span class="comment">Redistribution and use in source and binary forms, with or without</span>
31 <span class="comment">modification, are permitted provided that the following conditions are</span>
32 <span class="comment">met:</span>
33 <span class="comment"></span>
34 <span class="comment"> * Redistributions of source code must retain the above copyright</span>
35 <span class="comment"> notice, this list of conditions and the following disclaimer.</span>
36 <span class="comment"></span>
37 <span class="comment"> * Redistributions in binary form must reproduce the above</span>
38 <span class="comment"> copyright notice, this list of conditions and the following</span>
39 <span class="comment"> disclaimer in the documentation and/or other materials provided</span>
40 <span class="comment"> with the distribution.</span>
41 <span class="comment"></span>
42 <span class="comment"> * Neither the name of Intel Corporation nor the names of its</span>
43 <span class="comment"> contributors may be used to endorse or promote products derived</span>
44 <span class="comment"> from this software without specific prior written permission.</span>
45 <span class="comment"></span>
46 <span class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
47 <span class="comment">"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
48 <span class="comment">LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
49 <span class="comment">A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
50 <span class="comment">OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
51 <span class="comment">SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
52 <span class="comment">LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
53 <span class="comment">DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
54 <span class="comment">THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
55 <span class="comment">(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
56 <span class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
57 <span class="comment">END_LEGAL */</span>
59 <span class="keyword">extern</span> <span class="stringliteral">"C"</span> {
60 <span class="preprocessor">#include "<a class="code" href="xed-interface_8h.html">xed-interface.h</a>"</span>
62 <span class="preprocessor">#include <iostream></span>
63 <span class="preprocessor">#include <iomanip></span>
64 <span class="keyword">using namespace </span>std;
66 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv);
68 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv) {
69 <span class="comment">// initialize the XED tables -- one time.</span>
70 <a class="code" href="group__INIT.html#g26aa0242b953b5fd0d14b1fa19442627">xed_tables_init</a>();
72 <span class="comment">// The state of the machine -- required for decoding</span>
73 <a class="code" href="group__INIT.html#g58af142456a133c3df29c763216a85cf">xed_state_t</a> dstate;
74 <a class="code" href="group__INIT.html#g8eea80ff7aa0fc77c3c3e90ce3e1fd64">xed_state_zero</a>(&dstate);
75 <a class="code" href="group__INIT.html#g2363cf0a5b4628b09c0dfd1641119714">xed_state_init</a>(&dstate,
76 <a class="code" href="xed-machine-mode-enum_8h.html#754db9d73c5365644094cd161fe570a7a96a9d517621e28100e179eff7c92458">XED_MACHINE_MODE_LEGACY_32</a>,
77 <a class="code" href="xed-address-width-enum_8h.html#2fe76cf1d3e62a77190798dc87c0a8651d4c2a3aeffa1872b2f24730e4c83d02">XED_ADDRESS_WIDTH_32b</a>,
78 <a class="code" href="xed-address-width-enum_8h.html#2fe76cf1d3e62a77190798dc87c0a8651d4c2a3aeffa1872b2f24730e4c83d02">XED_ADDRESS_WIDTH_32b</a>);
80 <span class="comment">// create the decoded instruction, and fill in the machine mode (dstate)</span>
81 <a class="code" href="group__DEC.html#ga704925b5f80885a0ac56640a7c70937">xed_decoded_inst_t</a> xedd;
82 <a class="code" href="group__DEC.html#ge32686224b685dfc7be3f13504e0a0df">xed_decoded_inst_zero_set_mode</a>(&xedd, &dstate);
84 <span class="comment">// make up a simple 2Byte instruction to decode</span>
85 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bytes = 2;
86 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> itext[15] = { 0, 0};
88 <span class="comment">// call decode</span>
89 <a class="code" href="xed-error-enum_8h.html#2611877aa5e8b566c1c2be45aa89c792">xed_error_enum_t</a> xed_error = <a class="code" href="group__DEC.html#g9a27c2bb97caf98a6024567b261d0652">xed_decode</a>(&xedd,
90 <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(<span class="keyword">const</span> xed_uint8_t*,itext),
93 <span class="comment">// check for errors</span>
94 <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> okay = (xed_error == <a class="code" href="xed-error-enum_8h.html#2611877aa5e8b566c1c2be45aa89c792d9f5736eacb4d9dedd9aadf1d75b9de6">XED_ERROR_NONE</a>);
95 <span class="keywordflow">if</span> (okay) {
96 cout << <span class="stringliteral">"OK"</span> << endl;
97 <span class="keywordflow">return</span> 0;
99 <span class="keywordflow">return</span> 1;
100 (void) argc; (void) argv; <span class="comment">//pacify compiler</span>
103 There is a makefile in the examples directory. Here's how to compile it from a kit: <div class="fragment"><pre class="fragment">% g++ -Ipath-to-xed2-kit/include -Ipath-to-xed2-kit/examples -c path-to-xed2-kit/examples/xed-min.cpp
104 % g++ -o xed-min xed-min.o path-to-xed2-kit/lib/libxed.a
105 </pre></div> where path-to-xed2-kit is where you have your include, examples and lib directories from an installed XED2 kit.<p>
106 Here is a more detailed example (examples/xed-ex1.cpp) that walks the operands much like the printing routines do for the <a class="el" href="group__DEC.html#ga704925b5f80885a0ac56640a7c70937">xed_decoded_inst_t</a> .<p>
107 <div class="fragment"><pre class="fragment"><span class="comment">/*BEGIN_LEGAL </span>
108 <span class="comment">Copyright (c) 2007, Intel Corp.</span>
109 <span class="comment">All rights reserved.</span>
110 <span class="comment"></span>
111 <span class="comment">Redistribution and use in source and binary forms, with or without</span>
112 <span class="comment">modification, are permitted provided that the following conditions are</span>
113 <span class="comment">met:</span>
114 <span class="comment"></span>
115 <span class="comment"> * Redistributions of source code must retain the above copyright</span>
116 <span class="comment"> notice, this list of conditions and the following disclaimer.</span>
117 <span class="comment"></span>
118 <span class="comment"> * Redistributions in binary form must reproduce the above</span>
119 <span class="comment"> copyright notice, this list of conditions and the following</span>
120 <span class="comment"> disclaimer in the documentation and/or other materials provided</span>
121 <span class="comment"> with the distribution.</span>
122 <span class="comment"></span>
123 <span class="comment"> * Neither the name of Intel Corporation nor the names of its</span>
124 <span class="comment"> contributors may be used to endorse or promote products derived</span>
125 <span class="comment"> from this software without specific prior written permission.</span>
126 <span class="comment"></span>
127 <span class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
128 <span class="comment">"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
129 <span class="comment">LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
130 <span class="comment">A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
131 <span class="comment">OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
132 <span class="comment">SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
133 <span class="comment">LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
134 <span class="comment">DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
135 <span class="comment">THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
136 <span class="comment">(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
137 <span class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
138 <span class="comment">END_LEGAL */</span>
140 <span class="keyword">extern</span> <span class="stringliteral">"C"</span> {
141 <span class="preprocessor">#include "<a class="code" href="xed-interface_8h.html">xed-interface.h</a>"</span>
143 <span class="preprocessor">#include "xed-examples-ostreams.H"</span>
144 <span class="preprocessor">#include <iostream></span>
145 <span class="preprocessor">#include <iomanip></span>
146 <span class="preprocessor">#include <sstream></span>
147 <span class="preprocessor">#include <cassert></span>
148 <span class="keyword">using namespace </span>std;
150 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv);
152 <span class="keywordtype">void</span> print_attributes(<a class="code" href="group__DEC.html#ga704925b5f80885a0ac56640a7c70937">xed_decoded_inst_t</a>* xedd) {
153 <span class="keyword">const</span> <a class="code" href="group__DEC.html#g2b28c31e1e83e74ef5f613b38e0cc0ec">xed_inst_t</a>* xi = <a class="code" href="group__DEC.html#ge507752abfa509bd72ee0903e873fe9e">xed_decoded_inst_inst</a>(xedd);
154 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i, nattributes = <a class="code" href="group__DEC.html#g1dee8af51e3d8ed5a6c5dac13780be9e">xed_attribute_max</a>();
155 xed_uint32_t all_attributes = <a class="code" href="group__DEC.html#gfa48c095dbf6e00636253f974b2093d1">xed_inst_get_attributes</a>(xi);
156 <span class="keywordflow">if</span> (all_attributes == 0)
157 <span class="keywordflow">return</span>;
158 cout << <span class="stringliteral">"ATTRIBUTES: "</span>;
159 <span class="keywordflow">for</span>(i=0;i<nattributes;i++) {
160 <a class="code" href="xed-attribute-enum_8h.html#848d4cf396be5a647413e94bc6f0a383">xed_attribute_enum_t</a> attr = <a class="code" href="group__DEC.html#g38f0b100d724d97d80a8291a494dde06">xed_attribute</a>(i);
161 <span class="keywordflow">if</span> (<a class="code" href="group__DEC.html#gdae8e18eaeb265c2aab6fc82a216e5de">xed_inst_get_attribute</a>(xi,attr))
162 cout << <a class="code" href="xed-attribute-enum_8h.html#46e1e07daead7a33e8704bc684fe795c">xed_attribute_enum_t2str</a>(attr) << <span class="stringliteral">" "</span>;
167 <span class="keywordtype">void</span> print_flags(<a class="code" href="group__DEC.html#ga704925b5f80885a0ac56640a7c70937">xed_decoded_inst_t</a>* xedd) {
168 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i, nflags;
169 <span class="keywordflow">if</span> (<a class="code" href="group__DEC.html#g6922f0d03774f1d9ec1d402fb70e5c63">xed_decoded_inst_uses_rflags</a>(xedd)) {
170 cout << <span class="stringliteral">"FLAGS:"</span> << endl;
171 <span class="keyword">const</span> <a class="code" href="group__FLAGS.html#g7a0efe6ee18616a7d37af47d4e3cae10">xed_simple_flag_t</a>* rfi = <a class="code" href="group__DEC.html#g275353ead71e5915f810ef06c4149b68">xed_decoded_inst_get_rflags_info</a>(xedd);
172 <span class="keywordflow">if</span> (<a class="code" href="group__FLAGS.html#g9aca7e505fe7962aa715528f32b18784">xed_simple_flag_reads_flags</a>(rfi)) {
173 cout << <span class="stringliteral">" reads-rflags "</span>;
175 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="group__FLAGS.html#g6bf79b1d9e94986b06db3977172ceeff">xed_simple_flag_writes_flags</a>(rfi)) {
176 <span class="comment">//XED provides may-write and must-write information</span>
177 <span class="keywordflow">if</span> (<a class="code" href="group__FLAGS.html#g7ef6569c3ed439bc8987307492a59281">xed_simple_flag_get_may_write</a>(rfi)) {
178 cout << <span class="stringliteral">" may-write-rflags "</span>;
180 <span class="keywordflow">if</span> (<a class="code" href="group__FLAGS.html#gb8e5992bf7dc342a056c4f57c80c01ed">xed_simple_flag_get_must_write</a>(rfi)) {
181 cout << <span class="stringliteral">" must-write-rflags "</span>;
184 nflags = <a class="code" href="group__FLAGS.html#g786dd6f5adb1f8d6aa47f53c1531473c">xed_simple_flag_get_nflags</a>(rfi);
185 <span class="keywordflow">for</span>( i=0;i<nflags ;i++) {
186 <span class="keyword">const</span> <a class="code" href="group__FLAGS.html#g9a54b90e10974a59ee94c57d364254d2">xed_flag_action_t</a>* fa = <a class="code" href="group__FLAGS.html#g1db7706b1121de4f70e82fc85e3988c1">xed_simple_flag_get_flag_action</a>(rfi,i);
187 <span class="keywordtype">char</span> buf[500];
188 <a class="code" href="group__FLAGS.html#gabc09792128a39245636f4b0aab77f42">xed_flag_action_print</a>(fa,buf,500);
189 cout << buf << <span class="stringliteral">" "</span>;
192 <span class="comment">// or as as bit-union</span>
193 <span class="keyword">const</span> <a class="code" href="unionxed__flag__set__s.html">xed_flag_set_t</a>* read_set = <a class="code" href="group__FLAGS.html#g0ae38bd952ce6da5eac4dac97c943caa">xed_simple_flag_get_read_flag_set</a>(rfi);
194 <span class="keyword">const</span> <a class="code" href="unionxed__flag__set__s.html">xed_flag_set_t</a>* written_set = <a class="code" href="group__FLAGS.html#gfd8226ec18ea804e5abbe9e6fef0c526">xed_simple_flag_get_written_flag_set</a>(rfi);
195 <span class="keywordtype">char</span> buf[500];
196 <a class="code" href="group__FLAGS.html#g7f7a68d1f3d02a08b60205a96e025bb2">xed_flag_set_print</a>(read_set,buf,500);
197 cout << <span class="stringliteral">" read: "</span> << buf << endl;
198 <a class="code" href="group__FLAGS.html#g7f7a68d1f3d02a08b60205a96e025bb2">xed_flag_set_print</a>(written_set,buf,500);
199 cout << <span class="stringliteral">" written: "</span> << buf << endl;
203 <span class="keywordtype">void</span> print_memops(<a class="code" href="group__DEC.html#ga704925b5f80885a0ac56640a7c70937">xed_decoded_inst_t</a>* xedd) {
204 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i, memops = <a class="code" href="group__DEC.html#gc093ecf9904ce025bafa8e7318ded0ec">xed_decoded_inst_number_of_memory_operands</a>(xedd);
205 cout << <span class="stringliteral">"Memory Operands"</span> << endl;
207 <span class="keywordflow">for</span>( i=0;i<memops ; i++) {
208 <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> r_or_w = <span class="keyword">false</span>;
209 cout << <span class="stringliteral">" "</span> << i << <span class="stringliteral">" "</span>;
210 <span class="keywordflow">if</span> ( <a class="code" href="group__DEC.html#g1d1b81a6e49ae396bdad946439794b5f">xed_decoded_inst_mem_read</a>(xedd,i)) {
211 cout << <span class="stringliteral">"read "</span>;
212 r_or_w = <span class="keyword">true</span>;
214 <span class="keywordflow">if</span> (<a class="code" href="group__DEC.html#geda7bba6faea14f777752fbab269d425">xed_decoded_inst_mem_written</a>(xedd,i)) {
215 cout << <span class="stringliteral">"written "</span>;
216 r_or_w = <span class="keyword">true</span>;
218 <span class="keywordflow">if</span> (!r_or_w) {
219 cout << <span class="stringliteral">"agen "</span>; <span class="comment">// LEA instructions</span>
221 <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> seg = <a class="code" href="group__DEC.html#g1451e49df729a4fe1e650db6cb3343d2">xed_decoded_inst_get_seg_reg</a>(xedd,i);
222 <span class="keywordflow">if</span> (seg != <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>) {
223 cout << <span class="stringliteral">"SEG= "</span> << <a class="code" href="xed-reg-enum_8h.html#2219331ccd4d809d431e81fe5e857e95">xed_reg_enum_t2str</a>(seg) << <span class="stringliteral">" "</span>;
225 <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> base = <a class="code" href="group__DEC.html#gef27a2e2c7c6cb84d8e6ba239267172a">xed_decoded_inst_get_base_reg</a>(xedd,i);
226 <span class="keywordflow">if</span> (base != <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>) {
227 cout << <span class="stringliteral">"BASE= "</span> << <a class="code" href="xed-reg-enum_8h.html#2219331ccd4d809d431e81fe5e857e95">xed_reg_enum_t2str</a>(base) << <span class="stringliteral">"/"</span>
228 << <a class="code" href="xed-reg-class-enum_8h.html#316b262608066a946aaa86cde7b1debb">xed_reg_class_enum_t2str</a>(<a class="code" href="group__REGINTFC.html#g9003309edac48c9c1dfca2187497c613">xed_reg_class</a>(base)) << <span class="stringliteral">" "</span>;
230 <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> indx = <a class="code" href="group__DEC.html#gd39ecfe4d1c3d95161f291e4d9a18280">xed_decoded_inst_get_index_reg</a>(xedd,i);
231 <span class="keywordflow">if</span> (i == 0 && indx != <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61fac474058f0819d415285511086bf219">XED_REG_INVALID</a>) {
232 cout << <span class="stringliteral">"INDEX= "</span> << <a class="code" href="xed-reg-enum_8h.html#2219331ccd4d809d431e81fe5e857e95">xed_reg_enum_t2str</a>(indx)
233 << <span class="stringliteral">"/"</span> << <a class="code" href="xed-reg-class-enum_8h.html#316b262608066a946aaa86cde7b1debb">xed_reg_class_enum_t2str</a>(<a class="code" href="group__REGINTFC.html#g9003309edac48c9c1dfca2187497c613">xed_reg_class</a>(indx)) << <span class="stringliteral">" "</span>;
234 <span class="keywordflow">if</span> (<a class="code" href="group__DEC.html#g77a570e03d56cd31e50f4bc54104b0f9">xed_decoded_inst_get_scale</a>(xedd,i) != 0) {
235 <span class="comment">// only have a scale if the index exists.</span>
236 cout << <span class="stringliteral">"SCALE= "</span> << <a class="code" href="group__DEC.html#g77a570e03d56cd31e50f4bc54104b0f9">xed_decoded_inst_get_scale</a>(xedd,i) << <span class="stringliteral">" "</span>;
239 <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> disp_bits = <a class="code" href="group__DEC.html#g275efe423fe90a10a674da18f3265bd4">xed_decoded_inst_get_memory_displacement_width</a>(xedd,i);
240 <span class="keywordflow">if</span> (disp_bits) {
241 cout << <span class="stringliteral">"DISPLACEMENT_BYTES= "</span> << disp_bits << <span class="stringliteral">" "</span>;
242 xed_int64_t disp = <a class="code" href="group__DEC.html#ga8d22454961035b0fa6121c5f419817d">xed_decoded_inst_get_memory_displacement</a>(xedd,i);
243 cout << hex << setfill(<span class="charliteral">'0'</span>) << setw(16) << disp << setfill(<span class="charliteral">' '</span>) << dec;
247 cout << <span class="stringliteral">" MemopBytes = "</span> << <a class="code" href="group__DEC.html#gecce1ea119eb21d3569ee0058d5ce084">xed_decoded_inst_get_memory_operand_length</a>(xedd,0) << endl;
250 <span class="keywordtype">void</span> print_operands(<a class="code" href="group__DEC.html#ga704925b5f80885a0ac56640a7c70937">xed_decoded_inst_t</a>* xedd) {
251 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i, noperands;
252 cout << <span class="stringliteral">"Operands"</span> << endl;
253 <span class="keyword">const</span> <a class="code" href="group__DEC.html#g2b28c31e1e83e74ef5f613b38e0cc0ec">xed_inst_t</a>* xi = <a class="code" href="group__DEC.html#ge507752abfa509bd72ee0903e873fe9e">xed_decoded_inst_inst</a>(xedd);
254 noperands = <a class="code" href="group__DEC.html#g5808f0c3992221777a51c9356bbfc1cf">xed_inst_noperands</a>(xi);
255 <span class="keywordflow">for</span>( i=0; i < noperands ; i++) {
256 <span class="keyword">const</span> <a class="code" href="group__DEC.html#g6e11e56c314f3035be79171df2f6938f">xed_operand_t</a>* op = <a class="code" href="group__DEC.html#g05c6c3704a2be54cdced61f99437c146">xed_inst_operand</a>(xi,i);
257 <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a">xed_operand_enum_t</a> op_name = <a class="code" href="group__DEC.html#g57209697b0dfb3e9ed4f694ca7cc16a4">xed_operand_name</a>(op);
258 cout << i << <span class="stringliteral">" "</span> << <a class="code" href="xed-operand-enum_8h.html#2e1b95b3b4b059703a3be3780a990ade">xed_operand_enum_t2str</a>(op_name) << <span class="stringliteral">" "</span>;
259 <span class="keywordflow">switch</span>(op_name) {
260 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a3ce839ecfbe4f991f6c46b7cb767a703">XED_OPERAND_AGEN</a>:
261 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a17757f8f75fb149d6a9ceff628403994">XED_OPERAND_MEM0</a>:
262 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011abe26987877ba7bfe6b67c7106fd77286">XED_OPERAND_MEM1</a>:
263 <span class="comment">// we print memops in a different function</span>
264 <span class="keywordflow">break</span>;
265 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011af84141b5908fd0d494f446a66f3eeef3">XED_OPERAND_PTR</a>: <span class="comment">// pointer (always in conjunction with a IMM0)</span>
266 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a6f36302cd147e020b2662b75fa314c17">XED_OPERAND_RELBR</a>: { <span class="comment">// branch displacements</span>
267 <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> disp_bits = <a class="code" href="group__DEC.html#g6ce6a33dea91f1cb846c78cf2848be58">xed_decoded_inst_get_branch_displacement_width</a>(xedd);
268 <span class="keywordflow">if</span> (disp_bits) {
269 cout << <span class="stringliteral">"BRANCH_DISPLACEMENT_BYTES= "</span> << disp_bits << <span class="stringliteral">" "</span>;
270 xed_int32_t disp = <a class="code" href="group__DEC.html#gada9b13de03dfeefff70f2d219504aae">xed_decoded_inst_get_branch_displacement</a>(xedd);
271 cout << hex << setfill(<span class="charliteral">'0'</span>) << setw(8) << disp << setfill(<span class="charliteral">' '</span>) << dec;
274 <span class="keywordflow">break</span>;
276 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a7cfee5454147cd3ea586172facd26f30">XED_OPERAND_IMM0</a>: { <span class="comment">// immediates</span>
277 <a class="code" href="xed-types_8h.html#0c92e8263b7ca02d8e4826ae5b79bb30">xed_uint_t</a> width = <a class="code" href="group__DEC.html#g91e972de2b4dfd4edac004d2cdf2768c">xed_decoded_inst_get_immediate_width</a>(xedd);
278 <span class="keywordflow">if</span> (<a class="code" href="group__DEC.html#g7c752cb527745114566367dfa0bb176c">xed_decoded_inst_get_immediate_is_signed</a>(xedd)) {
279 xed_int32_t x =<a class="code" href="group__DEC.html#gbbc8dec2bddec619bfe8f9a39c7ffdf4">xed_decoded_inst_get_signed_immediate</a>(xedd);
280 cout << hex << setfill(<span class="charliteral">'0'</span>) << setw(8) << x << setfill(<span class="charliteral">' '</span>) << dec
281 << <span class="charliteral">'('</span> << width << <span class="charliteral">')'</span>;
283 <span class="keywordflow">else</span> {
284 xed_uint64_t x = <a class="code" href="group__DEC.html#g79461981ed1722ab09a094915fb72428">xed_decoded_inst_get_unsigned_immediate</a>(xedd);
285 cout << hex << setfill(<span class="charliteral">'0'</span>) << setw(16) << x << setfill(<span class="charliteral">' '</span>) << dec
286 << <span class="charliteral">'('</span> << width << <span class="charliteral">')'</span>;
288 <span class="keywordflow">break</span>;
290 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011aecf4b40f8ec183182501a80b93b5b4dc">XED_OPERAND_IMM1</a>: { <span class="comment">// immediates</span>
291 xed_uint8_t x = <a class="code" href="group__DEC.html#gd1d32b618885f9d22aa75101664497e4">xed_decoded_inst_get_second_immediate</a>(xedd);
292 cout << hex << setfill(<span class="charliteral">'0'</span>) << setw(2) << (int)x << setfill(<span class="charliteral">' '</span>) << dec;
293 <span class="keywordflow">break</span>;
296 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a4a8a5c45ea6041f25d7b98e3892bb389">XED_OPERAND_REG0</a>:
297 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011af28c17e44b1cec75cbc35eaf230002cb">XED_OPERAND_REG1</a>:
298 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011abbe83849a642b40143efdeea44fa0497">XED_OPERAND_REG2</a>:
299 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011ad0c2b5884293abd53b930c1793382db1">XED_OPERAND_REG3</a>:
300 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a41eccb1a0eed942d3c1ce94d4932e6a7">XED_OPERAND_REG4</a>:
301 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a7deb7d4548980dee2208d9d5fde56fb6">XED_OPERAND_REG5</a>:
302 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011aacd4abc0766200998483d7d87ff12928">XED_OPERAND_REG6</a>:
303 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011abeb51b32bc8f34c0656208db36b05396">XED_OPERAND_REG7</a>:
304 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011abff9f6414b9de3a43c845721de9f97f4">XED_OPERAND_REG8</a>:
305 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011acd2ee03d98deab4a0fdf2a908a7f5114">XED_OPERAND_REG9</a>:
306 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a0f17743f40d66545cd14bdb17bb74497">XED_OPERAND_REG10</a>:
307 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011abcbb7154d3db34753a5e3de4b383d390">XED_OPERAND_REG11</a>:
308 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a34fec04200b37f89b8fcd0c45f67019c">XED_OPERAND_REG12</a>:
309 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011a897fd5ea6caef885e2691ade6686bf63">XED_OPERAND_REG13</a>:
310 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011abe80e57c468c838db74b56af55cbd8a6">XED_OPERAND_REG14</a>:
311 <span class="keywordflow">case</span> <a class="code" href="xed-operand-enum_8h.html#09c2a35d8bb7bfe68bb3d34b0a5e011af123139f3655bdbec0d3898aec5acc0f">XED_OPERAND_REG15</a>: {
312 <a class="code" href="xed-reg-enum_8h.html#f05c33c5a68e9304d1d8ac0408ae3f61">xed_reg_enum_t</a> r = <a class="code" href="group__DEC.html#g5635f3a3d121bbcbb64d548dbb32e4c5">xed_decoded_inst_get_reg</a>(xedd, op_name);
313 cout << <a class="code" href="xed-operand-enum_8h.html#2e1b95b3b4b059703a3be3780a990ade">xed_operand_enum_t2str</a>(op_name) << <span class="stringliteral">"="</span> << <a class="code" href="xed-reg-enum_8h.html#2219331ccd4d809d431e81fe5e857e95">xed_reg_enum_t2str</a>(r);
314 <span class="keywordflow">break</span>;
316 <span class="keywordflow">default</span>:
317 cout << <span class="stringliteral">"[Not currently printing value of field "</span> << <a class="code" href="xed-operand-enum_8h.html#2e1b95b3b4b059703a3be3780a990ade">xed_operand_enum_t2str</a>(op_name) << <span class="charliteral">']'</span>;
318 <span class="keywordflow">break</span>;
321 cout << <span class="stringliteral">" "</span> << <a class="code" href="xed-operand-visibility-enum_8h.html#1599399c8155e07c2eb230bb6875aa8a">xed_operand_visibility_enum_t2str</a>(<a class="code" href="group__DEC.html#g2e8b5df9fc68c6aa7fbeb98735e1d4a9">xed_operand_operand_visibility</a>(op))
322 << <span class="stringliteral">" / "</span> << <a class="code" href="xed-operand-action-enum_8h.html#c4a01bed223e067779f08893924836dc">xed_operand_action_enum_t2str</a>(<a class="code" href="group__DEC.html#ge5299214951891952401b5061e48a6ca">xed_operand_rw</a>(op))
323 << <span class="stringliteral">" / "</span> << <a class="code" href="xed-operand-width-enum_8h.html#0b6efac075c3dda631990ba013a5bbfb">xed_operand_width_enum_t2str</a>(<a class="code" href="group__DEC.html#g1159569c734bf712a40a2a88542d549d">xed_operand_width</a>(op));
324 cout << <span class="stringliteral">" bytes="</span> << <a class="code" href="group__DEC.html#ga030199ba499d2bcb67cbf7740d8d4c6">xed_decoded_inst_operand_length</a>(xedd,i);
329 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv) {
330 <a class="code" href="group__INIT.html#g58af142456a133c3df29c763216a85cf">xed_state_t</a> dstate;
331 <a class="code" href="group__DEC.html#ga704925b5f80885a0ac56640a7c70937">xed_decoded_inst_t</a> xedd;
332 <span class="keywordtype">int</span> i, bytes = 0;
333 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> itext[<a class="code" href="xed-common-defs_8h.html#214b18e98040dbace0d9e0a0a7937484">XED_MAX_INSTRUCTION_BYTES</a>];
334 <a class="code" href="xed-types_8h.html#d355c921b747945a82d62233a599c7b5">xed_bool_t</a> long_mode = <span class="keyword">false</span>;
335 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> first_argv;
337 <a class="code" href="group__INIT.html#g26aa0242b953b5fd0d14b1fa19442627">xed_tables_init</a>();
338 <a class="code" href="group__INIT.html#g8eea80ff7aa0fc77c3c3e90ce3e1fd64">xed_state_zero</a>(&dstate);
339 <span class="keywordflow">if</span> (argc > 2 && strcmp(argv[1], <span class="stringliteral">"-64"</span>) == 0)
340 long_mode = <span class="keyword">true</span>;
342 <span class="keywordflow">if</span> (long_mode) {
344 dstate.mmode=<a class="code" href="xed-machine-mode-enum_8h.html#754db9d73c5365644094cd161fe570a7708dc25876ca1910c387c0a4f2f066cb">XED_MACHINE_MODE_LONG_64</a>;
346 <span class="keywordflow">else</span> {
348 <a class="code" href="group__INIT.html#g2363cf0a5b4628b09c0dfd1641119714">xed_state_init</a>(&dstate,
349 <a class="code" href="xed-machine-mode-enum_8h.html#754db9d73c5365644094cd161fe570a7a96a9d517621e28100e179eff7c92458">XED_MACHINE_MODE_LEGACY_32</a>,
350 <a class="code" href="xed-address-width-enum_8h.html#2fe76cf1d3e62a77190798dc87c0a8651d4c2a3aeffa1872b2f24730e4c83d02">XED_ADDRESS_WIDTH_32b</a>,
351 <a class="code" href="xed-address-width-enum_8h.html#2fe76cf1d3e62a77190798dc87c0a8651d4c2a3aeffa1872b2f24730e4c83d02">XED_ADDRESS_WIDTH_32b</a>);
354 <a class="code" href="group__DEC.html#ge32686224b685dfc7be3f13504e0a0df">xed_decoded_inst_zero_set_mode</a>(&xedd, &dstate);
356 <span class="keywordflow">for</span>( i=first_argv ;i < argc; i++) {
357 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> x;
358 <span class="comment">// sscanf is deprecated for MSVS8, so I'm using istringstreams</span>
359 <span class="comment">//sscanf(argv[i],"%x", &x);</span>
360 istringstream s(argv[i]);
361 s >> hex >> x;
362 assert(bytes < <a class="code" href="xed-common-defs_8h.html#214b18e98040dbace0d9e0a0a7937484">XED_MAX_INSTRUCTION_BYTES</a>);
363 itext[bytes++] = <a class="code" href="xed-portability_8h.html#8f026df65b9734e9def65ff4059605c5">STATIC_CAST</a>(xed_uint8_t,x);
365 <span class="keywordflow">if</span> (bytes == 0) {
366 cout << <span class="stringliteral">"Must supply some hex bytes"</span> << endl;
370 cout << <span class="stringliteral">"Attempting to decode: "</span> << hex << setfill(<span class="charliteral">'0'</span>) ;
371 <span class="keywordflow">for</span>(i=0;i<bytes;i++)
372 cout << setw(2) << static_cast<xed_uint_t>(itext[i]) << <span class="stringliteral">" "</span>;
373 cout << endl << setfill(<span class="charliteral">' '</span>) << dec;
375 <a class="code" href="xed-error-enum_8h.html#2611877aa5e8b566c1c2be45aa89c792">xed_error_enum_t</a> xed_error = <a class="code" href="group__DEC.html#g9a27c2bb97caf98a6024567b261d0652">xed_decode</a>(&xedd,
376 <a class="code" href="xed-portability_8h.html#52e37c5ddf0c67630b91bcd101521585">REINTERPRET_CAST</a>(<span class="keyword">const</span> xed_uint8_t*,itext),
378 <span class="keywordflow">switch</span>(xed_error) {
379 <span class="keywordflow">case</span> <a class="code" href="xed-error-enum_8h.html#2611877aa5e8b566c1c2be45aa89c792d9f5736eacb4d9dedd9aadf1d75b9de6">XED_ERROR_NONE</a>:
380 <span class="keywordflow">break</span>;
381 <span class="keywordflow">case</span> <a class="code" href="xed-error-enum_8h.html#2611877aa5e8b566c1c2be45aa89c7924e1f9ac48c70bc8ff830829266e6d10a">XED_ERROR_BUFFER_TOO_SHORT</a>:
382 cout << <span class="stringliteral">"Not enough bytes provided"</span> << endl;
384 <span class="keywordflow">case</span> <a class="code" href="xed-error-enum_8h.html#2611877aa5e8b566c1c2be45aa89c7922ade7c52f8c2eb9b6ae4c6e4cb4bd0d5">XED_ERROR_GENERAL_ERROR</a>:
385 cout << <span class="stringliteral">"Could not decode given input."</span> << endl;
387 <span class="keywordflow">default</span>:
388 cout << <span class="stringliteral">"Unhandled error code "</span> << <a class="code" href="xed-error-enum_8h.html#3a44865dce1b468619bc95ad8593b0bf">xed_error_enum_t2str</a>(xed_error) << endl;
393 cout << <span class="stringliteral">"iclass "</span>
394 << <a class="code" href="xed-iclass-enum_8h.html#97f9a6174db43637bf0af371441fde97">xed_iclass_enum_t2str</a>(<a class="code" href="group__DEC.html#g2bc965a8dc2a1fee79b80b2c45d4329c">xed_decoded_inst_get_iclass</a>(&xedd)) << <span class="stringliteral">"\t"</span>;
395 cout << <span class="stringliteral">"category "</span>
396 << <a class="code" href="xed-category-enum_8h.html#14cc11e45d2f7ef8af382c8304682216">xed_category_enum_t2str</a>(<a class="code" href="group__DEC.html#gdb8cfb26a825d8a8d8dcbf49857eab63">xed_decoded_inst_get_category</a>(&xedd)) << <span class="stringliteral">"\t"</span>;
397 cout << <span class="stringliteral">"ISA-extension "</span>
398 << <a class="code" href="xed-extension-enum_8h.html#abb91fa22dcd7e51662b50b7c7488ee7">xed_extension_enum_t2str</a>(<a class="code" href="group__DEC.html#g2ad01ffd078ac7166c8a2bc1be1b6d4d">xed_decoded_inst_get_extension</a>(&xedd)) << endl;
399 cout << <span class="stringliteral">"instruction-length "</span>
400 << <a class="code" href="group__DEC.html#gd1051f7b86c94d5670f684a6ea79fcdf">xed_decoded_inst_get_length</a>(&xedd) << endl;
401 cout << <span class="stringliteral">"effective-operand-width "</span>
402 << <a class="code" href="group__OPERANDS.html#gd3d1c499fb13d8906bea608f9be2375b">xed_operand_values_get_effective_operand_width</a>(<a class="code" href="group__DEC.html#g38e372d3227817713159035cb47ad1fd">xed_decoded_inst_operands_const</a>(&xedd)) << endl;
403 cout << <span class="stringliteral">"effective-address-width "</span>
404 << <a class="code" href="group__OPERANDS.html#g179da221c07e9bc7d86b6a23f668677c">xed_operand_values_get_effective_address_width</a>(<a class="code" href="group__DEC.html#g38e372d3227817713159035cb47ad1fd">xed_decoded_inst_operands_const</a>(&xedd)) << endl;
405 cout << <span class="stringliteral">"iform-enum-name "</span>
406 << <a class="code" href="xed-iform-enum_8h.html#a5982ee859cf508d10f1fe5c7e0d2f61">xed_iform_enum_t2str</a>(<a class="code" href="group__DEC.html#gf51f3a8153bdedec0d8864cc0e89b5c7">xed_decoded_inst_get_iform_enum</a>(&xedd)) << endl;
407 cout << <span class="stringliteral">"iform-enum-name-dispatch (zero based) "</span>
408 << <a class="code" href="group__DEC.html#g8c85bf31ee09bde1bb5b957699a38f71">xed_decoded_inst_get_iform_enum_dispatch</a>(&xedd) << endl;
409 cout << <span class="stringliteral">"iclass-max-iform-dispatch "</span>
410 << <a class="code" href="group__DEC.html#g7b2e9c4095bddf90c3679c9fdd54b20c">xed_iform_max_per_iclass</a>(<a class="code" href="group__DEC.html#g2bc965a8dc2a1fee79b80b2c45d4329c">xed_decoded_inst_get_iclass</a>(&xedd)) << endl;
412 <span class="comment">// operands</span>
413 print_operands(&xedd);
415 <span class="comment">// memops</span>
416 print_memops(&xedd);
418 <span class="comment">// flags</span>
419 print_flags(&xedd);
421 <span class="comment">// attributes</span>
422 print_attributes(&xedd);
423 <span class="keywordflow">return</span> 0;
426 Here are a few examples of running the program:<p>
427 <div class="fragment"><pre class="fragment">% ./xed-ex1 0 0
428 iclass ADD category INT_ALU ISA-extension BASE
430 effective-operand-width 8b
431 effective-address-width 32b
434 1 REG AL EXPLICIT / R
435 2 REG EFLAGS SUPPRESSED / W
437 0 read SEG= DS BASE= EAX/REG32
440 must-write-rflags of-mod sf-mod zf-mod af-mod pf-mod cf-mod
442 written: of sf zf af pf cf
443 ===============================================================================
445 % ./xed-ex1 f2 0f 58 9c 24 e0 00 00 00
446 iclass ADDSD category SSE ISA-extension SSE2
448 effective-operand-width 32b
449 effective-address-width 32b
451 0 REG XMM3 EXPLICIT / RW
454 0 read SEG= SS BASE= ESP/REG32 DISPLACEMENT= DISP32 0x000000e0
456 ===============================================================================
458 iclass PAUSE category INT_ALU ISA-extension BASE
460 effective-operand-width 32b
461 effective-address-width 32b
465 ===============================================================================
468 <table border="0" cellpadding="0" cellspacing="0">
471 <hr size="1"><address style="align: right;"><small>Generated on Thu May 15 03:15:09 2008 for XED2 by
472 <a href="http://www.doxygen.org/index.html">
473 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>