1 | /* Common header file that is included by all of qemu. */
|
---|
2 | #ifndef QEMU_COMMON_H
|
---|
3 | #define QEMU_COMMON_H
|
---|
4 |
|
---|
5 | #include "config-host.h"
|
---|
6 |
|
---|
7 | #ifdef VBOX
|
---|
8 |
|
---|
9 | # include <iprt/string.h>
|
---|
10 | # include <iprt/types.h>
|
---|
11 | # include <iprt/ctype.h>
|
---|
12 |
|
---|
13 | void pstrcpy(char *buf, int buf_size, const char *str);
|
---|
14 | char *pstrcat(char *buf, int buf_size, const char *s);
|
---|
15 | # define snprintf RTStrPrintf
|
---|
16 |
|
---|
17 | # define qemu_isalnum(c) RT_C_IS_ALNUM((unsigned char)(c))
|
---|
18 | # define qemu_isalpha(c) RT_C_IS_ALPHA((unsigned char)(c))
|
---|
19 | # define qemu_iscntrl(c) RT_C_IS_CNTRL((unsigned char)(c))
|
---|
20 | # define qemu_isdigit(c) RT_C_IS_DIGIT((unsigned char)(c))
|
---|
21 | # define qemu_isgraph(c) RT_C_IS_GRAPH((unsigned char)(c))
|
---|
22 | # define qemu_islower(c) RT_C_IS_LOWER((unsigned char)(c))
|
---|
23 | # define qemu_isprint(c) RT_C_IS_PRINT((unsigned char)(c))
|
---|
24 | # define qemu_ispunct(c) RT_C_IS_PUNCT((unsigned char)(c))
|
---|
25 | # define qemu_isspace(c) RT_C_IS_SPACE((unsigned char)(c))
|
---|
26 | # define qemu_isupper(c) RT_C_IS_UPPER((unsigned char)(c))
|
---|
27 | # define qemu_isxdigit(c) RT_C_IS_XDIGIT((unsigned char)(c))
|
---|
28 | # define qemu_tolower(c) RT_C_TO_LOWER((unsigned char)(c))
|
---|
29 | # define qemu_toupper(c) RT_C_TO_UPPER((unsigned char)(c))
|
---|
30 | # define qemu_isascii(c) RT_C_IS_ASCII((unsigned char)(c))
|
---|
31 | # define qemu_toascii(c) RT_C_TO_ASCII((unsigned char)(c))
|
---|
32 |
|
---|
33 | # define qemu_init_vcpu(env) do { } while (0) /* we don't need this :-) */
|
---|
34 |
|
---|
35 | # define QEMU_NORETURN __attribute__((__noreturn__))
|
---|
36 | # ifdef CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT
|
---|
37 | # define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
---|
38 | # else
|
---|
39 | # define QEMU_WARN_UNUSED_RESULT
|
---|
40 | # endif
|
---|
41 | #define QEMU_BUILD_BUG_ON(x) typedef char __build_bug_on__##__LINE__[(x)?-1:1];
|
---|
42 |
|
---|
43 | #include <stdio.h>
|
---|
44 | #include "cpu.h"
|
---|
45 |
|
---|
46 |
|
---|
47 | #else /* !VBOX */
|
---|
48 | #ifdef _WIN32
|
---|
49 | #define WIN32_LEAN_AND_MEAN
|
---|
50 | #define WINVER 0x0501 /* needed for ipv6 bits */
|
---|
51 | #include <windows.h>
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | #define QEMU_NORETURN __attribute__ ((__noreturn__))
|
---|
55 | #ifdef CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT
|
---|
56 | #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
---|
57 | #else
|
---|
58 | #define QEMU_WARN_UNUSED_RESULT
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | #define QEMU_BUILD_BUG_ON(x) typedef char __build_bug_on__##__LINE__[(x)?-1:1];
|
---|
62 |
|
---|
63 | typedef struct QEMUTimer QEMUTimer;
|
---|
64 | typedef struct QEMUFile QEMUFile;
|
---|
65 | typedef struct QEMUBH QEMUBH;
|
---|
66 | typedef struct DeviceState DeviceState;
|
---|
67 |
|
---|
68 |
|
---|
69 | /* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
|
---|
70 | cannot include the following headers without conflicts. This condition has
|
---|
71 | to be removed once dyngen is gone. */
|
---|
72 | #ifndef __DYNGEN_EXEC_H__
|
---|
73 |
|
---|
74 | /* we put basic includes here to avoid repeating them in device drivers */
|
---|
75 | #include <stdlib.h>
|
---|
76 | #include <stdio.h>
|
---|
77 | #include <stdarg.h>
|
---|
78 | #include <stdbool.h>
|
---|
79 | #include <string.h>
|
---|
80 | #include <strings.h>
|
---|
81 | #include <inttypes.h>
|
---|
82 | #include <limits.h>
|
---|
83 | #include <time.h>
|
---|
84 | #include <ctype.h>
|
---|
85 | #include <errno.h>
|
---|
86 | #include <unistd.h>
|
---|
87 | #include <fcntl.h>
|
---|
88 | #include <sys/stat.h>
|
---|
89 | #include <assert.h>
|
---|
90 |
|
---|
91 | #ifndef O_LARGEFILE
|
---|
92 | #define O_LARGEFILE 0
|
---|
93 | #endif
|
---|
94 | #ifndef O_BINARY
|
---|
95 | #define O_BINARY 0
|
---|
96 | #endif
|
---|
97 | #ifndef MAP_ANONYMOUS
|
---|
98 | #define MAP_ANONYMOUS MAP_ANON
|
---|
99 | #endif
|
---|
100 | #ifndef ENOMEDIUM
|
---|
101 | #define ENOMEDIUM ENODEV
|
---|
102 | #endif
|
---|
103 | #if !defined(ENOTSUP)
|
---|
104 | #define ENOTSUP 4096
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | #ifndef CONFIG_IOVEC
|
---|
108 | #define CONFIG_IOVEC
|
---|
109 | struct iovec {
|
---|
110 | void *iov_base;
|
---|
111 | size_t iov_len;
|
---|
112 | };
|
---|
113 | /*
|
---|
114 | * Use the same value as Linux for now.
|
---|
115 | */
|
---|
116 | #define IOV_MAX 1024
|
---|
117 | #else
|
---|
118 | #include <sys/uio.h>
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | #ifdef _WIN32
|
---|
122 | #define fsync _commit
|
---|
123 | #define lseek _lseeki64
|
---|
124 | extern int qemu_ftruncate64(int, int64_t);
|
---|
125 | #define ftruncate qemu_ftruncate64
|
---|
126 |
|
---|
127 | static inline char *realpath(const char *path, char *resolved_path)
|
---|
128 | {
|
---|
129 | _fullpath(resolved_path, path, _MAX_PATH);
|
---|
130 | return resolved_path;
|
---|
131 | }
|
---|
132 |
|
---|
133 | #define PRId64 "I64d"
|
---|
134 | #define PRIx64 "I64x"
|
---|
135 | #define PRIu64 "I64u"
|
---|
136 | #define PRIo64 "I64o"
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | /* FIXME: Remove NEED_CPU_H. */
|
---|
140 | #ifndef NEED_CPU_H
|
---|
141 |
|
---|
142 | #include <setjmp.h>
|
---|
143 | #include "osdep.h"
|
---|
144 | #include "bswap.h"
|
---|
145 |
|
---|
146 | #else
|
---|
147 |
|
---|
148 | #include "cpu.h"
|
---|
149 |
|
---|
150 | #endif /* !defined(NEED_CPU_H) */
|
---|
151 |
|
---|
152 | /* bottom halves */
|
---|
153 | typedef void QEMUBHFunc(void *opaque);
|
---|
154 |
|
---|
155 | void async_context_push(void);
|
---|
156 | void async_context_pop(void);
|
---|
157 | int get_async_context_id(void);
|
---|
158 |
|
---|
159 | QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
|
---|
160 | void qemu_bh_schedule(QEMUBH *bh);
|
---|
161 | /* Bottom halfs that are scheduled from a bottom half handler are instantly
|
---|
162 | * invoked. This can create an infinite loop if a bottom half handler
|
---|
163 | * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by
|
---|
164 | * ensuring that the bottom half isn't executed until the next main loop
|
---|
165 | * iteration.
|
---|
166 | */
|
---|
167 | void qemu_bh_schedule_idle(QEMUBH *bh);
|
---|
168 | void qemu_bh_cancel(QEMUBH *bh);
|
---|
169 | void qemu_bh_delete(QEMUBH *bh);
|
---|
170 | int qemu_bh_poll(void);
|
---|
171 | void qemu_bh_update_timeout(int *timeout);
|
---|
172 |
|
---|
173 | uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
|
---|
174 |
|
---|
175 | void qemu_get_timedate(struct tm *tm, int offset);
|
---|
176 | int qemu_timedate_diff(struct tm *tm);
|
---|
177 |
|
---|
178 | /* cutils.c */
|
---|
179 | void pstrcpy(char *buf, int buf_size, const char *str);
|
---|
180 | char *pstrcat(char *buf, int buf_size, const char *s);
|
---|
181 | int strstart(const char *str, const char *val, const char **ptr);
|
---|
182 | int stristart(const char *str, const char *val, const char **ptr);
|
---|
183 | int qemu_strnlen(const char *s, int max_len);
|
---|
184 | time_t mktimegm(struct tm *tm);
|
---|
185 | int qemu_fls(int i);
|
---|
186 | int qemu_fdatasync(int fd);
|
---|
187 | int fcntl_setfl(int fd, int flag);
|
---|
188 |
|
---|
189 | /* path.c */
|
---|
190 | void init_paths(const char *prefix);
|
---|
191 | const char *path(const char *pathname);
|
---|
192 |
|
---|
193 | #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 |
|
---|
209 | void *qemu_malloc(size_t size);
|
---|
210 | void *qemu_realloc(void *ptr, size_t size);
|
---|
211 | void *qemu_mallocz(size_t size);
|
---|
212 | void qemu_free(void *ptr);
|
---|
213 | char *qemu_strdup(const char *str);
|
---|
214 | char *qemu_strndup(const char *str, size_t size);
|
---|
215 |
|
---|
216 | void qemu_mutex_lock_iothread(void);
|
---|
217 | void qemu_mutex_unlock_iothread(void);
|
---|
218 |
|
---|
219 | int qemu_open(const char *name, int flags, ...);
|
---|
220 | ssize_t qemu_write_full(int fd, const void *buf, size_t count)
|
---|
221 | QEMU_WARN_UNUSED_RESULT;
|
---|
222 | void qemu_set_cloexec(int fd);
|
---|
223 |
|
---|
224 | #ifndef _WIN32
|
---|
225 | int qemu_eventfd(int pipefd[2]);
|
---|
226 | int qemu_pipe(int pipefd[2]);
|
---|
227 | #endif
|
---|
228 |
|
---|
229 | /* Error handling. */
|
---|
230 |
|
---|
231 | void QEMU_NORETURN hw_error(const char *fmt, ...)
|
---|
232 | __attribute__ ((__format__ (__printf__, 1, 2)));
|
---|
233 |
|
---|
234 | /* IO callbacks. */
|
---|
235 | typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
|
---|
236 | typedef int IOCanReadHandler(void *opaque);
|
---|
237 | typedef void IOHandler(void *opaque);
|
---|
238 |
|
---|
239 | struct ParallelIOArg {
|
---|
240 | void *buffer;
|
---|
241 | int count;
|
---|
242 | };
|
---|
243 |
|
---|
244 | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
|
---|
245 |
|
---|
246 | /* A load of opaque types so that device init declarations don't have to
|
---|
247 | pull in all the real definitions. */
|
---|
248 | typedef struct NICInfo NICInfo;
|
---|
249 | typedef struct HCIInfo HCIInfo;
|
---|
250 | typedef struct AudioState AudioState;
|
---|
251 | typedef struct BlockDriverState BlockDriverState;
|
---|
252 | typedef struct DisplayState DisplayState;
|
---|
253 | typedef struct DisplayChangeListener DisplayChangeListener;
|
---|
254 | typedef struct DisplaySurface DisplaySurface;
|
---|
255 | typedef struct DisplayAllocator DisplayAllocator;
|
---|
256 | typedef struct PixelFormat PixelFormat;
|
---|
257 | typedef struct TextConsole TextConsole;
|
---|
258 | typedef TextConsole QEMUConsole;
|
---|
259 | typedef struct CharDriverState CharDriverState;
|
---|
260 | typedef struct MACAddr MACAddr;
|
---|
261 | typedef struct VLANState VLANState;
|
---|
262 | typedef struct VLANClientState VLANClientState;
|
---|
263 | typedef struct i2c_bus i2c_bus;
|
---|
264 | typedef struct i2c_slave i2c_slave;
|
---|
265 | typedef struct SMBusDevice SMBusDevice;
|
---|
266 | typedef struct PCIHostState PCIHostState;
|
---|
267 | typedef struct PCIExpressHost PCIExpressHost;
|
---|
268 | typedef struct PCIBus PCIBus;
|
---|
269 | typedef struct PCIDevice PCIDevice;
|
---|
270 | typedef struct SerialState SerialState;
|
---|
271 | typedef struct IRQState *qemu_irq;
|
---|
272 | typedef struct PCMCIACardState PCMCIACardState;
|
---|
273 | typedef struct MouseTransformInfo MouseTransformInfo;
|
---|
274 | typedef struct uWireSlave uWireSlave;
|
---|
275 | typedef struct I2SCodec I2SCodec;
|
---|
276 | typedef struct SSIBus SSIBus;
|
---|
277 | typedef struct EventNotifier EventNotifier;
|
---|
278 | typedef struct VirtIODevice VirtIODevice;
|
---|
279 |
|
---|
280 | typedef uint64_t pcibus_t;
|
---|
281 |
|
---|
282 | void cpu_exec_init_all(unsigned long tb_size);
|
---|
283 |
|
---|
284 | /* CPU save/load. */
|
---|
285 | void cpu_save(QEMUFile *f, void *opaque);
|
---|
286 | int cpu_load(QEMUFile *f, void *opaque, int version_id);
|
---|
287 |
|
---|
288 | /* Force QEMU to stop what it's doing and service IO */
|
---|
289 | void qemu_service_io(void);
|
---|
290 |
|
---|
291 | /* Force QEMU to process pending events */
|
---|
292 | void qemu_notify_event(void);
|
---|
293 |
|
---|
294 | /* Unblock cpu */
|
---|
295 | void qemu_cpu_kick(void *env);
|
---|
296 | int qemu_cpu_self(void *env);
|
---|
297 |
|
---|
298 | /* work queue */
|
---|
299 | struct qemu_work_item {
|
---|
300 | struct qemu_work_item *next;
|
---|
301 | void (*func)(void *data);
|
---|
302 | void *data;
|
---|
303 | int done;
|
---|
304 | };
|
---|
305 |
|
---|
306 | #ifdef CONFIG_USER_ONLY
|
---|
307 | #define qemu_init_vcpu(env) do { } while (0)
|
---|
308 | #else
|
---|
309 | void qemu_init_vcpu(void *env);
|
---|
310 | #endif
|
---|
311 |
|
---|
312 | typedef struct QEMUIOVector {
|
---|
313 | struct iovec *iov;
|
---|
314 | int niov;
|
---|
315 | int nalloc;
|
---|
316 | size_t size;
|
---|
317 | } QEMUIOVector;
|
---|
318 |
|
---|
319 | void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
|
---|
320 | void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
|
---|
321 | void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
|
---|
322 | void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
|
---|
323 | void qemu_iovec_destroy(QEMUIOVector *qiov);
|
---|
324 | void qemu_iovec_reset(QEMUIOVector *qiov);
|
---|
325 | void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
|
---|
326 | void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
|
---|
327 |
|
---|
328 | struct Monitor;
|
---|
329 | typedef struct Monitor Monitor;
|
---|
330 |
|
---|
331 | /* Convert a byte between binary and BCD. */
|
---|
332 | static inline uint8_t to_bcd(uint8_t val)
|
---|
333 | {
|
---|
334 | return ((val / 10) << 4) | (val % 10);
|
---|
335 | }
|
---|
336 |
|
---|
337 | static inline uint8_t from_bcd(uint8_t val)
|
---|
338 | {
|
---|
339 | return ((val >> 4) * 10) + (val & 0x0f);
|
---|
340 | }
|
---|
341 |
|
---|
342 | #include "module.h"
|
---|
343 |
|
---|
344 | #endif /* dyngen-exec.h hack */
|
---|
345 |
|
---|
346 | #endif /* !VBOX */
|
---|
347 |
|
---|
348 | #endif
|
---|