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