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 */
50 #define xglue(x, y) x ## y
51 #define glue(x, y) xglue(x, y)
52 #define stringify(s) tostring(s)
53 #define tostring(s) #s
56 #if defined(WORDS_BIGENDIAN)
57 static inline uint32_t be32_to_cpu(uint32_t v
)
62 static inline uint16_t be16_to_cpu(uint16_t v
)
67 static inline uint32_t le32_to_cpu(uint32_t v
)
72 static inline uint16_t le16_to_cpu(uint16_t v
)
78 static inline uint32_t be32_to_cpu(uint32_t v
)
83 static inline uint16_t be16_to_cpu(uint16_t v
)
88 static inline uint32_t le32_to_cpu(uint32_t v
)
93 static inline uint16_t le16_to_cpu(uint16_t v
)
101 extern int reset_requested
;
103 typedef void (IOPortWriteFunc
)(void *opaque
, uint32_t address
, uint32_t data
);
104 typedef uint32_t (IOPortReadFunc
)(void *opaque
, uint32_t address
);
106 int register_ioport_read(int start
, int length
, int size
,
107 IOPortReadFunc
*func
, void *opaque
);
108 int register_ioport_write(int start
, int length
, int size
,
109 IOPortWriteFunc
*func
, void *opaque
);
110 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
);
112 void hw_error(const char *fmt
, ...);
114 int load_image(const char *filename
, uint8_t *addr
);
115 extern const char *bios_dir
;
117 void pstrcpy(char *buf
, int buf_size
, const char *str
);
118 char *pstrcat(char *buf
, int buf_size
, const char *s
);
120 int serial_open_device(void);
122 extern int vm_running
;
124 typedef void VMStopHandler(void *opaque
, int reason
);
126 int qemu_add_vm_stop_handler(VMStopHandler
*cb
, void *opaque
);
127 void qemu_del_vm_stop_handler(VMStopHandler
*cb
, void *opaque
);
130 void vm_stop(int reason
);
132 /* network redirectors support */
136 typedef struct NetDriverState
{
143 extern NetDriverState nd_table
[MAX_NICS
];
145 void net_send_packet(NetDriverState
*nd
, const uint8_t *buf
, int size
);
147 /* async I/O support */
149 typedef void IOReadHandler(void *opaque
, const uint8_t *buf
, int size
);
150 typedef int IOCanRWHandler(void *opaque
);
152 int qemu_add_fd_read_handler(int fd
, IOCanRWHandler
*fd_can_read
,
153 IOReadHandler
*fd_read
, void *opaque
);
154 void qemu_del_fd_read_handler(int fd
);
158 typedef struct QEMUClock QEMUClock
;
159 typedef struct QEMUTimer QEMUTimer
;
160 typedef void QEMUTimerCB(void *opaque
);
162 /* The real time clock should be used only for stuff which does not
163 change the virtual machine state, as it is run even if the virtual
164 machine is stopped. The real time clock has a frequency or 1000
166 extern QEMUClock
*rt_clock
;
168 /* Rge virtual clock is only run during the emulation. It is stopped
169 when the virtual machine is stopped. Virtual timers use a high
170 precision clock, usually cpu cycles (use ticks_per_sec). */
171 extern QEMUClock
*vm_clock
;
173 int64_t qemu_get_clock(QEMUClock
*clock
);
175 QEMUTimer
*qemu_new_timer(QEMUClock
*clock
, QEMUTimerCB
*cb
, void *opaque
);
176 void qemu_free_timer(QEMUTimer
*ts
);
177 void qemu_del_timer(QEMUTimer
*ts
);
178 void qemu_mod_timer(QEMUTimer
*ts
, int64_t expire_time
);
179 int qemu_timer_pending(QEMUTimer
*ts
);
181 extern int64_t ticks_per_sec
;
182 extern int pit_min_timer_count
;
184 void cpu_enable_ticks(void);
185 void cpu_disable_ticks(void);
189 typedef FILE QEMUFile
;
191 void qemu_put_buffer(QEMUFile
*f
, const uint8_t *buf
, int size
);
192 void qemu_put_byte(QEMUFile
*f
, int v
);
193 void qemu_put_be16(QEMUFile
*f
, unsigned int v
);
194 void qemu_put_be32(QEMUFile
*f
, unsigned int v
);
195 void qemu_put_be64(QEMUFile
*f
, uint64_t v
);
196 int qemu_get_buffer(QEMUFile
*f
, uint8_t *buf
, int size
);
197 int qemu_get_byte(QEMUFile
*f
);
198 unsigned int qemu_get_be16(QEMUFile
*f
);
199 unsigned int qemu_get_be32(QEMUFile
*f
);
200 uint64_t qemu_get_be64(QEMUFile
*f
);
202 static inline void qemu_put_be64s(QEMUFile
*f
, const uint64_t *pv
)
204 qemu_put_be64(f
, *pv
);
207 static inline void qemu_put_be32s(QEMUFile
*f
, const uint32_t *pv
)
209 qemu_put_be32(f
, *pv
);
212 static inline void qemu_put_be16s(QEMUFile
*f
, const uint16_t *pv
)
214 qemu_put_be16(f
, *pv
);
217 static inline void qemu_put_8s(QEMUFile
*f
, const uint8_t *pv
)
219 qemu_put_byte(f
, *pv
);
222 static inline void qemu_get_be64s(QEMUFile
*f
, uint64_t *pv
)
224 *pv
= qemu_get_be64(f
);
227 static inline void qemu_get_be32s(QEMUFile
*f
, uint32_t *pv
)
229 *pv
= qemu_get_be32(f
);
232 static inline void qemu_get_be16s(QEMUFile
*f
, uint16_t *pv
)
234 *pv
= qemu_get_be16(f
);
237 static inline void qemu_get_8s(QEMUFile
*f
, uint8_t *pv
)
239 *pv
= qemu_get_byte(f
);
242 int64_t qemu_ftell(QEMUFile
*f
);
243 int64_t qemu_fseek(QEMUFile
*f
, int64_t pos
, int whence
);
245 typedef void SaveStateHandler(QEMUFile
*f
, void *opaque
);
246 typedef int LoadStateHandler(QEMUFile
*f
, void *opaque
, int version_id
);
248 int qemu_loadvm(const char *filename
);
249 int qemu_savevm(const char *filename
);
250 int register_savevm(const char *idstr
,
253 SaveStateHandler
*save_state
,
254 LoadStateHandler
*load_state
,
256 void qemu_get_timer(QEMUFile
*f
, QEMUTimer
*ts
);
257 void qemu_put_timer(QEMUFile
*f
, QEMUTimer
*ts
);
260 typedef struct BlockDriverState BlockDriverState
;
262 BlockDriverState
*bdrv_new(const char *device_name
);
263 void bdrv_delete(BlockDriverState
*bs
);
264 int bdrv_open(BlockDriverState
*bs
, const char *filename
, int snapshot
);
265 void bdrv_close(BlockDriverState
*bs
);
266 int bdrv_read(BlockDriverState
*bs
, int64_t sector_num
,
267 uint8_t *buf
, int nb_sectors
);
268 int bdrv_write(BlockDriverState
*bs
, int64_t sector_num
,
269 const uint8_t *buf
, int nb_sectors
);
270 void bdrv_get_geometry(BlockDriverState
*bs
, int64_t *nb_sectors_ptr
);
271 int bdrv_commit(BlockDriverState
*bs
);
272 void bdrv_set_boot_sector(BlockDriverState
*bs
, const uint8_t *data
, int size
);
274 #define BDRV_TYPE_HD 0
275 #define BDRV_TYPE_CDROM 1
276 #define BDRV_TYPE_FLOPPY 2
278 void bdrv_set_geometry_hint(BlockDriverState
*bs
,
279 int cyls
, int heads
, int secs
);
280 void bdrv_set_type_hint(BlockDriverState
*bs
, int type
);
281 void bdrv_get_geometry_hint(BlockDriverState
*bs
,
282 int *pcyls
, int *pheads
, int *psecs
);
283 int bdrv_get_type_hint(BlockDriverState
*bs
);
284 int bdrv_is_removable(BlockDriverState
*bs
);
285 int bdrv_is_read_only(BlockDriverState
*bs
);
286 int bdrv_is_inserted(BlockDriverState
*bs
);
287 int bdrv_is_locked(BlockDriverState
*bs
);
288 void bdrv_set_locked(BlockDriverState
*bs
, int locked
);
289 void bdrv_set_change_cb(BlockDriverState
*bs
,
290 void (*change_cb
)(void *opaque
), void *opaque
);
292 void bdrv_info(void);
293 BlockDriverState
*bdrv_find(const char *name
);
297 #define VGA_RAM_SIZE (4096 * 1024)
299 typedef struct DisplayState
{
303 void (*dpy_update
)(struct DisplayState
*s
, int x
, int y
, int w
, int h
);
304 void (*dpy_resize
)(struct DisplayState
*s
, int w
, int h
);
305 void (*dpy_refresh
)(struct DisplayState
*s
);
308 static inline void dpy_update(DisplayState
*s
, int x
, int y
, int w
, int h
)
310 s
->dpy_update(s
, x
, y
, w
, h
);
313 static inline void dpy_resize(DisplayState
*s
, int w
, int h
)
315 s
->dpy_resize(s
, w
, h
);
318 int vga_initialize(DisplayState
*ds
, uint8_t *vga_ram_base
,
319 unsigned long vga_ram_offset
, int vga_ram_size
);
320 void vga_update_display(void);
321 void vga_screen_dump(const char *filename
);
324 void sdl_display_init(DisplayState
*ds
);
329 extern BlockDriverState
*bs_table
[MAX_DISKS
];
331 void ide_init(int iobase
, int iobase2
, int irq
,
332 BlockDriverState
*hd0
, BlockDriverState
*hd1
);
342 void AUD_open (int rfreq
, int rnchannels
, audfmt_e rfmt
);
343 void AUD_reset (int rfreq
, int rnchannels
, audfmt_e rfmt
);
344 int AUD_write (void *in_buf
, int size
);
346 void AUD_adjust_estimate (int _leftover
);
347 int AUD_get_free (void);
348 int AUD_get_live (void);
349 int AUD_get_buffer_size (void);
350 void AUD_init (void);
353 typedef int (*DMA_transfer_handler
) (void *opaque
, target_ulong addr
, int size
);
354 int DMA_get_channel_mode (int nchan
);
355 void DMA_hold_DREQ (int nchan
);
356 void DMA_release_DREQ (int nchan
);
357 void DMA_schedule(int nchan
);
359 void DMA_init (void);
360 void DMA_register_channel (int nchan
,
361 DMA_transfer_handler transfer_handler
, void *opaque
);
364 void SB16_run (void);
365 void SB16_init (void);
369 extern BlockDriverState
*fd_table
[MAX_FD
];
371 typedef struct fdctrl_t fdctrl_t
;
373 fdctrl_t
*fdctrl_init (int irq_lvl
, int dma_chann
, int mem_mapped
,
375 BlockDriverState
**fds
);
376 int fdctrl_get_drive_type(fdctrl_t
*fdctrl
, int drive_num
);
380 void ne2000_init(int base
, int irq
, NetDriverState
*nd
);
384 void kbd_put_keycode(int keycode
);
386 #define MOUSE_EVENT_LBUTTON 0x01
387 #define MOUSE_EVENT_RBUTTON 0x02
388 #define MOUSE_EVENT_MBUTTON 0x04
389 void kbd_mouse_event(int dx
, int dy
, int dz
, int buttons_state
);
395 typedef struct RTCState RTCState
;
397 RTCState
*rtc_init(int base
, int irq
);
398 void rtc_set_memory(RTCState
*s
, int addr
, int val
);
399 void rtc_set_date(RTCState
*s
, const struct tm
*tm
);
403 typedef struct SerialState SerialState
;
405 extern SerialState
*serial_console
;
407 SerialState
*serial_init(int base
, int irq
, int fd
);
408 int serial_can_receive(SerialState
*s
);
409 void serial_receive_byte(SerialState
*s
, int ch
);
410 void serial_receive_break(SerialState
*s
);
414 void pic_set_irq(int irq
, int level
);
419 #define PIT_FREQ 1193182
421 typedef struct PITChannelState
{
422 int count
; /* can be 65536 */
423 uint16_t latched_count
;
426 uint8_t bcd
; /* not supported */
427 uint8_t gate
; /* timer start */
428 int64_t count_load_time
;
430 int64_t next_transition_time
;
431 QEMUTimer
*irq_timer
;
435 extern PITChannelState pit_channels
[3];
437 void pit_init(int base
, int irq
);
438 void pit_set_gate(PITChannelState
*s
, int val
);
439 int pit_get_out(PITChannelState
*s
, int64_t current_time
);
440 int pit_get_out_edges(PITChannelState
*s
);
443 void pc_init(int ram_size
, int vga_ram_size
, int boot_device
,
444 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
445 const char *kernel_filename
, const char *kernel_cmdline
,
446 const char *initrd_filename
);
449 void monitor_init(void);
450 void term_printf(const char *fmt
, ...);
451 void term_flush(void);
452 void term_print_help(void);
456 #define DEFAULT_GDBSTUB_PORT 1234
458 int gdbserver_start(int port
);