]> git.proxmox.com Git - mirror_qemu.git/blob - vl.h
base memory size in cmos
[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 #ifndef O_BINARY
43 #define O_BINARY 0
44 #endif
45
46 #ifdef _WIN32
47 #define lseek64 lseek
48 #endif
49
50 #include "cpu.h"
51
52 #ifndef glue
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
57 #endif
58
59 #if defined(WORDS_BIGENDIAN)
60 static inline uint32_t be32_to_cpu(uint32_t v)
61 {
62 return v;
63 }
64
65 static inline uint16_t be16_to_cpu(uint16_t v)
66 {
67 return v;
68 }
69
70 static inline uint32_t le32_to_cpu(uint32_t v)
71 {
72 return bswap32(v);
73 }
74
75 static inline uint16_t le16_to_cpu(uint16_t v)
76 {
77 return bswap16(v);
78 }
79
80 #else
81 static inline uint32_t be32_to_cpu(uint32_t v)
82 {
83 return bswap32(v);
84 }
85
86 static inline uint16_t be16_to_cpu(uint16_t v)
87 {
88 return bswap16(v);
89 }
90
91 static inline uint32_t le32_to_cpu(uint32_t v)
92 {
93 return v;
94 }
95
96 static inline uint16_t le16_to_cpu(uint16_t v)
97 {
98 return v;
99 }
100 #endif
101
102
103 /* vl.c */
104 extern int reset_requested;
105
106 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
107 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
108
109 int register_ioport_read(int start, int length, int size,
110 IOPortReadFunc *func, void *opaque);
111 int register_ioport_write(int start, int length, int size,
112 IOPortWriteFunc *func, void *opaque);
113 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
114
115 void hw_error(const char *fmt, ...);
116
117 int load_image(const char *filename, uint8_t *addr);
118 extern const char *bios_dir;
119
120 void pstrcpy(char *buf, int buf_size, const char *str);
121 char *pstrcat(char *buf, int buf_size, const char *s);
122
123 int serial_open_device(void);
124
125 extern int vm_running;
126
127 typedef void VMStopHandler(void *opaque, int reason);
128
129 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
130 void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
131
132 void vm_start(void);
133 void vm_stop(int reason);
134
135 /* network redirectors support */
136
137 #define MAX_NICS 8
138
139 typedef struct NetDriverState {
140 int fd;
141 uint8_t macaddr[6];
142 char ifname[16];
143 } NetDriverState;
144
145 extern int nb_nics;
146 extern NetDriverState nd_table[MAX_NICS];
147
148 void net_send_packet(NetDriverState *nd, const uint8_t *buf, int size);
149
150 /* async I/O support */
151
152 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
153 typedef int IOCanRWHandler(void *opaque);
154
155 int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read,
156 IOReadHandler *fd_read, void *opaque);
157 void qemu_del_fd_read_handler(int fd);
158
159 /* timers */
160
161 typedef struct QEMUClock QEMUClock;
162 typedef struct QEMUTimer QEMUTimer;
163 typedef void QEMUTimerCB(void *opaque);
164
165 /* The real time clock should be used only for stuff which does not
166 change the virtual machine state, as it is run even if the virtual
167 machine is stopped. The real time clock has a frequency or 1000
168 Hz. */
169 extern QEMUClock *rt_clock;
170
171 /* Rge virtual clock is only run during the emulation. It is stopped
172 when the virtual machine is stopped. Virtual timers use a high
173 precision clock, usually cpu cycles (use ticks_per_sec). */
174 extern QEMUClock *vm_clock;
175
176 int64_t qemu_get_clock(QEMUClock *clock);
177
178 QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
179 void qemu_free_timer(QEMUTimer *ts);
180 void qemu_del_timer(QEMUTimer *ts);
181 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
182 int qemu_timer_pending(QEMUTimer *ts);
183
184 extern int64_t ticks_per_sec;
185 extern int pit_min_timer_count;
186
187 void cpu_enable_ticks(void);
188 void cpu_disable_ticks(void);
189
190 /* VM Load/Save */
191
192 typedef FILE QEMUFile;
193
194 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
195 void qemu_put_byte(QEMUFile *f, int v);
196 void qemu_put_be16(QEMUFile *f, unsigned int v);
197 void qemu_put_be32(QEMUFile *f, unsigned int v);
198 void qemu_put_be64(QEMUFile *f, uint64_t v);
199 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
200 int qemu_get_byte(QEMUFile *f);
201 unsigned int qemu_get_be16(QEMUFile *f);
202 unsigned int qemu_get_be32(QEMUFile *f);
203 uint64_t qemu_get_be64(QEMUFile *f);
204
205 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
206 {
207 qemu_put_be64(f, *pv);
208 }
209
210 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
211 {
212 qemu_put_be32(f, *pv);
213 }
214
215 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
216 {
217 qemu_put_be16(f, *pv);
218 }
219
220 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
221 {
222 qemu_put_byte(f, *pv);
223 }
224
225 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
226 {
227 *pv = qemu_get_be64(f);
228 }
229
230 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
231 {
232 *pv = qemu_get_be32(f);
233 }
234
235 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
236 {
237 *pv = qemu_get_be16(f);
238 }
239
240 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
241 {
242 *pv = qemu_get_byte(f);
243 }
244
245 int64_t qemu_ftell(QEMUFile *f);
246 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
247
248 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
249 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
250
251 int qemu_loadvm(const char *filename);
252 int qemu_savevm(const char *filename);
253 int register_savevm(const char *idstr,
254 int instance_id,
255 int version_id,
256 SaveStateHandler *save_state,
257 LoadStateHandler *load_state,
258 void *opaque);
259 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
260 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
261
262 /* block.c */
263 typedef struct BlockDriverState BlockDriverState;
264
265 BlockDriverState *bdrv_new(const char *device_name);
266 void bdrv_delete(BlockDriverState *bs);
267 int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
268 void bdrv_close(BlockDriverState *bs);
269 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
270 uint8_t *buf, int nb_sectors);
271 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
272 const uint8_t *buf, int nb_sectors);
273 void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
274 int bdrv_commit(BlockDriverState *bs);
275 void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
276
277 #define BDRV_TYPE_HD 0
278 #define BDRV_TYPE_CDROM 1
279 #define BDRV_TYPE_FLOPPY 2
280
281 void bdrv_set_geometry_hint(BlockDriverState *bs,
282 int cyls, int heads, int secs);
283 void bdrv_set_type_hint(BlockDriverState *bs, int type);
284 void bdrv_get_geometry_hint(BlockDriverState *bs,
285 int *pcyls, int *pheads, int *psecs);
286 int bdrv_get_type_hint(BlockDriverState *bs);
287 int bdrv_is_removable(BlockDriverState *bs);
288 int bdrv_is_read_only(BlockDriverState *bs);
289 int bdrv_is_inserted(BlockDriverState *bs);
290 int bdrv_is_locked(BlockDriverState *bs);
291 void bdrv_set_locked(BlockDriverState *bs, int locked);
292 void bdrv_set_change_cb(BlockDriverState *bs,
293 void (*change_cb)(void *opaque), void *opaque);
294
295 void bdrv_info(void);
296 BlockDriverState *bdrv_find(const char *name);
297
298 /* vga.c */
299
300 #define VGA_RAM_SIZE (4096 * 1024)
301
302 typedef struct DisplayState {
303 uint8_t *data;
304 int linesize;
305 int depth;
306 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
307 void (*dpy_resize)(struct DisplayState *s, int w, int h);
308 void (*dpy_refresh)(struct DisplayState *s);
309 } DisplayState;
310
311 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
312 {
313 s->dpy_update(s, x, y, w, h);
314 }
315
316 static inline void dpy_resize(DisplayState *s, int w, int h)
317 {
318 s->dpy_resize(s, w, h);
319 }
320
321 int vga_initialize(DisplayState *ds, uint8_t *vga_ram_base,
322 unsigned long vga_ram_offset, int vga_ram_size);
323 void vga_update_display(void);
324 void vga_screen_dump(const char *filename);
325
326 /* sdl.c */
327 void sdl_display_init(DisplayState *ds);
328
329 /* ide.c */
330 #define MAX_DISKS 4
331
332 extern BlockDriverState *bs_table[MAX_DISKS];
333
334 void ide_init(int iobase, int iobase2, int irq,
335 BlockDriverState *hd0, BlockDriverState *hd1);
336
337 /* oss.c */
338 typedef enum {
339 AUD_FMT_U8,
340 AUD_FMT_S8,
341 AUD_FMT_U16,
342 AUD_FMT_S16
343 } audfmt_e;
344
345 void AUD_open (int rfreq, int rnchannels, audfmt_e rfmt);
346 void AUD_reset (int rfreq, int rnchannels, audfmt_e rfmt);
347 int AUD_write (void *in_buf, int size);
348 void AUD_run (void);
349 void AUD_adjust_estimate (int _leftover);
350 int AUD_get_free (void);
351 int AUD_get_live (void);
352 int AUD_get_buffer_size (void);
353 void AUD_init (void);
354
355 /* dma.c */
356 typedef int (*DMA_transfer_handler) (void *opaque, target_ulong addr, int size);
357 int DMA_get_channel_mode (int nchan);
358 void DMA_hold_DREQ (int nchan);
359 void DMA_release_DREQ (int nchan);
360 void DMA_schedule(int nchan);
361 void DMA_run (void);
362 void DMA_init (void);
363 void DMA_register_channel (int nchan,
364 DMA_transfer_handler transfer_handler, void *opaque);
365
366 /* sb16.c */
367 void SB16_run (void);
368 void SB16_init (void);
369
370 /* fdc.c */
371 #define MAX_FD 2
372 extern BlockDriverState *fd_table[MAX_FD];
373
374 typedef struct fdctrl_t fdctrl_t;
375
376 fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped,
377 uint32_t io_base,
378 BlockDriverState **fds);
379 int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
380
381 /* ne2000.c */
382
383 void ne2000_init(int base, int irq, NetDriverState *nd);
384
385 /* pckbd.c */
386
387 void kbd_put_keycode(int keycode);
388
389 #define MOUSE_EVENT_LBUTTON 0x01
390 #define MOUSE_EVENT_RBUTTON 0x02
391 #define MOUSE_EVENT_MBUTTON 0x04
392 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
393
394 void kbd_init(void);
395
396 /* mc146818rtc.c */
397
398 typedef struct RTCState RTCState;
399
400 RTCState *rtc_init(int base, int irq);
401 void rtc_set_memory(RTCState *s, int addr, int val);
402 void rtc_set_date(RTCState *s, const struct tm *tm);
403
404 /* serial.c */
405
406 typedef struct SerialState SerialState;
407
408 extern SerialState *serial_console;
409
410 SerialState *serial_init(int base, int irq, int fd);
411 int serial_can_receive(SerialState *s);
412 void serial_receive_byte(SerialState *s, int ch);
413 void serial_receive_break(SerialState *s);
414
415 /* i8259.c */
416
417 void pic_set_irq(int irq, int level);
418 void pic_init(void);
419
420 /* i8254.c */
421
422 #define PIT_FREQ 1193182
423
424 typedef struct PITChannelState {
425 int count; /* can be 65536 */
426 uint16_t latched_count;
427 uint8_t rw_state;
428 uint8_t mode;
429 uint8_t bcd; /* not supported */
430 uint8_t gate; /* timer start */
431 int64_t count_load_time;
432 /* irq handling */
433 int64_t next_transition_time;
434 QEMUTimer *irq_timer;
435 int irq;
436 } PITChannelState;
437
438 extern PITChannelState pit_channels[3];
439
440 void pit_init(int base, int irq);
441 void pit_set_gate(PITChannelState *s, int val);
442 int pit_get_out(PITChannelState *s, int64_t current_time);
443 int pit_get_out_edges(PITChannelState *s);
444
445 /* pc.c */
446 void pc_init(int ram_size, int vga_ram_size, int boot_device,
447 DisplayState *ds, const char **fd_filename, int snapshot,
448 const char *kernel_filename, const char *kernel_cmdline,
449 const char *initrd_filename);
450
451 /* monitor.c */
452 void monitor_init(void);
453 void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
454 void term_flush(void);
455 void term_print_help(void);
456
457 /* gdbstub.c */
458
459 #define DEFAULT_GDBSTUB_PORT 1234
460
461 int gdbserver_start(int port);
462
463 #endif /* VL_H */