PC machine support
[qemu] / vl.h
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 #include <limits.h>
34 #include <time.h>
35 #include <ctype.h>
36 #include <errno.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <sys/stat.h>
40 #include "audio/audio.h"
41
42 #ifndef O_LARGEFILE
43 #define O_LARGEFILE 0
44 #endif
45 #ifndef O_BINARY
46 #define O_BINARY 0
47 #endif
48
49 #ifdef _WIN32
50 #define lseek _lseeki64
51 #define ENOTSUP 4096
52 /* XXX: find 64 bit version */
53 #define ftruncate chsize
54
55 static inline char *realpath(const char *path, char *resolved_path)
56 {
57     _fullpath(resolved_path, path, _MAX_PATH);
58     return resolved_path;
59 }
60 #endif
61
62 #ifdef QEMU_TOOL
63
64 /* we use QEMU_TOOL in the command line tools which do not depend on
65    the target CPU type */
66 #include "config-host.h"
67 #include <setjmp.h>
68 #include "osdep.h"
69 #include "bswap.h"
70
71 #else
72
73 #include "cpu.h"
74 #include "gdbstub.h"
75
76 #endif /* !defined(QEMU_TOOL) */
77
78 #ifndef glue
79 #define xglue(x, y) x ## y
80 #define glue(x, y) xglue(x, y)
81 #define stringify(s)    tostring(s)
82 #define tostring(s)     #s
83 #endif
84
85 /* vl.c */
86 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
87
88 void hw_error(const char *fmt, ...);
89
90 int get_image_size(const char *filename);
91 int load_image(const char *filename, uint8_t *addr);
92 extern const char *bios_dir;
93
94 void pstrcpy(char *buf, int buf_size, const char *str);
95 char *pstrcat(char *buf, int buf_size, const char *s);
96 int strstart(const char *str, const char *val, const char **ptr);
97
98 extern int vm_running;
99
100 typedef void VMStopHandler(void *opaque, int reason);
101
102 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
103 void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
104
105 void vm_start(void);
106 void vm_stop(int reason);
107
108 typedef void QEMUResetHandler(void *opaque);
109
110 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
111 void qemu_system_reset_request(void);
112 void qemu_system_shutdown_request(void);
113
114 void main_loop_wait(int timeout);
115
116 extern int audio_enabled;
117 extern int sb16_enabled;
118 extern int adlib_enabled;
119 extern int gus_enabled;
120 extern int ram_size;
121 extern int bios_size;
122 extern int rtc_utc;
123 extern int cirrus_vga_enabled;
124 extern int graphic_width;
125 extern int graphic_height;
126 extern int graphic_depth;
127 extern const char *keyboard_layout;
128 extern int kqemu_allowed;
129 extern int win2k_install_hack;
130
131 /* XXX: make it dynamic */
132 #if defined (TARGET_PPC)
133 #define BIOS_SIZE (512 * 1024)
134 #else
135 #define BIOS_SIZE ((256 + 64) * 1024)
136 #endif
137
138 /* keyboard/mouse support */
139
140 #define MOUSE_EVENT_LBUTTON 0x01
141 #define MOUSE_EVENT_RBUTTON 0x02
142 #define MOUSE_EVENT_MBUTTON 0x04
143
144 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
145 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
146
147 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
148 void qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque);
149
150 void kbd_put_keycode(int keycode);
151 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
152
153 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
154    constants) */
155 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
156 #define QEMU_KEY_BACKSPACE  0x007f
157 #define QEMU_KEY_UP         QEMU_KEY_ESC1('A')
158 #define QEMU_KEY_DOWN       QEMU_KEY_ESC1('B')
159 #define QEMU_KEY_RIGHT      QEMU_KEY_ESC1('C')
160 #define QEMU_KEY_LEFT       QEMU_KEY_ESC1('D')
161 #define QEMU_KEY_HOME       QEMU_KEY_ESC1(1)
162 #define QEMU_KEY_END        QEMU_KEY_ESC1(4)
163 #define QEMU_KEY_PAGEUP     QEMU_KEY_ESC1(5)
164 #define QEMU_KEY_PAGEDOWN   QEMU_KEY_ESC1(6)
165 #define QEMU_KEY_DELETE     QEMU_KEY_ESC1(3)
166
167 #define QEMU_KEY_CTRL_UP         0xe400
168 #define QEMU_KEY_CTRL_DOWN       0xe401
169 #define QEMU_KEY_CTRL_LEFT       0xe402
170 #define QEMU_KEY_CTRL_RIGHT      0xe403
171 #define QEMU_KEY_CTRL_HOME       0xe404
172 #define QEMU_KEY_CTRL_END        0xe405
173 #define QEMU_KEY_CTRL_PAGEUP     0xe406
174 #define QEMU_KEY_CTRL_PAGEDOWN   0xe407
175
176 void kbd_put_keysym(int keysym);
177
178 /* async I/O support */
179
180 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
181 typedef int IOCanRWHandler(void *opaque);
182
183 int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read, 
184                              IOReadHandler *fd_read, void *opaque);
185 void qemu_del_fd_read_handler(int fd);
186
187 /* character device */
188
189 #define CHR_EVENT_BREAK 0 /* serial break char */
190 #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
191
192 typedef void IOEventHandler(void *opaque, int event);
193
194 typedef struct CharDriverState {
195     int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
196     void (*chr_add_read_handler)(struct CharDriverState *s, 
197                                  IOCanRWHandler *fd_can_read, 
198                                  IOReadHandler *fd_read, void *opaque);
199     IOEventHandler *chr_event;
200     void (*chr_send_event)(struct CharDriverState *chr, int event);
201     void *opaque;
202 } CharDriverState;
203
204 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
205 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
206 void qemu_chr_send_event(CharDriverState *s, int event);
207 void qemu_chr_add_read_handler(CharDriverState *s, 
208                                IOCanRWHandler *fd_can_read, 
209                                IOReadHandler *fd_read, void *opaque);
210 void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event);
211                                
212 /* consoles */
213
214 typedef struct DisplayState DisplayState;
215 typedef struct TextConsole TextConsole;
216
217 extern TextConsole *vga_console;
218
219 TextConsole *graphic_console_init(DisplayState *ds);
220 int is_active_console(TextConsole *s);
221 CharDriverState *text_console_init(DisplayState *ds);
222 void console_select(unsigned int index);
223
224 /* serial ports */
225
226 #define MAX_SERIAL_PORTS 4
227
228 extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
229
230 /* parallel ports */
231
232 #define MAX_PARALLEL_PORTS 3
233
234 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
235
236 /* network redirectors support */
237
238 #define MAX_NICS 8
239
240 typedef struct NetDriverState {
241     int index; /* index number in QEMU */
242     uint8_t macaddr[6];
243     char ifname[16];
244     void (*send_packet)(struct NetDriverState *nd, 
245                         const uint8_t *buf, int size);
246     void (*add_read_packet)(struct NetDriverState *nd, 
247                             IOCanRWHandler *fd_can_read, 
248                             IOReadHandler *fd_read, void *opaque);
249     /* tun specific data */
250     int fd;
251     /* slirp specific data */
252 } NetDriverState;
253
254 extern int nb_nics;
255 extern NetDriverState nd_table[MAX_NICS];
256
257 void qemu_send_packet(NetDriverState *nd, const uint8_t *buf, int size);
258 void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read, 
259                           IOReadHandler *fd_read, void *opaque);
260
261 /* timers */
262
263 typedef struct QEMUClock QEMUClock;
264 typedef struct QEMUTimer QEMUTimer;
265 typedef void QEMUTimerCB(void *opaque);
266
267 /* The real time clock should be used only for stuff which does not
268    change the virtual machine state, as it is run even if the virtual
269    machine is stopped. The real time clock has a frequency of 1000
270    Hz. */
271 extern QEMUClock *rt_clock;
272
273 /* The virtual clock is only run during the emulation. It is stopped
274    when the virtual machine is stopped. Virtual timers use a high
275    precision clock, usually cpu cycles (use ticks_per_sec). */
276 extern QEMUClock *vm_clock;
277
278 int64_t qemu_get_clock(QEMUClock *clock);
279
280 QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
281 void qemu_free_timer(QEMUTimer *ts);
282 void qemu_del_timer(QEMUTimer *ts);
283 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
284 int qemu_timer_pending(QEMUTimer *ts);
285
286 extern int64_t ticks_per_sec;
287 extern int pit_min_timer_count;
288
289 void cpu_enable_ticks(void);
290 void cpu_disable_ticks(void);
291
292 /* VM Load/Save */
293
294 typedef FILE QEMUFile;
295
296 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
297 void qemu_put_byte(QEMUFile *f, int v);
298 void qemu_put_be16(QEMUFile *f, unsigned int v);
299 void qemu_put_be32(QEMUFile *f, unsigned int v);
300 void qemu_put_be64(QEMUFile *f, uint64_t v);
301 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
302 int qemu_get_byte(QEMUFile *f);
303 unsigned int qemu_get_be16(QEMUFile *f);
304 unsigned int qemu_get_be32(QEMUFile *f);
305 uint64_t qemu_get_be64(QEMUFile *f);
306
307 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
308 {
309     qemu_put_be64(f, *pv);
310 }
311
312 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
313 {
314     qemu_put_be32(f, *pv);
315 }
316
317 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
318 {
319     qemu_put_be16(f, *pv);
320 }
321
322 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
323 {
324     qemu_put_byte(f, *pv);
325 }
326
327 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
328 {
329     *pv = qemu_get_be64(f);
330 }
331
332 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
333 {
334     *pv = qemu_get_be32(f);
335 }
336
337 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
338 {
339     *pv = qemu_get_be16(f);
340 }
341
342 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
343 {
344     *pv = qemu_get_byte(f);
345 }
346
347 #if TARGET_LONG_BITS == 64
348 #define qemu_put_betl qemu_put_be64
349 #define qemu_get_betl qemu_get_be64
350 #define qemu_put_betls qemu_put_be64s
351 #define qemu_get_betls qemu_get_be64s
352 #else
353 #define qemu_put_betl qemu_put_be32
354 #define qemu_get_betl qemu_get_be32
355 #define qemu_put_betls qemu_put_be32s
356 #define qemu_get_betls qemu_get_be32s
357 #endif
358
359 int64_t qemu_ftell(QEMUFile *f);
360 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
361
362 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
363 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
364
365 int qemu_loadvm(const char *filename);
366 int qemu_savevm(const char *filename);
367 int register_savevm(const char *idstr, 
368                     int instance_id, 
369                     int version_id,
370                     SaveStateHandler *save_state,
371                     LoadStateHandler *load_state,
372                     void *opaque);
373 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
374 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
375
376 /* block.c */
377 typedef struct BlockDriverState BlockDriverState;
378 typedef struct BlockDriver BlockDriver;
379
380 extern BlockDriver bdrv_raw;
381 extern BlockDriver bdrv_cow;
382 extern BlockDriver bdrv_qcow;
383 extern BlockDriver bdrv_vmdk;
384 extern BlockDriver bdrv_cloop;
385 extern BlockDriver bdrv_dmg;
386 extern BlockDriver bdrv_bochs;
387 extern BlockDriver bdrv_vpc;
388 extern BlockDriver bdrv_vvfat;
389
390 void bdrv_init(void);
391 BlockDriver *bdrv_find_format(const char *format_name);
392 int bdrv_create(BlockDriver *drv, 
393                 const char *filename, int64_t size_in_sectors,
394                 const char *backing_file, int flags);
395 BlockDriverState *bdrv_new(const char *device_name);
396 void bdrv_delete(BlockDriverState *bs);
397 int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
398 int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
399                BlockDriver *drv);
400 void bdrv_close(BlockDriverState *bs);
401 int bdrv_read(BlockDriverState *bs, int64_t sector_num, 
402               uint8_t *buf, int nb_sectors);
403 int bdrv_write(BlockDriverState *bs, int64_t sector_num, 
404                const uint8_t *buf, int nb_sectors);
405 void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
406 int bdrv_commit(BlockDriverState *bs);
407 void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
408
409 #define BDRV_TYPE_HD     0
410 #define BDRV_TYPE_CDROM  1
411 #define BDRV_TYPE_FLOPPY 2
412 #define BIOS_ATA_TRANSLATION_AUTO 0
413 #define BIOS_ATA_TRANSLATION_NONE 1
414 #define BIOS_ATA_TRANSLATION_LBA  2
415
416 void bdrv_set_geometry_hint(BlockDriverState *bs, 
417                             int cyls, int heads, int secs);
418 void bdrv_set_type_hint(BlockDriverState *bs, int type);
419 void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
420 void bdrv_get_geometry_hint(BlockDriverState *bs, 
421                             int *pcyls, int *pheads, int *psecs);
422 int bdrv_get_type_hint(BlockDriverState *bs);
423 int bdrv_get_translation_hint(BlockDriverState *bs);
424 int bdrv_is_removable(BlockDriverState *bs);
425 int bdrv_is_read_only(BlockDriverState *bs);
426 int bdrv_is_inserted(BlockDriverState *bs);
427 int bdrv_is_locked(BlockDriverState *bs);
428 void bdrv_set_locked(BlockDriverState *bs, int locked);
429 void bdrv_set_change_cb(BlockDriverState *bs, 
430                         void (*change_cb)(void *opaque), void *opaque);
431 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
432 void bdrv_info(void);
433 BlockDriverState *bdrv_find(const char *name);
434 void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
435 int bdrv_is_encrypted(BlockDriverState *bs);
436 int bdrv_set_key(BlockDriverState *bs, const char *key);
437 void bdrv_iterate_format(void (*it)(void *opaque, const char *name), 
438                          void *opaque);
439 const char *bdrv_get_device_name(BlockDriverState *bs);
440
441 int qcow_get_cluster_size(BlockDriverState *bs);
442 int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num,
443                           const uint8_t *buf);
444
445 #ifndef QEMU_TOOL
446
447 typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size, 
448                                  int boot_device,
449              DisplayState *ds, const char **fd_filename, int snapshot,
450              const char *kernel_filename, const char *kernel_cmdline,
451              const char *initrd_filename);
452
453 typedef struct QEMUMachine {
454     const char *name;
455     const char *desc;
456     QEMUMachineInitFunc *init;
457     struct QEMUMachine *next;
458 } QEMUMachine;
459
460 int qemu_register_machine(QEMUMachine *m);
461
462 typedef void SetIRQFunc(void *opaque, int irq_num, int level);
463
464 /* ISA bus */
465
466 extern target_phys_addr_t isa_mem_base;
467
468 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
469 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
470
471 int register_ioport_read(int start, int length, int size, 
472                          IOPortReadFunc *func, void *opaque);
473 int register_ioport_write(int start, int length, int size, 
474                           IOPortWriteFunc *func, void *opaque);
475 void isa_unassign_ioport(int start, int length);
476
477 /* PCI bus */
478
479 extern int pci_enabled;
480
481 extern target_phys_addr_t pci_mem_base;
482
483 typedef struct PCIBus PCIBus;
484 typedef struct PCIDevice PCIDevice;
485
486 typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, 
487                                 uint32_t address, uint32_t data, int len);
488 typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, 
489                                    uint32_t address, int len);
490 typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, 
491                                 uint32_t addr, uint32_t size, int type);
492
493 #define PCI_ADDRESS_SPACE_MEM           0x00
494 #define PCI_ADDRESS_SPACE_IO            0x01
495 #define PCI_ADDRESS_SPACE_MEM_PREFETCH  0x08
496
497 typedef struct PCIIORegion {
498     uint32_t addr; /* current PCI mapping address. -1 means not mapped */
499     uint32_t size;
500     uint8_t type;
501     PCIMapIORegionFunc *map_func;
502 } PCIIORegion;
503
504 #define PCI_ROM_SLOT 6
505 #define PCI_NUM_REGIONS 7
506 struct PCIDevice {
507     /* PCI config space */
508     uint8_t config[256];
509
510     /* the following fields are read only */
511     PCIBus *bus;
512     int devfn;
513     char name[64];
514     PCIIORegion io_regions[PCI_NUM_REGIONS];
515     
516     /* do not access the following fields */
517     PCIConfigReadFunc *config_read;
518     PCIConfigWriteFunc *config_write;
519     int irq_index;
520 };
521
522 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
523                                int instance_size, int devfn,
524                                PCIConfigReadFunc *config_read, 
525                                PCIConfigWriteFunc *config_write);
526
527 void pci_register_io_region(PCIDevice *pci_dev, int region_num, 
528                             uint32_t size, int type, 
529                             PCIMapIORegionFunc *map_func);
530
531 void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level);
532
533 uint32_t pci_default_read_config(PCIDevice *d, 
534                                  uint32_t address, int len);
535 void pci_default_write_config(PCIDevice *d, 
536                               uint32_t address, uint32_t val, int len);
537 void generic_pci_save(QEMUFile* f, void *opaque);
538 int generic_pci_load(QEMUFile* f, void *opaque, int version_id);
539
540 extern struct PIIX3State *piix3_state;
541
542 PCIBus *i440fx_init(void);
543 void piix3_init(PCIBus *bus);
544 void pci_bios_init(void);
545 void pci_info(void);
546
547 /* temporary: will be moved in platform specific file */
548 void pci_set_pic(PCIBus *bus, SetIRQFunc *set_irq, void *irq_opaque);
549 PCIBus *pci_prep_init(void);
550 PCIBus *pci_grackle_init(uint32_t base);
551 PCIBus *pci_pmac_init(void);
552
553 /* openpic.c */
554 typedef struct openpic_t openpic_t;
555 void openpic_set_irq(void *opaque, int n_IRQ, int level);
556 openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus);
557
558 /* heathrow_pic.c */
559 typedef struct HeathrowPICS HeathrowPICS;
560 void heathrow_pic_set_irq(void *opaque, int num, int level);
561 HeathrowPICS *heathrow_pic_init(int *pmem_index);
562
563 /* vga.c */
564
565 #define VGA_RAM_SIZE (4096 * 1024)
566
567 struct DisplayState {
568     uint8_t *data;
569     int linesize;
570     int depth;
571     int width;
572     int height;
573     void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
574     void (*dpy_resize)(struct DisplayState *s, int w, int h);
575     void (*dpy_refresh)(struct DisplayState *s);
576 };
577
578 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
579 {
580     s->dpy_update(s, x, y, w, h);
581 }
582
583 static inline void dpy_resize(DisplayState *s, int w, int h)
584 {
585     s->dpy_resize(s, w, h);
586 }
587
588 int vga_initialize(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
589                    unsigned long vga_ram_offset, int vga_ram_size);
590 void vga_update_display(void);
591 void vga_invalidate_display(void);
592 void vga_screen_dump(const char *filename);
593
594 /* cirrus_vga.c */
595 void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
596                          unsigned long vga_ram_offset, int vga_ram_size);
597 void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base, 
598                          unsigned long vga_ram_offset, int vga_ram_size);
599
600 /* sdl.c */
601 void sdl_display_init(DisplayState *ds, int full_screen);
602
603 /* cocoa.m */
604 void cocoa_display_init(DisplayState *ds, int full_screen);
605
606 /* ide.c */
607 #define MAX_DISKS 4
608
609 extern BlockDriverState *bs_table[MAX_DISKS];
610
611 void isa_ide_init(int iobase, int iobase2, int irq,
612                   BlockDriverState *hd0, BlockDriverState *hd1);
613 void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
614                          int secondary_ide_enabled);
615 void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table);
616 int pmac_ide_init (BlockDriverState **hd_table,
617                    SetIRQFunc *set_irq, void *irq_opaque, int irq);
618
619 /* sb16.c */
620 void SB16_init (void);
621
622 /* adlib.c */
623 void Adlib_init (void);
624
625 /* gus.c */
626 void GUS_init (void);
627
628 /* dma.c */
629 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
630 int DMA_get_channel_mode (int nchan);
631 int DMA_read_memory (int nchan, void *buf, int pos, int size);
632 int DMA_write_memory (int nchan, void *buf, int pos, int size);
633 void DMA_hold_DREQ (int nchan);
634 void DMA_release_DREQ (int nchan);
635 void DMA_schedule(int nchan);
636 void DMA_run (void);
637 void DMA_init (int high_page_enable);
638 void DMA_register_channel (int nchan,
639                            DMA_transfer_handler transfer_handler,
640                            void *opaque);
641 /* fdc.c */
642 #define MAX_FD 2
643 extern BlockDriverState *fd_table[MAX_FD];
644
645 typedef struct fdctrl_t fdctrl_t;
646
647 fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, 
648                        uint32_t io_base,
649                        BlockDriverState **fds);
650 int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
651
652 /* ne2000.c */
653
654 void isa_ne2000_init(int base, int irq, NetDriverState *nd);
655 void pci_ne2000_init(PCIBus *bus, NetDriverState *nd);
656
657 /* pckbd.c */
658
659 void kbd_init(void);
660
661 /* mc146818rtc.c */
662
663 typedef struct RTCState RTCState;
664
665 RTCState *rtc_init(int base, int irq);
666 void rtc_set_memory(RTCState *s, int addr, int val);
667 void rtc_set_date(RTCState *s, const struct tm *tm);
668
669 /* serial.c */
670
671 typedef struct SerialState SerialState;
672 SerialState *serial_init(int base, int irq, CharDriverState *chr);
673
674 /* parallel.c */
675
676 typedef struct ParallelState ParallelState;
677 ParallelState *parallel_init(int base, int irq, CharDriverState *chr);
678
679 /* i8259.c */
680
681 void pic_set_irq(int irq, int level);
682 void pic_set_irq_new(void *opaque, int irq, int level);
683 void pic_init(void);
684 uint32_t pic_intack_read(CPUState *env);
685 void pic_info(void);
686 void irq_info(void);
687
688 /* APIC */
689 int apic_init(CPUState *env);
690 int apic_get_interrupt(CPUState *env);
691
692 /* i8254.c */
693
694 #define PIT_FREQ 1193182
695
696 typedef struct PITState PITState;
697
698 PITState *pit_init(int base, int irq);
699 void pit_set_gate(PITState *pit, int channel, int val);
700 int pit_get_gate(PITState *pit, int channel);
701 int pit_get_out(PITState *pit, int channel, int64_t current_time);
702
703 /* pc.c */
704 extern QEMUMachine pc_machine;
705
706 /* ppc.c */
707 extern QEMUMachine prep_machine;
708 extern QEMUMachine core99_machine;
709 extern QEMUMachine heathrow_machine;
710
711 #ifdef TARGET_PPC
712 ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq);
713 #endif
714 void PREP_debug_write (void *opaque, uint32_t addr, uint32_t val);
715
716 extern CPUWriteMemoryFunc *PPC_io_write[];
717 extern CPUReadMemoryFunc *PPC_io_read[];
718 extern int prep_enabled;
719 void PPC_debug_write (void *opaque, uint32_t addr, uint32_t val);
720
721 /* sun4m.c */
722 extern QEMUMachine sun4m_machine;
723 uint32_t iommu_translate(uint32_t addr);
724
725 /* iommu.c */
726 void *iommu_init(uint32_t addr);
727 uint32_t iommu_translate_local(void *opaque, uint32_t addr);
728
729 /* lance.c */
730 void lance_init(NetDriverState *nd, int irq, uint32_t leaddr, uint32_t ledaddr);
731
732 /* tcx.c */
733 void *tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
734                unsigned long vram_offset, int vram_size, int width, int height);
735 void tcx_update_display(void *opaque);
736 void tcx_invalidate_display(void *opaque);
737 void tcx_screen_dump(void *opaque, const char *filename);
738
739 /* slavio_intctl.c */
740 void *slavio_intctl_init();
741 void slavio_pic_info(void *opaque);
742 void slavio_irq_info(void *opaque);
743 void slavio_pic_set_irq(void *opaque, int irq, int level);
744
745 /* magic-load.c */
746 int load_elf(const char *filename, uint8_t *addr);
747 int load_aout(const char *filename, uint8_t *addr);
748
749 /* slavio_timer.c */
750 void slavio_timer_init(uint32_t addr1, int irq1, uint32_t addr2, int irq2);
751
752 /* slavio_serial.c */
753 SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDriverState *chr2);
754 void slavio_serial_ms_kbd_init(int base, int irq);
755
756 /* esp.c */
757 void esp_init(BlockDriverState **bd, int irq, uint32_t espaddr, uint32_t espdaddr);
758
759 /* NVRAM helpers */
760 #include "hw/m48t59.h"
761
762 void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value);
763 uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr);
764 void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value);
765 uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr);
766 void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr, uint32_t value);
767 uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr);
768 void NVRAM_set_string (m48t59_t *nvram, uint32_t addr,
769                        const unsigned char *str, uint32_t max);
770 int NVRAM_get_string (m48t59_t *nvram, uint8_t *dst, uint16_t addr, int max);
771 void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr,
772                     uint32_t start, uint32_t count);
773 int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
774                           const unsigned char *arch,
775                           uint32_t RAM_size, int boot_device,
776                           uint32_t kernel_image, uint32_t kernel_size,
777                           const char *cmdline,
778                           uint32_t initrd_image, uint32_t initrd_size,
779                           uint32_t NVRAM_image,
780                           int width, int height, int depth);
781
782 /* adb.c */
783
784 #define MAX_ADB_DEVICES 16
785
786 #define ADB_MAX_OUT_LEN 16
787
788 typedef struct ADBDevice ADBDevice;
789
790 /* buf = NULL means polling */
791 typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
792                               const uint8_t *buf, int len);
793 typedef int ADBDeviceReset(ADBDevice *d);
794
795 struct ADBDevice {
796     struct ADBBusState *bus;
797     int devaddr;
798     int handler;
799     ADBDeviceRequest *devreq;
800     ADBDeviceReset *devreset;
801     void *opaque;
802 };
803
804 typedef struct ADBBusState {
805     ADBDevice devices[MAX_ADB_DEVICES];
806     int nb_devices;
807     int poll_index;
808 } ADBBusState;
809
810 int adb_request(ADBBusState *s, uint8_t *buf_out,
811                 const uint8_t *buf, int len);
812 int adb_poll(ADBBusState *s, uint8_t *buf_out);
813
814 ADBDevice *adb_register_device(ADBBusState *s, int devaddr, 
815                                ADBDeviceRequest *devreq, 
816                                ADBDeviceReset *devreset, 
817                                void *opaque);
818 void adb_kbd_init(ADBBusState *bus);
819 void adb_mouse_init(ADBBusState *bus);
820
821 /* cuda.c */
822
823 extern ADBBusState adb_bus;
824 int cuda_init(SetIRQFunc *set_irq, void *irq_opaque, int irq);
825
826 #endif /* defined(QEMU_TOOL) */
827
828 /* monitor.c */
829 void monitor_init(CharDriverState *hd, int show_banner);
830 void term_puts(const char *str);
831 void term_vprintf(const char *fmt, va_list ap);
832 void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
833 void term_flush(void);
834 void term_print_help(void);
835 void monitor_readline(const char *prompt, int is_password,
836                       char *buf, int buf_size);
837
838 /* readline.c */
839 typedef void ReadLineFunc(void *opaque, const char *str);
840
841 extern int completion_index;
842 void add_completion(const char *str);
843 void readline_handle_byte(int ch);
844 void readline_find_completion(const char *cmdline);
845 const char *readline_get_history(unsigned int index);
846 void readline_start(const char *prompt, int is_password,
847                     ReadLineFunc *readline_func, void *opaque);
848
849 #endif /* VL_H */