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.
32 /// @author Mark Charney <mark.charney@intel.com>
39 //#include <libc/string.h>
40 #include <xed/xed-common-hdrs.h>
41 #include <xed/xed-types.h>
42 #include <xed/xed-portability.h>
45 ////////////////////////////////////////////////////////////////////////////
47 ////////////////////////////////////////////////////////////////////////////
48 extern int xed_verbose;
49 #define XED_MESSAGES 0
51 #if defined(XED_MESSAGES)
52 //# include <stdio.h> // only with XED_MESSAGES defined
54 //#include <libc/string.h>
56 extern void *xed_log_file;
58 //extern int fprintf(struct file_struct *file, char *s, const char *fmt, ...);
62 #define XED_EMIT_MESSAGES (XED_MESSAGES==1 && xed_verbose >= 1)
63 #define XED_INFO_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 2)
64 #define XED_INFO2_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 3)
65 #define XED_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 4)
66 #define XED_MORE_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 5)
67 #define XED_VERY_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 6)
70 # define XED_FUNCNAME __func__
72 # define XED_FUNCNAME ""
78 if (XED_EMIT_MESSAGES) { \
79 if (XED_VERY_VERBOSE) { \
80 fprintf(xed_log_file,"%s:%d:%s: ", \
81 __FILE__, __LINE__, XED_FUNCNAME); \
84 fflush(xed_log_file); \
91 if (XED_VERY_VERBOSE) { \
92 fprintf(xed_log_file,"%s:%d:%s: ", \
93 __FILE__, __LINE__, XED_FUNCNAME); \
96 fflush(xed_log_file); \
100 #define XED2VMSG(x) \
102 if (XED_VERY_VERBOSE) { \
103 fprintf(xed_log_file,"%s:%d:%s: ", \
104 __FILE__, __LINE__, XED_FUNCNAME); \
106 fflush(xed_log_file); \
112 if (XED_EMIT_MESSAGES) { \
113 fprintf(xed_log_file,"%s:%d:%s: ", \
114 __FILE__, __LINE__, XED_FUNCNAME); \
116 fflush(xed_log_file); \
127 # define XED2DIE(x) do { xed_assert(0); } while(0)
130 #if defined(XED_ASSERTS)
131 # define xed_assert(x) do { if (( x )== 0) xed_internal_assert( #x, __FILE__, __LINE__); } while(0)
133 # define xed_assert(x) do { } while(0)
135 XED_NORETURN XED_NOINLINE XED_DLL_EXPORT void xed_internal_assert(const char* s, const char* file, int line);
138 /// This is for registering a function to be called during XED's assert
139 /// processing. If you do not register an abort function, then the system's
140 /// abort function will be called. If your supplied function returns, then
141 /// abort() will still be called.
143 /// @param fn This is a function pointer for a function that should handle the
144 /// assertion reporting. The function pointer points to a function that
145 /// takes 4 arguments:
146 /// (1) msg, the assertion message,
147 /// (2) file, the file name,
148 /// (3) line, the line number (as an integer), and
149 /// (4) other, a void pointer that is supplied as thei
150 /// 2nd argument to this registration.
151 /// @param other This is a void* that is passed back to your supplied function fn
152 /// as its 4th argument. It can be zero if you don't need this
153 /// feature. You can used this to convey whatever additional context
154 /// to your assertion handler (like FILE* pointers etc.).
156 XED_DLL_EXPORT void xed_register_abort_function(void (*fn)(const char* msg,
157 const char* file, int line, void* other),
161 ////////////////////////////////////////////////////////////////////////////
163 ////////////////////////////////////////////////////////////////////////////
164 char* xed_downcase_buf(char* s);
166 int xed_itoa(char* buf, xed_uint64_t f, int buflen);
167 int xed_itoa_hex_zeros(char* buf, xed_uint64_t f, xed_uint_t xed_bits_to_print, xed_bool_t leading_zeros, int buflen);
168 int xed_itoa_hex(char* buf, xed_uint64_t f, xed_uint_t xed_bits_to_print, int buflen);
169 int xed_itoa_signed(char* buf, xed_int64_t f, int buflen);
171 char xed_to_ascii_hex_nibble(xed_uint_t x);
173 int xed_sprintf_uint8_hex(char* buf, xed_uint8_t x, int buflen);
174 int xed_sprintf_uint16_hex(char* buf, xed_uint16_t x, int buflen);
175 int xed_sprintf_uint32_hex(char* buf, xed_uint32_t x, int buflen);
176 int xed_sprintf_uint64_hex(char* buf, xed_uint64_t x, int buflen);
177 int xed_sprintf_uint8(char* buf, xed_uint8_t x, int buflen);
178 int xed_sprintf_uint16(char* buf, xed_uint16_t x, int buflen);
179 int xed_sprintf_uint32(char* buf, xed_uint32_t x, int buflen);
180 int xed_sprintf_uint64(char* buf, xed_uint64_t x, int buflen);
181 int xed_sprintf_int8(char* buf, xed_int8_t x, int buflen);
182 int xed_sprintf_int16(char* buf, xed_int16_t x, int buflen);
183 int xed_sprintf_int32(char* buf, xed_int32_t x, int buflen);
184 int xed_sprintf_int64(char* buf, xed_int64_t x, int buflen);
187 //typedef struct file_struct *FILE;
189 /// Set the FILE* for XED's log msgs
190 XED_DLL_EXPORT void xed_set_log_file(void* o);
193 /// Set the verbosity level for XED
194 XED_DLL_EXPORT void xed_set_verbosity(int v);
196 void xed_derror(const char* s);
197 void xed_dwarn(const char* s);
199 XED_DLL_EXPORT xed_int64_t xed_sign_extend32_64(xed_int32_t x);
200 XED_DLL_EXPORT xed_int64_t xed_sign_extend16_64(xed_int16_t x);
201 XED_DLL_EXPORT xed_int64_t xed_sign_extend8_64(xed_int8_t x);
203 XED_DLL_EXPORT xed_int32_t xed_sign_extend16_32(xed_int16_t x);
204 XED_DLL_EXPORT xed_int32_t xed_sign_extend8_32(xed_int8_t x);
206 XED_DLL_EXPORT xed_int16_t xed_sign_extend8_16(xed_int8_t x);
208 ///arbitrary sign extension from a qty of "bits" length to 32b
209 XED_DLL_EXPORT xed_int32_t xed_sign_extend_arbitrary_to_32(xed_uint32_t x, unsigned int bits);
211 ///arbitrary sign extension from a qty of "bits" length to 64b
212 XED_DLL_EXPORT xed_int64_t xed_sign_extend_arbitrary_to_64(xed_uint64_t x, unsigned int bits);
215 XED_DLL_EXPORT xed_uint64_t xed_zero_extend32_64(xed_uint32_t x);
216 XED_DLL_EXPORT xed_uint64_t xed_zero_extend16_64(xed_uint16_t x);
217 XED_DLL_EXPORT xed_uint64_t xed_zero_extend8_64(xed_uint8_t x);
219 XED_DLL_EXPORT xed_uint32_t xed_zero_extend16_32(xed_uint16_t x);
220 XED_DLL_EXPORT xed_uint32_t xed_zero_extend8_32(xed_uint8_t x);
222 XED_DLL_EXPORT xed_uint16_t xed_zero_extend8_16(xed_uint8_t x);
224 XED_DLL_EXPORT xed_int32_t
225 xed_little_endian_to_int32(xed_uint64_t x, unsigned int len);
227 XED_DLL_EXPORT xed_int64_t
228 xed_little_endian_to_int64(xed_uint64_t x, unsigned int len);
229 XED_DLL_EXPORT xed_uint64_t
230 xed_little_endian_to_uint64(xed_uint64_t x, unsigned int len);
232 XED_DLL_EXPORT xed_int64_t
233 xed_little_endian_hilo_to_int64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
234 XED_DLL_EXPORT xed_uint64_t
235 xed_little_endian_hilo_to_uint64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
237 XED_DLL_EXPORT xed_uint8_t
238 xed_get_byte(xed_uint64_t x, unsigned int i, unsigned int len);
240 static XED_INLINE xed_uint64_t xed_make_uint64(xed_uint32_t hi, xed_uint32_t lo) {
246 static XED_INLINE xed_int64_t xed_make_int64(xed_uint32_t hi, xed_uint32_t lo) {
250 return STATIC_CAST(xed_int64_t,y);
253 /// returns the number of bytes required to store the UNSIGNED number x
254 /// given a mask of legal lengths. For the legal_widths argument, bit 0
255 /// implies 1 byte is a legal return width, bit 1 implies that 2 bytes is a
256 /// legal return width, bit 2 implies that 4 bytes is a legal return width.
257 /// This returns 8 (indicating 8B) if none of the provided legal widths
259 XED_DLL_EXPORT xed_uint_t xed_shortest_width_unsigned(xed_uint64_t x, xed_uint8_t legal_widths);
261 /// returns the number of bytes required to store the SIGNED number x
262 /// given a mask of legal lengths. For the legal_widths argument, bit 0 implies 1
263 /// byte is a legal return width, bit 1 implies that 2 bytes is a legal
264 /// return width, bit 2 implies that 4 bytes is a legal return width. This
265 /// returns 8 (indicating 8B) if none of the provided legal widths applies.
266 XED_DLL_EXPORT xed_uint_t xed_shortest_width_signed(xed_int64_t x, xed_uint8_t legal_widths);
268 ////////////////////////////////////////////////////////////////////////////
270 ////////////////////////////////////////////////////////////////////////////
272 ////////////////////////////////////////////////////////////////////////////
275 //pref: "../../xed-util.c"