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
30 extern int reset_requested
;
31 extern int64_t ticks_per_sec
;
32 extern int pit_min_timer_count
;
34 typedef void (IOPortWriteFunc
)(void *opaque
, uint32_t address
, uint32_t data
);
35 typedef uint32_t (IOPortReadFunc
)(void *opaque
, uint32_t address
);
37 int register_ioport_read(int start
, int length
, int size
,
38 IOPortReadFunc
*func
, void *opaque
);
39 int register_ioport_write(int start
, int length
, int size
,
40 IOPortWriteFunc
*func
, void *opaque
);
41 int64_t cpu_get_ticks(void);
42 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
);
44 void hw_error(const char *fmt
, ...);
46 int load_image(const char *filename
, uint8_t *addr
);
47 extern const char *bios_dir
;
49 void pstrcpy(char *buf
, int buf_size
, const char *str
);
50 char *pstrcat(char *buf
, int buf_size
, const char *s
);
52 int serial_open_device(void);
54 /* network redirectors support */
58 typedef struct NetDriverState
{
65 extern NetDriverState nd_table
[MAX_NICS
];
67 void net_send_packet(NetDriverState
*nd
, const uint8_t *buf
, int size
);
69 /* async I/O support */
71 typedef void IOReadHandler(void *opaque
, const uint8_t *buf
, int size
);
72 typedef int IOCanRWHandler(void *opaque
);
74 int add_fd_read_handler(int fd
, IOCanRWHandler
*fd_can_read
,
75 IOReadHandler
*fd_read
, void *opaque
);
78 typedef struct BlockDriverState BlockDriverState
;
80 BlockDriverState
*bdrv_new(const char *device_name
);
81 void bdrv_delete(BlockDriverState
*bs
);
82 int bdrv_open(BlockDriverState
*bs
, const char *filename
, int snapshot
);
83 void bdrv_close(BlockDriverState
*bs
);
84 int bdrv_read(BlockDriverState
*bs
, int64_t sector_num
,
85 uint8_t *buf
, int nb_sectors
);
86 int bdrv_write(BlockDriverState
*bs
, int64_t sector_num
,
87 const uint8_t *buf
, int nb_sectors
);
88 void bdrv_get_geometry(BlockDriverState
*bs
, int64_t *nb_sectors_ptr
);
89 int bdrv_commit(BlockDriverState
*bs
);
90 void bdrv_set_boot_sector(BlockDriverState
*bs
, const uint8_t *data
, int size
);
92 #define BDRV_TYPE_HD 0
93 #define BDRV_TYPE_CDROM 1
94 #define BDRV_TYPE_FLOPPY 2
96 void bdrv_set_geometry_hint(BlockDriverState
*bs
,
97 int cyls
, int heads
, int secs
);
98 void bdrv_set_type_hint(BlockDriverState
*bs
, int type
);
99 void bdrv_get_geometry_hint(BlockDriverState
*bs
,
100 int *pcyls
, int *pheads
, int *psecs
);
101 int bdrv_get_type_hint(BlockDriverState
*bs
);
102 int bdrv_is_removable(BlockDriverState
*bs
);
103 int bdrv_is_read_only(BlockDriverState
*bs
);
104 int bdrv_is_inserted(BlockDriverState
*bs
);
105 int bdrv_is_locked(BlockDriverState
*bs
);
106 void bdrv_set_locked(BlockDriverState
*bs
, int locked
);
107 void bdrv_set_change_cb(BlockDriverState
*bs
,
108 void (*change_cb
)(void *opaque
), void *opaque
);
110 void bdrv_info(void);
111 BlockDriverState
*bdrv_find(const char *name
);
115 #define VGA_RAM_SIZE (4096 * 1024)
117 typedef struct DisplayState
{
121 void (*dpy_update
)(struct DisplayState
*s
, int x
, int y
, int w
, int h
);
122 void (*dpy_resize
)(struct DisplayState
*s
, int w
, int h
);
123 void (*dpy_refresh
)(struct DisplayState
*s
);
126 static inline void dpy_update(DisplayState
*s
, int x
, int y
, int w
, int h
)
128 s
->dpy_update(s
, x
, y
, w
, h
);
131 static inline void dpy_resize(DisplayState
*s
, int w
, int h
)
133 s
->dpy_resize(s
, w
, h
);
136 int vga_initialize(DisplayState
*ds
, uint8_t *vga_ram_base
,
137 unsigned long vga_ram_offset
, int vga_ram_size
);
138 void vga_update_display(void);
139 void vga_screen_dump(const char *filename
);
142 void sdl_display_init(DisplayState
*ds
);
147 extern BlockDriverState
*bs_table
[MAX_DISKS
];
149 void ide_init(int iobase
, int iobase2
, int irq
,
150 BlockDriverState
*hd0
, BlockDriverState
*hd1
);
160 void AUD_open (int rfreq
, int rnchannels
, audfmt_e rfmt
);
161 void AUD_reset (int rfreq
, int rnchannels
, audfmt_e rfmt
);
162 int AUD_write (void *in_buf
, int size
);
164 void AUD_adjust_estimate (int _leftover
);
165 int AUD_get_free (void);
166 int AUD_get_live (void);
167 int AUD_get_buffer_size (void);
168 void AUD_init (void);
171 typedef int (*DMA_transfer_handler
) (void *opaque
, target_ulong addr
, int size
);
172 int DMA_get_channel_mode (int nchan
);
173 void DMA_hold_DREQ (int nchan
);
174 void DMA_release_DREQ (int nchan
);
175 void DMA_schedule(int nchan
);
177 void DMA_init (void);
178 void DMA_register_channel (int nchan
,
179 DMA_transfer_handler transfer_handler
, void *opaque
);
182 void SB16_run (void);
183 void SB16_init (void);
187 extern BlockDriverState
*fd_table
[MAX_FD
];
189 typedef struct fdctrl_t fdctrl_t
;
191 fdctrl_t
*fdctrl_init (int irq_lvl
, int dma_chann
, int mem_mapped
,
193 BlockDriverState
**fds
);
194 int fdctrl_get_drive_type(fdctrl_t
*fdctrl
, int drive_num
);
198 void ne2000_init(int base
, int irq
, NetDriverState
*nd
);
202 void kbd_put_keycode(int keycode
);
204 #define MOUSE_EVENT_LBUTTON 0x01
205 #define MOUSE_EVENT_RBUTTON 0x02
206 #define MOUSE_EVENT_MBUTTON 0x04
207 void kbd_mouse_event(int dx
, int dy
, int dz
, int buttons_state
);
213 typedef struct RTCState
{
214 uint8_t cmos_data
[128];
219 extern RTCState rtc_state
;
221 void rtc_init(int base
, int irq
);
222 void rtc_timer(void);
226 typedef struct SerialState SerialState
;
228 extern SerialState
*serial_console
;
230 SerialState
*serial_init(int base
, int irq
, int fd
);
231 int serial_can_receive(SerialState
*s
);
232 void serial_receive_byte(SerialState
*s
, int ch
);
233 void serial_receive_break(SerialState
*s
);
237 void pic_set_irq(int irq
, int level
);
242 #define PIT_FREQ 1193182
244 typedef struct PITChannelState
{
245 int count
; /* can be 65536 */
246 uint16_t latched_count
;
249 uint8_t bcd
; /* not supported */
250 uint8_t gate
; /* timer start */
251 int64_t count_load_time
;
252 int64_t count_last_edge_check_time
;
255 extern PITChannelState pit_channels
[3];
257 void pit_init(int base
);
258 void pit_set_gate(PITChannelState
*s
, int val
);
259 int pit_get_out(PITChannelState
*s
);
260 int pit_get_out_edges(PITChannelState
*s
);
263 void pc_init(int ram_size
, int vga_ram_size
, int boot_device
,
264 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
265 const char *kernel_filename
, const char *kernel_cmdline
,
266 const char *initrd_filename
);
269 void monitor_init(void);
270 void term_printf(const char *fmt
, ...);
271 void term_flush(void);
272 void term_print_help(void);