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