VirtualBox

source: vbox/trunk/src/recompiler/vl.h@ 204

最後變更 在這個檔案從204是 1,由 vboxsync 提交於 55 年 前

import

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette