]> git.proxmox.com Git - mirror_qemu.git/blob - vl.h
fixed SDL probing for cross compilation
[mirror_qemu.git] / vl.h
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 <time.h>
34 #include <ctype.h>
35 #include <errno.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38
39 #ifndef O_LARGEFILE
40 #define O_LARGEFILE 0
41 #endif
42
43 #ifdef _WIN32
44 #define lseek64 lseek
45 #endif
46
47 #include "cpu.h"
48
49 #ifndef glue
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
54 #endif
55
56 #if defined(WORDS_BIGENDIAN)
57 static inline uint32_t be32_to_cpu(uint32_t v)
58 {
59 return v;
60 }
61
62 static inline uint16_t be16_to_cpu(uint16_t v)
63 {
64 return v;
65 }
66
67 static inline uint32_t le32_to_cpu(uint32_t v)
68 {
69 return bswap32(v);
70 }
71
72 static inline uint16_t le16_to_cpu(uint16_t v)
73 {
74 return bswap16(v);
75 }
76
77 #else
78 static inline uint32_t be32_to_cpu(uint32_t v)
79 {
80 return bswap32(v);
81 }
82
83 static inline uint16_t be16_to_cpu(uint16_t v)
84 {
85 return bswap16(v);
86 }
87
88 static inline uint32_t le32_to_cpu(uint32_t v)
89 {
90 return v;
91 }
92
93 static inline uint16_t le16_to_cpu(uint16_t v)
94 {
95 return v;
96 }
97 #endif
98
99
100 /* vl.c */
101 extern int reset_requested;
102
103 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
104 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
105
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);
111
112 void hw_error(const char *fmt, ...);
113
114 int load_image(const char *filename, uint8_t *addr);
115 extern const char *bios_dir;
116
117 void pstrcpy(char *buf, int buf_size, const char *str);
118 char *pstrcat(char *buf, int buf_size, const char *s);
119
120 int serial_open_device(void);
121
122 extern int vm_running;
123
124 typedef void VMStopHandler(void *opaque, int reason);
125
126 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
127 void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
128
129 void vm_start(void);
130 void vm_stop(int reason);
131
132 /* network redirectors support */
133
134 #define MAX_NICS 8
135
136 typedef struct NetDriverState {
137 int fd;
138 uint8_t macaddr[6];
139 char ifname[16];
140 } NetDriverState;
141
142 extern int nb_nics;
143 extern NetDriverState nd_table[MAX_NICS];
144
145 void net_send_packet(NetDriverState *nd, const uint8_t *buf, int size);
146
147 /* async I/O support */
148
149 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
150 typedef int IOCanRWHandler(void *opaque);
151
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);
155
156 /* timers */
157
158 typedef struct QEMUClock QEMUClock;
159 typedef struct QEMUTimer QEMUTimer;
160 typedef void QEMUTimerCB(void *opaque);
161
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
165 Hz. */
166 extern QEMUClock *rt_clock;
167
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;
172
173 int64_t qemu_get_clock(QEMUClock *clock);
174
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);
180
181 extern int64_t ticks_per_sec;
182 extern int pit_min_timer_count;
183
184 void cpu_enable_ticks(void);
185 void cpu_disable_ticks(void);
186
187 /* VM Load/Save */
188
189 typedef FILE QEMUFile;
190
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);
201
202 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
203 {
204 qemu_put_be64(f, *pv);
205 }
206
207 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
208 {
209 qemu_put_be32(f, *pv);
210 }
211
212 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
213 {
214 qemu_put_be16(f, *pv);
215 }
216
217 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
218 {
219 qemu_put_byte(f, *pv);
220 }
221
222 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
223 {
224 *pv = qemu_get_be64(f);
225 }
226
227 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
228 {
229 *pv = qemu_get_be32(f);
230 }
231
232 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
233 {
234 *pv = qemu_get_be16(f);
235 }
236
237 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
238 {
239 *pv = qemu_get_byte(f);
240 }
241
242 int64_t qemu_ftell(QEMUFile *f);
243 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
244
245 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
246 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
247
248 int qemu_loadvm(const char *filename);
249 int qemu_savevm(const char *filename);
250 int register_savevm(const char *idstr,
251 int instance_id,
252 int version_id,
253 SaveStateHandler *save_state,
254 LoadStateHandler *load_state,
255 void *opaque);
256 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
257 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
258
259 /* block.c */
260 typedef struct BlockDriverState BlockDriverState;
261
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);
273
274 #define BDRV_TYPE_HD 0
275 #define BDRV_TYPE_CDROM 1
276 #define BDRV_TYPE_FLOPPY 2
277
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);
291
292 void bdrv_info(void);
293 BlockDriverState *bdrv_find(const char *name);
294
295 /* vga.c */
296
297 #define VGA_RAM_SIZE (4096 * 1024)
298
299 typedef struct DisplayState {
300 uint8_t *data;
301 int linesize;
302 int depth;
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);
306 } DisplayState;
307
308 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
309 {
310 s->dpy_update(s, x, y, w, h);
311 }
312
313 static inline void dpy_resize(DisplayState *s, int w, int h)
314 {
315 s->dpy_resize(s, w, h);
316 }
317
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);
322
323 /* sdl.c */
324 void sdl_display_init(DisplayState *ds);
325
326 /* ide.c */
327 #define MAX_DISKS 4
328
329 extern BlockDriverState *bs_table[MAX_DISKS];
330
331 void ide_init(int iobase, int iobase2, int irq,
332 BlockDriverState *hd0, BlockDriverState *hd1);
333
334 /* oss.c */
335 typedef enum {
336 AUD_FMT_U8,
337 AUD_FMT_S8,
338 AUD_FMT_U16,
339 AUD_FMT_S16
340 } audfmt_e;
341
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);
345 void AUD_run (void);
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);
351
352 /* dma.c */
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);
358 void DMA_run (void);
359 void DMA_init (void);
360 void DMA_register_channel (int nchan,
361 DMA_transfer_handler transfer_handler, void *opaque);
362
363 /* sb16.c */
364 void SB16_run (void);
365 void SB16_init (void);
366
367 /* fdc.c */
368 #define MAX_FD 2
369 extern BlockDriverState *fd_table[MAX_FD];
370
371 typedef struct fdctrl_t fdctrl_t;
372
373 fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped,
374 uint32_t io_base,
375 BlockDriverState **fds);
376 int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
377
378 /* ne2000.c */
379
380 void ne2000_init(int base, int irq, NetDriverState *nd);
381
382 /* pckbd.c */
383
384 void kbd_put_keycode(int keycode);
385
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);
390
391 void kbd_init(void);
392
393 /* mc146818rtc.c */
394
395 typedef struct RTCState RTCState;
396
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);
400
401 /* serial.c */
402
403 typedef struct SerialState SerialState;
404
405 extern SerialState *serial_console;
406
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);
411
412 /* i8259.c */
413
414 void pic_set_irq(int irq, int level);
415 void pic_init(void);
416
417 /* i8254.c */
418
419 #define PIT_FREQ 1193182
420
421 typedef struct PITChannelState {
422 int count; /* can be 65536 */
423 uint16_t latched_count;
424 uint8_t rw_state;
425 uint8_t mode;
426 uint8_t bcd; /* not supported */
427 uint8_t gate; /* timer start */
428 int64_t count_load_time;
429 /* irq handling */
430 int64_t next_transition_time;
431 QEMUTimer *irq_timer;
432 int irq;
433 } PITChannelState;
434
435 extern PITChannelState pit_channels[3];
436
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);
441
442 /* pc.c */
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);
447
448 /* monitor.c */
449 void monitor_init(void);
450 void term_printf(const char *fmt, ...);
451 void term_flush(void);
452 void term_print_help(void);
453
454 /* gdbstub.c */
455
456 #define DEFAULT_GDBSTUB_PORT 1234
457
458 int gdbserver_start(int port);
459
460 #endif /* VL_H */