1 /* Common header file that is included by all of qemu. */
6 #include "config-host.h"
8 #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
12 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
14 typedef struct QEMUTimer QEMUTimer
;
15 typedef struct QEMUFile QEMUFile
;
16 typedef struct QEMUBH QEMUBH
;
17 typedef struct DeviceState DeviceState
;
20 typedef struct Monitor Monitor
;
22 /* we put basic includes here to avoid repeating them in device drivers */
43 #include "qemu-os-win32.h"
47 #include "qemu-os-posix.h"
57 #define MAP_ANONYMOUS MAP_ANON
60 #define ENOMEDIUM ENODEV
66 #define TIME_MAX LONG_MAX
76 * Use the same value as Linux for now.
83 typedef int (*fprintf_function
)(FILE *f
, const char *fmt
, ...)
88 #define lseek _lseeki64
89 int qemu_ftruncate64(int, int64_t);
90 #define ftruncate qemu_ftruncate64
92 static inline char *realpath(const char *path
, char *resolved_path
)
94 _fullpath(resolved_path
, path
, _MAX_PATH
);
99 /* FIXME: Remove NEED_CPU_H. */
109 #endif /* !defined(NEED_CPU_H) */
111 /* main function, renamed */
112 #if defined(CONFIG_COCOA)
113 int qemu_main(int argc
, char **argv
, char **envp
);
117 typedef void QEMUBHFunc(void *opaque
);
119 QEMUBH
*qemu_bh_new(QEMUBHFunc
*cb
, void *opaque
);
120 void qemu_bh_schedule(QEMUBH
*bh
);
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
127 void qemu_bh_schedule_idle(QEMUBH
*bh
);
128 void qemu_bh_cancel(QEMUBH
*bh
);
129 void qemu_bh_delete(QEMUBH
*bh
);
130 int qemu_bh_poll(void);
131 void qemu_bh_update_timeout(int *timeout
);
133 void qemu_get_timedate(struct tm
*tm
, int offset
);
134 int qemu_timedate_diff(struct tm
*tm
);
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
);
141 int qemu_strnlen(const char *s
, int max_len
);
142 time_t mktimegm(struct tm
*tm
);
144 int qemu_fdatasync(int fd
);
145 int fcntl_setfl(int fd
, int flag
);
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.
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'
159 int64_t strtosz(const char *nptr
, char **end
);
160 int64_t strtosz_suffix(const char *nptr
, char **end
, const char default_suffix
);
161 int64_t strtosz_suffix_unit(const char *nptr
, char **end
,
162 const char default_suffix
, int64_t unit
);
165 void init_paths(const char *prefix
);
166 const char *path(const char *pathname
);
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))
184 void *qemu_oom_check(void *ptr
);
186 void qemu_mutex_lock_iothread(void);
187 void qemu_mutex_unlock_iothread(void);
189 int qemu_open(const char *name
, int flags
, ...);
190 ssize_t
qemu_write_full(int fd
, const void *buf
, size_t count
)
191 QEMU_WARN_UNUSED_RESULT
;
192 void qemu_set_cloexec(int fd
);
195 int qemu_add_child_watch(pid_t pid
);
196 int qemu_eventfd(int pipefd
[2]);
197 int qemu_pipe(int pipefd
[2]);
201 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
203 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
206 /* Error handling. */
208 void QEMU_NORETURN
hw_error(const char *fmt
, ...) GCC_FMT_ATTR(1, 2);
211 typedef void IOReadHandler(void *opaque
, const uint8_t *buf
, int size
);
212 typedef int IOCanReadHandler(void *opaque
);
213 typedef void IOHandler(void *opaque
);
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
);
218 struct ParallelIOArg
{
223 typedef int (*DMA_transfer_handler
) (void *opaque
, int nchan
, int pos
, int size
);
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
;
228 typedef struct HCIInfo HCIInfo
;
229 typedef struct AudioState AudioState
;
230 typedef struct BlockDriverState BlockDriverState
;
231 typedef struct DriveInfo DriveInfo
;
232 typedef struct DisplayState DisplayState
;
233 typedef struct DisplayChangeListener DisplayChangeListener
;
234 typedef struct DisplaySurface DisplaySurface
;
235 typedef struct DisplayAllocator DisplayAllocator
;
236 typedef struct PixelFormat PixelFormat
;
237 typedef struct TextConsole TextConsole
;
238 typedef TextConsole QEMUConsole
;
239 typedef struct CharDriverState CharDriverState
;
240 typedef struct MACAddr MACAddr
;
241 typedef struct VLANState VLANState
;
242 typedef struct VLANClientState VLANClientState
;
243 typedef struct i2c_bus i2c_bus
;
244 typedef struct i2c_slave i2c_slave
;
245 typedef struct SMBusDevice SMBusDevice
;
246 typedef struct PCIHostState PCIHostState
;
247 typedef struct PCIExpressHost PCIExpressHost
;
248 typedef struct PCIBus PCIBus
;
249 typedef struct PCIDevice PCIDevice
;
250 typedef struct PCIExpressDevice PCIExpressDevice
;
251 typedef struct PCIBridge PCIBridge
;
252 typedef struct PCIEAERMsg PCIEAERMsg
;
253 typedef struct PCIEAERLog PCIEAERLog
;
254 typedef struct PCIEAERErr PCIEAERErr
;
255 typedef struct PCIEPort PCIEPort
;
256 typedef struct PCIESlot PCIESlot
;
257 typedef struct SerialState SerialState
;
258 typedef struct IRQState
*qemu_irq
;
259 typedef struct PCMCIACardState PCMCIACardState
;
260 typedef struct MouseTransformInfo MouseTransformInfo
;
261 typedef struct uWireSlave uWireSlave
;
262 typedef struct I2SCodec I2SCodec
;
263 typedef struct SSIBus SSIBus
;
264 typedef struct EventNotifier EventNotifier
;
265 typedef struct VirtIODevice VirtIODevice
;
266 typedef struct QEMUSGList QEMUSGList
;
268 typedef uint64_t pcibus_t
;
270 void tcg_exec_init(unsigned long tb_size
);
271 bool tcg_enabled(void);
273 void cpu_exec_init_all(void);
276 void cpu_save(QEMUFile
*f
, void *opaque
);
277 int cpu_load(QEMUFile
*f
, void *opaque
, int version_id
);
279 /* Force QEMU to stop what it's doing and service IO */
280 void qemu_service_io(void);
282 /* Force QEMU to process pending events */
283 void qemu_notify_event(void);
286 void qemu_cpu_kick(void *env
);
287 void qemu_cpu_kick_self(void);
288 int qemu_cpu_is_self(void *env
);
289 bool all_cpu_threads_idle(void);
292 struct qemu_work_item
{
293 struct qemu_work_item
*next
;
294 void (*func
)(void *data
);
299 #ifdef CONFIG_USER_ONLY
300 #define qemu_init_vcpu(env) do { } while (0)
302 void qemu_init_vcpu(void *env
);
305 typedef struct QEMUIOVector
{
312 void qemu_iovec_init(QEMUIOVector
*qiov
, int alloc_hint
);
313 void qemu_iovec_init_external(QEMUIOVector
*qiov
, struct iovec
*iov
, int niov
);
314 void qemu_iovec_add(QEMUIOVector
*qiov
, void *base
, size_t len
);
315 void qemu_iovec_copy(QEMUIOVector
*dst
, QEMUIOVector
*src
, uint64_t skip
,
317 void qemu_iovec_concat(QEMUIOVector
*dst
, QEMUIOVector
*src
, size_t size
);
318 void qemu_iovec_destroy(QEMUIOVector
*qiov
);
319 void qemu_iovec_reset(QEMUIOVector
*qiov
);
320 void qemu_iovec_to_buffer(QEMUIOVector
*qiov
, void *buf
);
321 void qemu_iovec_from_buffer(QEMUIOVector
*qiov
, const void *buf
, size_t count
);
322 void qemu_iovec_memset(QEMUIOVector
*qiov
, int c
, size_t count
);
323 void qemu_iovec_memset_skip(QEMUIOVector
*qiov
, int c
, size_t count
,
326 void qemu_progress_init(int enabled
, float min_skip
);
327 void qemu_progress_end(void);
328 void qemu_progress_print(float delta
, int max
);
330 #define QEMU_FILE_TYPE_BIOS 0
331 #define QEMU_FILE_TYPE_KEYMAP 1
332 char *qemu_find_file(int type
, const char *name
);
334 /* OS specific functions */
335 void os_setup_early_signal_handling(void);
336 char *os_find_datadir(const char *argv0
);
337 void os_parse_cmd_args(int index
, const char *optarg
);
338 void os_pidfile_error(void);
340 /* Convert a byte between binary and BCD. */
341 static inline uint8_t to_bcd(uint8_t val
)
343 return ((val
/ 10) << 4) | (val
% 10);
346 static inline uint8_t from_bcd(uint8_t val
)
348 return ((val
>> 4) * 10) + (val
& 0x0f);
351 /* compute with 96 bit intermediate result: (a*b)/c */
352 static inline uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
357 #ifdef HOST_WORDS_BIGENDIAN
367 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
368 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
371 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;