blob: 5091ca14e7a91f76ad9f5fdbc407545baf00e27f [file] [log] [blame]
bellardfc01f7e2003-06-30 10:03:06 +00001/*
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
bellard67b915a2004-03-31 23:37:16 +000027/* 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>
bellard85571bc2004-11-07 18:04:02 +000033#include <limits.h>
bellard8a7ddc32004-03-31 19:00:16 +000034#include <time.h>
bellard67b915a2004-03-31 23:37:16 +000035#include <ctype.h>
36#include <errno.h>
37#include <unistd.h>
38#include <fcntl.h>
bellard7d3505c2004-05-12 19:32:15 +000039#include <sys/stat.h>
bellardfb065182004-11-09 23:09:44 +000040#include "audio/audio.h"
bellard67b915a2004-03-31 23:37:16 +000041
42#ifndef O_LARGEFILE
43#define O_LARGEFILE 0
44#endif
bellard40c3bac2004-04-04 12:56:28 +000045#ifndef O_BINARY
46#define O_BINARY 0
47#endif
bellard67b915a2004-03-31 23:37:16 +000048
49#ifdef _WIN32
bellard57d1a2b2004-08-03 21:15:11 +000050#define lseek _lseeki64
51#define ENOTSUP 4096
52/* XXX: find 64 bit version */
53#define ftruncate chsize
54
55static inline char *realpath(const char *path, char *resolved_path)
56{
57 _fullpath(resolved_path, path, _MAX_PATH);
58 return resolved_path;
59}
bellard67b915a2004-03-31 23:37:16 +000060#endif
bellard8a7ddc32004-03-31 19:00:16 +000061
bellardea2384d2004-08-01 21:59:26 +000062#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
bellard16f62432004-02-25 23:25:55 +000073#include "cpu.h"
74
bellardea2384d2004-08-01 21:59:26 +000075#endif /* !defined(QEMU_TOOL) */
76
bellard67b915a2004-03-31 23:37:16 +000077#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
bellard33e39632003-07-06 17:15:21 +000084/* vl.c */
bellard80cabfa2004-03-14 12:20:30 +000085uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
bellard313aa562003-08-10 21:52:11 +000086
bellard80cabfa2004-03-14 12:20:30 +000087void hw_error(const char *fmt, ...);
88
bellard7587cf42004-06-20 13:43:27 +000089int get_image_size(const char *filename);
bellard80cabfa2004-03-14 12:20:30 +000090int load_image(const char *filename, uint8_t *addr);
91extern const char *bios_dir;
92
93void pstrcpy(char *buf, int buf_size, const char *str);
94char *pstrcat(char *buf, int buf_size, const char *s);
bellard82c643f2004-07-14 17:28:13 +000095int strstart(const char *str, const char *val, const char **ptr);
bellardc4b1fcc2004-03-14 21:44:30 +000096
bellard8a7ddc32004-03-31 19:00:16 +000097extern int vm_running;
98
99typedef void VMStopHandler(void *opaque, int reason);
100
101int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
102void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
103
104void vm_start(void);
105void vm_stop(int reason);
106
bellardbb0c6722004-06-20 12:37:32 +0000107typedef void QEMUResetHandler(void *opaque);
108
109void qemu_register_reset(QEMUResetHandler *func, void *opaque);
110void qemu_system_reset_request(void);
111void qemu_system_shutdown_request(void);
112
bellardea2384d2004-08-01 21:59:26 +0000113void main_loop_wait(int timeout);
114
bellardaaaa7df2004-04-26 20:56:53 +0000115extern int audio_enabled;
bellardfb065182004-11-09 23:09:44 +0000116extern int sb16_enabled;
117extern int adlib_enabled;
118extern int gus_enabled;
bellard0ced6582004-05-23 21:06:12 +0000119extern int ram_size;
120extern int bios_size;
bellardee22c2f2004-06-03 12:49:50 +0000121extern int rtc_utc;
bellard1f042752004-06-05 13:46:47 +0000122extern int cirrus_vga_enabled;
bellard28b9b5a2004-06-21 16:46:35 +0000123extern int graphic_width;
124extern int graphic_height;
125extern int graphic_depth;
bellard3d11d0e2004-12-12 16:56:30 +0000126extern const char *keyboard_layout;
bellardd993e022005-02-10 22:00:06 +0000127extern int kqemu_allowed;
bellard0ced6582004-05-23 21:06:12 +0000128
129/* XXX: make it dynamic */
130#if defined (TARGET_PPC)
131#define BIOS_SIZE (512 * 1024)
132#else
bellard7587cf42004-06-20 13:43:27 +0000133#define BIOS_SIZE ((256 + 64) * 1024)
bellard0ced6582004-05-23 21:06:12 +0000134#endif
bellardaaaa7df2004-04-26 20:56:53 +0000135
bellard63066f42004-06-03 18:45:02 +0000136/* keyboard/mouse support */
137
138#define MOUSE_EVENT_LBUTTON 0x01
139#define MOUSE_EVENT_RBUTTON 0x02
140#define MOUSE_EVENT_MBUTTON 0x04
141
142typedef void QEMUPutKBDEvent(void *opaque, int keycode);
143typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
144
145void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
146void qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque);
147
148void kbd_put_keycode(int keycode);
149void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
150
bellard82c643f2004-07-14 17:28:13 +0000151/* 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
174void kbd_put_keysym(int keysym);
175
bellardc4b1fcc2004-03-14 21:44:30 +0000176/* async I/O support */
177
178typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
179typedef int IOCanRWHandler(void *opaque);
180
bellard8a7ddc32004-03-31 19:00:16 +0000181int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read,
182 IOReadHandler *fd_read, void *opaque);
183void qemu_del_fd_read_handler(int fd);
184
bellard82c643f2004-07-14 17:28:13 +0000185/* character device */
186
187#define CHR_EVENT_BREAK 0 /* serial break char */
bellardea2384d2004-08-01 21:59:26 +0000188#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
bellard82c643f2004-07-14 17:28:13 +0000189
190typedef void IOEventHandler(void *opaque, int event);
191
192typedef 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;
bellardeb45f5f2004-09-18 19:33:09 +0000198 void (*chr_send_event)(struct CharDriverState *chr, int event);
bellard82c643f2004-07-14 17:28:13 +0000199 void *opaque;
200} CharDriverState;
201
202void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
203int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
bellardea2384d2004-08-01 21:59:26 +0000204void qemu_chr_send_event(CharDriverState *s, int event);
bellard82c643f2004-07-14 17:28:13 +0000205void qemu_chr_add_read_handler(CharDriverState *s,
206 IOCanRWHandler *fd_can_read,
207 IOReadHandler *fd_read, void *opaque);
208void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event);
209
bellard82c643f2004-07-14 17:28:13 +0000210/* consoles */
211
212typedef struct DisplayState DisplayState;
213typedef struct TextConsole TextConsole;
214
215extern TextConsole *vga_console;
216
217TextConsole *graphic_console_init(DisplayState *ds);
218int is_active_console(TextConsole *s);
219CharDriverState *text_console_init(DisplayState *ds);
220void console_select(unsigned int index);
221
bellard8d11df92004-08-24 21:13:40 +0000222/* serial ports */
223
224#define MAX_SERIAL_PORTS 4
225
226extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
227
bellard6508fe52005-01-15 12:02:56 +0000228/* parallel ports */
229
230#define MAX_PARALLEL_PORTS 3
231
232extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
233
bellardc20709a2004-04-21 23:27:19 +0000234/* network redirectors support */
235
236#define MAX_NICS 8
237
238typedef 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
252extern int nb_nics;
253extern NetDriverState nd_table[MAX_NICS];
254
255void qemu_send_packet(NetDriverState *nd, const uint8_t *buf, int size);
256void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read,
257 IOReadHandler *fd_read, void *opaque);
258
bellard8a7ddc32004-03-31 19:00:16 +0000259/* timers */
260
261typedef struct QEMUClock QEMUClock;
262typedef struct QEMUTimer QEMUTimer;
263typedef 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
bellard69b91032004-05-18 23:05:28 +0000267 machine is stopped. The real time clock has a frequency of 1000
bellard8a7ddc32004-03-31 19:00:16 +0000268 Hz. */
269extern QEMUClock *rt_clock;
270
bellarde80cfcf2004-12-19 23:18:01 +0000271/* The virtual clock is only run during the emulation. It is stopped
bellard8a7ddc32004-03-31 19:00:16 +0000272 when the virtual machine is stopped. Virtual timers use a high
273 precision clock, usually cpu cycles (use ticks_per_sec). */
274extern QEMUClock *vm_clock;
275
276int64_t qemu_get_clock(QEMUClock *clock);
277
278QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
279void qemu_free_timer(QEMUTimer *ts);
280void qemu_del_timer(QEMUTimer *ts);
281void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
282int qemu_timer_pending(QEMUTimer *ts);
283
284extern int64_t ticks_per_sec;
285extern int pit_min_timer_count;
286
287void cpu_enable_ticks(void);
288void cpu_disable_ticks(void);
289
290/* VM Load/Save */
291
292typedef FILE QEMUFile;
293
294void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
295void qemu_put_byte(QEMUFile *f, int v);
296void qemu_put_be16(QEMUFile *f, unsigned int v);
297void qemu_put_be32(QEMUFile *f, unsigned int v);
298void qemu_put_be64(QEMUFile *f, uint64_t v);
299int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
300int qemu_get_byte(QEMUFile *f);
301unsigned int qemu_get_be16(QEMUFile *f);
302unsigned int qemu_get_be32(QEMUFile *f);
303uint64_t qemu_get_be64(QEMUFile *f);
304
305static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
306{
307 qemu_put_be64(f, *pv);
308}
309
310static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
311{
312 qemu_put_be32(f, *pv);
313}
314
315static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
316{
317 qemu_put_be16(f, *pv);
318}
319
320static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
321{
322 qemu_put_byte(f, *pv);
323}
324
325static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
326{
327 *pv = qemu_get_be64(f);
328}
329
330static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
331{
332 *pv = qemu_get_be32(f);
333}
334
335static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
336{
337 *pv = qemu_get_be16(f);
338}
339
340static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
341{
342 *pv = qemu_get_byte(f);
343}
344
bellardc27004e2005-01-03 23:35:10 +0000345#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
bellard8a7ddc32004-03-31 19:00:16 +0000357int64_t qemu_ftell(QEMUFile *f);
358int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
359
360typedef void SaveStateHandler(QEMUFile *f, void *opaque);
361typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
362
363int qemu_loadvm(const char *filename);
364int qemu_savevm(const char *filename);
365int register_savevm(const char *idstr,
366 int instance_id,
367 int version_id,
368 SaveStateHandler *save_state,
369 LoadStateHandler *load_state,
370 void *opaque);
371void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
372void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
bellardc4b1fcc2004-03-14 21:44:30 +0000373
bellardfc01f7e2003-06-30 10:03:06 +0000374/* block.c */
375typedef struct BlockDriverState BlockDriverState;
bellardea2384d2004-08-01 21:59:26 +0000376typedef struct BlockDriver BlockDriver;
bellardfc01f7e2003-06-30 10:03:06 +0000377
bellardea2384d2004-08-01 21:59:26 +0000378extern BlockDriver bdrv_raw;
379extern BlockDriver bdrv_cow;
380extern BlockDriver bdrv_qcow;
381extern BlockDriver bdrv_vmdk;
bellard3c565212004-09-29 21:29:14 +0000382extern BlockDriver bdrv_cloop;
bellard585d0ed2004-12-12 11:24:44 +0000383extern BlockDriver bdrv_dmg;
bellardea2384d2004-08-01 21:59:26 +0000384
385void bdrv_init(void);
386BlockDriver *bdrv_find_format(const char *format_name);
387int bdrv_create(BlockDriver *drv,
388 const char *filename, int64_t size_in_sectors,
389 const char *backing_file, int flags);
bellardc4b1fcc2004-03-14 21:44:30 +0000390BlockDriverState *bdrv_new(const char *device_name);
391void bdrv_delete(BlockDriverState *bs);
392int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
bellardea2384d2004-08-01 21:59:26 +0000393int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
394 BlockDriver *drv);
bellardfc01f7e2003-06-30 10:03:06 +0000395void bdrv_close(BlockDriverState *bs);
396int bdrv_read(BlockDriverState *bs, int64_t sector_num,
397 uint8_t *buf, int nb_sectors);
398int bdrv_write(BlockDriverState *bs, int64_t sector_num,
399 const uint8_t *buf, int nb_sectors);
400void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
bellard33e39632003-07-06 17:15:21 +0000401int bdrv_commit(BlockDriverState *bs);
bellard77fef8c2004-02-16 22:05:46 +0000402void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
bellardfc01f7e2003-06-30 10:03:06 +0000403
bellardc4b1fcc2004-03-14 21:44:30 +0000404#define BDRV_TYPE_HD 0
405#define BDRV_TYPE_CDROM 1
406#define BDRV_TYPE_FLOPPY 2
bellard46d47672004-11-16 01:45:27 +0000407#define BIOS_ATA_TRANSLATION_AUTO 0
408#define BIOS_ATA_TRANSLATION_NONE 1
409#define BIOS_ATA_TRANSLATION_LBA 2
bellardc4b1fcc2004-03-14 21:44:30 +0000410
411void bdrv_set_geometry_hint(BlockDriverState *bs,
412 int cyls, int heads, int secs);
413void bdrv_set_type_hint(BlockDriverState *bs, int type);
bellard46d47672004-11-16 01:45:27 +0000414void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
bellardc4b1fcc2004-03-14 21:44:30 +0000415void bdrv_get_geometry_hint(BlockDriverState *bs,
416 int *pcyls, int *pheads, int *psecs);
417int bdrv_get_type_hint(BlockDriverState *bs);
bellard46d47672004-11-16 01:45:27 +0000418int bdrv_get_translation_hint(BlockDriverState *bs);
bellardc4b1fcc2004-03-14 21:44:30 +0000419int bdrv_is_removable(BlockDriverState *bs);
420int bdrv_is_read_only(BlockDriverState *bs);
421int bdrv_is_inserted(BlockDriverState *bs);
422int bdrv_is_locked(BlockDriverState *bs);
423void bdrv_set_locked(BlockDriverState *bs, int locked);
424void bdrv_set_change_cb(BlockDriverState *bs,
425 void (*change_cb)(void *opaque), void *opaque);
bellardea2384d2004-08-01 21:59:26 +0000426void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
bellardc4b1fcc2004-03-14 21:44:30 +0000427void bdrv_info(void);
428BlockDriverState *bdrv_find(const char *name);
bellard82c643f2004-07-14 17:28:13 +0000429void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
bellardea2384d2004-08-01 21:59:26 +0000430int bdrv_is_encrypted(BlockDriverState *bs);
431int bdrv_set_key(BlockDriverState *bs, const char *key);
432void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
433 void *opaque);
434const char *bdrv_get_device_name(BlockDriverState *bs);
bellardc4b1fcc2004-03-14 21:44:30 +0000435
bellardea2384d2004-08-01 21:59:26 +0000436int qcow_get_cluster_size(BlockDriverState *bs);
437int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num,
438 const uint8_t *buf);
439
440#ifndef QEMU_TOOL
bellard26aa7d72004-04-28 22:26:05 +0000441/* ISA bus */
442
443extern target_phys_addr_t isa_mem_base;
444
445typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
446typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
447
448int register_ioport_read(int start, int length, int size,
449 IOPortReadFunc *func, void *opaque);
450int register_ioport_write(int start, int length, int size,
451 IOPortWriteFunc *func, void *opaque);
bellard69b91032004-05-18 23:05:28 +0000452void isa_unassign_ioport(int start, int length);
453
454/* PCI bus */
455
456extern int pci_enabled;
457
458extern target_phys_addr_t pci_mem_base;
459
bellard46e50e92004-06-21 19:43:00 +0000460typedef struct PCIBus PCIBus;
bellard69b91032004-05-18 23:05:28 +0000461typedef struct PCIDevice PCIDevice;
462
463typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
464 uint32_t address, uint32_t data, int len);
465typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
466 uint32_t address, int len);
467typedef 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
474typedef struct PCIIORegion {
bellard5768f5a2004-05-20 12:47:45 +0000475 uint32_t addr; /* current PCI mapping address. -1 means not mapped */
bellard69b91032004-05-18 23:05:28 +0000476 uint32_t size;
477 uint8_t type;
478 PCIMapIORegionFunc *map_func;
479} PCIIORegion;
480
bellard8a8696a2004-06-03 14:06:32 +0000481#define PCI_ROM_SLOT 6
482#define PCI_NUM_REGIONS 7
bellard69b91032004-05-18 23:05:28 +0000483struct PCIDevice {
484 /* PCI config space */
485 uint8_t config[256];
486
487 /* the following fields are read only */
bellard46e50e92004-06-21 19:43:00 +0000488 PCIBus *bus;
bellard69b91032004-05-18 23:05:28 +0000489 int devfn;
490 char name[64];
bellard8a8696a2004-06-03 14:06:32 +0000491 PCIIORegion io_regions[PCI_NUM_REGIONS];
bellard69b91032004-05-18 23:05:28 +0000492
493 /* do not access the following fields */
494 PCIConfigReadFunc *config_read;
495 PCIConfigWriteFunc *config_write;
bellard5768f5a2004-05-20 12:47:45 +0000496 int irq_index;
bellard69b91032004-05-18 23:05:28 +0000497};
498
bellard46e50e92004-06-21 19:43:00 +0000499PCIDevice *pci_register_device(PCIBus *bus, const char *name,
500 int instance_size, int devfn,
bellard69b91032004-05-18 23:05:28 +0000501 PCIConfigReadFunc *config_read,
502 PCIConfigWriteFunc *config_write);
503
504void pci_register_io_region(PCIDevice *pci_dev, int region_num,
505 uint32_t size, int type,
506 PCIMapIORegionFunc *map_func);
507
bellard5768f5a2004-05-20 12:47:45 +0000508void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level);
509
510uint32_t pci_default_read_config(PCIDevice *d,
511 uint32_t address, int len);
512void pci_default_write_config(PCIDevice *d,
513 uint32_t address, uint32_t val, int len);
bellard30ca2aa2004-10-03 13:56:00 +0000514void generic_pci_save(QEMUFile* f, void *opaque);
515int generic_pci_load(QEMUFile* f, void *opaque, int version_id);
bellard5768f5a2004-05-20 12:47:45 +0000516
bellard9995c512004-05-23 19:09:22 +0000517extern struct PIIX3State *piix3_state;
518
bellard46e50e92004-06-21 19:43:00 +0000519PCIBus *i440fx_init(void);
520void piix3_init(PCIBus *bus);
bellard69b91032004-05-18 23:05:28 +0000521void pci_bios_init(void);
bellard5768f5a2004-05-20 12:47:45 +0000522void pci_info(void);
bellard26aa7d72004-04-28 22:26:05 +0000523
bellard77d4bc32004-05-26 22:13:53 +0000524/* temporary: will be moved in platform specific file */
bellard46e50e92004-06-21 19:43:00 +0000525PCIBus *pci_prep_init(void);
526struct openpic_t;
527void pci_pmac_set_openpic(PCIBus *bus, struct openpic_t *openpic);
528PCIBus *pci_pmac_init(void);
bellard77d4bc32004-05-26 22:13:53 +0000529
bellard28b9b5a2004-06-21 16:46:35 +0000530/* openpic.c */
531typedef struct openpic_t openpic_t;
532void openpic_set_irq (openpic_t *opp, int n_IRQ, int level);
bellarde2733d22004-06-21 22:46:10 +0000533openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus);
bellard28b9b5a2004-06-21 16:46:35 +0000534
bellard313aa562003-08-10 21:52:11 +0000535/* vga.c */
536
bellard4fa0f5d2004-02-06 19:47:52 +0000537#define VGA_RAM_SIZE (4096 * 1024)
bellard313aa562003-08-10 21:52:11 +0000538
bellard82c643f2004-07-14 17:28:13 +0000539struct DisplayState {
bellard313aa562003-08-10 21:52:11 +0000540 uint8_t *data;
541 int linesize;
542 int depth;
bellard82c643f2004-07-14 17:28:13 +0000543 int width;
544 int height;
bellard313aa562003-08-10 21:52:11 +0000545 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);
bellard82c643f2004-07-14 17:28:13 +0000548};
bellard313aa562003-08-10 21:52:11 +0000549
550static 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
555static inline void dpy_resize(DisplayState *s, int w, int h)
556{
557 s->dpy_resize(s, w, h);
558}
559
bellard46e50e92004-06-21 19:43:00 +0000560int vga_initialize(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
561 unsigned long vga_ram_offset, int vga_ram_size);
bellard313aa562003-08-10 21:52:11 +0000562void vga_update_display(void);
bellardee38b4c2004-06-08 00:56:42 +0000563void vga_invalidate_display(void);
bellard59a983b2004-03-17 23:17:16 +0000564void vga_screen_dump(const char *filename);
bellard313aa562003-08-10 21:52:11 +0000565
bellardd6bfa222004-06-05 10:32:30 +0000566/* cirrus_vga.c */
bellard46e50e92004-06-21 19:43:00 +0000567void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
bellardd6bfa222004-06-05 10:32:30 +0000568 unsigned long vga_ram_offset, int vga_ram_size);
bellardd6bfa222004-06-05 10:32:30 +0000569void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
570 unsigned long vga_ram_offset, int vga_ram_size);
571
bellard313aa562003-08-10 21:52:11 +0000572/* sdl.c */
bellardd63d3072004-10-03 13:29:03 +0000573void sdl_display_init(DisplayState *ds, int full_screen);
bellard313aa562003-08-10 21:52:11 +0000574
bellardda4dbf72005-03-02 22:22:43 +0000575/* cocoa.m */
576void cocoa_display_init(DisplayState *ds, int full_screen);
577
bellard5391d802003-11-11 13:48:59 +0000578/* ide.c */
579#define MAX_DISKS 4
580
581extern BlockDriverState *bs_table[MAX_DISKS];
582
bellard69b91032004-05-18 23:05:28 +0000583void isa_ide_init(int iobase, int iobase2, int irq,
584 BlockDriverState *hd0, BlockDriverState *hd1);
bellard46e50e92004-06-21 19:43:00 +0000585void pci_ide_init(PCIBus *bus, BlockDriverState **hd_table);
586void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table);
bellard28b9b5a2004-06-21 16:46:35 +0000587int pmac_ide_init (BlockDriverState **hd_table,
588 openpic_t *openpic, int irq);
bellard5391d802003-11-11 13:48:59 +0000589
bellardfb065182004-11-09 23:09:44 +0000590/* sb16.c */
591void SB16_init (void);
592
593/* adlib.c */
594void Adlib_init (void);
595
596/* gus.c */
597void GUS_init (void);
bellard27503322003-11-13 01:46:15 +0000598
599/* dma.c */
bellard85571bc2004-11-07 18:04:02 +0000600typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
bellard27503322003-11-13 01:46:15 +0000601int DMA_get_channel_mode (int nchan);
bellard85571bc2004-11-07 18:04:02 +0000602int DMA_read_memory (int nchan, void *buf, int pos, int size);
603int DMA_write_memory (int nchan, void *buf, int pos, int size);
bellard27503322003-11-13 01:46:15 +0000604void DMA_hold_DREQ (int nchan);
605void DMA_release_DREQ (int nchan);
bellard16f62432004-02-25 23:25:55 +0000606void DMA_schedule(int nchan);
bellard27503322003-11-13 01:46:15 +0000607void DMA_run (void);
bellard28b9b5a2004-06-21 16:46:35 +0000608void DMA_init (int high_page_enable);
bellard27503322003-11-13 01:46:15 +0000609void DMA_register_channel (int nchan,
bellard85571bc2004-11-07 18:04:02 +0000610 DMA_transfer_handler transfer_handler,
611 void *opaque);
bellard7138fcf2004-01-05 00:02:28 +0000612/* fdc.c */
613#define MAX_FD 2
614extern BlockDriverState *fd_table[MAX_FD];
615
bellardbaca51f2004-03-19 23:05:34 +0000616typedef struct fdctrl_t fdctrl_t;
617
618fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped,
619 uint32_t io_base,
620 BlockDriverState **fds);
621int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
bellard7138fcf2004-01-05 00:02:28 +0000622
bellard80cabfa2004-03-14 12:20:30 +0000623/* ne2000.c */
624
bellard69b91032004-05-18 23:05:28 +0000625void isa_ne2000_init(int base, int irq, NetDriverState *nd);
bellard46e50e92004-06-21 19:43:00 +0000626void pci_ne2000_init(PCIBus *bus, NetDriverState *nd);
bellard80cabfa2004-03-14 12:20:30 +0000627
628/* pckbd.c */
629
bellard80cabfa2004-03-14 12:20:30 +0000630void kbd_init(void);
631
632/* mc146818rtc.c */
633
bellard8a7ddc32004-03-31 19:00:16 +0000634typedef struct RTCState RTCState;
bellard80cabfa2004-03-14 12:20:30 +0000635
bellard8a7ddc32004-03-31 19:00:16 +0000636RTCState *rtc_init(int base, int irq);
637void rtc_set_memory(RTCState *s, int addr, int val);
638void rtc_set_date(RTCState *s, const struct tm *tm);
bellard80cabfa2004-03-14 12:20:30 +0000639
640/* serial.c */
641
bellardc4b1fcc2004-03-14 21:44:30 +0000642typedef struct SerialState SerialState;
bellard82c643f2004-07-14 17:28:13 +0000643SerialState *serial_init(int base, int irq, CharDriverState *chr);
bellard80cabfa2004-03-14 12:20:30 +0000644
bellard6508fe52005-01-15 12:02:56 +0000645/* parallel.c */
646
647typedef struct ParallelState ParallelState;
648ParallelState *parallel_init(int base, int irq, CharDriverState *chr);
649
bellard80cabfa2004-03-14 12:20:30 +0000650/* i8259.c */
651
652void pic_set_irq(int irq, int level);
653void pic_init(void);
bellardc5df0182004-04-12 20:54:52 +0000654uint32_t pic_intack_read(CPUState *env);
bellardc20709a2004-04-21 23:27:19 +0000655void pic_info(void);
bellard4a0fb712004-05-21 11:39:07 +0000656void irq_info(void);
bellard80cabfa2004-03-14 12:20:30 +0000657
bellardc27004e2005-01-03 23:35:10 +0000658/* APIC */
659int apic_init(CPUState *env);
660int apic_get_interrupt(CPUState *env);
661
bellard80cabfa2004-03-14 12:20:30 +0000662/* i8254.c */
663
664#define PIT_FREQ 1193182
665
bellardec844b92004-05-03 23:18:25 +0000666typedef struct PITState PITState;
bellard80cabfa2004-03-14 12:20:30 +0000667
bellardec844b92004-05-03 23:18:25 +0000668PITState *pit_init(int base, int irq);
669void pit_set_gate(PITState *pit, int channel, int val);
670int pit_get_gate(PITState *pit, int channel);
671int pit_get_out(PITState *pit, int channel, int64_t current_time);
bellard80cabfa2004-03-14 12:20:30 +0000672
673/* pc.c */
674void pc_init(int ram_size, int vga_ram_size, int boot_device,
675 DisplayState *ds, const char **fd_filename, int snapshot,
676 const char *kernel_filename, const char *kernel_cmdline,
677 const char *initrd_filename);
678
bellard26aa7d72004-04-28 22:26:05 +0000679/* ppc.c */
680void ppc_init (int ram_size, int vga_ram_size, int boot_device,
681 DisplayState *ds, const char **fd_filename, int snapshot,
682 const char *kernel_filename, const char *kernel_cmdline,
683 const char *initrd_filename);
bellard77d4bc32004-05-26 22:13:53 +0000684void ppc_prep_init (int ram_size, int vga_ram_size, int boot_device,
685 DisplayState *ds, const char **fd_filename, int snapshot,
686 const char *kernel_filename, const char *kernel_cmdline,
687 const char *initrd_filename);
688void ppc_chrp_init(int ram_size, int vga_ram_size, int boot_device,
689 DisplayState *ds, const char **fd_filename, int snapshot,
690 const char *kernel_filename, const char *kernel_cmdline,
691 const char *initrd_filename);
bellard8cc43fe2004-05-26 23:29:15 +0000692#ifdef TARGET_PPC
693ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq);
694#endif
bellard64201202004-05-26 22:55:16 +0000695void PREP_debug_write (void *opaque, uint32_t addr, uint32_t val);
bellard77d4bc32004-05-26 22:13:53 +0000696
697extern CPUWriteMemoryFunc *PPC_io_write[];
698extern CPUReadMemoryFunc *PPC_io_read[];
699extern int prep_enabled;
bellard26aa7d72004-04-28 22:26:05 +0000700
bellarde95c8d52004-09-30 22:22:08 +0000701/* sun4m.c */
702void sun4m_init(int ram_size, int vga_ram_size, int boot_device,
703 DisplayState *ds, const char **fd_filename, int snapshot,
704 const char *kernel_filename, const char *kernel_cmdline,
705 const char *initrd_filename);
bellarde80cfcf2004-12-19 23:18:01 +0000706uint32_t iommu_translate(uint32_t addr);
bellarde95c8d52004-09-30 22:22:08 +0000707
708/* iommu.c */
bellarde80cfcf2004-12-19 23:18:01 +0000709void *iommu_init(uint32_t addr);
710uint32_t iommu_translate_local(void *opaque, uint32_t addr);
bellarde95c8d52004-09-30 22:22:08 +0000711
712/* lance.c */
bellard8d5f07f2004-10-04 21:23:09 +0000713void lance_init(NetDriverState *nd, int irq, uint32_t leaddr, uint32_t ledaddr);
bellarde95c8d52004-09-30 22:22:08 +0000714
715/* tcx.c */
bellarde80cfcf2004-12-19 23:18:01 +0000716void *tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
bellard6f7e9ae2005-03-13 09:43:36 +0000717 unsigned long vram_offset, int vram_size, int width, int height);
bellarde80cfcf2004-12-19 23:18:01 +0000718void tcx_update_display(void *opaque);
719void tcx_invalidate_display(void *opaque);
720void tcx_screen_dump(void *opaque, const char *filename);
bellarde95c8d52004-09-30 22:22:08 +0000721
bellarde80cfcf2004-12-19 23:18:01 +0000722/* slavio_intctl.c */
723void *slavio_intctl_init();
724void slavio_pic_info(void *opaque);
725void slavio_irq_info(void *opaque);
726void slavio_pic_set_irq(void *opaque, int irq, int level);
bellarde95c8d52004-09-30 22:22:08 +0000727
728/* magic-load.c */
bellarde80cfcf2004-12-19 23:18:01 +0000729int load_elf(const char *filename, uint8_t *addr);
730int load_aout(const char *filename, uint8_t *addr);
bellard8d5f07f2004-10-04 21:23:09 +0000731
bellarde80cfcf2004-12-19 23:18:01 +0000732/* slavio_timer.c */
733void slavio_timer_init(uint32_t addr1, int irq1, uint32_t addr2, int irq2);
734
735/* slavio_serial.c */
736SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDriverState *chr2);
737void slavio_serial_ms_kbd_init(int base, int irq);
bellarde95c8d52004-09-30 22:22:08 +0000738
bellard6f7e9ae2005-03-13 09:43:36 +0000739/* esp.c */
740void esp_init(BlockDriverState **bd, int irq, uint32_t espaddr, uint32_t espdaddr);
741
bellard64201202004-05-26 22:55:16 +0000742/* NVRAM helpers */
743#include "hw/m48t59.h"
744
745void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value);
746uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr);
747void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value);
748uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr);
749void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr, uint32_t value);
750uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr);
751void NVRAM_set_string (m48t59_t *nvram, uint32_t addr,
752 const unsigned char *str, uint32_t max);
753int NVRAM_get_string (m48t59_t *nvram, uint8_t *dst, uint16_t addr, int max);
754void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr,
755 uint32_t start, uint32_t count);
756int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
757 const unsigned char *arch,
758 uint32_t RAM_size, int boot_device,
759 uint32_t kernel_image, uint32_t kernel_size,
bellard28b9b5a2004-06-21 16:46:35 +0000760 const char *cmdline,
bellard64201202004-05-26 22:55:16 +0000761 uint32_t initrd_image, uint32_t initrd_size,
bellard28b9b5a2004-06-21 16:46:35 +0000762 uint32_t NVRAM_image,
763 int width, int height, int depth);
bellard64201202004-05-26 22:55:16 +0000764
bellard63066f42004-06-03 18:45:02 +0000765/* adb.c */
766
767#define MAX_ADB_DEVICES 16
768
bellarde2733d22004-06-21 22:46:10 +0000769#define ADB_MAX_OUT_LEN 16
770
bellard63066f42004-06-03 18:45:02 +0000771typedef struct ADBDevice ADBDevice;
772
bellarde2733d22004-06-21 22:46:10 +0000773/* buf = NULL means polling */
774typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
775 const uint8_t *buf, int len);
bellard12c28fe2004-07-12 20:26:20 +0000776typedef int ADBDeviceReset(ADBDevice *d);
777
bellard63066f42004-06-03 18:45:02 +0000778struct ADBDevice {
779 struct ADBBusState *bus;
780 int devaddr;
781 int handler;
bellarde2733d22004-06-21 22:46:10 +0000782 ADBDeviceRequest *devreq;
bellard12c28fe2004-07-12 20:26:20 +0000783 ADBDeviceReset *devreset;
bellard63066f42004-06-03 18:45:02 +0000784 void *opaque;
785};
786
787typedef struct ADBBusState {
788 ADBDevice devices[MAX_ADB_DEVICES];
789 int nb_devices;
bellarde2733d22004-06-21 22:46:10 +0000790 int poll_index;
bellard63066f42004-06-03 18:45:02 +0000791} ADBBusState;
792
bellarde2733d22004-06-21 22:46:10 +0000793int adb_request(ADBBusState *s, uint8_t *buf_out,
794 const uint8_t *buf, int len);
795int adb_poll(ADBBusState *s, uint8_t *buf_out);
bellard63066f42004-06-03 18:45:02 +0000796
797ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
bellarde2733d22004-06-21 22:46:10 +0000798 ADBDeviceRequest *devreq,
bellard12c28fe2004-07-12 20:26:20 +0000799 ADBDeviceReset *devreset,
bellard63066f42004-06-03 18:45:02 +0000800 void *opaque);
801void adb_kbd_init(ADBBusState *bus);
802void adb_mouse_init(ADBBusState *bus);
803
804/* cuda.c */
805
806extern ADBBusState adb_bus;
bellard28b9b5a2004-06-21 16:46:35 +0000807int cuda_init(openpic_t *openpic, int irq);
bellard63066f42004-06-03 18:45:02 +0000808
bellardea2384d2004-08-01 21:59:26 +0000809#endif /* defined(QEMU_TOOL) */
810
bellardc4b1fcc2004-03-14 21:44:30 +0000811/* monitor.c */
bellard82c643f2004-07-14 17:28:13 +0000812void monitor_init(CharDriverState *hd, int show_banner);
bellardea2384d2004-08-01 21:59:26 +0000813void term_puts(const char *str);
814void term_vprintf(const char *fmt, va_list ap);
bellard40c3bac2004-04-04 12:56:28 +0000815void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
bellardc4b1fcc2004-03-14 21:44:30 +0000816void term_flush(void);
817void term_print_help(void);
bellardea2384d2004-08-01 21:59:26 +0000818void monitor_readline(const char *prompt, int is_password,
819 char *buf, int buf_size);
820
821/* readline.c */
822typedef void ReadLineFunc(void *opaque, const char *str);
823
824extern int completion_index;
825void add_completion(const char *str);
826void readline_handle_byte(int ch);
827void readline_find_completion(const char *cmdline);
828const char *readline_get_history(unsigned int index);
829void readline_start(const char *prompt, int is_password,
830 ReadLineFunc *readline_func, void *opaque);
bellardc4b1fcc2004-03-14 21:44:30 +0000831
bellard8a7ddc32004-03-31 19:00:16 +0000832/* gdbstub.c */
833
834#define DEFAULT_GDBSTUB_PORT 1234
835
836int gdbserver_start(int port);
837
bellardfc01f7e2003-06-30 10:03:06 +0000838#endif /* VL_H */