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