]>
Commit | Line | Data |
---|---|---|
9fb26641 | 1 | |
04509ad9 EH |
2 | /* Common header file that is included by all of QEMU. |
3 | * | |
4 | * This file is supposed to be included only by .c files. No header file should | |
5 | * depend on qemu-common.h, as this would easily lead to circular header | |
6 | * dependencies. | |
7 | * | |
8 | * If a header file uses a definition from qemu-common.h, that definition | |
9 | * must be moved to a separate header file, and the header that uses it | |
10 | * must include that header. | |
11 | */ | |
faf07963 PB |
12 | #ifndef QEMU_COMMON_H |
13 | #define QEMU_COMMON_H | |
14 | ||
bfe7e449 | 15 | #include "qemu/osdep.h" |
1de7afc9 | 16 | #include "qemu/typedefs.h" |
fba0a593 | 17 | #include "qemu/fprintf-fn.h" |
beb6f0de | 18 | |
332ae28d PB |
19 | #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__) |
20 | #define WORDS_ALIGNED | |
21 | #endif | |
22 | ||
082b5557 | 23 | #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) |
24ebf5f3 | 24 | |
1ad9580b | 25 | #include "qemu/option.h" |
8f1ed5f5 | 26 | #include "qemu/host-utils.h" |
faf07963 | 27 | |
c0fd260e SW |
28 | /* HOST_LONG_BITS is the size of a native pointer in bits. */ |
29 | #if UINTPTR_MAX == UINT32_MAX | |
30 | # define HOST_LONG_BITS 32 | |
31 | #elif UINTPTR_MAX == UINT64_MAX | |
32 | # define HOST_LONG_BITS 64 | |
33 | #else | |
34 | # error Unknown pointer size | |
35 | #endif | |
36 | ||
4603ea01 PD |
37 | void cpu_ticks_init(void); |
38 | ||
946fb27c | 39 | /* icount */ |
1ad9580b | 40 | void configure_icount(QemuOpts *opts, Error **errp); |
946fb27c | 41 | extern int use_icount; |
a8bfac37 | 42 | extern int icount_align_option; |
27498bef ST |
43 | /* drift information for info jit command */ |
44 | extern int64_t max_delay; | |
45 | extern int64_t max_advance; | |
46 | void dump_drift_info(FILE *f, fprintf_function cpu_fprintf); | |
946fb27c | 47 | |
1de7afc9 | 48 | #include "qemu/bswap.h" |
faf07963 | 49 | |
9adea5f7 PB |
50 | /* FIXME: Remove NEED_CPU_H. */ |
51 | #ifdef NEED_CPU_H | |
faf07963 | 52 | #include "cpu.h" |
faf07963 PB |
53 | #endif /* !defined(NEED_CPU_H) */ |
54 | ||
3bbbee18 AF |
55 | /* main function, renamed */ |
56 | #if defined(CONFIG_COCOA) | |
57 | int qemu_main(int argc, char **argv, char **envp); | |
58 | #endif | |
59 | ||
f6503059 AZ |
60 | void qemu_get_timedate(struct tm *tm, int offset); |
61 | int qemu_timedate_diff(struct tm *tm); | |
62 | ||
c8057f95 PM |
63 | /** |
64 | * is_help_option: | |
65 | * @s: string to test | |
66 | * | |
67 | * Check whether @s is one of the standard strings which indicate | |
68 | * that the user is asking for a list of the valid values for a | |
69 | * command option like -cpu or -M. The current accepted strings | |
70 | * are 'help' and '?'. '?' is deprecated (it is a shell wildcard | |
71 | * which makes it annoying to use in a reliable way) but provided | |
72 | * for backwards compatibility. | |
73 | * | |
74 | * Returns: true if @s is a request for a list. | |
75 | */ | |
76 | static inline bool is_help_option(const char *s) | |
77 | { | |
78 | return !strcmp(s, "?") || !strcmp(s, "help"); | |
79 | } | |
80 | ||
ab603663 PM |
81 | /* util/cutils.c */ |
82 | /** | |
83 | * pstrcpy: | |
84 | * @buf: buffer to copy string into | |
85 | * @buf_size: size of @buf in bytes | |
86 | * @str: string to copy | |
87 | * | |
88 | * Copy @str into @buf, including the trailing NUL, but do not | |
89 | * write more than @buf_size bytes. The resulting buffer is | |
90 | * always NUL terminated (even if the source string was too long). | |
91 | * If @buf_size is zero or negative then no bytes are copied. | |
92 | * | |
93 | * This function is similar to strncpy(), but avoids two of that | |
94 | * function's problems: | |
95 | * * if @str fits in the buffer, pstrcpy() does not zero-fill the | |
96 | * remaining space at the end of @buf | |
97 | * * if @str is too long, pstrcpy() will copy the first @buf_size-1 | |
98 | * bytes and then add a NUL | |
99 | */ | |
faf07963 | 100 | void pstrcpy(char *buf, int buf_size, const char *str); |
ab603663 PM |
101 | /** |
102 | * strpadcpy: | |
103 | * @buf: buffer to copy string into | |
104 | * @buf_size: size of @buf in bytes | |
105 | * @str: string to copy | |
106 | * @pad: character to pad the remainder of @buf with | |
107 | * | |
108 | * Copy @str into @buf (but *not* its trailing NUL!), and then pad the | |
109 | * rest of the buffer with the @pad character. If @str is too large | |
110 | * for the buffer then it is truncated, so that @buf contains the | |
111 | * first @buf_size characters of @str, with no terminator. | |
112 | */ | |
2a025ae4 | 113 | void strpadcpy(char *buf, int buf_size, const char *str, char pad); |
ab603663 PM |
114 | /** |
115 | * pstrcat: | |
116 | * @buf: buffer containing existing string | |
117 | * @buf_size: size of @buf in bytes | |
118 | * @s: string to concatenate to @buf | |
119 | * | |
120 | * Append a copy of @s to the string already in @buf, but do not | |
121 | * allow the buffer to overflow. If the existing contents of @buf | |
122 | * plus @str would total more than @buf_size bytes, then write | |
123 | * as much of @str as will fit followed by a NUL terminator. | |
124 | * | |
125 | * @buf must already contain a NUL-terminated string, or the | |
126 | * behaviour is undefined. | |
127 | * | |
128 | * Returns: @buf. | |
129 | */ | |
faf07963 | 130 | char *pstrcat(char *buf, int buf_size, const char *s); |
ab603663 PM |
131 | /** |
132 | * strstart: | |
133 | * @str: string to test | |
134 | * @val: prefix string to look for | |
135 | * @ptr: NULL, or pointer to be written to indicate start of | |
136 | * the remainder of the string | |
137 | * | |
138 | * Test whether @str starts with the prefix @val. | |
139 | * If it does (including the degenerate case where @str and @val | |
140 | * are equal) then return true. If @ptr is not NULL then a | |
141 | * pointer to the first character following the prefix is written | |
142 | * to it. If @val is not a prefix of @str then return false (and | |
143 | * @ptr is not written to). | |
144 | * | |
145 | * Returns: true if @str starts with prefix @val, false otherwise. | |
146 | */ | |
faf07963 | 147 | int strstart(const char *str, const char *val, const char **ptr); |
ab603663 PM |
148 | /** |
149 | * stristart: | |
150 | * @str: string to test | |
151 | * @val: prefix string to look for | |
152 | * @ptr: NULL, or pointer to be written to indicate start of | |
153 | * the remainder of the string | |
154 | * | |
155 | * Test whether @str starts with the case-insensitive prefix @val. | |
156 | * This function behaves identically to strstart(), except that the | |
157 | * comparison is made after calling qemu_toupper() on each pair of | |
158 | * characters. | |
159 | * | |
160 | * Returns: true if @str starts with case-insensitive prefix @val, | |
161 | * false otherwise. | |
162 | */ | |
faf07963 | 163 | int stristart(const char *str, const char *val, const char **ptr); |
ab603663 PM |
164 | /** |
165 | * qemu_strnlen: | |
166 | * @s: string | |
167 | * @max_len: maximum number of bytes in @s to scan | |
168 | * | |
169 | * Return the length of the string @s, like strlen(), but do not | |
170 | * examine more than @max_len bytes of the memory pointed to by @s. | |
171 | * If no NUL terminator is found within @max_len bytes, then return | |
172 | * @max_len instead. | |
173 | * | |
174 | * This function has the same behaviour as the POSIX strnlen() | |
175 | * function. | |
176 | * | |
177 | * Returns: length of @s in bytes, or @max_len, whichever is smaller. | |
178 | */ | |
d43277c5 | 179 | int qemu_strnlen(const char *s, int max_len); |
ab603663 PM |
180 | /** |
181 | * qemu_strsep: | |
182 | * @input: pointer to string to parse | |
183 | * @delim: string containing delimiter characters to search for | |
184 | * | |
185 | * Locate the first occurrence of any character in @delim within | |
186 | * the string referenced by @input, and replace it with a NUL. | |
187 | * The location of the next character after the delimiter character | |
188 | * is stored into @input. | |
189 | * If the end of the string was reached without finding a delimiter | |
190 | * character, then NULL is stored into @input. | |
191 | * If @input points to a NULL pointer on entry, return NULL. | |
192 | * The return value is always the original value of *@input (and | |
193 | * so now points to a NUL-terminated string corresponding to the | |
194 | * part of the input up to the first delimiter). | |
195 | * | |
196 | * This function has the same behaviour as the BSD strsep() function. | |
197 | * | |
198 | * Returns: the pointer originally in @input. | |
199 | */ | |
a38ed811 | 200 | char *qemu_strsep(char **input, const char *delim); |
faf07963 | 201 | time_t mktimegm(struct tm *tm); |
6f1953c4 | 202 | int qemu_fdatasync(int fd); |
db1a4972 | 203 | int fcntl_setfl(int fd, int flag); |
443916d1 | 204 | int qemu_parse_fd(const char *param); |
764e0fa4 CT |
205 | int qemu_strtol(const char *nptr, const char **endptr, int base, |
206 | long *result); | |
c817c015 CT |
207 | int qemu_strtoul(const char *nptr, const char **endptr, int base, |
208 | unsigned long *result); | |
8ac4df40 CT |
209 | int qemu_strtoll(const char *nptr, const char **endptr, int base, |
210 | int64_t *result); | |
3904e6bf CT |
211 | int qemu_strtoull(const char *nptr, const char **endptr, int base, |
212 | uint64_t *result); | |
d8427002 | 213 | |
e3f9fe2d EH |
214 | int parse_uint(const char *s, unsigned long long *value, char **endptr, |
215 | int base); | |
216 | int parse_uint_full(const char *s, unsigned long long *value, int base); | |
217 | ||
d7142456 | 218 | /* |
4677bb40 MAL |
219 | * qemu_strtosz() suffixes used to specify the default treatment of an |
220 | * argument passed to qemu_strtosz() without an explicit suffix. | |
d7142456 | 221 | * These should be defined using upper case characters in the range |
4677bb40 | 222 | * A-Z, as qemu_strtosz() will use qemu_toupper() on the given argument |
d7142456 JS |
223 | * prior to comparison. |
224 | */ | |
4677bb40 MAL |
225 | #define QEMU_STRTOSZ_DEFSUFFIX_EB 'E' |
226 | #define QEMU_STRTOSZ_DEFSUFFIX_PB 'P' | |
227 | #define QEMU_STRTOSZ_DEFSUFFIX_TB 'T' | |
228 | #define QEMU_STRTOSZ_DEFSUFFIX_GB 'G' | |
229 | #define QEMU_STRTOSZ_DEFSUFFIX_MB 'M' | |
230 | #define QEMU_STRTOSZ_DEFSUFFIX_KB 'K' | |
231 | #define QEMU_STRTOSZ_DEFSUFFIX_B 'B' | |
232 | int64_t qemu_strtosz(const char *nptr, char **end); | |
233 | int64_t qemu_strtosz_suffix(const char *nptr, char **end, | |
234 | const char default_suffix); | |
235 | int64_t qemu_strtosz_suffix_unit(const char *nptr, char **end, | |
a732e1ba | 236 | const char default_suffix, int64_t unit); |
076b35b5 ND |
237 | #define K_BYTE (1ULL << 10) |
238 | #define M_BYTE (1ULL << 20) | |
239 | #define G_BYTE (1ULL << 30) | |
240 | #define T_BYTE (1ULL << 40) | |
241 | #define P_BYTE (1ULL << 50) | |
242 | #define E_BYTE (1ULL << 60) | |
faf07963 | 243 | |
44e3e053 WX |
244 | /* used to print char* safely */ |
245 | #define STR_OR_NULL(str) ((str) ? (str) : "null") | |
246 | ||
f5bebbbb | 247 | /* id.c */ |
a0f19136 JC |
248 | |
249 | typedef enum IdSubSystems { | |
250 | ID_QDEV, | |
251 | ID_BLOCK, | |
252 | ID_MAX /* last element, used as array size */ | |
253 | } IdSubSystems; | |
254 | ||
255 | char *id_generate(IdSubSystems id); | |
f5bebbbb MA |
256 | bool id_wellformed(const char *id); |
257 | ||
37022086 BS |
258 | /* path.c */ |
259 | void init_paths(const char *prefix); | |
260 | const char *path(const char *pathname); | |
261 | ||
cd390083 BS |
262 | #define qemu_isalnum(c) isalnum((unsigned char)(c)) |
263 | #define qemu_isalpha(c) isalpha((unsigned char)(c)) | |
264 | #define qemu_iscntrl(c) iscntrl((unsigned char)(c)) | |
265 | #define qemu_isdigit(c) isdigit((unsigned char)(c)) | |
266 | #define qemu_isgraph(c) isgraph((unsigned char)(c)) | |
267 | #define qemu_islower(c) islower((unsigned char)(c)) | |
268 | #define qemu_isprint(c) isprint((unsigned char)(c)) | |
269 | #define qemu_ispunct(c) ispunct((unsigned char)(c)) | |
270 | #define qemu_isspace(c) isspace((unsigned char)(c)) | |
271 | #define qemu_isupper(c) isupper((unsigned char)(c)) | |
272 | #define qemu_isxdigit(c) isxdigit((unsigned char)(c)) | |
273 | #define qemu_tolower(c) tolower((unsigned char)(c)) | |
274 | #define qemu_toupper(c) toupper((unsigned char)(c)) | |
275 | #define qemu_isascii(c) isascii((unsigned char)(c)) | |
276 | #define qemu_toascii(c) toascii((unsigned char)(c)) | |
277 | ||
b152aa84 | 278 | void *qemu_oom_check(void *ptr); |
ca10f867 | 279 | |
7c7c0629 JQ |
280 | ssize_t qemu_write_full(int fd, const void *buf, size_t count) |
281 | QEMU_WARN_UNUSED_RESULT; | |
40ff6d7e KW |
282 | |
283 | #ifndef _WIN32 | |
284 | int qemu_pipe(int pipefd[2]); | |
4efeabbb MT |
285 | /* like openpty() but also makes it raw; return master fd */ |
286 | int qemu_openpty_raw(int *aslave, char *pty_name); | |
40ff6d7e KW |
287 | #endif |
288 | ||
00aa0040 | 289 | #ifdef _WIN32 |
58455eb9 SW |
290 | /* MinGW needs type casts for the 'buf' and 'optval' arguments. */ |
291 | #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \ | |
292 | getsockopt(sockfd, level, optname, (void *)optval, optlen) | |
293 | #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \ | |
294 | setsockopt(sockfd, level, optname, (const void *)optval, optlen) | |
00aa0040 | 295 | #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags) |
73062dfe SW |
296 | #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \ |
297 | sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen) | |
00aa0040 | 298 | #else |
58455eb9 SW |
299 | #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \ |
300 | getsockopt(sockfd, level, optname, optval, optlen) | |
301 | #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \ | |
302 | setsockopt(sockfd, level, optname, optval, optlen) | |
00aa0040 | 303 | #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags) |
73062dfe SW |
304 | #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \ |
305 | sendto(sockfd, buf, len, flags, destaddr, addrlen) | |
00aa0040 BS |
306 | #endif |
307 | ||
87ecb68b PB |
308 | /* Error handling. */ |
309 | ||
e5924d89 | 310 | void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2); |
87ecb68b | 311 | |
87ecb68b PB |
312 | struct ParallelIOArg { |
313 | void *buffer; | |
314 | int count; | |
315 | }; | |
316 | ||
317 | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); | |
318 | ||
186993ee MT |
319 | typedef uint64_t pcibus_t; |
320 | ||
679042f0 AP |
321 | typedef struct PCIHostDeviceAddress { |
322 | unsigned int domain; | |
323 | unsigned int bus; | |
324 | unsigned int slot; | |
325 | unsigned int function; | |
326 | } PCIHostDeviceAddress; | |
327 | ||
d5ab9713 JK |
328 | void tcg_exec_init(unsigned long tb_size); |
329 | bool tcg_enabled(void); | |
330 | ||
331 | void cpu_exec_init_all(void); | |
d2053c3c | 332 | |
b3c7724c | 333 | /* CPU save/load. */ |
8d0f2bae | 334 | #ifdef CPU_SAVE_VERSION |
b3c7724c PB |
335 | void cpu_save(QEMUFile *f, void *opaque); |
336 | int cpu_load(QEMUFile *f, void *opaque, int version_id); | |
8d0f2bae | 337 | #endif |
b3c7724c | 338 | |
8edac960 | 339 | /* Unblock cpu */ |
46d62fac | 340 | void qemu_cpu_kick_self(void); |
8edac960 | 341 | |
e82bcec2 MT |
342 | /* work queue */ |
343 | struct qemu_work_item { | |
344 | struct qemu_work_item *next; | |
345 | void (*func)(void *data); | |
346 | void *data; | |
347 | int done; | |
3c02270d | 348 | bool free; |
e82bcec2 MT |
349 | }; |
350 | ||
8c5135f9 PB |
351 | |
352 | /** | |
2fc8ae1d MT |
353 | * Sends a (part of) iovec down a socket, yielding when the socket is full, or |
354 | * Receives data into a (part of) iovec from a socket, | |
355 | * yielding when there is no data in the socket. | |
356 | * The same interface as qemu_sendv_recvv(), with added yielding. | |
357 | * XXX should mark these as coroutine_fn | |
8c5135f9 | 358 | */ |
2fc8ae1d MT |
359 | ssize_t qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt, |
360 | size_t offset, size_t bytes, bool do_send); | |
361 | #define qemu_co_recvv(sockfd, iov, iov_cnt, offset, bytes) \ | |
362 | qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, false) | |
363 | #define qemu_co_sendv(sockfd, iov, iov_cnt, offset, bytes) \ | |
364 | qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, true) | |
8c5135f9 PB |
365 | |
366 | /** | |
2fc8ae1d | 367 | * The same as above, but with just a single buffer |
8c5135f9 | 368 | */ |
2fc8ae1d MT |
369 | ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send); |
370 | #define qemu_co_recv(sockfd, buf, bytes) \ | |
371 | qemu_co_send_recv(sockfd, buf, bytes, false) | |
372 | #define qemu_co_send(sockfd, buf, bytes) \ | |
373 | qemu_co_send_recv(sockfd, buf, bytes, true) | |
8c5135f9 | 374 | |
44e3ee8a AL |
375 | typedef struct QEMUIOVector { |
376 | struct iovec *iov; | |
377 | int niov; | |
378 | int nalloc; | |
249aa745 | 379 | size_t size; |
44e3ee8a AL |
380 | } QEMUIOVector; |
381 | ||
382 | void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); | |
522584a5 | 383 | void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov); |
44e3ee8a | 384 | void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len); |
1b093c48 MT |
385 | void qemu_iovec_concat(QEMUIOVector *dst, |
386 | QEMUIOVector *src, size_t soffset, size_t sbytes); | |
519661ee PB |
387 | size_t qemu_iovec_concat_iov(QEMUIOVector *dst, |
388 | struct iovec *src_iov, unsigned int src_cnt, | |
389 | size_t soffset, size_t sbytes); | |
43f35cb5 | 390 | bool qemu_iovec_is_zero(QEMUIOVector *qiov); |
44e3ee8a | 391 | void qemu_iovec_destroy(QEMUIOVector *qiov); |
be959463 | 392 | void qemu_iovec_reset(QEMUIOVector *qiov); |
d5e6b161 MT |
393 | size_t qemu_iovec_to_buf(QEMUIOVector *qiov, size_t offset, |
394 | void *buf, size_t bytes); | |
03396148 MT |
395 | size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset, |
396 | const void *buf, size_t bytes); | |
3d9b4925 MT |
397 | size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset, |
398 | int fillc, size_t bytes); | |
f70d7f7e BC |
399 | ssize_t qemu_iovec_compare(QEMUIOVector *a, QEMUIOVector *b); |
400 | void qemu_iovec_clone(QEMUIOVector *dest, const QEMUIOVector *src, void *buf); | |
58f423fb | 401 | void qemu_iovec_discard_back(QEMUIOVector *qiov, size_t bytes); |
44e3ee8a | 402 | |
1a6d39fd SH |
403 | bool buffer_is_zero(const void *buf, size_t len); |
404 | ||
6b837bc4 JS |
405 | void qemu_progress_init(int enabled, float min_skip); |
406 | void qemu_progress_end(void); | |
3bfe4dbf | 407 | void qemu_progress_print(float delta, int max); |
31459f46 | 408 | const char *qemu_get_vm_name(void); |
6b837bc4 | 409 | |
082b5557 BS |
410 | #define QEMU_FILE_TYPE_BIOS 0 |
411 | #define QEMU_FILE_TYPE_KEYMAP 1 | |
412 | char *qemu_find_file(int type, const char *name); | |
413 | ||
414 | /* OS specific functions */ | |
415 | void os_setup_early_signal_handling(void); | |
10f5bff6 | 416 | char *os_find_datadir(void); |
082b5557 | 417 | void os_parse_cmd_args(int index, const char *optarg); |
082b5557 | 418 | |
abd0c6bd PB |
419 | /* Convert a byte between binary and BCD. */ |
420 | static inline uint8_t to_bcd(uint8_t val) | |
421 | { | |
422 | return ((val / 10) << 4) | (val % 10); | |
423 | } | |
424 | ||
425 | static inline uint8_t from_bcd(uint8_t val) | |
426 | { | |
427 | return ((val >> 4) * 10) + (val & 0x0f); | |
428 | } | |
429 | ||
3951690a SH |
430 | /* Round number down to multiple */ |
431 | #define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m)) | |
432 | ||
433 | /* Round number up to multiple */ | |
434 | #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m)) | |
435 | ||
1de7afc9 | 436 | #include "qemu/module.h" |
0bfe3ca5 | 437 | |
e6546bb9 OW |
438 | /* |
439 | * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128) | |
440 | * Input is limited to 14-bit numbers | |
441 | */ | |
442 | ||
443 | int uleb128_encode_small(uint8_t *out, uint32_t n); | |
444 | int uleb128_decode_small(const uint8_t *in, uint32_t *n); | |
445 | ||
cb2744ea MA |
446 | /* unicode.c */ |
447 | int mod_utf8_codepoint(const char *s, size_t n, char **end); | |
448 | ||
6ff66f50 PC |
449 | /* |
450 | * Hexdump a buffer to a file. An optional string prefix is added to every line | |
451 | */ | |
452 | ||
3568ac2a | 453 | void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size); |
6ff66f50 | 454 | |
c61ca00a PL |
455 | /* vector definitions */ |
456 | #ifdef __ALTIVEC__ | |
457 | #include <altivec.h> | |
8593e050 PB |
458 | /* The altivec.h header says we're allowed to undef these for |
459 | * C++ compatibility. Here we don't care about C++, but we | |
460 | * undef them anyway to avoid namespace pollution. | |
461 | */ | |
462 | #undef vector | |
463 | #undef pixel | |
464 | #undef bool | |
465 | #define VECTYPE __vector unsigned char | |
c61ca00a PL |
466 | #define SPLAT(p) vec_splat(vec_ld(0, p), 0) |
467 | #define ALL_EQ(v1, v2) vec_all_eq(v1, v2) | |
34664507 | 468 | #define VEC_OR(v1, v2) ((v1) | (v2)) |
c61ca00a PL |
469 | /* altivec.h may redefine the bool macro as vector type. |
470 | * Reset it to POSIX semantics. */ | |
c61ca00a PL |
471 | #define bool _Bool |
472 | #elif defined __SSE2__ | |
473 | #include <emmintrin.h> | |
474 | #define VECTYPE __m128i | |
475 | #define SPLAT(p) _mm_set1_epi8(*(p)) | |
476 | #define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF) | |
34664507 | 477 | #define VEC_OR(v1, v2) (_mm_or_si128(v1, v2)) |
c61ca00a PL |
478 | #else |
479 | #define VECTYPE unsigned long | |
480 | #define SPLAT(p) (*(p) * (~0UL / 255)) | |
481 | #define ALL_EQ(v1, v2) ((v1) == (v2)) | |
34664507 | 482 | #define VEC_OR(v1, v2) ((v1) | (v2)) |
c61ca00a PL |
483 | #endif |
484 | ||
41a259bd PL |
485 | #define BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR 8 |
486 | static inline bool | |
487 | can_use_buffer_find_nonzero_offset(const void *buf, size_t len) | |
488 | { | |
489 | return (len % (BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR | |
490 | * sizeof(VECTYPE)) == 0 | |
491 | && ((uintptr_t) buf) % sizeof(VECTYPE) == 0); | |
492 | } | |
493 | size_t buffer_find_nonzero_offset(const void *buf, size_t len); | |
494 | ||
b16352ac AL |
495 | /* |
496 | * helper to parse debug environment variables | |
497 | */ | |
498 | int parse_debug_env(const char *name, int max, int initial); | |
499 | ||
4297c8ee | 500 | const char *qemu_ether_ntoa(const MACAddr *mac); |
87f50caa | 501 | void page_size_init(void); |
4297c8ee | 502 | |
faf07963 | 503 | #endif |