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 / examples / xed-examples-util.h
1 /*BEGIN_LEGAL 
2 Intel Open Source License 
3
4 Copyright (c) 2002-2007 Intel Corporation 
5 All rights reserved. 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9
10 Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.  Redistributions
12 in binary form must reproduce the above copyright notice, this list of
13 conditions and the following disclaimer in the documentation and/or
14 other materials provided with the distribution.  Neither the name of
15 the Intel Corporation nor the names of its contributors may be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
18  
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 END_LEGAL */
31 /// @file xed-examples-util.H
32 /// @author Mark Charney   <mark.charney@intel.com>
33
34
35 #ifndef _XED_EXAMPLES_UTIL_H_
36 # define _XED_EXAMPLES_UTIL_H_
37
38 #include <stdio.h>
39 #include "xed-interface.h"
40
41 extern int intel_syntax;
42 extern int att_syntax;
43 extern int xed_syntax;
44 extern int client_verbose;
45
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)
50
51 char* xed_upcase_buf(char* s);
52
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);
56
57 /// Converts "112233" in to 0x112233
58 xed_uint64_t convert_ascii_hex_to_int(const char* s);
59
60
61 unsigned int xed_convert_ascii_to_hex(const char* src, 
62                                       xed_uint8_t* dst, 
63                                       unsigned int max_bytes);
64
65
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
68
69 void xedex_derror(const char* s);
70 void xedex_dwarn(const char* s);
71
72 //////////////////////////////////////////////////////////////////////
73
74
75 typedef struct {
76     xed_state_t dstate;
77     int ninst;
78     int decode_only;
79 } xed_decode_file_info_t;
80
81 void xed_decode_file_info_init(xed_decode_file_info_t* p,
82                                const xed_state_t* arg_dstate,
83                                int anrg_ninst,
84                                int arg_decode_only);
85
86 void xed_map_region(const char* path,
87                     void** start,
88                     unsigned int* length);
89
90 void
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
95                int ninst,
96                xed_uint64_t runtime_vaddr,  // where this region would live at runtime
97                int decode_only,
98                char* (*symfn)(xed_uint64_t)); // a function to convert addresses to symbols
99
100
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);
106
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);
112
113
114 void xed_print_decode_stats();
115
116 int
117 fn_disassemble_xed(xed_syntax_enum_t syntax,
118                    char* buf,
119                    int buflen,
120                    xed_decoded_inst_t* xedd,
121                    xed_uint64_t runtime_instruction_address);
122
123 void disassemble(char* buf,
124                  int buflen,
125                  xed_decoded_inst_t* xedd,
126                  xed_uint64_t runtime_instruction_address);
127
128 xed_uint64_t  get_time();
129
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);
133
134 #endif // file
135 //Local Variables:
136 //pref: "xed-examples-util.c"
137 //End: