2 Intel Open Source License
4 Copyright (c) 2002-2007 Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
10 Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer. Redistributions
12 in binary form must reproduce the above copyright notice, this list of
13 conditions and the following disclaimer in the documentation and/or
14 other materials provided with the distribution. Neither the name of
15 the Intel Corporation nor the names of its contributors may be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 /// @file xed-examples-util.H
32 /// @author Mark Charney <mark.charney@intel.com>
35 #ifndef _XED_EXAMPLES_UTIL_H_
36 # define _XED_EXAMPLES_UTIL_H_
39 #include "xed-interface.h"
41 extern int intel_syntax;
42 extern int att_syntax;
43 extern int xed_syntax;
44 extern int client_verbose;
46 #define CLIENT_VERBOSE (client_verbose > 2)
47 #define CLIENT_VERBOSE1 (client_verbose > 3)
48 #define CLIENT_VERBOSE2 (client_verbose > 4)
49 #define CLIENT_VERBOSE3 (client_verbose > 5)
51 char* xed_upcase_buf(char* s);
53 /// Accepts K / M / G (or B) qualifiers ot multiply
54 xed_int64_t xed_atoi_general(char* buf, int mul);
55 xed_int64_t xed_atoi_hex(char* buf);
57 /// Converts "112233" in to 0x112233
58 xed_uint64_t convert_ascii_hex_to_int(const char* s);
61 unsigned int xed_convert_ascii_to_hex(const char* src,
63 unsigned int max_bytes);
66 void xed_print_hex_lines(char* buf , const xed_uint8_t* array, const int length); // breaks lines at 16 bytes.
67 void xed_print_hex_line(char* buf, const xed_uint8_t* array, const int length); // no endl
69 void xedex_derror(const char* s);
70 void xedex_dwarn(const char* s);
72 //////////////////////////////////////////////////////////////////////
79 } xed_decode_file_info_t;
81 void xed_decode_file_info_init(xed_decode_file_info_t* p,
82 const xed_state_t* arg_dstate,
86 void xed_map_region(const char* path,
88 unsigned int* length);
91 xed_disas_test(const xed_state_t* dstate,
92 unsigned char* s, // start of image
93 unsigned char* a, // start of instructions to decode region
94 unsigned char* q, // end of region
96 xed_uint64_t runtime_vaddr, // where this region would live at runtime
98 char* (*symfn)(xed_uint64_t)); // a function to convert addresses to symbols
101 // returns 1 on success, 0 on failure
102 xed_uint_t disas_decode_binary(const xed_state_t* dstate,
103 const xed_uint8_t* hex_decode_text,
104 const unsigned int bytes,
105 xed_decoded_inst_t* xedd);
107 // returns encode length on success, 0 on failure
108 xed_uint_t disas_decode_encode_binary(const xed_state_t* dstate,
109 const xed_uint8_t* decode_text_binary,
110 const unsigned int bytes,
111 xed_decoded_inst_t* xedd);
114 void xed_print_decode_stats();
117 fn_disassemble_xed(xed_syntax_enum_t syntax,
120 xed_decoded_inst_t* xedd,
121 xed_uint64_t runtime_instruction_address);
123 void disassemble(char* buf,
125 xed_decoded_inst_t* xedd,
126 xed_uint64_t runtime_instruction_address);
128 xed_uint64_t get_time();
130 // 64b version missing on some MS compilers so I wrap it for portability.
131 // This function is rather limited and only handles base 10 and base 16.
132 xed_int64_t xed_strtoll(const char* buf, int base);
136 //pref: "xed-examples-util.c"