1 /* Declarations for use by hardware emulation. */
5 #include "qemu-common.h"
7 #if defined(TARGET_PHYS_ADDR_BITS) && !defined(NEED_CPU_H)
10 #include "cpu-common.h"
18 /* This function writes a chunk of data to a file at the given position.
19 * The pos argument can be ignored if the file is only being used for
20 * streaming. The handler should try to write all of the data it can.
22 typedef int (QEMUFilePutBufferFunc
)(void *opaque
, const uint8_t *buf
,
23 int64_t pos
, int size
);
25 /* Read a chunk of data from a file at the given position. The pos argument
26 * can be ignored if the file is only be used for streaming. The number of
27 * bytes actually read should be returned.
29 typedef int (QEMUFileGetBufferFunc
)(void *opaque
, uint8_t *buf
,
30 int64_t pos
, int size
);
32 /* Close a file and return an error code */
33 typedef int (QEMUFileCloseFunc
)(void *opaque
);
35 /* Called to determine if the file has exceeded it's bandwidth allocation. The
36 * bandwidth capping is a soft limit, not a hard limit.
38 typedef int (QEMUFileRateLimit
)(void *opaque
);
40 /* Called to change the current bandwidth allocation. This function must return
41 * the new actual bandwidth. It should be new_rate if everything goes ok, and
42 * the old rate otherwise
44 typedef size_t (QEMUFileSetRateLimit
)(void *opaque
, size_t new_rate
);
46 QEMUFile
*qemu_fopen_ops(void *opaque
, QEMUFilePutBufferFunc
*put_buffer
,
47 QEMUFileGetBufferFunc
*get_buffer
,
48 QEMUFileCloseFunc
*close
,
49 QEMUFileRateLimit
*rate_limit
,
50 QEMUFileSetRateLimit
*set_rate_limit
);
51 QEMUFile
*qemu_fopen(const char *filename
, const char *mode
);
52 QEMUFile
*qemu_fopen_socket(int fd
);
53 QEMUFile
*qemu_popen(FILE *popen_file
, const char *mode
);
54 QEMUFile
*qemu_popen_cmd(const char *command
, const char *mode
);
55 int qemu_popen_fd(QEMUFile
*f
);
56 void qemu_fflush(QEMUFile
*f
);
57 int qemu_fclose(QEMUFile
*f
);
58 void qemu_put_buffer(QEMUFile
*f
, const uint8_t *buf
, int size
);
59 void qemu_put_byte(QEMUFile
*f
, int v
);
61 static inline void qemu_put_ubyte(QEMUFile
*f
, unsigned int v
)
63 qemu_put_byte(f
, (int)v
);
66 #define qemu_put_sbyte qemu_put_byte
68 void qemu_put_be16(QEMUFile
*f
, unsigned int v
);
69 void qemu_put_be32(QEMUFile
*f
, unsigned int v
);
70 void qemu_put_be64(QEMUFile
*f
, uint64_t v
);
71 int qemu_get_buffer(QEMUFile
*f
, uint8_t *buf
, int size
);
72 int qemu_get_byte(QEMUFile
*f
);
74 static inline unsigned int qemu_get_ubyte(QEMUFile
*f
)
76 return (unsigned int)qemu_get_byte(f
);
79 #define qemu_get_sbyte qemu_get_byte
81 unsigned int qemu_get_be16(QEMUFile
*f
);
82 unsigned int qemu_get_be32(QEMUFile
*f
);
83 uint64_t qemu_get_be64(QEMUFile
*f
);
84 int qemu_file_rate_limit(QEMUFile
*f
);
85 size_t qemu_file_set_rate_limit(QEMUFile
*f
, size_t new_rate
);
86 int qemu_file_has_error(QEMUFile
*f
);
87 void qemu_file_set_error(QEMUFile
*f
);
89 /* Try to send any outstanding data. This function is useful when output is
90 * halted due to rate limiting or EAGAIN errors occur as it can be used to
92 void qemu_file_put_notify(QEMUFile
*f
);
94 static inline void qemu_put_be64s(QEMUFile
*f
, const uint64_t *pv
)
96 qemu_put_be64(f
, *pv
);
99 static inline void qemu_put_be32s(QEMUFile
*f
, const uint32_t *pv
)
101 qemu_put_be32(f
, *pv
);
104 static inline void qemu_put_be16s(QEMUFile
*f
, const uint16_t *pv
)
106 qemu_put_be16(f
, *pv
);
109 static inline void qemu_put_8s(QEMUFile
*f
, const uint8_t *pv
)
111 qemu_put_byte(f
, *pv
);
114 static inline void qemu_get_be64s(QEMUFile
*f
, uint64_t *pv
)
116 *pv
= qemu_get_be64(f
);
119 static inline void qemu_get_be32s(QEMUFile
*f
, uint32_t *pv
)
121 *pv
= qemu_get_be32(f
);
124 static inline void qemu_get_be16s(QEMUFile
*f
, uint16_t *pv
)
126 *pv
= qemu_get_be16(f
);
129 static inline void qemu_get_8s(QEMUFile
*f
, uint8_t *pv
)
131 *pv
= qemu_get_byte(f
);
134 // Signed versions for type safety
135 static inline void qemu_put_sbuffer(QEMUFile
*f
, const int8_t *buf
, int size
)
137 qemu_put_buffer(f
, (const uint8_t *)buf
, size
);
140 static inline void qemu_put_sbe16(QEMUFile
*f
, int v
)
142 qemu_put_be16(f
, (unsigned int)v
);
145 static inline void qemu_put_sbe32(QEMUFile
*f
, int v
)
147 qemu_put_be32(f
, (unsigned int)v
);
150 static inline void qemu_put_sbe64(QEMUFile
*f
, int64_t v
)
152 qemu_put_be64(f
, (uint64_t)v
);
155 static inline size_t qemu_get_sbuffer(QEMUFile
*f
, int8_t *buf
, int size
)
157 return qemu_get_buffer(f
, (uint8_t *)buf
, size
);
160 static inline int qemu_get_sbe16(QEMUFile
*f
)
162 return (int)qemu_get_be16(f
);
165 static inline int qemu_get_sbe32(QEMUFile
*f
)
167 return (int)qemu_get_be32(f
);
170 static inline int64_t qemu_get_sbe64(QEMUFile
*f
)
172 return (int64_t)qemu_get_be64(f
);
175 static inline void qemu_put_s8s(QEMUFile
*f
, const int8_t *pv
)
177 qemu_put_8s(f
, (const uint8_t *)pv
);
180 static inline void qemu_put_sbe16s(QEMUFile
*f
, const int16_t *pv
)
182 qemu_put_be16s(f
, (const uint16_t *)pv
);
185 static inline void qemu_put_sbe32s(QEMUFile
*f
, const int32_t *pv
)
187 qemu_put_be32s(f
, (const uint32_t *)pv
);
190 static inline void qemu_put_sbe64s(QEMUFile
*f
, const int64_t *pv
)
192 qemu_put_be64s(f
, (const uint64_t *)pv
);
195 static inline void qemu_get_s8s(QEMUFile
*f
, int8_t *pv
)
197 qemu_get_8s(f
, (uint8_t *)pv
);
200 static inline void qemu_get_sbe16s(QEMUFile
*f
, int16_t *pv
)
202 qemu_get_be16s(f
, (uint16_t *)pv
);
205 static inline void qemu_get_sbe32s(QEMUFile
*f
, int32_t *pv
)
207 qemu_get_be32s(f
, (uint32_t *)pv
);
210 static inline void qemu_get_sbe64s(QEMUFile
*f
, int64_t *pv
)
212 qemu_get_be64s(f
, (uint64_t *)pv
);
216 #if TARGET_LONG_BITS == 64
217 #define qemu_put_betl qemu_put_be64
218 #define qemu_get_betl qemu_get_be64
219 #define qemu_put_betls qemu_put_be64s
220 #define qemu_get_betls qemu_get_be64s
221 #define qemu_put_sbetl qemu_put_sbe64
222 #define qemu_get_sbetl qemu_get_sbe64
223 #define qemu_put_sbetls qemu_put_sbe64s
224 #define qemu_get_sbetls qemu_get_sbe64s
226 #define qemu_put_betl qemu_put_be32
227 #define qemu_get_betl qemu_get_be32
228 #define qemu_put_betls qemu_put_be32s
229 #define qemu_get_betls qemu_get_be32s
230 #define qemu_put_sbetl qemu_put_sbe32
231 #define qemu_get_sbetl qemu_get_sbe32
232 #define qemu_put_sbetls qemu_put_sbe32s
233 #define qemu_get_sbetls qemu_get_sbe32s
237 int64_t qemu_ftell(QEMUFile
*f
);
238 int64_t qemu_fseek(QEMUFile
*f
, int64_t pos
, int whence
);
240 typedef void SaveStateHandler(QEMUFile
*f
, void *opaque
);
241 typedef int SaveLiveStateHandler(QEMUFile
*f
, int stage
, void *opaque
);
242 typedef int LoadStateHandler(QEMUFile
*f
, void *opaque
, int version_id
);
244 int register_savevm(const char *idstr
,
247 SaveStateHandler
*save_state
,
248 LoadStateHandler
*load_state
,
251 int register_savevm_live(const char *idstr
,
254 SaveLiveStateHandler
*save_live_state
,
255 SaveStateHandler
*save_state
,
256 LoadStateHandler
*load_state
,
259 void unregister_savevm(const char *idstr
, void *opaque
);
261 typedef void QEMUResetHandler(void *opaque
);
263 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
);
264 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
);
266 /* handler to set the boot_device order for a specific type of QEMUMachine */
267 /* return 0 if success */
268 typedef int QEMUBootSetHandler(void *opaque
, const char *boot_devices
);
269 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
);
270 int qemu_boot_set(const char *boot_devices
);