Statistics
| Branch: | Revision:

root / qemu-common.h @ 9c17d615

History | View | Annotate | Download (11.7 kB)

1 9fb26641 Orit Wasserman
2 04509ad9 Eduardo Habkost
/* Common header file that is included by all of QEMU.
3 04509ad9 Eduardo Habkost
 *
4 04509ad9 Eduardo Habkost
 * This file is supposed to be included only by .c files. No header file should
5 04509ad9 Eduardo Habkost
 * depend on qemu-common.h, as this would easily lead to circular header
6 04509ad9 Eduardo Habkost
 * dependencies.
7 04509ad9 Eduardo Habkost
 *
8 04509ad9 Eduardo Habkost
 * If a header file uses a definition from qemu-common.h, that definition
9 04509ad9 Eduardo Habkost
 * must be moved to a separate header file, and the header that uses it
10 04509ad9 Eduardo Habkost
 * must include that header.
11 04509ad9 Eduardo Habkost
 */
12 faf07963 pbrook
#ifndef QEMU_COMMON_H
13 faf07963 pbrook
#define QEMU_COMMON_H
14 faf07963 pbrook
15 1de7afc9 Paolo Bonzini
#include "qemu/compiler.h"
16 beb6f0de Kevin Wolf
#include "config-host.h"
17 1de7afc9 Paolo Bonzini
#include "qemu/typedefs.h"
18 beb6f0de Kevin Wolf
19 332ae28d Paolo Bonzini
#if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
20 332ae28d Paolo Bonzini
#define WORDS_ALIGNED
21 332ae28d Paolo Bonzini
#endif
22 332ae28d Paolo Bonzini
23 082b5557 Blue Swirl
#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
24 24ebf5f3 Paolo Bonzini
25 faf07963 pbrook
/* we put basic includes here to avoid repeating them in device drivers */
26 faf07963 pbrook
#include <stdlib.h>
27 faf07963 pbrook
#include <stdio.h>
28 faf07963 pbrook
#include <stdarg.h>
29 11165820 Paul Brook
#include <stdbool.h>
30 faf07963 pbrook
#include <string.h>
31 c8906845 balrog
#include <strings.h>
32 faf07963 pbrook
#include <inttypes.h>
33 faf07963 pbrook
#include <limits.h>
34 faf07963 pbrook
#include <time.h>
35 faf07963 pbrook
#include <ctype.h>
36 faf07963 pbrook
#include <errno.h>
37 faf07963 pbrook
#include <unistd.h>
38 faf07963 pbrook
#include <fcntl.h>
39 faf07963 pbrook
#include <sys/stat.h>
40 dcfd0865 Hervé Poussineau
#include <sys/time.h>
41 55616505 Paul Brook
#include <assert.h>
42 86f69a92 Alexandre Raymond
#include <signal.h>
43 14015304 Anthony Liguori
#include <glib.h>
44 faf07963 pbrook
45 082b5557 Blue Swirl
#ifdef _WIN32
46 9c17d615 Paolo Bonzini
#include "sysemu/os-win32.h"
47 082b5557 Blue Swirl
#endif
48 082b5557 Blue Swirl
49 082b5557 Blue Swirl
#ifdef CONFIG_POSIX
50 9c17d615 Paolo Bonzini
#include "sysemu/os-posix.h"
51 082b5557 Blue Swirl
#endif
52 082b5557 Blue Swirl
53 faf07963 pbrook
#ifndef O_LARGEFILE
54 faf07963 pbrook
#define O_LARGEFILE 0
55 faf07963 pbrook
#endif
56 faf07963 pbrook
#ifndef O_BINARY
57 faf07963 pbrook
#define O_BINARY 0
58 faf07963 pbrook
#endif
59 0e74e66b Juan Quintela
#ifndef MAP_ANONYMOUS
60 0e74e66b Juan Quintela
#define MAP_ANONYMOUS MAP_ANON
61 0e74e66b Juan Quintela
#endif
62 faf07963 pbrook
#ifndef ENOMEDIUM
63 faf07963 pbrook
#define ENOMEDIUM ENODEV
64 faf07963 pbrook
#endif
65 4c955388 Anthony Liguori
#if !defined(ENOTSUP)
66 2880bc32 Juan Quintela
#define ENOTSUP 4096
67 2880bc32 Juan Quintela
#endif
68 2084a8e3 Paolo Bonzini
#if !defined(ECANCELED)
69 2084a8e3 Paolo Bonzini
#define ECANCELED 4097
70 2084a8e3 Paolo Bonzini
#endif
71 3c9405a0 Gerd Hoffmann
#ifndef TIME_MAX
72 3c9405a0 Gerd Hoffmann
#define TIME_MAX LONG_MAX
73 3c9405a0 Gerd Hoffmann
#endif
74 faf07963 pbrook
75 c0fd260e Stefan Weil
/* HOST_LONG_BITS is the size of a native pointer in bits. */
76 c0fd260e Stefan Weil
#if UINTPTR_MAX == UINT32_MAX
77 c0fd260e Stefan Weil
# define HOST_LONG_BITS 32
78 c0fd260e Stefan Weil
#elif UINTPTR_MAX == UINT64_MAX
79 c0fd260e Stefan Weil
# define HOST_LONG_BITS 64
80 c0fd260e Stefan Weil
#else
81 c0fd260e Stefan Weil
# error Unknown pointer size
82 c0fd260e Stefan Weil
#endif
83 c0fd260e Stefan Weil
84 6114fdb0 Juan Quintela
#ifndef CONFIG_IOVEC
85 6114fdb0 Juan Quintela
#define CONFIG_IOVEC
86 bf9298b9 aliguori
struct iovec {
87 bf9298b9 aliguori
    void *iov_base;
88 bf9298b9 aliguori
    size_t iov_len;
89 bf9298b9 aliguori
};
90 e2a305fb Christoph Hellwig
/*
91 e2a305fb Christoph Hellwig
 * Use the same value as Linux for now.
92 e2a305fb Christoph Hellwig
 */
93 e2a305fb Christoph Hellwig
#define IOV_MAX                1024
94 331dadde blueswir1
#else
95 331dadde blueswir1
#include <sys/uio.h>
96 bf9298b9 aliguori
#endif
97 bf9298b9 aliguori
98 f868445a Stefan Weil
typedef int (*fprintf_function)(FILE *f, const char *fmt, ...)
99 f868445a Stefan Weil
    GCC_FMT_ATTR(2, 3);
100 f868445a Stefan Weil
101 faf07963 pbrook
#ifdef _WIN32
102 faf07963 pbrook
#define fsync _commit
103 371c6489 Stefan Weil
#if !defined(lseek)
104 371c6489 Stefan Weil
# define lseek _lseeki64
105 371c6489 Stefan Weil
#endif
106 64b85a8f Blue Swirl
int qemu_ftruncate64(int, int64_t);
107 371c6489 Stefan Weil
#if !defined(ftruncate)
108 371c6489 Stefan Weil
# define ftruncate qemu_ftruncate64
109 371c6489 Stefan Weil
#endif
110 faf07963 pbrook
111 faf07963 pbrook
static inline char *realpath(const char *path, char *resolved_path)
112 faf07963 pbrook
{
113 faf07963 pbrook
    _fullpath(resolved_path, path, _MAX_PATH);
114 faf07963 pbrook
    return resolved_path;
115 faf07963 pbrook
}
116 faf07963 pbrook
#endif
117 faf07963 pbrook
118 946fb27c Paolo Bonzini
/* icount */
119 946fb27c Paolo Bonzini
void configure_icount(const char *option);
120 946fb27c Paolo Bonzini
extern int use_icount;
121 946fb27c Paolo Bonzini
122 faf07963 pbrook
/* FIXME: Remove NEED_CPU_H.  */
123 faf07963 pbrook
#ifndef NEED_CPU_H
124 faf07963 pbrook
125 1de7afc9 Paolo Bonzini
#include "qemu/osdep.h"
126 1de7afc9 Paolo Bonzini
#include "qemu/bswap.h"
127 faf07963 pbrook
128 faf07963 pbrook
#else
129 faf07963 pbrook
130 faf07963 pbrook
#include "cpu.h"
131 faf07963 pbrook
132 faf07963 pbrook
#endif /* !defined(NEED_CPU_H) */
133 faf07963 pbrook
134 3bbbee18 Andreas Färber
/* main function, renamed */
135 3bbbee18 Andreas Färber
#if defined(CONFIG_COCOA)
136 3bbbee18 Andreas Färber
int qemu_main(int argc, char **argv, char **envp);
137 3bbbee18 Andreas Färber
#endif
138 3bbbee18 Andreas Färber
139 f6503059 balrog
void qemu_get_timedate(struct tm *tm, int offset);
140 f6503059 balrog
int qemu_timedate_diff(struct tm *tm);
141 f6503059 balrog
142 c8057f95 Peter Maydell
/**
143 c8057f95 Peter Maydell
 * is_help_option:
144 c8057f95 Peter Maydell
 * @s: string to test
145 c8057f95 Peter Maydell
 *
146 c8057f95 Peter Maydell
 * Check whether @s is one of the standard strings which indicate
147 c8057f95 Peter Maydell
 * that the user is asking for a list of the valid values for a
148 c8057f95 Peter Maydell
 * command option like -cpu or -M. The current accepted strings
149 c8057f95 Peter Maydell
 * are 'help' and '?'. '?' is deprecated (it is a shell wildcard
150 c8057f95 Peter Maydell
 * which makes it annoying to use in a reliable way) but provided
151 c8057f95 Peter Maydell
 * for backwards compatibility.
152 c8057f95 Peter Maydell
 *
153 c8057f95 Peter Maydell
 * Returns: true if @s is a request for a list.
154 c8057f95 Peter Maydell
 */
155 c8057f95 Peter Maydell
static inline bool is_help_option(const char *s)
156 c8057f95 Peter Maydell
{
157 c8057f95 Peter Maydell
    return !strcmp(s, "?") || !strcmp(s, "help");
158 c8057f95 Peter Maydell
}
159 c8057f95 Peter Maydell
160 faf07963 pbrook
/* cutils.c */
161 faf07963 pbrook
void pstrcpy(char *buf, int buf_size, const char *str);
162 2a025ae4 Dmitry Fleytman
void strpadcpy(char *buf, int buf_size, const char *str, char pad);
163 faf07963 pbrook
char *pstrcat(char *buf, int buf_size, const char *s);
164 faf07963 pbrook
int strstart(const char *str, const char *val, const char **ptr);
165 faf07963 pbrook
int stristart(const char *str, const char *val, const char **ptr);
166 d43277c5 Blue Swirl
int qemu_strnlen(const char *s, int max_len);
167 faf07963 pbrook
time_t mktimegm(struct tm *tm);
168 ad46db9a blueswir1
int qemu_fls(int i);
169 6f1953c4 Christoph Hellwig
int qemu_fdatasync(int fd);
170 db1a4972 Paolo Bonzini
int fcntl_setfl(int fd, int flag);
171 443916d1 Stefan Berger
int qemu_parse_fd(const char *param);
172 d8427002 Jes Sorensen
173 d7142456 Jes Sorensen
/*
174 d7142456 Jes Sorensen
 * strtosz() suffixes used to specify the default treatment of an
175 d7142456 Jes Sorensen
 * argument passed to strtosz() without an explicit suffix.
176 d7142456 Jes Sorensen
 * These should be defined using upper case characters in the range
177 d7142456 Jes Sorensen
 * A-Z, as strtosz() will use qemu_toupper() on the given argument
178 d7142456 Jes Sorensen
 * prior to comparison.
179 d7142456 Jes Sorensen
 */
180 d8427002 Jes Sorensen
#define STRTOSZ_DEFSUFFIX_TB        'T'
181 d8427002 Jes Sorensen
#define STRTOSZ_DEFSUFFIX_GB        'G'
182 d8427002 Jes Sorensen
#define STRTOSZ_DEFSUFFIX_MB        'M'
183 d8427002 Jes Sorensen
#define STRTOSZ_DEFSUFFIX_KB        'K'
184 d8427002 Jes Sorensen
#define STRTOSZ_DEFSUFFIX_B        'B'
185 70b4f4bb Jes Sorensen
int64_t strtosz(const char *nptr, char **end);
186 70b4f4bb Jes Sorensen
int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
187 a732e1ba Joerg Roedel
int64_t strtosz_suffix_unit(const char *nptr, char **end,
188 a732e1ba Joerg Roedel
                            const char default_suffix, int64_t unit);
189 faf07963 pbrook
190 37022086 Blue Swirl
/* path.c */
191 37022086 Blue Swirl
void init_paths(const char *prefix);
192 37022086 Blue Swirl
const char *path(const char *pathname);
193 37022086 Blue Swirl
194 cd390083 blueswir1
#define qemu_isalnum(c)                isalnum((unsigned char)(c))
195 cd390083 blueswir1
#define qemu_isalpha(c)                isalpha((unsigned char)(c))
196 cd390083 blueswir1
#define qemu_iscntrl(c)                iscntrl((unsigned char)(c))
197 cd390083 blueswir1
#define qemu_isdigit(c)                isdigit((unsigned char)(c))
198 cd390083 blueswir1
#define qemu_isgraph(c)                isgraph((unsigned char)(c))
199 cd390083 blueswir1
#define qemu_islower(c)                islower((unsigned char)(c))
200 cd390083 blueswir1
#define qemu_isprint(c)                isprint((unsigned char)(c))
201 cd390083 blueswir1
#define qemu_ispunct(c)                ispunct((unsigned char)(c))
202 cd390083 blueswir1
#define qemu_isspace(c)                isspace((unsigned char)(c))
203 cd390083 blueswir1
#define qemu_isupper(c)                isupper((unsigned char)(c))
204 cd390083 blueswir1
#define qemu_isxdigit(c)        isxdigit((unsigned char)(c))
205 cd390083 blueswir1
#define qemu_tolower(c)                tolower((unsigned char)(c))
206 cd390083 blueswir1
#define qemu_toupper(c)                toupper((unsigned char)(c))
207 cd390083 blueswir1
#define qemu_isascii(c)                isascii((unsigned char)(c))
208 cd390083 blueswir1
#define qemu_toascii(c)                toascii((unsigned char)(c))
209 cd390083 blueswir1
210 b152aa84 Jes Sorensen
void *qemu_oom_check(void *ptr);
211 ca10f867 aurel32
212 7c7c0629 Juan Quintela
ssize_t qemu_write_full(int fd, const void *buf, size_t count)
213 7c7c0629 Juan Quintela
    QEMU_WARN_UNUSED_RESULT;
214 993295fe Paolo Bonzini
ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags)
215 993295fe Paolo Bonzini
    QEMU_WARN_UNUSED_RESULT;
216 8c5135f9 Paolo Bonzini
ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags)
217 993295fe Paolo Bonzini
    QEMU_WARN_UNUSED_RESULT;
218 40ff6d7e Kevin Wolf
219 40ff6d7e Kevin Wolf
#ifndef _WIN32
220 40ff6d7e Kevin Wolf
int qemu_pipe(int pipefd[2]);
221 40ff6d7e Kevin Wolf
#endif
222 40ff6d7e Kevin Wolf
223 00aa0040 Blue Swirl
#ifdef _WIN32
224 58455eb9 Stefan Weil
/* MinGW needs type casts for the 'buf' and 'optval' arguments. */
225 58455eb9 Stefan Weil
#define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
226 58455eb9 Stefan Weil
    getsockopt(sockfd, level, optname, (void *)optval, optlen)
227 58455eb9 Stefan Weil
#define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
228 58455eb9 Stefan Weil
    setsockopt(sockfd, level, optname, (const void *)optval, optlen)
229 00aa0040 Blue Swirl
#define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
230 73062dfe Stefan Weil
#define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
231 73062dfe Stefan Weil
    sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen)
232 00aa0040 Blue Swirl
#else
233 58455eb9 Stefan Weil
#define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
234 58455eb9 Stefan Weil
    getsockopt(sockfd, level, optname, optval, optlen)
235 58455eb9 Stefan Weil
#define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
236 58455eb9 Stefan Weil
    setsockopt(sockfd, level, optname, optval, optlen)
237 00aa0040 Blue Swirl
#define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
238 73062dfe Stefan Weil
#define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
239 73062dfe Stefan Weil
    sendto(sockfd, buf, len, flags, destaddr, addrlen)
240 00aa0040 Blue Swirl
#endif
241 00aa0040 Blue Swirl
242 87ecb68b pbrook
/* Error handling.  */
243 87ecb68b pbrook
244 e5924d89 Stefan Weil
void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
245 87ecb68b pbrook
246 87ecb68b pbrook
struct ParallelIOArg {
247 87ecb68b pbrook
    void *buffer;
248 87ecb68b pbrook
    int count;
249 87ecb68b pbrook
};
250 87ecb68b pbrook
251 87ecb68b pbrook
typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
252 87ecb68b pbrook
253 186993ee Michael S. Tsirkin
typedef uint64_t pcibus_t;
254 186993ee Michael S. Tsirkin
255 4e4fa398 Jan Kiszka
typedef enum LostTickPolicy {
256 4e4fa398 Jan Kiszka
    LOST_TICK_DISCARD,
257 4e4fa398 Jan Kiszka
    LOST_TICK_DELAY,
258 4e4fa398 Jan Kiszka
    LOST_TICK_MERGE,
259 4e4fa398 Jan Kiszka
    LOST_TICK_SLEW,
260 1ce05125 Paolo Bonzini
    LOST_TICK_MAX
261 4e4fa398 Jan Kiszka
} LostTickPolicy;
262 4e4fa398 Jan Kiszka
263 679042f0 Anthony PERARD
typedef struct PCIHostDeviceAddress {
264 679042f0 Anthony PERARD
    unsigned int domain;
265 679042f0 Anthony PERARD
    unsigned int bus;
266 679042f0 Anthony PERARD
    unsigned int slot;
267 679042f0 Anthony PERARD
    unsigned int function;
268 679042f0 Anthony PERARD
} PCIHostDeviceAddress;
269 679042f0 Anthony PERARD
270 d5ab9713 Jan Kiszka
void tcg_exec_init(unsigned long tb_size);
271 d5ab9713 Jan Kiszka
bool tcg_enabled(void);
272 d5ab9713 Jan Kiszka
273 d5ab9713 Jan Kiszka
void cpu_exec_init_all(void);
274 d2053c3c Blue Swirl
275 b3c7724c pbrook
/* CPU save/load.  */
276 b3c7724c pbrook
void cpu_save(QEMUFile *f, void *opaque);
277 b3c7724c pbrook
int cpu_load(QEMUFile *f, void *opaque, int version_id);
278 b3c7724c pbrook
279 8edac960 aliguori
/* Unblock cpu */
280 46d62fac Jan Kiszka
void qemu_cpu_kick_self(void);
281 8edac960 aliguori
282 e82bcec2 Marcelo Tosatti
/* work queue */
283 e82bcec2 Marcelo Tosatti
struct qemu_work_item {
284 e82bcec2 Marcelo Tosatti
    struct qemu_work_item *next;
285 e82bcec2 Marcelo Tosatti
    void (*func)(void *data);
286 e82bcec2 Marcelo Tosatti
    void *data;
287 e82bcec2 Marcelo Tosatti
    int done;
288 e82bcec2 Marcelo Tosatti
};
289 e82bcec2 Marcelo Tosatti
290 0bf46a40 aliguori
#ifdef CONFIG_USER_ONLY
291 0bf46a40 aliguori
#define qemu_init_vcpu(env) do { } while (0)
292 0bf46a40 aliguori
#else
293 0bf46a40 aliguori
void qemu_init_vcpu(void *env);
294 0bf46a40 aliguori
#endif
295 0bf46a40 aliguori
296 8c5135f9 Paolo Bonzini
297 8c5135f9 Paolo Bonzini
/**
298 2fc8ae1d Michael Tokarev
 * Sends a (part of) iovec down a socket, yielding when the socket is full, or
299 2fc8ae1d Michael Tokarev
 * Receives data into a (part of) iovec from a socket,
300 2fc8ae1d Michael Tokarev
 * yielding when there is no data in the socket.
301 2fc8ae1d Michael Tokarev
 * The same interface as qemu_sendv_recvv(), with added yielding.
302 2fc8ae1d Michael Tokarev
 * XXX should mark these as coroutine_fn
303 8c5135f9 Paolo Bonzini
 */
304 2fc8ae1d Michael Tokarev
ssize_t qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt,
305 2fc8ae1d Michael Tokarev
                            size_t offset, size_t bytes, bool do_send);
306 2fc8ae1d Michael Tokarev
#define qemu_co_recvv(sockfd, iov, iov_cnt, offset, bytes) \
307 2fc8ae1d Michael Tokarev
  qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, false)
308 2fc8ae1d Michael Tokarev
#define qemu_co_sendv(sockfd, iov, iov_cnt, offset, bytes) \
309 2fc8ae1d Michael Tokarev
  qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, true)
310 8c5135f9 Paolo Bonzini
311 8c5135f9 Paolo Bonzini
/**
312 2fc8ae1d Michael Tokarev
 * The same as above, but with just a single buffer
313 8c5135f9 Paolo Bonzini
 */
314 2fc8ae1d Michael Tokarev
ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send);
315 2fc8ae1d Michael Tokarev
#define qemu_co_recv(sockfd, buf, bytes) \
316 2fc8ae1d Michael Tokarev
  qemu_co_send_recv(sockfd, buf, bytes, false)
317 2fc8ae1d Michael Tokarev
#define qemu_co_send(sockfd, buf, bytes) \
318 2fc8ae1d Michael Tokarev
  qemu_co_send_recv(sockfd, buf, bytes, true)
319 8c5135f9 Paolo Bonzini
320 44e3ee8a aliguori
typedef struct QEMUIOVector {
321 44e3ee8a aliguori
    struct iovec *iov;
322 44e3ee8a aliguori
    int niov;
323 44e3ee8a aliguori
    int nalloc;
324 249aa745 aliguori
    size_t size;
325 44e3ee8a aliguori
} QEMUIOVector;
326 44e3ee8a aliguori
327 44e3ee8a aliguori
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
328 522584a5 aliguori
void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
329 44e3ee8a aliguori
void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
330 1b093c48 Michael Tokarev
void qemu_iovec_concat(QEMUIOVector *dst,
331 1b093c48 Michael Tokarev
                       QEMUIOVector *src, size_t soffset, size_t sbytes);
332 44e3ee8a aliguori
void qemu_iovec_destroy(QEMUIOVector *qiov);
333 be959463 aliguori
void qemu_iovec_reset(QEMUIOVector *qiov);
334 d5e6b161 Michael Tokarev
size_t qemu_iovec_to_buf(QEMUIOVector *qiov, size_t offset,
335 d5e6b161 Michael Tokarev
                         void *buf, size_t bytes);
336 03396148 Michael Tokarev
size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset,
337 03396148 Michael Tokarev
                           const void *buf, size_t bytes);
338 3d9b4925 Michael Tokarev
size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
339 3d9b4925 Michael Tokarev
                         int fillc, size_t bytes);
340 44e3ee8a aliguori
341 1a6d39fd Stefan Hajnoczi
bool buffer_is_zero(const void *buf, size_t len);
342 1a6d39fd Stefan Hajnoczi
343 6b837bc4 Jes Sorensen
void qemu_progress_init(int enabled, float min_skip);
344 6b837bc4 Jes Sorensen
void qemu_progress_end(void);
345 3bfe4dbf Jes Sorensen
void qemu_progress_print(float delta, int max);
346 31459f46 Ronnie Sahlberg
const char *qemu_get_vm_name(void);
347 6b837bc4 Jes Sorensen
348 082b5557 Blue Swirl
#define QEMU_FILE_TYPE_BIOS   0
349 082b5557 Blue Swirl
#define QEMU_FILE_TYPE_KEYMAP 1
350 082b5557 Blue Swirl
char *qemu_find_file(int type, const char *name);
351 082b5557 Blue Swirl
352 082b5557 Blue Swirl
/* OS specific functions */
353 082b5557 Blue Swirl
void os_setup_early_signal_handling(void);
354 082b5557 Blue Swirl
char *os_find_datadir(const char *argv0);
355 082b5557 Blue Swirl
void os_parse_cmd_args(int index, const char *optarg);
356 082b5557 Blue Swirl
void os_pidfile_error(void);
357 082b5557 Blue Swirl
358 abd0c6bd Paul Brook
/* Convert a byte between binary and BCD.  */
359 abd0c6bd Paul Brook
static inline uint8_t to_bcd(uint8_t val)
360 abd0c6bd Paul Brook
{
361 abd0c6bd Paul Brook
    return ((val / 10) << 4) | (val % 10);
362 abd0c6bd Paul Brook
}
363 abd0c6bd Paul Brook
364 abd0c6bd Paul Brook
static inline uint8_t from_bcd(uint8_t val)
365 abd0c6bd Paul Brook
{
366 abd0c6bd Paul Brook
    return ((val >> 4) * 10) + (val & 0x0f);
367 abd0c6bd Paul Brook
}
368 abd0c6bd Paul Brook
369 338b922e malc
/* compute with 96 bit intermediate result: (a*b)/c */
370 338b922e malc
static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
371 338b922e malc
{
372 338b922e malc
    union {
373 338b922e malc
        uint64_t ll;
374 338b922e malc
        struct {
375 338b922e malc
#ifdef HOST_WORDS_BIGENDIAN
376 338b922e malc
            uint32_t high, low;
377 338b922e malc
#else
378 338b922e malc
            uint32_t low, high;
379 338b922e malc
#endif
380 338b922e malc
        } l;
381 338b922e malc
    } u, res;
382 338b922e malc
    uint64_t rl, rh;
383 338b922e malc
384 338b922e malc
    u.ll = a;
385 338b922e malc
    rl = (uint64_t)u.l.low * (uint64_t)b;
386 338b922e malc
    rh = (uint64_t)u.l.high * (uint64_t)b;
387 338b922e malc
    rh += (rl >> 32);
388 338b922e malc
    res.l.high = rh / c;
389 338b922e malc
    res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c;
390 338b922e malc
    return res.ll;
391 338b922e malc
}
392 338b922e malc
393 3951690a Stefan Hajnoczi
/* Round number down to multiple */
394 3951690a Stefan Hajnoczi
#define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m))
395 3951690a Stefan Hajnoczi
396 3951690a Stefan Hajnoczi
/* Round number up to multiple */
397 3951690a Stefan Hajnoczi
#define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m))
398 3951690a Stefan Hajnoczi
399 9fb26641 Orit Wasserman
static inline bool is_power_of_2(uint64_t value)
400 9fb26641 Orit Wasserman
{
401 9fb26641 Orit Wasserman
    if (!value) {
402 9fb26641 Orit Wasserman
        return 0;
403 9fb26641 Orit Wasserman
    }
404 9fb26641 Orit Wasserman
405 9fb26641 Orit Wasserman
    return !(value & (value - 1));
406 9fb26641 Orit Wasserman
}
407 9fb26641 Orit Wasserman
408 9fb26641 Orit Wasserman
/* round down to the nearest power of 2*/
409 9fb26641 Orit Wasserman
int64_t pow2floor(int64_t value);
410 9fb26641 Orit Wasserman
411 1de7afc9 Paolo Bonzini
#include "qemu/module.h"
412 0bfe3ca5 Anthony Liguori
413 e6546bb9 Orit Wasserman
/*
414 e6546bb9 Orit Wasserman
 * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128)
415 e6546bb9 Orit Wasserman
 * Input is limited to 14-bit numbers
416 e6546bb9 Orit Wasserman
 */
417 e6546bb9 Orit Wasserman
418 e6546bb9 Orit Wasserman
int uleb128_encode_small(uint8_t *out, uint32_t n);
419 e6546bb9 Orit Wasserman
int uleb128_decode_small(const uint8_t *in, uint32_t *n);
420 e6546bb9 Orit Wasserman
421 faf07963 pbrook
#endif