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