]>
Commit | Line | Data |
---|---|---|
faf07963 PB |
1 | /* Common header file that is included by all of qemu. */ |
2 | #ifndef QEMU_COMMON_H | |
3 | #define QEMU_COMMON_H | |
4 | ||
5c026320 | 5 | #include "compiler.h" |
beb6f0de KW |
6 | #include "config-host.h" |
7 | ||
332ae28d PB |
8 | #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__) |
9 | #define WORDS_ALIGNED | |
10 | #endif | |
11 | ||
082b5557 | 12 | #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) |
24ebf5f3 | 13 | |
29e922b6 BS |
14 | typedef struct QEMUTimer QEMUTimer; |
15 | typedef struct QEMUFile QEMUFile; | |
16 | typedef struct QEMUBH QEMUBH; | |
92a16d7a | 17 | typedef struct DeviceState DeviceState; |
29e922b6 | 18 | |
316378e4 JK |
19 | struct Monitor; |
20 | typedef struct Monitor Monitor; | |
21 | ||
faf07963 PB |
22 | /* we put basic includes here to avoid repeating them in device drivers */ |
23 | #include <stdlib.h> | |
24 | #include <stdio.h> | |
25 | #include <stdarg.h> | |
11165820 | 26 | #include <stdbool.h> |
faf07963 | 27 | #include <string.h> |
c8906845 | 28 | #include <strings.h> |
faf07963 PB |
29 | #include <inttypes.h> |
30 | #include <limits.h> | |
31 | #include <time.h> | |
32 | #include <ctype.h> | |
33 | #include <errno.h> | |
34 | #include <unistd.h> | |
35 | #include <fcntl.h> | |
36 | #include <sys/stat.h> | |
dcfd0865 | 37 | #include <sys/time.h> |
55616505 | 38 | #include <assert.h> |
86f69a92 | 39 | #include <signal.h> |
14015304 | 40 | #include <glib.h> |
faf07963 | 41 | |
082b5557 BS |
42 | #ifdef _WIN32 |
43 | #include "qemu-os-win32.h" | |
44 | #endif | |
45 | ||
46 | #ifdef CONFIG_POSIX | |
47 | #include "qemu-os-posix.h" | |
48 | #endif | |
49 | ||
faf07963 PB |
50 | #ifndef O_LARGEFILE |
51 | #define O_LARGEFILE 0 | |
52 | #endif | |
53 | #ifndef O_BINARY | |
54 | #define O_BINARY 0 | |
55 | #endif | |
0e74e66b JQ |
56 | #ifndef MAP_ANONYMOUS |
57 | #define MAP_ANONYMOUS MAP_ANON | |
58 | #endif | |
faf07963 PB |
59 | #ifndef ENOMEDIUM |
60 | #define ENOMEDIUM ENODEV | |
61 | #endif | |
4c955388 | 62 | #if !defined(ENOTSUP) |
2880bc32 JQ |
63 | #define ENOTSUP 4096 |
64 | #endif | |
3c9405a0 GH |
65 | #ifndef TIME_MAX |
66 | #define TIME_MAX LONG_MAX | |
67 | #endif | |
faf07963 | 68 | |
6114fdb0 JQ |
69 | #ifndef CONFIG_IOVEC |
70 | #define CONFIG_IOVEC | |
bf9298b9 AL |
71 | struct iovec { |
72 | void *iov_base; | |
73 | size_t iov_len; | |
74 | }; | |
e2a305fb CH |
75 | /* |
76 | * Use the same value as Linux for now. | |
77 | */ | |
78 | #define IOV_MAX 1024 | |
331dadde BS |
79 | #else |
80 | #include <sys/uio.h> | |
bf9298b9 AL |
81 | #endif |
82 | ||
f868445a SW |
83 | typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) |
84 | GCC_FMT_ATTR(2, 3); | |
85 | ||
faf07963 | 86 | #ifdef _WIN32 |
faf07963 PB |
87 | #define fsync _commit |
88 | #define lseek _lseeki64 | |
64b85a8f | 89 | int qemu_ftruncate64(int, int64_t); |
faf07963 PB |
90 | #define ftruncate qemu_ftruncate64 |
91 | ||
faf07963 PB |
92 | static inline char *realpath(const char *path, char *resolved_path) |
93 | { | |
94 | _fullpath(resolved_path, path, _MAX_PATH); | |
95 | return resolved_path; | |
96 | } | |
faf07963 PB |
97 | #endif |
98 | ||
99 | /* FIXME: Remove NEED_CPU_H. */ | |
100 | #ifndef NEED_CPU_H | |
101 | ||
faf07963 PB |
102 | #include "osdep.h" |
103 | #include "bswap.h" | |
104 | ||
105 | #else | |
106 | ||
107 | #include "cpu.h" | |
108 | ||
109 | #endif /* !defined(NEED_CPU_H) */ | |
110 | ||
3bbbee18 AF |
111 | /* main function, renamed */ |
112 | #if defined(CONFIG_COCOA) | |
113 | int qemu_main(int argc, char **argv, char **envp); | |
114 | #endif | |
115 | ||
faf07963 | 116 | /* bottom halves */ |
faf07963 PB |
117 | typedef void QEMUBHFunc(void *opaque); |
118 | ||
119 | QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque); | |
120 | void qemu_bh_schedule(QEMUBH *bh); | |
80d3580b AL |
121 | /* Bottom halfs that are scheduled from a bottom half handler are instantly |
122 | * invoked. This can create an infinite loop if a bottom half handler | |
123 | * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by | |
124 | * ensuring that the bottom half isn't executed until the next main loop | |
125 | * iteration. | |
126 | */ | |
1b435b10 | 127 | void qemu_bh_schedule_idle(QEMUBH *bh); |
faf07963 PB |
128 | void qemu_bh_cancel(QEMUBH *bh); |
129 | void qemu_bh_delete(QEMUBH *bh); | |
130 | int qemu_bh_poll(void); | |
4f999d05 | 131 | void qemu_bh_update_timeout(int *timeout); |
faf07963 | 132 | |
f6503059 AZ |
133 | void qemu_get_timedate(struct tm *tm, int offset); |
134 | int qemu_timedate_diff(struct tm *tm); | |
135 | ||
faf07963 PB |
136 | /* cutils.c */ |
137 | void pstrcpy(char *buf, int buf_size, const char *str); | |
138 | char *pstrcat(char *buf, int buf_size, const char *s); | |
139 | int strstart(const char *str, const char *val, const char **ptr); | |
140 | int stristart(const char *str, const char *val, const char **ptr); | |
d43277c5 | 141 | int qemu_strnlen(const char *s, int max_len); |
faf07963 | 142 | time_t mktimegm(struct tm *tm); |
ad46db9a | 143 | int qemu_fls(int i); |
6f1953c4 | 144 | int qemu_fdatasync(int fd); |
db1a4972 | 145 | int fcntl_setfl(int fd, int flag); |
d8427002 | 146 | |
d7142456 JS |
147 | /* |
148 | * strtosz() suffixes used to specify the default treatment of an | |
149 | * argument passed to strtosz() without an explicit suffix. | |
150 | * These should be defined using upper case characters in the range | |
151 | * A-Z, as strtosz() will use qemu_toupper() on the given argument | |
152 | * prior to comparison. | |
153 | */ | |
d8427002 JS |
154 | #define STRTOSZ_DEFSUFFIX_TB 'T' |
155 | #define STRTOSZ_DEFSUFFIX_GB 'G' | |
156 | #define STRTOSZ_DEFSUFFIX_MB 'M' | |
157 | #define STRTOSZ_DEFSUFFIX_KB 'K' | |
158 | #define STRTOSZ_DEFSUFFIX_B 'B' | |
70b4f4bb JS |
159 | int64_t strtosz(const char *nptr, char **end); |
160 | int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix); | |
a732e1ba JR |
161 | int64_t strtosz_suffix_unit(const char *nptr, char **end, |
162 | const char default_suffix, int64_t unit); | |
faf07963 | 163 | |
37022086 BS |
164 | /* path.c */ |
165 | void init_paths(const char *prefix); | |
166 | const char *path(const char *pathname); | |
167 | ||
cd390083 BS |
168 | #define qemu_isalnum(c) isalnum((unsigned char)(c)) |
169 | #define qemu_isalpha(c) isalpha((unsigned char)(c)) | |
170 | #define qemu_iscntrl(c) iscntrl((unsigned char)(c)) | |
171 | #define qemu_isdigit(c) isdigit((unsigned char)(c)) | |
172 | #define qemu_isgraph(c) isgraph((unsigned char)(c)) | |
173 | #define qemu_islower(c) islower((unsigned char)(c)) | |
174 | #define qemu_isprint(c) isprint((unsigned char)(c)) | |
175 | #define qemu_ispunct(c) ispunct((unsigned char)(c)) | |
176 | #define qemu_isspace(c) isspace((unsigned char)(c)) | |
177 | #define qemu_isupper(c) isupper((unsigned char)(c)) | |
178 | #define qemu_isxdigit(c) isxdigit((unsigned char)(c)) | |
179 | #define qemu_tolower(c) tolower((unsigned char)(c)) | |
180 | #define qemu_toupper(c) toupper((unsigned char)(c)) | |
181 | #define qemu_isascii(c) isascii((unsigned char)(c)) | |
182 | #define qemu_toascii(c) toascii((unsigned char)(c)) | |
183 | ||
b152aa84 | 184 | void *qemu_oom_check(void *ptr); |
ca10f867 | 185 | |
d549db5a GC |
186 | void qemu_mutex_lock_iothread(void); |
187 | void qemu_mutex_unlock_iothread(void); | |
188 | ||
40ff6d7e | 189 | int qemu_open(const char *name, int flags, ...); |
7c7c0629 JQ |
190 | ssize_t qemu_write_full(int fd, const void *buf, size_t count) |
191 | QEMU_WARN_UNUSED_RESULT; | |
40ff6d7e KW |
192 | void qemu_set_cloexec(int fd); |
193 | ||
194 | #ifndef _WIN32 | |
4d54ec78 | 195 | int qemu_add_child_watch(pid_t pid); |
f3dfda61 | 196 | int qemu_eventfd(int pipefd[2]); |
40ff6d7e KW |
197 | int qemu_pipe(int pipefd[2]); |
198 | #endif | |
199 | ||
00aa0040 BS |
200 | #ifdef _WIN32 |
201 | #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags) | |
202 | #else | |
203 | #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags) | |
204 | #endif | |
205 | ||
87ecb68b PB |
206 | /* Error handling. */ |
207 | ||
e5924d89 | 208 | void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2); |
87ecb68b PB |
209 | |
210 | /* IO callbacks. */ | |
211 | typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size); | |
7b27a769 | 212 | typedef int IOCanReadHandler(void *opaque); |
87ecb68b PB |
213 | typedef void IOHandler(void *opaque); |
214 | ||
02981419 PB |
215 | void qemu_iohandler_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set *xfds); |
216 | void qemu_iohandler_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds, int rc); | |
217 | ||
87ecb68b PB |
218 | struct ParallelIOArg { |
219 | void *buffer; | |
220 | int count; | |
221 | }; | |
222 | ||
223 | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); | |
224 | ||
225 | /* A load of opaque types so that device init declarations don't have to | |
226 | pull in all the real definitions. */ | |
227 | typedef struct NICInfo NICInfo; | |
1ae26a18 | 228 | typedef struct HCIInfo HCIInfo; |
87ecb68b PB |
229 | typedef struct AudioState AudioState; |
230 | typedef struct BlockDriverState BlockDriverState; | |
2446333c | 231 | typedef struct DriveInfo DriveInfo; |
87ecb68b | 232 | typedef struct DisplayState DisplayState; |
7d957bd8 AL |
233 | typedef struct DisplayChangeListener DisplayChangeListener; |
234 | typedef struct DisplaySurface DisplaySurface; | |
7b5d76da | 235 | typedef struct DisplayAllocator DisplayAllocator; |
7d957bd8 | 236 | typedef struct PixelFormat PixelFormat; |
87ecb68b | 237 | typedef struct TextConsole TextConsole; |
c60e08d9 | 238 | typedef TextConsole QEMUConsole; |
87ecb68b | 239 | typedef struct CharDriverState CharDriverState; |
76d32cba | 240 | typedef struct MACAddr MACAddr; |
87ecb68b | 241 | typedef struct VLANState VLANState; |
f7105843 | 242 | typedef struct VLANClientState VLANClientState; |
87ecb68b PB |
243 | typedef struct i2c_bus i2c_bus; |
244 | typedef struct i2c_slave i2c_slave; | |
245 | typedef struct SMBusDevice SMBusDevice; | |
fb47a2e9 IY |
246 | typedef struct PCIHostState PCIHostState; |
247 | typedef struct PCIExpressHost PCIExpressHost; | |
87ecb68b PB |
248 | typedef struct PCIBus PCIBus; |
249 | typedef struct PCIDevice PCIDevice; | |
0428527c | 250 | typedef struct PCIExpressDevice PCIExpressDevice; |
68f79994 | 251 | typedef struct PCIBridge PCIBridge; |
34e65944 IY |
252 | typedef struct PCIEAERMsg PCIEAERMsg; |
253 | typedef struct PCIEAERLog PCIEAERLog; | |
254 | typedef struct PCIEAERErr PCIEAERErr; | |
bc20ba98 IY |
255 | typedef struct PCIEPort PCIEPort; |
256 | typedef struct PCIESlot PCIESlot; | |
87ecb68b PB |
257 | typedef struct SerialState SerialState; |
258 | typedef struct IRQState *qemu_irq; | |
bc24a225 PB |
259 | typedef struct PCMCIACardState PCMCIACardState; |
260 | typedef struct MouseTransformInfo MouseTransformInfo; | |
261 | typedef struct uWireSlave uWireSlave; | |
262 | typedef struct I2SCodec I2SCodec; | |
90d37239 | 263 | typedef struct SSIBus SSIBus; |
2292b339 | 264 | typedef struct EventNotifier EventNotifier; |
2be24aaa | 265 | typedef struct VirtIODevice VirtIODevice; |
d35bf9ad | 266 | typedef struct QEMUSGList QEMUSGList; |
87ecb68b | 267 | |
186993ee MT |
268 | typedef uint64_t pcibus_t; |
269 | ||
d5ab9713 JK |
270 | void tcg_exec_init(unsigned long tb_size); |
271 | bool tcg_enabled(void); | |
272 | ||
273 | void cpu_exec_init_all(void); | |
d2053c3c | 274 | |
b3c7724c PB |
275 | /* CPU save/load. */ |
276 | void cpu_save(QEMUFile *f, void *opaque); | |
277 | int cpu_load(QEMUFile *f, void *opaque, int version_id); | |
278 | ||
d9f75a4e AL |
279 | /* Force QEMU to process pending events */ |
280 | void qemu_notify_event(void); | |
281 | ||
8edac960 AL |
282 | /* Unblock cpu */ |
283 | void qemu_cpu_kick(void *env); | |
46d62fac | 284 | void qemu_cpu_kick_self(void); |
b7680cb6 | 285 | int qemu_cpu_is_self(void *env); |
ab33fcda | 286 | bool all_cpu_threads_idle(void); |
8edac960 | 287 | |
e82bcec2 MT |
288 | /* work queue */ |
289 | struct qemu_work_item { | |
290 | struct qemu_work_item *next; | |
291 | void (*func)(void *data); | |
292 | void *data; | |
293 | int done; | |
294 | }; | |
295 | ||
0bf46a40 AL |
296 | #ifdef CONFIG_USER_ONLY |
297 | #define qemu_init_vcpu(env) do { } while (0) | |
298 | #else | |
299 | void qemu_init_vcpu(void *env); | |
300 | #endif | |
301 | ||
44e3ee8a AL |
302 | typedef struct QEMUIOVector { |
303 | struct iovec *iov; | |
304 | int niov; | |
305 | int nalloc; | |
249aa745 | 306 | size_t size; |
44e3ee8a AL |
307 | } QEMUIOVector; |
308 | ||
309 | void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); | |
522584a5 | 310 | void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov); |
44e3ee8a | 311 | void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len); |
b8a83a4f KW |
312 | void qemu_iovec_copy(QEMUIOVector *dst, QEMUIOVector *src, uint64_t skip, |
313 | size_t size); | |
40b4f539 | 314 | void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size); |
44e3ee8a | 315 | void qemu_iovec_destroy(QEMUIOVector *qiov); |
be959463 | 316 | void qemu_iovec_reset(QEMUIOVector *qiov); |
44e3ee8a | 317 | void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf); |
249aa745 | 318 | void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count); |
b8a83a4f | 319 | void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count); |
e0d9c6f9 CT |
320 | void qemu_iovec_memset_skip(QEMUIOVector *qiov, int c, size_t count, |
321 | size_t skip); | |
44e3ee8a | 322 | |
6b837bc4 JS |
323 | void qemu_progress_init(int enabled, float min_skip); |
324 | void qemu_progress_end(void); | |
3bfe4dbf | 325 | void qemu_progress_print(float delta, int max); |
6b837bc4 | 326 | |
082b5557 BS |
327 | #define QEMU_FILE_TYPE_BIOS 0 |
328 | #define QEMU_FILE_TYPE_KEYMAP 1 | |
329 | char *qemu_find_file(int type, const char *name); | |
330 | ||
331 | /* OS specific functions */ | |
332 | void os_setup_early_signal_handling(void); | |
333 | char *os_find_datadir(const char *argv0); | |
334 | void os_parse_cmd_args(int index, const char *optarg); | |
335 | void os_pidfile_error(void); | |
336 | ||
abd0c6bd PB |
337 | /* Convert a byte between binary and BCD. */ |
338 | static inline uint8_t to_bcd(uint8_t val) | |
339 | { | |
340 | return ((val / 10) << 4) | (val % 10); | |
341 | } | |
342 | ||
343 | static inline uint8_t from_bcd(uint8_t val) | |
344 | { | |
345 | return ((val >> 4) * 10) + (val & 0x0f); | |
346 | } | |
347 | ||
338b922e | 348 | /* compute with 96 bit intermediate result: (a*b)/c */ |
349 | static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) | |
350 | { | |
351 | union { | |
352 | uint64_t ll; | |
353 | struct { | |
354 | #ifdef HOST_WORDS_BIGENDIAN | |
355 | uint32_t high, low; | |
356 | #else | |
357 | uint32_t low, high; | |
358 | #endif | |
359 | } l; | |
360 | } u, res; | |
361 | uint64_t rl, rh; | |
362 | ||
363 | u.ll = a; | |
364 | rl = (uint64_t)u.l.low * (uint64_t)b; | |
365 | rh = (uint64_t)u.l.high * (uint64_t)b; | |
366 | rh += (rl >> 32); | |
367 | res.l.high = rh / c; | |
368 | res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; | |
369 | return res.ll; | |
370 | } | |
371 | ||
0bfe3ca5 AL |
372 | #include "module.h" |
373 | ||
faf07963 | 374 | #endif |