VirtualBox

root/trunk/src/recompiler/vl.h

Revision 2422, 44.7 kB (checked in by vboxsync, 2 years ago)

Removed the old recompiler code.

  • Property svn:eol-style set to native
Line 
1 /*
2  * QEMU System Emulator header
3  *
4  * Copyright (c) 2003 Fabrice Bellard
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #ifndef VL_H
25 #define VL_H
26
27 /* we put basic includes here to avoid repeating them in device drivers */
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #include <inttypes.h>
33 #ifndef VBOX
34 #include <limits.h>
35 #include <time.h>
36 #include <ctype.h>
37 #include <errno.h>
38 #include <unistd.h>
39 #include <fcntl.h>
40 #include <sys/stat.h>
41 #include "audio/audio.h"
42 #endif /* !VBOX */
43
44 #ifndef O_LARGEFILE
45 #define O_LARGEFILE 0
46 #endif
47 #ifndef O_BINARY
48 #define O_BINARY 0
49 #endif
50
51 #ifndef ENOMEDIUM
52 #define ENOMEDIUM ENODEV
53 #endif
54
55 #ifdef _WIN32
56 #ifndef VBOX
57 #include <windows.h>
58 #define fsync _commit
59 #define lseek _lseeki64
60 #define ENOTSUP 4096
61 extern int qemu_ftruncate64(int, int64_t);
62 #define ftruncate qemu_ftruncate64
63
64
65 static inline char *realpath(const char *path, char *resolved_path)
66 {
67     _fullpath(resolved_path, path, _MAX_PATH);
68     return resolved_path;
69 }
70
71 #define PRId64 "I64d"
72 #define PRIx64 "I64x"
73 #define PRIu64 "I64u"
74 #define PRIo64 "I64o"
75 #endif /* !VBOX */
76 #endif
77
78 #ifdef QEMU_TOOL
79
80 /* we use QEMU_TOOL in the command line tools which do not depend on
81    the target CPU type */
82 #include "config-host.h"
83 #include <setjmp.h>
84 #include "osdep.h"
85 #include "bswap.h"
86
87 #else
88
89 #ifndef VBOX
90 #include "audio/audio.h"
91 #endif /* !VBOX */
92 #include "cpu.h"
93
94 #endif /* !defined(QEMU_TOOL) */
95
96 #ifdef VBOX
97 # include <VBox/types.h>
98 # include "REMInternal.h"
99 #endif /* VBOX */
100
101 #ifndef glue
102 #define xglue(x, y) x ## y
103 #define glue(x, y) xglue(x, y)
104 #define stringify(s)    tostring(s)
105 #define tostring(s)     #s
106 #endif
107
108 #ifndef MIN
109 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
110 #endif
111 #ifndef MAX
112 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
113 #endif
114
115 /* cutils.c */
116 void pstrcpy(char *buf, int buf_size, const char *str);
117 char *pstrcat(char *buf, int buf_size, const char *s);
118 int strstart(const char *str, const char *val, const char **ptr);
119 int stristart(const char *str, const char *val, const char **ptr);
120
121 /* vl.c */
122 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
123
124 void hw_error(const char *fmt, ...);
125
126 extern const char *bios_dir;
127
128 extern int vm_running;
129
130 typedef struct vm_change_state_entry VMChangeStateEntry;
131 typedef void VMChangeStateHandler(void *opaque, int running);
132 typedef void VMStopHandler(void *opaque, int reason);
133
134 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
135                                                      void *opaque);
136 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
137
138 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
139 void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
140
141 void vm_start(void);
142 void vm_stop(int reason);
143
144 typedef void QEMUResetHandler(void *opaque);
145
146 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
147 void qemu_system_reset_request(void);
148 void qemu_system_shutdown_request(void);
149 void qemu_system_powerdown_request(void);
150 #if !defined(TARGET_SPARC)
151 // Please implement a power failure function to signal the OS
152 #define qemu_system_powerdown() do{}while(0)
153 #else
154 void qemu_system_powerdown(void);
155 #endif
156
157 void main_loop_wait(int timeout);
158
159 extern int ram_size;
160 extern int bios_size;
161 extern int rtc_utc;
162 extern int cirrus_vga_enabled;
163 extern int graphic_width;
164 extern int graphic_height;
165 extern int graphic_depth;
166 extern const char *keyboard_layout;
167 extern int kqemu_allowed;
168 extern int win2k_install_hack;
169 extern int usb_enabled;
170 extern int smp_cpus;
171 extern int no_quit;
172 extern int semihosting_enabled;
173 extern int autostart;
174
175 #ifndef VBOX
176 #define MAX_OPTION_ROMS 16
177 extern const char *option_rom[MAX_OPTION_ROMS];
178 extern int nb_option_roms;
179
180 /* XXX: make it dynamic */
181 #if defined (TARGET_PPC) || defined (TARGET_SPARC64)
182 #define BIOS_SIZE ((512 + 32) * 1024)
183 #elif defined(TARGET_MIPS)
184 #define BIOS_SIZE (4 * 1024 * 1024)
185 #else
186 #define BIOS_SIZE ((256 + 64) * 1024)
187 #endif
188
189 /* keyboard/mouse support */
190
191 #define MOUSE_EVENT_LBUTTON 0x01
192 #define MOUSE_EVENT_RBUTTON 0x02
193 #define MOUSE_EVENT_MBUTTON 0x04
194
195 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
196 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
197
198 typedef struct QEMUPutMouseEntry {
199     QEMUPutMouseEvent *qemu_put_mouse_event;
200     void *qemu_put_mouse_event_opaque;
201     int qemu_put_mouse_event_absolute;
202     char *qemu_put_mouse_event_name;
203
204     /* used internally by qemu for handling mice */
205     struct QEMUPutMouseEntry *next;
206 } QEMUPutMouseEntry;
207
208 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
209 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
210                                                 void *opaque, int absolute,
211                                                 const char *name);
212 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
213
214 void kbd_put_keycode(int keycode);
215 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
216 int kbd_mouse_is_absolute(void);
217
218 void do_info_mice(void);
219 void do_mouse_set(int index);
220
221 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
222    constants) */
223 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
224 #define QEMU_KEY_BACKSPACE  0x007f
225 #define QEMU_KEY_UP         QEMU_KEY_ESC1('A')
226 #define QEMU_KEY_DOWN       QEMU_KEY_ESC1('B')
227 #define QEMU_KEY_RIGHT      QEMU_KEY_ESC1('C')
228 #define QEMU_KEY_LEFT       QEMU_KEY_ESC1('D')
229 #define QEMU_KEY_HOME       QEMU_KEY_ESC1(1)
230 #define QEMU_KEY_END        QEMU_KEY_ESC1(4)
231 #define QEMU_KEY_PAGEUP     QEMU_KEY_ESC1(5)
232 #define QEMU_KEY_PAGEDOWN   QEMU_KEY_ESC1(6)
233 #define QEMU_KEY_DELETE     QEMU_KEY_ESC1(3)
234
235 #define QEMU_KEY_CTRL_UP         0xe400
236 #define QEMU_KEY_CTRL_DOWN       0xe401
237 #define QEMU_KEY_CTRL_LEFT       0xe402
238 #define QEMU_KEY_CTRL_RIGHT      0xe403
239 #define QEMU_KEY_CTRL_HOME       0xe404
240 #define QEMU_KEY_CTRL_END        0xe405
241 #define QEMU_KEY_CTRL_PAGEUP     0xe406
242 #define QEMU_KEY_CTRL_PAGEDOWN   0xe407
243
244 void kbd_put_keysym(int keysym);
245
246 /* async I/O support */
247
248 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
249 typedef int IOCanRWHandler(void *opaque);
250 typedef void IOHandler(void *opaque);
251
252 int qemu_set_fd_handler2(int fd,
253                          IOCanRWHandler *fd_read_poll,
254                          IOHandler *fd_read,
255                          IOHandler *fd_write,
256                          void *opaque);
257 int qemu_set_fd_handler(int fd,
258                         IOHandler *fd_read,
259                         IOHandler *fd_write,
260                         void *opaque);
261
262 /* Polling handling */
263
264 /* return TRUE if no sleep should be done afterwards */
265 typedef int PollingFunc(void *opaque);
266
267 int qemu_add_polling_cb(PollingFunc *func, void *opaque);
268 void qemu_del_polling_cb(PollingFunc *func, void *opaque);
269
270 #ifdef _WIN32
271 /* Wait objects handling */
272 typedef void WaitObjectFunc(void *opaque);
273
274 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
275 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
276 #endif
277
278 typedef struct QEMUBH QEMUBH;
279
280 /* character device */
281
282 #define CHR_EVENT_BREAK 0 /* serial break char */
283 #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
284 #define CHR_EVENT_RESET 2 /* new connection established */
285
286
287 #define CHR_IOCTL_SERIAL_SET_PARAMS   1
288 typedef struct {
289     int speed;
290     int parity;
291     int data_bits;
292     int stop_bits;
293 } QEMUSerialSetParams;
294
295 #define CHR_IOCTL_SERIAL_SET_BREAK    2
296
297 #define CHR_IOCTL_PP_READ_DATA        3
298 #define CHR_IOCTL_PP_WRITE_DATA       4
299 #define CHR_IOCTL_PP_READ_CONTROL     5
300 #define CHR_IOCTL_PP_WRITE_CONTROL    6
301 #define CHR_IOCTL_PP_READ_STATUS      7
302
303 typedef void IOEventHandler(void *opaque, int event);
304
305 typedef struct CharDriverState {
306     int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
307     void (*chr_update_read_handler)(struct CharDriverState *s);
308     int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
309     IOEventHandler *chr_event;
310     IOCanRWHandler *chr_can_read;
311     IOReadHandler *chr_read;
312     void *handler_opaque;
313     void (*chr_send_event)(struct CharDriverState *chr, int event);
314     void (*chr_close)(struct CharDriverState *chr);
315     void *opaque;
316     QEMUBH *bh;
317 } CharDriverState;
318
319 CharDriverState *qemu_chr_open(const char *filename);
320 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
321 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
322 void qemu_chr_send_event(CharDriverState *s, int event);
323 void qemu_chr_add_handlers(CharDriverState *s,
324                            IOCanRWHandler *fd_can_read,
325                            IOReadHandler *fd_read,
326                            IOEventHandler *fd_event,
327                            void *opaque);
328 int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
329 void qemu_chr_reset(CharDriverState *s);
330 int qemu_chr_can_read(CharDriverState *s);
331 void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
332
333 /* consoles */
334
335 typedef struct DisplayState DisplayState;
336 typedef struct TextConsole TextConsole;
337
338 typedef void (*vga_hw_update_ptr)(void *);
339 typedef void (*vga_hw_invalidate_ptr)(void *);
340 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
341
342 TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
343                                   vga_hw_invalidate_ptr invalidate,
344                                   vga_hw_screen_dump_ptr screen_dump,
345                                   void *opaque);
346 void vga_hw_update(void);
347 void vga_hw_invalidate(void);
348 void vga_hw_screen_dump(const char *filename);
349
350 int is_graphic_console(void);
351 CharDriverState *text_console_init(DisplayState *ds);
352 void console_select(unsigned int index);
353
354 /* serial ports */
355
356 #define MAX_SERIAL_PORTS 4
357
358 extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
359
360 /* parallel ports */
361
362 #define MAX_PARALLEL_PORTS 3
363
364 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
365
366 /* VLANs support */
367
368 typedef struct VLANClientState VLANClientState;
369
370 struct VLANClientState {
371     IOReadHandler *fd_read;
372     /* Packets may still be sent if this returns zero.  It's used to
373        rate-limit the slirp code.  */
374     IOCanRWHandler *fd_can_read;
375     void *opaque;
376     struct VLANClientState *next;
377     struct VLANState *vlan;
378     char info_str[256];
379 };
380
381 typedef struct VLANState {
382     int id;
383     VLANClientState *first_client;
384     struct VLANState *next;
385 } VLANState;
386
387 VLANState *qemu_find_vlan(int id);
388 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
389                                       IOReadHandler *fd_read,
390                                       IOCanRWHandler *fd_can_read,
391                                       void *opaque);
392 int qemu_can_send_packet(VLANClientState *vc);
393 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
394 void qemu_handler_true(void *opaque);
395
396 void do_info_network(void);
397
398 /* TAP win32 */
399 int tap_win32_init(VLANState *vlan, const char *ifname);
400
401 /* NIC info */
402
403 #define MAX_NICS 8
404
405 typedef struct NICInfo {
406     uint8_t macaddr[6];
407     const char *model;
408     VLANState *vlan;
409 } NICInfo;
410
411 extern int nb_nics;
412 extern NICInfo nd_table[MAX_NICS];
413
414 /* timers */
415
416 typedef struct QEMUClock QEMUClock;
417 typedef struct QEMUTimer QEMUTimer;
418 typedef void QEMUTimerCB(void *opaque);
419
420 /* The real time clock should be used only for stuff which does not
421    change the virtual machine state, as it is run even if the virtual
422    machine is stopped. The real time clock has a frequency of 1000
423    Hz. */
424 extern QEMUClock *rt_clock;
425
426 /* The virtual clock is only run during the emulation. It is stopped
427    when the virtual machine is stopped. Virtual timers use a high
428    precision clock, usually cpu cycles (use ticks_per_sec). */
429 extern QEMUClock *vm_clock;
430
431 int64_t qemu_get_clock(QEMUClock *clock);
432
433 QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
434 void qemu_free_timer(QEMUTimer *ts);
435 void qemu_del_timer(QEMUTimer *ts);
436 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
437 int qemu_timer_pending(QEMUTimer *ts);
438
439 extern int64_t ticks_per_sec;
440 extern int pit_min_timer_count;
441
442 int64_t cpu_get_ticks(void);
443 void cpu_enable_ticks(void);
444 void cpu_disable_ticks(void);
445
446 /* VM Load/Save */
447
448 typedef struct QEMUFile QEMUFile;
449
450 QEMUFile *qemu_fopen(const char *filename, const char *mode);
451 void qemu_fflush(QEMUFile *f);
452 void qemu_fclose(QEMUFile *f);
453 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
454 void qemu_put_byte(QEMUFile *f, int v);
455 void qemu_put_be16(QEMUFile *f, unsigned int v);
456 void qemu_put_be32(QEMUFile *f, unsigned int v);
457 void qemu_put_be64(QEMUFile *f, uint64_t v);
458 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
459 int qemu_get_byte(QEMUFile *f);
460 unsigned int qemu_get_be16(QEMUFile *f);
461 unsigned int qemu_get_be32(QEMUFile *f);
462 uint64_t qemu_get_be64(QEMUFile *f);
463
464 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
465 {
466     qemu_put_be64(f, *pv);
467 }
468
469 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
470 {
471     qemu_put_be32(f, *pv);
472 }
473
474 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
475 {
476     qemu_put_be16(f, *pv);
477 }
478
479 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
480 {
481     qemu_put_byte(f, *pv);
482 }
483
484 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
485 {
486     *pv = qemu_get_be64(f);
487 }
488
489 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
490 {
491     *pv = qemu_get_be32(f);
492 }
493
494 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
495 {
496     *pv = qemu_get_be16(f);
497 }
498
499 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
500 {
501     *pv = qemu_get_byte(f);
502 }
503
504 #if TARGET_LONG_BITS == 64
505 #define qemu_put_betl qemu_put_be64
506 #define qemu_get_betl qemu_get_be64
507 #define qemu_put_betls qemu_put_be64s
508 #define qemu_get_betls qemu_get_be64s
509 #else
510 #define qemu_put_betl qemu_put_be32
511 #define qemu_get_betl qemu_get_be32
512 #define qemu_put_betls qemu_put_be32s
513 #define qemu_get_betls qemu_get_be32s
514 #endif
515
516 int64_t qemu_ftell(QEMUFile *f);
517 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
518
519 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
520 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
521
522 int register_savevm(const char *idstr,
523                     int instance_id,
524                     int version_id,
525                     SaveStateHandler *save_state,
526                     LoadStateHandler *load_state,
527                     void *opaque);
528 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
529 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
530
531 void cpu_save(QEMUFile *f, void *opaque);
532 int cpu_load(QEMUFile *f, void *opaque, int version_id);
533
534 void do_savevm(const char *name);
535 void do_loadvm(const char *name);
536 void do_delvm(const char *name);
537 void do_info_snapshots(void);
538
539 /* bottom halves */
540 typedef void QEMUBHFunc(void *opaque);
541
542 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
543 void qemu_bh_schedule(QEMUBH *bh);
544 void qemu_bh_cancel(QEMUBH *bh);
545 void qemu_bh_delete(QEMUBH *bh);
546 int qemu_bh_poll(void);
547
548 /* block.c */
549 typedef struct BlockDriverState BlockDriverState;
550 typedef struct BlockDriver BlockDriver;
551
552 extern BlockDriver bdrv_raw;
553 extern BlockDriver bdrv_host_device;
554 extern BlockDriver bdrv_cow;
555 extern BlockDriver bdrv_qcow;
556 extern BlockDriver bdrv_vmdk;
557 extern BlockDriver bdrv_cloop;
558 extern BlockDriver bdrv_dmg;
559 extern BlockDriver bdrv_bochs;
560 extern BlockDriver bdrv_vpc;
561 extern BlockDriver bdrv_vvfat;
562 extern BlockDriver bdrv_qcow2;
563
564 typedef struct BlockDriverInfo {
565     /* in bytes, 0 if irrelevant */
566     int cluster_size;
567     /* offset at which the VM state can be saved (0 if not possible) */
568     int64_t vm_state_offset;
569 } BlockDriverInfo;
570
571 typedef struct QEMUSnapshotInfo {
572     char id_str[128]; /* unique snapshot id */
573     /* the following fields are informative. They are not needed for
574        the consistency of the snapshot */
575     char name[256]; /* user choosen name */
576     uint32_t vm_state_size; /* VM state info size */
577     uint32_t date_sec; /* UTC date of the snapshot */
578     uint32_t date_nsec;
579     uint64_t vm_clock_nsec; /* VM clock relative to boot */
580 } QEMUSnapshotInfo;
581
582 #define BDRV_O_RDONLY      0x0000
583 #define BDRV_O_RDWR        0x0002
584 #define BDRV_O_ACCESS      0x0003
585 #define BDRV_O_CREAT       0x0004 /* create an empty file */
586 #define BDRV_O_SNAPSHOT    0x0008 /* open the file read only and save writes in a snapshot */
587 #define BDRV_O_FILE        0x0010 /* open as a raw file (do not try to
588                                      use a disk image format on top of
589                                      it (default for
590                                      bdrv_file_open()) */
591
592 void bdrv_init(void);
593 BlockDriver *bdrv_find_format(const char *format_name);
594 int bdrv_create(BlockDriver *drv,
595                 const char *filename, int64_t size_in_sectors,
596                 const char *backing_file, int flags);
597 BlockDriverState *bdrv_new(const char *device_name);
598 void bdrv_delete(BlockDriverState *bs);
599 int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
600 int bdrv_open(BlockDriverState *bs, const char *filename, int flags);
601 int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
602                BlockDriver *drv);
603 void bdrv_close(BlockDriverState *bs);
604 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
605               uint8_t *buf, int nb_sectors);
606 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
607                const uint8_t *buf, int nb_sectors);
608 int bdrv_pread(BlockDriverState *bs, int64_t offset,
609                void *buf, int count);
610 int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
611                 const void *buf, int count);
612 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
613 int64_t bdrv_getlength(BlockDriverState *bs);
614 void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
615 int bdrv_commit(BlockDriverState *bs);
616 void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
617 /* async block I/O */
618 typedef struct BlockDriverAIOCB BlockDriverAIOCB;
619 typedef void BlockDriverCompletionFunc(void *opaque, int ret);
620
621 BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,
622                                 uint8_t *buf, int nb_sectors,
623                                 BlockDriverCompletionFunc *cb, void *opaque);
624 BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
625                                  const uint8_t *buf, int nb_sectors,
626                                  BlockDriverCompletionFunc *cb, void *opaque);
627 void bdrv_aio_cancel(BlockDriverAIOCB *acb);
628
629 void qemu_aio_init(void);
630 void qemu_aio_poll(void);
631 void qemu_aio_flush(void);
632 void qemu_aio_wait_start(void);
633 void qemu_aio_wait(void);
634 void qemu_aio_wait_end(void);
635
636 /* Ensure contents are flushed to disk.  */
637 void bdrv_flush(BlockDriverState *bs);
638
639 #define BDRV_TYPE_HD     0
640 #define BDRV_TYPE_CDROM  1
641 #define BDRV_TYPE_FLOPPY 2
642 #define BIOS_ATA_TRANSLATION_AUTO   0
643 #define BIOS_ATA_TRANSLATION_NONE   1
644 #define BIOS_ATA_TRANSLATION_LBA    2
645 #define BIOS_ATA_TRANSLATION_LARGE  3
646 #define BIOS_ATA_TRANSLATION_RECHS  4
647
648 void bdrv_set_geometry_hint(BlockDriverState *bs,
649                             int cyls, int heads, int secs);
650 void bdrv_set_type_hint(BlockDriverState *bs, int type);
651 void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
652 void bdrv_get_geometry_hint(BlockDriverState *bs,
653                             int *pcyls, int *pheads, int *psecs);
654 int bdrv_get_type_hint(BlockDriverState *bs);
655 int bdrv_get_translation_hint(BlockDriverState *bs);
656 int bdrv_is_removable(BlockDriverState *bs);
657 int bdrv_is_read_only(BlockDriverState *bs);
658 int bdrv_is_inserted(BlockDriverState *bs);
659 int bdrv_media_changed(BlockDriverState *bs);
660 int bdrv_is_locked(BlockDriverState *bs);
661 void bdrv_set_locked(BlockDriverState *bs, int locked);
662 void bdrv_eject(BlockDriverState *bs, int eject_flag);
663 void bdrv_set_change_cb(BlockDriverState *bs,
664                         void (*change_cb)(void *opaque), void *opaque);
665 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
666 void bdrv_info(void);
667 BlockDriverState *bdrv_find(const char *name);
668 void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
669 int bdrv_is_encrypted(BlockDriverState *bs);
670 int bdrv_set_key(BlockDriverState *bs, const char *key);
671 void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
672                          void *opaque);
673 const char *bdrv_get_device_name(BlockDriverState *bs);
674 int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
675                           const uint8_t *buf, int nb_sectors);
676 int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
677
678 void bdrv_get_backing_filename(BlockDriverState *bs,
679                                char *filename, int filename_size);
680 int bdrv_snapshot_create(BlockDriverState *bs,
681                          QEMUSnapshotInfo *sn_info);
682 int bdrv_snapshot_goto(BlockDriverState *bs,
683                        const char *snapshot_id);
684 int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
685 int bdrv_snapshot_list(BlockDriverState *bs,
686                        QEMUSnapshotInfo **psn_info);
687 char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
688
689 char *get_human_readable_size(char *buf, int buf_size, int64_t size);
690 int path_is_absolute(const char *path);
691 void path_combine(char *dest, int dest_size,
692                   const char *base_path,
693                   const char *filename);
694
695 #ifndef QEMU_TOOL
696
697 typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size,
698                                  int boot_device,
699              DisplayState *ds, const char **fd_filename, int snapshot,
700              const char *kernel_filename, const char *kernel_cmdline,
701              const char *initrd_filename);
702
703 typedef struct QEMUMachine {
704     const char *name;
705     const char *desc;
706     QEMUMachineInitFunc *init;
707     struct QEMUMachine *next;
708 } QEMUMachine;
709
710 int qemu_register_machine(QEMUMachine *m);
711
712 typedef void SetIRQFunc(void *opaque, int irq_num, int level);
713 typedef void IRQRequestFunc(void *opaque, int level);
714
715 /* ISA bus */
716
717 extern target_phys_addr_t isa_mem_base;
718
719 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
720 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
721
722 int register_ioport_read(int start, int length, int size,
723                          IOPortReadFunc *func, void *opaque);
724 int register_ioport_write(int start, int length, int size,
725                           IOPortWriteFunc *func, void *opaque);
726 void isa_unassign_ioport(int start, int length);
727
728 void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size);
729
730 /* PCI bus */
731
732 extern target_phys_addr_t pci_mem_base;
733
734 typedef struct PCIBus PCIBus;
735 typedef struct PCIDevice PCIDevice;
736
737 typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
738                                 uint32_t address, uint32_t data, int len);
739 typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
740                                    uint32_t address, int len);
741 typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num,
742                                 uint32_t addr, uint32_t size, int type);
743
744 #define PCI_ADDRESS_SPACE_MEM           0x00
745 #define PCI_ADDRESS_SPACE_IO            0x01
746 #define PCI_ADDRESS_SPACE_MEM_PREFETCH  0x08
747
748 typedef struct PCIIORegion {
749     uint32_t addr; /* current PCI mapping address. -1 means not mapped */
750     uint32_t size;
751     uint8_t type;
752     PCIMapIORegionFunc *map_func;
753 } PCIIORegion;
754
755 #define PCI_ROM_SLOT 6
756 #define PCI_NUM_REGIONS 7
757
758 #define PCI_DEVICES_MAX 64
759
760 #define PCI_VENDOR_ID           0x00    /* 16 bits */
761 #define PCI_DEVICE_ID           0x02    /* 16 bits */
762 #define PCI_COMMAND             0x04    /* 16 bits */
763 #define  PCI_COMMAND_IO         0x1     /* Enable response in I/O space */
764 #define  PCI_COMMAND_MEMORY     0x2     /* Enable response in Memory space */
765 #define PCI_CLASS_DEVICE  &