blob: ac9985cc6d15e18ae8ff67fba709395ba69ba393 [file] [log] [blame]
Orit Wasserman9fb26642012-08-06 21:42:50 +03001
pbrookfaf07962007-11-11 02:51:17 +00002/* Common header file that is included by all of qemu. */
3#ifndef QEMU_COMMON_H
4#define QEMU_COMMON_H
5
Luiz Capitulino5c026322011-07-11 14:24:44 -03006#include "compiler.h"
Kevin Wolfbeb6f0d2010-01-15 12:56:41 +01007#include "config-host.h"
8
Paolo Bonzini332ae282011-07-28 12:10:28 +02009#if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
10#define WORDS_ALIGNED
11#endif
12
Blue Swirl082b5552011-03-27 09:04:57 +000013#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
Paolo Bonzini24ebf5f2010-02-18 21:25:23 +010014
Blue Swirl29e922b2010-03-29 19:24:00 +000015typedef struct QEMUTimer QEMUTimer;
16typedef struct QEMUFile QEMUFile;
Paolo Bonzinif627aab2012-10-29 23:45:23 +010017typedef struct QEMUBH QEMUBH;
Blue Swirl92a16d72010-06-19 07:47:42 +000018typedef struct DeviceState DeviceState;
Blue Swirl29e922b2010-03-29 19:24:00 +000019
Jan Kiszka316378e2011-03-02 08:56:09 +010020struct Monitor;
21typedef struct Monitor Monitor;
Isaku Yamahata6607ae22012-06-19 18:43:09 +030022typedef struct MigrationParams MigrationParams;
Jan Kiszka316378e2011-03-02 08:56:09 +010023
pbrookfaf07962007-11-11 02:51:17 +000024/* we put basic includes here to avoid repeating them in device drivers */
25#include <stdlib.h>
26#include <stdio.h>
27#include <stdarg.h>
Paul Brook11165822010-06-13 19:00:50 +010028#include <stdbool.h>
pbrookfaf07962007-11-11 02:51:17 +000029#include <string.h>
balrogc8906842008-11-12 17:18:41 +000030#include <strings.h>
pbrookfaf07962007-11-11 02:51:17 +000031#include <inttypes.h>
32#include <limits.h>
33#include <time.h>
34#include <ctype.h>
35#include <errno.h>
36#include <unistd.h>
37#include <fcntl.h>
38#include <sys/stat.h>
Hervé Poussineaudcfd0862011-03-06 13:23:13 +000039#include <sys/time.h>
Paul Brook55616502009-05-13 20:51:49 +010040#include <assert.h>
Alexandre Raymond86f69a92011-06-01 22:21:30 -040041#include <signal.h>
Anthony Liguori14015302011-08-20 22:18:37 -050042#include <glib.h>
pbrookfaf07962007-11-11 02:51:17 +000043
Blue Swirl082b5552011-03-27 09:04:57 +000044#ifdef _WIN32
45#include "qemu-os-win32.h"
46#endif
47
48#ifdef CONFIG_POSIX
49#include "qemu-os-posix.h"
50#endif
51
pbrookfaf07962007-11-11 02:51:17 +000052#ifndef O_LARGEFILE
53#define O_LARGEFILE 0
54#endif
55#ifndef O_BINARY
56#define O_BINARY 0
57#endif
Juan Quintela0e74e662009-07-27 16:12:57 +020058#ifndef MAP_ANONYMOUS
59#define MAP_ANONYMOUS MAP_ANON
60#endif
pbrookfaf07962007-11-11 02:51:17 +000061#ifndef ENOMEDIUM
62#define ENOMEDIUM ENODEV
63#endif
Anthony Liguori4c955382009-07-28 15:48:31 -050064#if !defined(ENOTSUP)
Juan Quintela2880bc32009-07-27 16:13:22 +020065#define ENOTSUP 4096
66#endif
Paolo Bonzini2084a8e2012-05-10 09:27:50 +020067#if !defined(ECANCELED)
68#define ECANCELED 4097
69#endif
Gerd Hoffmann3c9405a2010-10-07 11:50:45 +020070#ifndef TIME_MAX
71#define TIME_MAX LONG_MAX
72#endif
pbrookfaf07962007-11-11 02:51:17 +000073
Stefan Weilc0fd2602012-02-01 21:04:13 +010074/* HOST_LONG_BITS is the size of a native pointer in bits. */
75#if UINTPTR_MAX == UINT32_MAX
76# define HOST_LONG_BITS 32
77#elif UINTPTR_MAX == UINT64_MAX
78# define HOST_LONG_BITS 64
79#else
80# error Unknown pointer size
81#endif
82
Juan Quintela6114fdb2009-07-27 16:12:59 +020083#ifndef CONFIG_IOVEC
84#define CONFIG_IOVEC
aliguoribf9298b2008-12-05 20:05:26 +000085struct iovec {
86 void *iov_base;
87 size_t iov_len;
88};
Christoph Hellwige2a305f2010-01-26 14:49:08 +010089/*
90 * Use the same value as Linux for now.
91 */
92#define IOV_MAX 1024
blueswir1331dadd2008-12-06 19:44:56 +000093#else
94#include <sys/uio.h>
aliguoribf9298b2008-12-05 20:05:26 +000095#endif
96
Stefan Weilf8684452010-10-22 23:03:30 +020097typedef int (*fprintf_function)(FILE *f, const char *fmt, ...)
98 GCC_FMT_ATTR(2, 3);
99
pbrookfaf07962007-11-11 02:51:17 +0000100#ifdef _WIN32
pbrookfaf07962007-11-11 02:51:17 +0000101#define fsync _commit
Stefan Weil371c6482012-03-10 11:14:31 +0100102#if !defined(lseek)
103# define lseek _lseeki64
104#endif
Blue Swirl64b85a82011-01-23 16:21:20 +0000105int qemu_ftruncate64(int, int64_t);
Stefan Weil371c6482012-03-10 11:14:31 +0100106#if !defined(ftruncate)
107# define ftruncate qemu_ftruncate64
108#endif
pbrookfaf07962007-11-11 02:51:17 +0000109
pbrookfaf07962007-11-11 02:51:17 +0000110static inline char *realpath(const char *path, char *resolved_path)
111{
112 _fullpath(resolved_path, path, _MAX_PATH);
113 return resolved_path;
114}
pbrookfaf07962007-11-11 02:51:17 +0000115#endif
116
Paolo Bonzini946fb272011-09-12 13:57:37 +0200117/* icount */
118void configure_icount(const char *option);
119extern int use_icount;
120
pbrookfaf07962007-11-11 02:51:17 +0000121/* FIXME: Remove NEED_CPU_H. */
122#ifndef NEED_CPU_H
123
pbrookfaf07962007-11-11 02:51:17 +0000124#include "osdep.h"
125#include "bswap.h"
126
127#else
128
129#include "cpu.h"
130
131#endif /* !defined(NEED_CPU_H) */
132
Andreas Färber3bbbee12011-05-29 19:42:51 +0200133/* main function, renamed */
134#if defined(CONFIG_COCOA)
135int qemu_main(int argc, char **argv, char **envp);
136#endif
137
balrogf6503052008-02-17 11:42:19 +0000138void qemu_get_timedate(struct tm *tm, int offset);
139int qemu_timedate_diff(struct tm *tm);
140
Peter Maydellc8057f92012-08-02 13:45:54 +0100141/**
142 * is_help_option:
143 * @s: string to test
144 *
145 * Check whether @s is one of the standard strings which indicate
146 * that the user is asking for a list of the valid values for a
147 * command option like -cpu or -M. The current accepted strings
148 * are 'help' and '?'. '?' is deprecated (it is a shell wildcard
149 * which makes it annoying to use in a reliable way) but provided
150 * for backwards compatibility.
151 *
152 * Returns: true if @s is a request for a list.
153 */
154static inline bool is_help_option(const char *s)
155{
156 return !strcmp(s, "?") || !strcmp(s, "help");
157}
158
pbrookfaf07962007-11-11 02:51:17 +0000159/* cutils.c */
160void pstrcpy(char *buf, int buf_size, const char *str);
Dmitry Fleytman2a025ae2012-07-09 08:50:43 +0200161void strpadcpy(char *buf, int buf_size, const char *str, char pad);
pbrookfaf07962007-11-11 02:51:17 +0000162char *pstrcat(char *buf, int buf_size, const char *s);
163int strstart(const char *str, const char *val, const char **ptr);
164int stristart(const char *str, const char *val, const char **ptr);
Blue Swirld43277c2009-07-01 18:24:44 +0000165int qemu_strnlen(const char *s, int max_len);
pbrookfaf07962007-11-11 02:51:17 +0000166time_t mktimegm(struct tm *tm);
blueswir1ad46db92008-12-11 19:37:54 +0000167int qemu_fls(int i);
Christoph Hellwig6f1953c2009-09-04 19:01:32 +0200168int qemu_fdatasync(int fd);
Paolo Bonzinidb1a4972010-03-10 11:38:55 +0100169int fcntl_setfl(int fd, int flag);
Stefan Berger443916d2011-09-28 06:41:32 -0400170int qemu_parse_fd(const char *param);
Jes Sorensend8427002010-12-09 14:17:24 +0100171
Jes Sorensend7142452011-01-26 11:54:58 +0100172/*
173 * strtosz() suffixes used to specify the default treatment of an
174 * argument passed to strtosz() without an explicit suffix.
175 * These should be defined using upper case characters in the range
176 * A-Z, as strtosz() will use qemu_toupper() on the given argument
177 * prior to comparison.
178 */
Jes Sorensend8427002010-12-09 14:17:24 +0100179#define STRTOSZ_DEFSUFFIX_TB 'T'
180#define STRTOSZ_DEFSUFFIX_GB 'G'
181#define STRTOSZ_DEFSUFFIX_MB 'M'
182#define STRTOSZ_DEFSUFFIX_KB 'K'
183#define STRTOSZ_DEFSUFFIX_B 'B'
Jes Sorensen70b4f4b2011-01-05 11:41:02 +0100184int64_t strtosz(const char *nptr, char **end);
185int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
Joerg Roedela732e1b2011-07-07 16:13:11 +0200186int64_t strtosz_suffix_unit(const char *nptr, char **end,
187 const char default_suffix, int64_t unit);
pbrookfaf07962007-11-11 02:51:17 +0000188
Blue Swirl37022082009-08-15 07:51:59 +0000189/* path.c */
190void init_paths(const char *prefix);
191const char *path(const char *pathname);
192
blueswir1cd390082008-11-16 13:53:32 +0000193#define qemu_isalnum(c) isalnum((unsigned char)(c))
194#define qemu_isalpha(c) isalpha((unsigned char)(c))
195#define qemu_iscntrl(c) iscntrl((unsigned char)(c))
196#define qemu_isdigit(c) isdigit((unsigned char)(c))
197#define qemu_isgraph(c) isgraph((unsigned char)(c))
198#define qemu_islower(c) islower((unsigned char)(c))
199#define qemu_isprint(c) isprint((unsigned char)(c))
200#define qemu_ispunct(c) ispunct((unsigned char)(c))
201#define qemu_isspace(c) isspace((unsigned char)(c))
202#define qemu_isupper(c) isupper((unsigned char)(c))
203#define qemu_isxdigit(c) isxdigit((unsigned char)(c))
204#define qemu_tolower(c) tolower((unsigned char)(c))
205#define qemu_toupper(c) toupper((unsigned char)(c))
206#define qemu_isascii(c) isascii((unsigned char)(c))
207#define qemu_toascii(c) toascii((unsigned char)(c))
208
Jes Sorensenb152aa82010-10-26 10:39:26 +0200209void *qemu_oom_check(void *ptr);
aurel32ca10f862008-04-11 21:35:42 +0000210
Kevin Wolf40ff6d72009-12-02 12:24:42 +0100211int qemu_open(const char *name, int flags, ...);
Corey Bryant2e1e79d2012-08-14 16:43:46 -0400212int qemu_close(int fd);
Juan Quintela7c7c0622010-01-20 00:56:09 +0100213ssize_t qemu_write_full(int fd, const void *buf, size_t count)
214 QEMU_WARN_UNUSED_RESULT;
Paolo Bonzini993295f2011-09-17 16:27:59 +0200215ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags)
216 QEMU_WARN_UNUSED_RESULT;
Paolo Bonzini8c5135f2011-09-08 13:46:25 +0200217ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags)
Paolo Bonzini993295f2011-09-17 16:27:59 +0200218 QEMU_WARN_UNUSED_RESULT;
Kevin Wolf40ff6d72009-12-02 12:24:42 +0100219
220#ifndef _WIN32
221int qemu_pipe(int pipefd[2]);
222#endif
223
Blue Swirl00aa0042011-07-23 20:04:29 +0000224#ifdef _WIN32
Stefan Weil58455eb2012-09-28 19:07:39 +0200225/* MinGW needs type casts for the 'buf' and 'optval' arguments. */
226#define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
227 getsockopt(sockfd, level, optname, (void *)optval, optlen)
228#define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
229 setsockopt(sockfd, level, optname, (const void *)optval, optlen)
Blue Swirl00aa0042011-07-23 20:04:29 +0000230#define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
Stefan Weil73062df2012-09-22 21:13:28 +0200231#define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
232 sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen)
Blue Swirl00aa0042011-07-23 20:04:29 +0000233#else
Stefan Weil58455eb2012-09-28 19:07:39 +0200234#define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
235 getsockopt(sockfd, level, optname, optval, optlen)
236#define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
237 setsockopt(sockfd, level, optname, optval, optlen)
Blue Swirl00aa0042011-07-23 20:04:29 +0000238#define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
Stefan Weil73062df2012-09-22 21:13:28 +0200239#define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
240 sendto(sockfd, buf, len, flags, destaddr, addrlen)
Blue Swirl00aa0042011-07-23 20:04:29 +0000241#endif
242
pbrook87ecb682007-11-17 17:14:51 +0000243/* Error handling. */
244
Stefan Weile5924d82010-09-23 21:28:03 +0200245void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
pbrook87ecb682007-11-17 17:14:51 +0000246
pbrook87ecb682007-11-17 17:14:51 +0000247struct ParallelIOArg {
248 void *buffer;
249 int count;
250};
251
252typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
253
254/* A load of opaque types so that device init declarations don't have to
255 pull in all the real definitions. */
256typedef struct NICInfo NICInfo;
balrog1ae26a12008-09-28 23:19:47 +0000257typedef struct HCIInfo HCIInfo;
pbrook87ecb682007-11-17 17:14:51 +0000258typedef struct AudioState AudioState;
259typedef struct BlockDriverState BlockDriverState;
Blue Swirl24463332010-08-24 15:22:24 +0000260typedef struct DriveInfo DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000261typedef struct DisplayState DisplayState;
aliguori7d957bd2009-01-15 22:14:11 +0000262typedef struct DisplayChangeListener DisplayChangeListener;
263typedef struct DisplaySurface DisplaySurface;
264typedef struct PixelFormat PixelFormat;
Gerd Hoffmann76ffb0b2012-09-28 13:24:17 +0200265typedef struct QemuConsole QemuConsole;
pbrook87ecb682007-11-17 17:14:51 +0000266typedef struct CharDriverState CharDriverState;
Gerd Hoffmann76d32cb2009-10-21 15:25:22 +0200267typedef struct MACAddr MACAddr;
Stefan Hajnoczi4e68f7a2012-07-24 16:35:13 +0100268typedef struct NetClientState NetClientState;
pbrook87ecb682007-11-17 17:14:51 +0000269typedef struct i2c_bus i2c_bus;
Hervé Poussineau48a18b32011-12-15 22:09:51 +0100270typedef struct ISABus ISABus;
Markus Armbrusterdfc65f12012-05-11 17:22:19 +0200271typedef struct ISADevice ISADevice;
pbrook87ecb682007-11-17 17:14:51 +0000272typedef struct SMBusDevice SMBusDevice;
Isaku Yamahatafb47a2e2009-11-12 14:58:41 +0900273typedef struct PCIHostState PCIHostState;
274typedef struct PCIExpressHost PCIExpressHost;
pbrook87ecb682007-11-17 17:14:51 +0000275typedef struct PCIBus PCIBus;
276typedef struct PCIDevice PCIDevice;
Isaku Yamahata04285272010-10-19 18:06:34 +0900277typedef struct PCIExpressDevice PCIExpressDevice;
Isaku Yamahata68f79992010-07-13 13:01:42 +0900278typedef struct PCIBridge PCIBridge;
Isaku Yamahata34e65942010-11-16 17:26:09 +0900279typedef struct PCIEAERMsg PCIEAERMsg;
280typedef struct PCIEAERLog PCIEAERLog;
281typedef struct PCIEAERErr PCIEAERErr;
Isaku Yamahatabc20ba92010-10-20 17:18:52 +0900282typedef struct PCIEPort PCIEPort;
283typedef struct PCIESlot PCIESlot;
Jan Kiszka14de9ba2012-05-16 15:41:09 -0300284typedef struct MSIMessage MSIMessage;
pbrook87ecb682007-11-17 17:14:51 +0000285typedef struct SerialState SerialState;
286typedef struct IRQState *qemu_irq;
Paul Brookbc24a222009-05-10 01:44:56 +0100287typedef struct PCMCIACardState PCMCIACardState;
288typedef struct MouseTransformInfo MouseTransformInfo;
289typedef struct uWireSlave uWireSlave;
290typedef struct I2SCodec I2SCodec;
Paul Brook90d37232009-05-14 22:35:09 +0100291typedef struct SSIBus SSIBus;
Michael S. Tsirkin2292b332010-03-17 13:07:58 +0200292typedef struct EventNotifier EventNotifier;
Michael S. Tsirkin2be24aa2010-03-17 13:08:10 +0200293typedef struct VirtIODevice VirtIODevice;
Gerd Hoffmannd35bf9a2011-07-12 13:36:23 +0200294typedef struct QEMUSGList QEMUSGList;
Michael S. Tsirkin1dc324d2012-02-12 14:12:21 +0200295typedef struct SHPCDevice SHPCDevice;
pbrook87ecb682007-11-17 17:14:51 +0000296
Michael S. Tsirkin186993e2010-02-10 21:25:42 +0200297typedef uint64_t pcibus_t;
298
Jan Kiszka4e4fa392012-01-23 20:15:11 +0100299typedef enum LostTickPolicy {
300 LOST_TICK_DISCARD,
301 LOST_TICK_DELAY,
302 LOST_TICK_MERGE,
303 LOST_TICK_SLEW,
Paolo Bonzini1ce05122012-02-02 22:09:44 +0100304 LOST_TICK_MAX
Jan Kiszka4e4fa392012-01-23 20:15:11 +0100305} LostTickPolicy;
306
Anthony PERARD679042f2012-06-21 15:36:23 +0000307typedef struct PCIHostDeviceAddress {
308 unsigned int domain;
309 unsigned int bus;
310 unsigned int slot;
311 unsigned int function;
312} PCIHostDeviceAddress;
313
Jan Kiszkad5ab9712011-08-02 16:10:21 +0200314void tcg_exec_init(unsigned long tb_size);
315bool tcg_enabled(void);
316
317void cpu_exec_init_all(void);
Blue Swirld2053c32010-03-29 19:23:48 +0000318
pbrookb3c77242008-06-30 16:31:04 +0000319/* CPU save/load. */
320void cpu_save(QEMUFile *f, void *opaque);
321int cpu_load(QEMUFile *f, void *opaque, int version_id);
322
aliguori8edac962009-04-24 18:03:45 +0000323/* Unblock cpu */
Jan Kiszka46d62fa2011-02-01 22:15:59 +0100324void qemu_cpu_kick_self(void);
aliguori8edac962009-04-24 18:03:45 +0000325
Marcelo Tosattie82bcec2010-05-04 09:45:22 -0300326/* work queue */
327struct qemu_work_item {
328 struct qemu_work_item *next;
329 void (*func)(void *data);
330 void *data;
331 int done;
332};
333
aliguori0bf46a42009-04-24 18:03:41 +0000334#ifdef CONFIG_USER_ONLY
335#define qemu_init_vcpu(env) do { } while (0)
336#else
337void qemu_init_vcpu(void *env);
338#endif
339
Paolo Bonzini8c5135f2011-09-08 13:46:25 +0200340
341/**
Michael Tokarev2fc8ae12012-06-07 20:22:46 +0400342 * Sends a (part of) iovec down a socket, yielding when the socket is full, or
343 * Receives data into a (part of) iovec from a socket,
344 * yielding when there is no data in the socket.
345 * The same interface as qemu_sendv_recvv(), with added yielding.
346 * XXX should mark these as coroutine_fn
Paolo Bonzini8c5135f2011-09-08 13:46:25 +0200347 */
Michael Tokarev2fc8ae12012-06-07 20:22:46 +0400348ssize_t qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt,
349 size_t offset, size_t bytes, bool do_send);
350#define qemu_co_recvv(sockfd, iov, iov_cnt, offset, bytes) \
351 qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, false)
352#define qemu_co_sendv(sockfd, iov, iov_cnt, offset, bytes) \
353 qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, true)
Paolo Bonzini8c5135f2011-09-08 13:46:25 +0200354
355/**
Michael Tokarev2fc8ae12012-06-07 20:22:46 +0400356 * The same as above, but with just a single buffer
Paolo Bonzini8c5135f2011-09-08 13:46:25 +0200357 */
Michael Tokarev2fc8ae12012-06-07 20:22:46 +0400358ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send);
359#define qemu_co_recv(sockfd, buf, bytes) \
360 qemu_co_send_recv(sockfd, buf, bytes, false)
361#define qemu_co_send(sockfd, buf, bytes) \
362 qemu_co_send_recv(sockfd, buf, bytes, true)
Paolo Bonzini8c5135f2011-09-08 13:46:25 +0200363
aliguori44e3ee82009-01-22 16:59:20 +0000364typedef struct QEMUIOVector {
365 struct iovec *iov;
366 int niov;
367 int nalloc;
aliguori249aa742009-01-26 17:17:52 +0000368 size_t size;
aliguori44e3ee82009-01-22 16:59:20 +0000369} QEMUIOVector;
370
371void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
aliguori522584a2009-03-28 17:46:10 +0000372void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
aliguori44e3ee82009-01-22 16:59:20 +0000373void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
Michael Tokarev1b093c42012-03-12 21:28:06 +0400374void qemu_iovec_concat(QEMUIOVector *dst,
375 QEMUIOVector *src, size_t soffset, size_t sbytes);
aliguori44e3ee82009-01-22 16:59:20 +0000376void qemu_iovec_destroy(QEMUIOVector *qiov);
aliguoribe959462009-02-05 21:23:54 +0000377void qemu_iovec_reset(QEMUIOVector *qiov);
Michael Tokarevd5e6b162012-06-07 20:21:06 +0400378size_t qemu_iovec_to_buf(QEMUIOVector *qiov, size_t offset,
379 void *buf, size_t bytes);
Michael Tokarev03396142012-06-07 20:17:55 +0400380size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset,
381 const void *buf, size_t bytes);
Michael Tokarev3d9b4922012-03-10 16:54:23 +0400382size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
383 int fillc, size_t bytes);
aliguori44e3ee82009-01-22 16:59:20 +0000384
Stefan Hajnoczi1a6d39f2012-02-07 13:27:24 +0000385bool buffer_is_zero(const void *buf, size_t len);
386
Jes Sorensen6b837bc2011-03-30 14:16:25 +0200387void qemu_progress_init(int enabled, float min_skip);
388void qemu_progress_end(void);
Jes Sorensen3bfe4db2011-05-09 17:32:20 +0200389void qemu_progress_print(float delta, int max);
Ronnie Sahlberg31459f42012-08-06 18:24:55 +1000390const char *qemu_get_vm_name(void);
Jes Sorensen6b837bc2011-03-30 14:16:25 +0200391
Blue Swirl082b5552011-03-27 09:04:57 +0000392#define QEMU_FILE_TYPE_BIOS 0
393#define QEMU_FILE_TYPE_KEYMAP 1
394char *qemu_find_file(int type, const char *name);
395
396/* OS specific functions */
397void os_setup_early_signal_handling(void);
398char *os_find_datadir(const char *argv0);
399void os_parse_cmd_args(int index, const char *optarg);
400void os_pidfile_error(void);
401
Paul Brookabd0c6b2009-11-20 00:03:47 +0000402/* Convert a byte between binary and BCD. */
403static inline uint8_t to_bcd(uint8_t val)
404{
405 return ((val / 10) << 4) | (val % 10);
406}
407
408static inline uint8_t from_bcd(uint8_t val)
409{
410 return ((val >> 4) * 10) + (val & 0x0f);
411}
412
malc338b9222010-10-30 01:41:01 +0400413/* compute with 96 bit intermediate result: (a*b)/c */
414static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
415{
416 union {
417 uint64_t ll;
418 struct {
419#ifdef HOST_WORDS_BIGENDIAN
420 uint32_t high, low;
421#else
422 uint32_t low, high;
423#endif
424 } l;
425 } u, res;
426 uint64_t rl, rh;
427
428 u.ll = a;
429 rl = (uint64_t)u.l.low * (uint64_t)b;
430 rh = (uint64_t)u.l.high * (uint64_t)b;
431 rh += (rl >> 32);
432 res.l.high = rh / c;
433 res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c;
434 return res.ll;
435}
436
Stefan Hajnoczi39516902011-11-17 13:40:25 +0000437/* Round number down to multiple */
438#define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m))
439
440/* Round number up to multiple */
441#define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m))
442
Orit Wasserman9fb26642012-08-06 21:42:50 +0300443static inline bool is_power_of_2(uint64_t value)
444{
445 if (!value) {
446 return 0;
447 }
448
449 return !(value & (value - 1));
450}
451
452/* round down to the nearest power of 2*/
453int64_t pow2floor(int64_t value);
454
Anthony Liguori0bfe3ca2009-05-14 19:29:53 +0100455#include "module.h"
456
Orit Wassermane6546bb2012-08-06 21:42:51 +0300457/*
458 * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128)
459 * Input is limited to 14-bit numbers
460 */
461
462int uleb128_encode_small(uint8_t *out, uint32_t n);
463int uleb128_decode_small(const uint8_t *in, uint32_t *n);
464
pbrookfaf07962007-11-11 02:51:17 +0000465#endif