1 /* Declarations for use by hardware emulation. */
5 #include "qemu-common.h"
10 /* This function writes a chunk of data to a file at the given position.
11 * The pos argument can be ignored if the file is only being used for
12 * streaming. The handler should try to write all of the data it can.
14 typedef void (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf,
15 int64_t pos, int size);
17 /* Read a chunk of data from a file at the given position. The pos argument
18 * can be ignored if the file is only be used for streaming. The number of
19 * bytes actually read should be returned.
21 typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,
22 int64_t pos, int size);
24 /* Close a file and return an error code */
25 typedef int (QEMUFileCloseFunc)(void *opaque);
27 /* Called to determine if the file has exceeded it's bandwidth allocation. The
28 * bandwidth capping is a soft limit, not a hard limit.
30 typedef int (QEMUFileRateLimit)(void *opaque);
32 QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
33 QEMUFileGetBufferFunc *get_buffer,
34 QEMUFileCloseFunc *close,
35 QEMUFileRateLimit *rate_limit);
36 QEMUFile *qemu_fopen(const char *filename, const char *mode);
37 QEMUFile *qemu_fopen_fd(int fd);
38 void qemu_fflush(QEMUFile *f);
39 int qemu_fclose(QEMUFile *f);
40 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
41 void qemu_put_byte(QEMUFile *f, int v);
42 void qemu_put_be16(QEMUFile *f, unsigned int v);
43 void qemu_put_be32(QEMUFile *f, unsigned int v);
44 void qemu_put_be64(QEMUFile *f, uint64_t v);
45 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
46 int qemu_get_byte(QEMUFile *f);
47 unsigned int qemu_get_be16(QEMUFile *f);
48 unsigned int qemu_get_be32(QEMUFile *f);
49 uint64_t qemu_get_be64(QEMUFile *f);
50 int qemu_file_rate_limit(QEMUFile *f);
52 /* Try to send any outstanding data. This function is useful when output is
53 * halted due to rate limiting or EAGAIN errors occur as it can be used to
55 void qemu_file_put_notify(QEMUFile *f);
57 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
59 qemu_put_be64(f, *pv);
62 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
64 qemu_put_be32(f, *pv);
67 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
69 qemu_put_be16(f, *pv);
72 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
74 qemu_put_byte(f, *pv);
77 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
79 *pv = qemu_get_be64(f);
82 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
84 *pv = qemu_get_be32(f);
87 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
89 *pv = qemu_get_be16(f);
92 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
94 *pv = qemu_get_byte(f);
98 #if TARGET_LONG_BITS == 64
99 #define qemu_put_betl qemu_put_be64
100 #define qemu_get_betl qemu_get_be64
101 #define qemu_put_betls qemu_put_be64s
102 #define qemu_get_betls qemu_get_be64s
104 #define qemu_put_betl qemu_put_be32
105 #define qemu_get_betl qemu_get_be32
106 #define qemu_put_betls qemu_put_be32s
107 #define qemu_get_betls qemu_get_be32s
111 int64_t qemu_ftell(QEMUFile *f);
112 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
114 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
115 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
117 int register_savevm(const char *idstr,
120 SaveStateHandler *save_state,
121 LoadStateHandler *load_state,
124 typedef void QEMUResetHandler(void *opaque);
126 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
128 /* handler to set the boot_device for a specific type of QEMUMachine */
129 /* return 0 if success */
130 typedef int QEMUBootSetHandler(void *opaque, const char *boot_device);
131 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
133 /* These should really be in isa.h, but are here to make pc.h happy. */
134 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
135 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);