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