2 * QEMU System Emulator header
4 * Copyright (c) 2003 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
27 /* we put basic includes here to avoid repeating them in device drivers */
47 #define lseek64 _lseeki64
53 #define xglue(x, y) x ## y
54 #define glue(x, y) xglue(x, y)
55 #define stringify(s) tostring(s)
56 #define tostring(s) #s
59 #if defined(WORDS_BIGENDIAN)
60 static inline uint32_t be32_to_cpu(uint32_t v
)
65 static inline uint16_t be16_to_cpu(uint16_t v
)
70 static inline uint32_t cpu_to_be32(uint32_t v
)
75 static inline uint16_t cpu_to_be16(uint16_t v
)
80 static inline uint32_t le32_to_cpu(uint32_t v
)
85 static inline uint16_t le16_to_cpu(uint16_t v
)
90 static inline uint32_t cpu_to_le32(uint32_t v
)
95 static inline uint16_t cpu_to_le16(uint16_t v
)
102 static inline uint32_t be32_to_cpu(uint32_t v
)
107 static inline uint16_t be16_to_cpu(uint16_t v
)
112 static inline uint32_t cpu_to_be32(uint32_t v
)
117 static inline uint16_t cpu_to_be16(uint16_t v
)
122 static inline uint32_t le32_to_cpu(uint32_t v
)
127 static inline uint16_t le16_to_cpu(uint16_t v
)
132 static inline uint32_t cpu_to_le32(uint32_t v
)
137 static inline uint16_t cpu_to_le16(uint16_t v
)
145 extern int reset_requested
;
147 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
);
149 void hw_error(const char *fmt
, ...);
151 int load_image(const char *filename
, uint8_t *addr
);
152 extern const char *bios_dir
;
154 void pstrcpy(char *buf
, int buf_size
, const char *str
);
155 char *pstrcat(char *buf
, int buf_size
, const char *s
);
157 int serial_open_device(void);
159 extern int vm_running
;
161 typedef void VMStopHandler(void *opaque
, int reason
);
163 int qemu_add_vm_stop_handler(VMStopHandler
*cb
, void *opaque
);
164 void qemu_del_vm_stop_handler(VMStopHandler
*cb
, void *opaque
);
167 void vm_stop(int reason
);
169 extern int audio_enabled
;
171 /* async I/O support */
173 typedef void IOReadHandler(void *opaque
, const uint8_t *buf
, int size
);
174 typedef int IOCanRWHandler(void *opaque
);
176 int qemu_add_fd_read_handler(int fd
, IOCanRWHandler
*fd_can_read
,
177 IOReadHandler
*fd_read
, void *opaque
);
178 void qemu_del_fd_read_handler(int fd
);
180 /* network redirectors support */
184 typedef struct NetDriverState
{
185 int index
; /* index number in QEMU */
188 void (*send_packet
)(struct NetDriverState
*nd
,
189 const uint8_t *buf
, int size
);
190 void (*add_read_packet
)(struct NetDriverState
*nd
,
191 IOCanRWHandler
*fd_can_read
,
192 IOReadHandler
*fd_read
, void *opaque
);
193 /* tun specific data */
195 /* slirp specific data */
199 extern NetDriverState nd_table
[MAX_NICS
];
201 void qemu_send_packet(NetDriverState
*nd
, const uint8_t *buf
, int size
);
202 void qemu_add_read_packet(NetDriverState
*nd
, IOCanRWHandler
*fd_can_read
,
203 IOReadHandler
*fd_read
, void *opaque
);
207 typedef struct QEMUClock QEMUClock
;
208 typedef struct QEMUTimer QEMUTimer
;
209 typedef void QEMUTimerCB(void *opaque
);
211 /* The real time clock should be used only for stuff which does not
212 change the virtual machine state, as it is run even if the virtual
213 machine is stopped. The real time clock has a frequency or 1000
215 extern QEMUClock
*rt_clock
;
217 /* Rge virtual clock is only run during the emulation. It is stopped
218 when the virtual machine is stopped. Virtual timers use a high
219 precision clock, usually cpu cycles (use ticks_per_sec). */
220 extern QEMUClock
*vm_clock
;
222 int64_t qemu_get_clock(QEMUClock
*clock
);
224 QEMUTimer
*qemu_new_timer(QEMUClock
*clock
, QEMUTimerCB
*cb
, void *opaque
);
225 void qemu_free_timer(QEMUTimer
*ts
);
226 void qemu_del_timer(QEMUTimer
*ts
);
227 void qemu_mod_timer(QEMUTimer
*ts
, int64_t expire_time
);
228 int qemu_timer_pending(QEMUTimer
*ts
);
230 extern int64_t ticks_per_sec
;
231 extern int pit_min_timer_count
;
233 void cpu_enable_ticks(void);
234 void cpu_disable_ticks(void);
238 typedef FILE QEMUFile
;
240 void qemu_put_buffer(QEMUFile
*f
, const uint8_t *buf
, int size
);
241 void qemu_put_byte(QEMUFile
*f
, int v
);
242 void qemu_put_be16(QEMUFile
*f
, unsigned int v
);
243 void qemu_put_be32(QEMUFile
*f
, unsigned int v
);
244 void qemu_put_be64(QEMUFile
*f
, uint64_t v
);
245 int qemu_get_buffer(QEMUFile
*f
, uint8_t *buf
, int size
);
246 int qemu_get_byte(QEMUFile
*f
);
247 unsigned int qemu_get_be16(QEMUFile
*f
);
248 unsigned int qemu_get_be32(QEMUFile
*f
);
249 uint64_t qemu_get_be64(QEMUFile
*f
);
251 static inline void qemu_put_be64s(QEMUFile
*f
, const uint64_t *pv
)
253 qemu_put_be64(f
, *pv
);
256 static inline void qemu_put_be32s(QEMUFile
*f
, const uint32_t *pv
)
258 qemu_put_be32(f
, *pv
);
261 static inline void qemu_put_be16s(QEMUFile
*f
, const uint16_t *pv
)
263 qemu_put_be16(f
, *pv
);
266 static inline void qemu_put_8s(QEMUFile
*f
, const uint8_t *pv
)
268 qemu_put_byte(f
, *pv
);
271 static inline void qemu_get_be64s(QEMUFile
*f
, uint64_t *pv
)
273 *pv
= qemu_get_be64(f
);
276 static inline void qemu_get_be32s(QEMUFile
*f
, uint32_t *pv
)
278 *pv
= qemu_get_be32(f
);
281 static inline void qemu_get_be16s(QEMUFile
*f
, uint16_t *pv
)
283 *pv
= qemu_get_be16(f
);
286 static inline void qemu_get_8s(QEMUFile
*f
, uint8_t *pv
)
288 *pv
= qemu_get_byte(f
);
291 int64_t qemu_ftell(QEMUFile
*f
);
292 int64_t qemu_fseek(QEMUFile
*f
, int64_t pos
, int whence
);
294 typedef void SaveStateHandler(QEMUFile
*f
, void *opaque
);
295 typedef int LoadStateHandler(QEMUFile
*f
, void *opaque
, int version_id
);
297 int qemu_loadvm(const char *filename
);
298 int qemu_savevm(const char *filename
);
299 int register_savevm(const char *idstr
,
302 SaveStateHandler
*save_state
,
303 LoadStateHandler
*load_state
,
305 void qemu_get_timer(QEMUFile
*f
, QEMUTimer
*ts
);
306 void qemu_put_timer(QEMUFile
*f
, QEMUTimer
*ts
);
309 typedef struct BlockDriverState BlockDriverState
;
311 BlockDriverState
*bdrv_new(const char *device_name
);
312 void bdrv_delete(BlockDriverState
*bs
);
313 int bdrv_open(BlockDriverState
*bs
, const char *filename
, int snapshot
);
314 void bdrv_close(BlockDriverState
*bs
);
315 int bdrv_read(BlockDriverState
*bs
, int64_t sector_num
,
316 uint8_t *buf
, int nb_sectors
);
317 int bdrv_write(BlockDriverState
*bs
, int64_t sector_num
,
318 const uint8_t *buf
, int nb_sectors
);
319 void bdrv_get_geometry(BlockDriverState
*bs
, int64_t *nb_sectors_ptr
);
320 int bdrv_commit(BlockDriverState
*bs
);
321 void bdrv_set_boot_sector(BlockDriverState
*bs
, const uint8_t *data
, int size
);
323 #define BDRV_TYPE_HD 0
324 #define BDRV_TYPE_CDROM 1
325 #define BDRV_TYPE_FLOPPY 2
327 void bdrv_set_geometry_hint(BlockDriverState
*bs
,
328 int cyls
, int heads
, int secs
);
329 void bdrv_set_type_hint(BlockDriverState
*bs
, int type
);
330 void bdrv_get_geometry_hint(BlockDriverState
*bs
,
331 int *pcyls
, int *pheads
, int *psecs
);
332 int bdrv_get_type_hint(BlockDriverState
*bs
);
333 int bdrv_is_removable(BlockDriverState
*bs
);
334 int bdrv_is_read_only(BlockDriverState
*bs
);
335 int bdrv_is_inserted(BlockDriverState
*bs
);
336 int bdrv_is_locked(BlockDriverState
*bs
);
337 void bdrv_set_locked(BlockDriverState
*bs
, int locked
);
338 void bdrv_set_change_cb(BlockDriverState
*bs
,
339 void (*change_cb
)(void *opaque
), void *opaque
);
341 void bdrv_info(void);
342 BlockDriverState
*bdrv_find(const char *name
);
346 extern target_phys_addr_t isa_mem_base
;
348 typedef void (IOPortWriteFunc
)(void *opaque
, uint32_t address
, uint32_t data
);
349 typedef uint32_t (IOPortReadFunc
)(void *opaque
, uint32_t address
);
351 int register_ioport_read(int start
, int length
, int size
,
352 IOPortReadFunc
*func
, void *opaque
);
353 int register_ioport_write(int start
, int length
, int size
,
354 IOPortWriteFunc
*func
, void *opaque
);
358 #define VGA_RAM_SIZE (4096 * 1024)
360 typedef struct DisplayState
{
364 void (*dpy_update
)(struct DisplayState
*s
, int x
, int y
, int w
, int h
);
365 void (*dpy_resize
)(struct DisplayState
*s
, int w
, int h
);
366 void (*dpy_refresh
)(struct DisplayState
*s
);
369 static inline void dpy_update(DisplayState
*s
, int x
, int y
, int w
, int h
)
371 s
->dpy_update(s
, x
, y
, w
, h
);
374 static inline void dpy_resize(DisplayState
*s
, int w
, int h
)
376 s
->dpy_resize(s
, w
, h
);
379 int vga_initialize(DisplayState
*ds
, uint8_t *vga_ram_base
,
380 unsigned long vga_ram_offset
, int vga_ram_size
);
381 void vga_update_display(void);
382 void vga_screen_dump(const char *filename
);
385 void sdl_display_init(DisplayState
*ds
);
390 extern BlockDriverState
*bs_table
[MAX_DISKS
];
392 void ide_init(int iobase
, int iobase2
, int irq
,
393 BlockDriverState
*hd0
, BlockDriverState
*hd1
);
403 void AUD_open (int rfreq
, int rnchannels
, audfmt_e rfmt
);
404 void AUD_reset (int rfreq
, int rnchannels
, audfmt_e rfmt
);
405 int AUD_write (void *in_buf
, int size
);
407 void AUD_adjust_estimate (int _leftover
);
408 int AUD_get_free (void);
409 int AUD_get_live (void);
410 int AUD_get_buffer_size (void);
411 void AUD_init (void);
414 typedef int (*DMA_transfer_handler
) (void *opaque
, target_ulong addr
, int size
);
415 int DMA_get_channel_mode (int nchan
);
416 void DMA_hold_DREQ (int nchan
);
417 void DMA_release_DREQ (int nchan
);
418 void DMA_schedule(int nchan
);
420 void DMA_init (void);
421 void DMA_register_channel (int nchan
,
422 DMA_transfer_handler transfer_handler
, void *opaque
);
425 void SB16_run (void);
426 void SB16_init (void);
430 extern BlockDriverState
*fd_table
[MAX_FD
];
432 typedef struct fdctrl_t fdctrl_t
;
434 fdctrl_t
*fdctrl_init (int irq_lvl
, int dma_chann
, int mem_mapped
,
436 BlockDriverState
**fds
);
437 int fdctrl_get_drive_type(fdctrl_t
*fdctrl
, int drive_num
);
441 void ne2000_init(int base
, int irq
, NetDriverState
*nd
);
445 void kbd_put_keycode(int keycode
);
447 #define MOUSE_EVENT_LBUTTON 0x01
448 #define MOUSE_EVENT_RBUTTON 0x02
449 #define MOUSE_EVENT_MBUTTON 0x04
450 void kbd_mouse_event(int dx
, int dy
, int dz
, int buttons_state
);
456 typedef struct RTCState RTCState
;
458 RTCState
*rtc_init(int base
, int irq
);
459 void rtc_set_memory(RTCState
*s
, int addr
, int val
);
460 void rtc_set_date(RTCState
*s
, const struct tm
*tm
);
464 typedef struct SerialState SerialState
;
466 extern SerialState
*serial_console
;
468 SerialState
*serial_init(int base
, int irq
, int fd
);
469 int serial_can_receive(SerialState
*s
);
470 void serial_receive_byte(SerialState
*s
, int ch
);
471 void serial_receive_break(SerialState
*s
);
475 void pic_set_irq(int irq
, int level
);
477 uint32_t pic_intack_read(CPUState
*env
);
482 #define PIT_FREQ 1193182
484 typedef struct PITState PITState
;
486 PITState
*pit_init(int base
, int irq
);
487 void pit_set_gate(PITState
*pit
, int channel
, int val
);
488 int pit_get_gate(PITState
*pit
, int channel
);
489 int pit_get_out(PITState
*pit
, int channel
, int64_t current_time
);
492 void pc_init(int ram_size
, int vga_ram_size
, int boot_device
,
493 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
494 const char *kernel_filename
, const char *kernel_cmdline
,
495 const char *initrd_filename
);
498 void ppc_init (int ram_size
, int vga_ram_size
, int boot_device
,
499 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
500 const char *kernel_filename
, const char *kernel_cmdline
,
501 const char *initrd_filename
);
504 void monitor_init(void);
505 void term_printf(const char *fmt
, ...) __attribute__ ((__format__ (__printf__
, 1, 2)));
506 void term_flush(void);
507 void term_print_help(void);
511 #define DEFAULT_GDBSTUB_PORT 1234
513 int gdbserver_start(int port
);