root / hw / hw.h @ bf0cb498
History | View | Annotate | Download (18.1 kB)
1 | 87ecb68b | pbrook | /* Declarations for use by hardware emulation. */
|
---|---|---|---|
2 | 87ecb68b | pbrook | #ifndef QEMU_HW_H
|
3 | 87ecb68b | pbrook | #define QEMU_HW_H
|
4 | 87ecb68b | pbrook | |
5 | 87ecb68b | pbrook | #include "qemu-common.h" |
6 | 1ad2134f | Paul Brook | |
7 | 1ad2134f | Paul Brook | #if defined(TARGET_PHYS_ADDR_BITS) && !defined(NEED_CPU_H)
|
8 | 1ad2134f | Paul Brook | #include "targphys.h" |
9 | 1ad2134f | Paul Brook | #include "poison.h" |
10 | 1ad2134f | Paul Brook | #include "cpu-common.h" |
11 | 1ad2134f | Paul Brook | #endif
|
12 | 1ad2134f | Paul Brook | |
13 | 32993977 | Isaku Yamahata | #include "ioport.h" |
14 | 87ecb68b | pbrook | #include "irq.h" |
15 | 87ecb68b | pbrook | |
16 | 87ecb68b | pbrook | /* VM Load/Save */
|
17 | 87ecb68b | pbrook | |
18 | 5dafc53f | aliguori | /* This function writes a chunk of data to a file at the given position.
|
19 | 5dafc53f | aliguori | * The pos argument can be ignored if the file is only being used for
|
20 | 5dafc53f | aliguori | * streaming. The handler should try to write all of the data it can.
|
21 | 5dafc53f | aliguori | */
|
22 | 871d2f07 | aliguori | typedef int (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf, |
23 | 871d2f07 | aliguori | int64_t pos, int size);
|
24 | 5dafc53f | aliguori | |
25 | 5dafc53f | aliguori | /* Read a chunk of data from a file at the given position. The pos argument
|
26 | 5dafc53f | aliguori | * can be ignored if the file is only be used for streaming. The number of
|
27 | 5dafc53f | aliguori | * bytes actually read should be returned.
|
28 | 5dafc53f | aliguori | */
|
29 | 5dafc53f | aliguori | typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, |
30 | 5dafc53f | aliguori | int64_t pos, int size);
|
31 | 5dafc53f | aliguori | |
32 | 5dafc53f | aliguori | /* Close a file and return an error code */
|
33 | 5dafc53f | aliguori | typedef int (QEMUFileCloseFunc)(void *opaque); |
34 | 5dafc53f | aliguori | |
35 | 5dafc53f | aliguori | /* Called to determine if the file has exceeded it's bandwidth allocation. The
|
36 | 5dafc53f | aliguori | * bandwidth capping is a soft limit, not a hard limit.
|
37 | 5dafc53f | aliguori | */
|
38 | 5dafc53f | aliguori | typedef int (QEMUFileRateLimit)(void *opaque); |
39 | 5dafc53f | aliguori | |
40 | 19629537 | Glauber Costa | /* Called to change the current bandwidth allocation. This function must return
|
41 | 19629537 | Glauber Costa | * the new actual bandwidth. It should be new_rate if everything goes ok, and
|
42 | 19629537 | Glauber Costa | * the old rate otherwise
|
43 | 19629537 | Glauber Costa | */
|
44 | 19629537 | Glauber Costa | typedef size_t (QEMUFileSetRateLimit)(void *opaque, size_t new_rate); |
45 | 19629537 | Glauber Costa | |
46 | 5dafc53f | aliguori | QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
|
47 | 5dafc53f | aliguori | QEMUFileGetBufferFunc *get_buffer, |
48 | 5dafc53f | aliguori | QEMUFileCloseFunc *close, |
49 | 19629537 | Glauber Costa | QEMUFileRateLimit *rate_limit, |
50 | 19629537 | Glauber Costa | QEMUFileSetRateLimit *set_rate_limit); |
51 | 87ecb68b | pbrook | QEMUFile *qemu_fopen(const char *filename, const char *mode); |
52 | 5ac1fad3 | Paolo Bonzini | QEMUFile *qemu_fdopen(int fd, const char *mode); |
53 | c1d36665 | aliguori | QEMUFile *qemu_fopen_socket(int fd);
|
54 | 065e2813 | aliguori | QEMUFile *qemu_popen(FILE *popen_file, const char *mode); |
55 | 065e2813 | aliguori | QEMUFile *qemu_popen_cmd(const char *command, const char *mode); |
56 | 7f79dd28 | Paolo Bonzini | int qemu_stdio_fd(QEMUFile *f);
|
57 | 87ecb68b | pbrook | void qemu_fflush(QEMUFile *f);
|
58 | 5dafc53f | aliguori | int qemu_fclose(QEMUFile *f);
|
59 | 2ca83a8d | blueswir1 | void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); |
60 | 2ca83a8d | blueswir1 | void qemu_put_byte(QEMUFile *f, int v); |
61 | b6c4f71f | blueswir1 | |
62 | b6c4f71f | blueswir1 | static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) |
63 | b6c4f71f | blueswir1 | { |
64 | b6c4f71f | blueswir1 | qemu_put_byte(f, (int)v);
|
65 | b6c4f71f | blueswir1 | } |
66 | b6c4f71f | blueswir1 | |
67 | b6c4f71f | blueswir1 | #define qemu_put_sbyte qemu_put_byte
|
68 | b6c4f71f | blueswir1 | |
69 | 2ca83a8d | blueswir1 | void qemu_put_be16(QEMUFile *f, unsigned int v); |
70 | 2ca83a8d | blueswir1 | void qemu_put_be32(QEMUFile *f, unsigned int v); |
71 | 87ecb68b | pbrook | void qemu_put_be64(QEMUFile *f, uint64_t v);
|
72 | 2ca83a8d | blueswir1 | int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size); |
73 | 2ca83a8d | blueswir1 | int qemu_get_byte(QEMUFile *f);
|
74 | b6c4f71f | blueswir1 | |
75 | b6c4f71f | blueswir1 | static inline unsigned int qemu_get_ubyte(QEMUFile *f) |
76 | b6c4f71f | blueswir1 | { |
77 | b6c4f71f | blueswir1 | return (unsigned int)qemu_get_byte(f); |
78 | b6c4f71f | blueswir1 | } |
79 | b6c4f71f | blueswir1 | |
80 | b6c4f71f | blueswir1 | #define qemu_get_sbyte qemu_get_byte
|
81 | b6c4f71f | blueswir1 | |
82 | 2ca83a8d | blueswir1 | unsigned int qemu_get_be16(QEMUFile *f); |
83 | 2ca83a8d | blueswir1 | unsigned int qemu_get_be32(QEMUFile *f); |
84 | 87ecb68b | pbrook | uint64_t qemu_get_be64(QEMUFile *f); |
85 | 5dafc53f | aliguori | int qemu_file_rate_limit(QEMUFile *f);
|
86 | 19629537 | Glauber Costa | size_t qemu_file_set_rate_limit(QEMUFile *f, size_t new_rate); |
87 | 871d2f07 | aliguori | int qemu_file_has_error(QEMUFile *f);
|
88 | 4dabe248 | aliguori | void qemu_file_set_error(QEMUFile *f);
|
89 | 5dafc53f | aliguori | |
90 | 5dafc53f | aliguori | /* Try to send any outstanding data. This function is useful when output is
|
91 | 5dafc53f | aliguori | * halted due to rate limiting or EAGAIN errors occur as it can be used to
|
92 | 5dafc53f | aliguori | * resume output. */
|
93 | 5dafc53f | aliguori | void qemu_file_put_notify(QEMUFile *f);
|
94 | 87ecb68b | pbrook | |
95 | 87ecb68b | pbrook | static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) |
96 | 87ecb68b | pbrook | { |
97 | 87ecb68b | pbrook | qemu_put_be64(f, *pv); |
98 | 87ecb68b | pbrook | } |
99 | 87ecb68b | pbrook | |
100 | 87ecb68b | pbrook | static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv) |
101 | 87ecb68b | pbrook | { |
102 | 87ecb68b | pbrook | qemu_put_be32(f, *pv); |
103 | 87ecb68b | pbrook | } |
104 | 87ecb68b | pbrook | |
105 | 87ecb68b | pbrook | static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv) |
106 | 87ecb68b | pbrook | { |
107 | 87ecb68b | pbrook | qemu_put_be16(f, *pv); |
108 | 87ecb68b | pbrook | } |
109 | 87ecb68b | pbrook | |
110 | 87ecb68b | pbrook | static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv) |
111 | 87ecb68b | pbrook | { |
112 | 87ecb68b | pbrook | qemu_put_byte(f, *pv); |
113 | 87ecb68b | pbrook | } |
114 | 87ecb68b | pbrook | |
115 | 87ecb68b | pbrook | static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv) |
116 | 87ecb68b | pbrook | { |
117 | 87ecb68b | pbrook | *pv = qemu_get_be64(f); |
118 | 87ecb68b | pbrook | } |
119 | 87ecb68b | pbrook | |
120 | 87ecb68b | pbrook | static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv) |
121 | 87ecb68b | pbrook | { |
122 | 87ecb68b | pbrook | *pv = qemu_get_be32(f); |
123 | 87ecb68b | pbrook | } |
124 | 87ecb68b | pbrook | |
125 | 87ecb68b | pbrook | static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv) |
126 | 87ecb68b | pbrook | { |
127 | 87ecb68b | pbrook | *pv = qemu_get_be16(f); |
128 | 87ecb68b | pbrook | } |
129 | 87ecb68b | pbrook | |
130 | 87ecb68b | pbrook | static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv) |
131 | 87ecb68b | pbrook | { |
132 | 87ecb68b | pbrook | *pv = qemu_get_byte(f); |
133 | 87ecb68b | pbrook | } |
134 | 87ecb68b | pbrook | |
135 | b6c4f71f | blueswir1 | // Signed versions for type safety
|
136 | b6c4f71f | blueswir1 | static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, int size) |
137 | b6c4f71f | blueswir1 | { |
138 | b6c4f71f | blueswir1 | qemu_put_buffer(f, (const uint8_t *)buf, size);
|
139 | b6c4f71f | blueswir1 | } |
140 | b6c4f71f | blueswir1 | |
141 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe16(QEMUFile *f, int v) |
142 | b6c4f71f | blueswir1 | { |
143 | b6c4f71f | blueswir1 | qemu_put_be16(f, (unsigned int)v); |
144 | b6c4f71f | blueswir1 | } |
145 | b6c4f71f | blueswir1 | |
146 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe32(QEMUFile *f, int v) |
147 | b6c4f71f | blueswir1 | { |
148 | b6c4f71f | blueswir1 | qemu_put_be32(f, (unsigned int)v); |
149 | b6c4f71f | blueswir1 | } |
150 | b6c4f71f | blueswir1 | |
151 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe64(QEMUFile *f, int64_t v) |
152 | b6c4f71f | blueswir1 | { |
153 | b6c4f71f | blueswir1 | qemu_put_be64(f, (uint64_t)v); |
154 | b6c4f71f | blueswir1 | } |
155 | b6c4f71f | blueswir1 | |
156 | b6c4f71f | blueswir1 | static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, int size) |
157 | b6c4f71f | blueswir1 | { |
158 | b6c4f71f | blueswir1 | return qemu_get_buffer(f, (uint8_t *)buf, size);
|
159 | b6c4f71f | blueswir1 | } |
160 | b6c4f71f | blueswir1 | |
161 | b6c4f71f | blueswir1 | static inline int qemu_get_sbe16(QEMUFile *f) |
162 | b6c4f71f | blueswir1 | { |
163 | b6c4f71f | blueswir1 | return (int)qemu_get_be16(f); |
164 | b6c4f71f | blueswir1 | } |
165 | b6c4f71f | blueswir1 | |
166 | b6c4f71f | blueswir1 | static inline int qemu_get_sbe32(QEMUFile *f) |
167 | b6c4f71f | blueswir1 | { |
168 | b6c4f71f | blueswir1 | return (int)qemu_get_be32(f); |
169 | b6c4f71f | blueswir1 | } |
170 | b6c4f71f | blueswir1 | |
171 | b6c4f71f | blueswir1 | static inline int64_t qemu_get_sbe64(QEMUFile *f) |
172 | b6c4f71f | blueswir1 | { |
173 | b6c4f71f | blueswir1 | return (int64_t)qemu_get_be64(f);
|
174 | b6c4f71f | blueswir1 | } |
175 | b6c4f71f | blueswir1 | |
176 | b6c4f71f | blueswir1 | static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv) |
177 | b6c4f71f | blueswir1 | { |
178 | b6c4f71f | blueswir1 | qemu_put_8s(f, (const uint8_t *)pv);
|
179 | b6c4f71f | blueswir1 | } |
180 | b6c4f71f | blueswir1 | |
181 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv) |
182 | b6c4f71f | blueswir1 | { |
183 | b6c4f71f | blueswir1 | qemu_put_be16s(f, (const uint16_t *)pv);
|
184 | b6c4f71f | blueswir1 | } |
185 | b6c4f71f | blueswir1 | |
186 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv) |
187 | b6c4f71f | blueswir1 | { |
188 | b6c4f71f | blueswir1 | qemu_put_be32s(f, (const uint32_t *)pv);
|
189 | b6c4f71f | blueswir1 | } |
190 | b6c4f71f | blueswir1 | |
191 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv) |
192 | b6c4f71f | blueswir1 | { |
193 | b6c4f71f | blueswir1 | qemu_put_be64s(f, (const uint64_t *)pv);
|
194 | b6c4f71f | blueswir1 | } |
195 | b6c4f71f | blueswir1 | |
196 | b6c4f71f | blueswir1 | static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv) |
197 | b6c4f71f | blueswir1 | { |
198 | b6c4f71f | blueswir1 | qemu_get_8s(f, (uint8_t *)pv); |
199 | b6c4f71f | blueswir1 | } |
200 | b6c4f71f | blueswir1 | |
201 | b6c4f71f | blueswir1 | static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv) |
202 | b6c4f71f | blueswir1 | { |
203 | b6c4f71f | blueswir1 | qemu_get_be16s(f, (uint16_t *)pv); |
204 | b6c4f71f | blueswir1 | } |
205 | b6c4f71f | blueswir1 | |
206 | b6c4f71f | blueswir1 | static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv) |
207 | b6c4f71f | blueswir1 | { |
208 | b6c4f71f | blueswir1 | qemu_get_be32s(f, (uint32_t *)pv); |
209 | b6c4f71f | blueswir1 | } |
210 | b6c4f71f | blueswir1 | |
211 | b6c4f71f | blueswir1 | static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv) |
212 | b6c4f71f | blueswir1 | { |
213 | b6c4f71f | blueswir1 | qemu_get_be64s(f, (uint64_t *)pv); |
214 | b6c4f71f | blueswir1 | } |
215 | b6c4f71f | blueswir1 | |
216 | 87ecb68b | pbrook | #ifdef NEED_CPU_H
|
217 | 87ecb68b | pbrook | #if TARGET_LONG_BITS == 64 |
218 | 87ecb68b | pbrook | #define qemu_put_betl qemu_put_be64
|
219 | 87ecb68b | pbrook | #define qemu_get_betl qemu_get_be64
|
220 | 87ecb68b | pbrook | #define qemu_put_betls qemu_put_be64s
|
221 | 87ecb68b | pbrook | #define qemu_get_betls qemu_get_be64s
|
222 | b6c4f71f | blueswir1 | #define qemu_put_sbetl qemu_put_sbe64
|
223 | b6c4f71f | blueswir1 | #define qemu_get_sbetl qemu_get_sbe64
|
224 | b6c4f71f | blueswir1 | #define qemu_put_sbetls qemu_put_sbe64s
|
225 | b6c4f71f | blueswir1 | #define qemu_get_sbetls qemu_get_sbe64s
|
226 | 87ecb68b | pbrook | #else
|
227 | 87ecb68b | pbrook | #define qemu_put_betl qemu_put_be32
|
228 | 87ecb68b | pbrook | #define qemu_get_betl qemu_get_be32
|
229 | 87ecb68b | pbrook | #define qemu_put_betls qemu_put_be32s
|
230 | 87ecb68b | pbrook | #define qemu_get_betls qemu_get_be32s
|
231 | b6c4f71f | blueswir1 | #define qemu_put_sbetl qemu_put_sbe32
|
232 | b6c4f71f | blueswir1 | #define qemu_get_sbetl qemu_get_sbe32
|
233 | b6c4f71f | blueswir1 | #define qemu_put_sbetls qemu_put_sbe32s
|
234 | b6c4f71f | blueswir1 | #define qemu_get_sbetls qemu_get_sbe32s
|
235 | 87ecb68b | pbrook | #endif
|
236 | 87ecb68b | pbrook | #endif
|
237 | 87ecb68b | pbrook | |
238 | 87ecb68b | pbrook | int64_t qemu_ftell(QEMUFile *f); |
239 | 87ecb68b | pbrook | int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
|
240 | 87ecb68b | pbrook | |
241 | 87ecb68b | pbrook | typedef void SaveStateHandler(QEMUFile *f, void *opaque); |
242 | 9366f418 | aliguori | typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque); |
243 | 87ecb68b | pbrook | typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); |
244 | 87ecb68b | pbrook | |
245 | 87ecb68b | pbrook | int register_savevm(const char *idstr, |
246 | 87ecb68b | pbrook | int instance_id,
|
247 | 87ecb68b | pbrook | int version_id,
|
248 | 87ecb68b | pbrook | SaveStateHandler *save_state, |
249 | 87ecb68b | pbrook | LoadStateHandler *load_state, |
250 | 87ecb68b | pbrook | void *opaque);
|
251 | 87ecb68b | pbrook | |
252 | 9366f418 | aliguori | int register_savevm_live(const char *idstr, |
253 | 9366f418 | aliguori | int instance_id,
|
254 | 9366f418 | aliguori | int version_id,
|
255 | 9366f418 | aliguori | SaveLiveStateHandler *save_live_state, |
256 | 9366f418 | aliguori | SaveStateHandler *save_state, |
257 | 9366f418 | aliguori | LoadStateHandler *load_state, |
258 | 9366f418 | aliguori | void *opaque);
|
259 | 9366f418 | aliguori | |
260 | 41bd13af | aliguori | void unregister_savevm(const char *idstr, void *opaque); |
261 | 41bd13af | aliguori | |
262 | 87ecb68b | pbrook | typedef void QEMUResetHandler(void *opaque); |
263 | 87ecb68b | pbrook | |
264 | a08d4367 | Jan Kiszka | void qemu_register_reset(QEMUResetHandler *func, void *opaque); |
265 | dda9b29f | Jan Kiszka | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque); |
266 | 87ecb68b | pbrook | |
267 | 76e30d0f | Jan Kiszka | /* handler to set the boot_device order for a specific type of QEMUMachine */
|
268 | 0ecdffbb | aurel32 | /* return 0 if success */
|
269 | 76e30d0f | Jan Kiszka | typedef int QEMUBootSetHandler(void *opaque, const char *boot_devices); |
270 | 3b4366de | blueswir1 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque); |
271 | 76e30d0f | Jan Kiszka | int qemu_boot_set(const char *boot_devices); |
272 | 0ecdffbb | aurel32 | |
273 | 9ed7d6ae | Juan Quintela | typedef struct VMStateInfo VMStateInfo; |
274 | 9ed7d6ae | Juan Quintela | typedef struct VMStateDescription VMStateDescription; |
275 | 9ed7d6ae | Juan Quintela | |
276 | 9ed7d6ae | Juan Quintela | struct VMStateInfo {
|
277 | 9ed7d6ae | Juan Quintela | const char *name; |
278 | 9ed7d6ae | Juan Quintela | int (*get)(QEMUFile *f, void *pv, size_t size); |
279 | 9ed7d6ae | Juan Quintela | void (*put)(QEMUFile *f, const void *pv, size_t size); |
280 | 9ed7d6ae | Juan Quintela | }; |
281 | 9ed7d6ae | Juan Quintela | |
282 | 9ed7d6ae | Juan Quintela | enum VMStateFlags {
|
283 | 9ed7d6ae | Juan Quintela | VMS_SINGLE = 0x001,
|
284 | dde0463b | Juan Quintela | VMS_POINTER = 0x002,
|
285 | f752a6aa | Juan Quintela | VMS_ARRAY = 0x004,
|
286 | ec245e21 | Juan Quintela | VMS_STRUCT = 0x008,
|
287 | b00319a9 | Juan Quintela | VMS_VARRAY = 0x010, /* Array with size in another field */ |
288 | 6f67c50f | Juan Quintela | VMS_BUFFER = 0x020, /* static sized buffer */ |
289 | 9ed7d6ae | Juan Quintela | }; |
290 | 9ed7d6ae | Juan Quintela | |
291 | 9ed7d6ae | Juan Quintela | typedef struct { |
292 | 9ed7d6ae | Juan Quintela | const char *name; |
293 | 9ed7d6ae | Juan Quintela | size_t offset; |
294 | 9ed7d6ae | Juan Quintela | size_t size; |
295 | f752a6aa | Juan Quintela | int num;
|
296 | b00319a9 | Juan Quintela | size_t num_offset; |
297 | 9ed7d6ae | Juan Quintela | const VMStateInfo *info;
|
298 | 9ed7d6ae | Juan Quintela | enum VMStateFlags flags;
|
299 | ec245e21 | Juan Quintela | const VMStateDescription *vmsd;
|
300 | 9ed7d6ae | Juan Quintela | int version_id;
|
301 | 9ed7d6ae | Juan Quintela | } VMStateField; |
302 | 9ed7d6ae | Juan Quintela | |
303 | 9ed7d6ae | Juan Quintela | struct VMStateDescription {
|
304 | 9ed7d6ae | Juan Quintela | const char *name; |
305 | 9ed7d6ae | Juan Quintela | int version_id;
|
306 | 9ed7d6ae | Juan Quintela | int minimum_version_id;
|
307 | 9ed7d6ae | Juan Quintela | int minimum_version_id_old;
|
308 | 9ed7d6ae | Juan Quintela | LoadStateHandler *load_state_old; |
309 | cff09e92 | Juan Quintela | int (*run_after_load)(void *opaque); |
310 | 9ed7d6ae | Juan Quintela | VMStateField *fields; |
311 | 9ed7d6ae | Juan Quintela | }; |
312 | 9ed7d6ae | Juan Quintela | |
313 | 9ed7d6ae | Juan Quintela | extern const VMStateInfo vmstate_info_int8; |
314 | 9ed7d6ae | Juan Quintela | extern const VMStateInfo vmstate_info_int16; |
315 | 9ed7d6ae | Juan Quintela | extern const VMStateInfo vmstate_info_int32; |
316 | 9ed7d6ae | Juan Quintela | extern const VMStateInfo vmstate_info_int64; |
317 | 9ed7d6ae | Juan Quintela | |
318 | 82501660 | Juan Quintela | extern const VMStateInfo vmstate_info_int32_equal; |
319 | 0a031e0a | Juan Quintela | extern const VMStateInfo vmstate_info_int32_le; |
320 | 82501660 | Juan Quintela | |
321 | 9ed7d6ae | Juan Quintela | extern const VMStateInfo vmstate_info_uint8; |
322 | 9ed7d6ae | Juan Quintela | extern const VMStateInfo vmstate_info_uint16; |
323 | 9ed7d6ae | Juan Quintela | extern const VMStateInfo vmstate_info_uint32; |
324 | 9ed7d6ae | Juan Quintela | extern const VMStateInfo vmstate_info_uint64; |
325 | 9ed7d6ae | Juan Quintela | |
326 | dde0463b | Juan Quintela | extern const VMStateInfo vmstate_info_timer; |
327 | 6f67c50f | Juan Quintela | extern const VMStateInfo vmstate_info_buffer; |
328 | dde0463b | Juan Quintela | |
329 | f752a6aa | Juan Quintela | #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) |
330 | b00319a9 | Juan Quintela | #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) |
331 | f752a6aa | Juan Quintela | |
332 | 9ed7d6ae | Juan Quintela | #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \
|
333 | 9ed7d6ae | Juan Quintela | .name = (stringify(_field)), \ |
334 | 9ed7d6ae | Juan Quintela | .version_id = (_version), \ |
335 | 9ed7d6ae | Juan Quintela | .size = sizeof(_type), \
|
336 | 9ed7d6ae | Juan Quintela | .info = &(_info), \ |
337 | 9ed7d6ae | Juan Quintela | .flags = VMS_SINGLE, \ |
338 | 9ed7d6ae | Juan Quintela | .offset = offsetof(_state, _field) \ |
339 | 9ed7d6ae | Juan Quintela | + type_check(_type,typeof_field(_state, _field)) \ |
340 | 9ed7d6ae | Juan Quintela | } |
341 | 9ed7d6ae | Juan Quintela | |
342 | dde0463b | Juan Quintela | #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
|
343 | dde0463b | Juan Quintela | .name = (stringify(_field)), \ |
344 | dde0463b | Juan Quintela | .version_id = (_version), \ |
345 | dde0463b | Juan Quintela | .info = &(_info), \ |
346 | dde0463b | Juan Quintela | .size = sizeof(_type), \
|
347 | dde0463b | Juan Quintela | .flags = VMS_SINGLE|VMS_POINTER, \ |
348 | dde0463b | Juan Quintela | .offset = offsetof(_state, _field) \ |
349 | dde0463b | Juan Quintela | + type_check(_type,typeof_field(_state, _field)) \ |
350 | dde0463b | Juan Quintela | } |
351 | dde0463b | Juan Quintela | |
352 | f752a6aa | Juan Quintela | #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
|
353 | f752a6aa | Juan Quintela | .name = (stringify(_field)), \ |
354 | f752a6aa | Juan Quintela | .version_id = (_version), \ |
355 | f752a6aa | Juan Quintela | .num = (_num), \ |
356 | f752a6aa | Juan Quintela | .info = &(_info), \ |
357 | f752a6aa | Juan Quintela | .size = sizeof(_type), \
|
358 | f752a6aa | Juan Quintela | .flags = VMS_ARRAY, \ |
359 | f752a6aa | Juan Quintela | .offset = offsetof(_state, _field) \ |
360 | f752a6aa | Juan Quintela | + type_check_array(_type,typeof_field(_state, _field),_num) \ |
361 | f752a6aa | Juan Quintela | } |
362 | f752a6aa | Juan Quintela | |
363 | b00319a9 | Juan Quintela | #define VMSTATE_VARRAY(_field, _state, _field_num, _version, _info, _type) {\
|
364 | b00319a9 | Juan Quintela | .name = (stringify(_field)), \ |
365 | b00319a9 | Juan Quintela | .version_id = (_version), \ |
366 | b00319a9 | Juan Quintela | .num_offset = offsetof(_state, _field_num) \ |
367 | b00319a9 | Juan Quintela | + type_check(int32_t,typeof_field(_state, _field_num)), \ |
368 | b00319a9 | Juan Quintela | .info = &(_info), \ |
369 | b00319a9 | Juan Quintela | .size = sizeof(_type), \
|
370 | b00319a9 | Juan Quintela | .flags = VMS_VARRAY|VMS_POINTER, \ |
371 | b00319a9 | Juan Quintela | .offset = offsetof(_state, _field) \ |
372 | b00319a9 | Juan Quintela | + type_check_pointer(_type,typeof_field(_state, _field)) \ |
373 | b00319a9 | Juan Quintela | } |
374 | b00319a9 | Juan Quintela | |
375 | ec245e21 | Juan Quintela | #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) { \
|
376 | ec245e21 | Juan Quintela | .name = (stringify(_field)), \ |
377 | ec245e21 | Juan Quintela | .version_id = (_version), \ |
378 | ec245e21 | Juan Quintela | .vmsd = &(_vmsd), \ |
379 | ec245e21 | Juan Quintela | .size = sizeof(_type), \
|
380 | ec245e21 | Juan Quintela | .flags = VMS_STRUCT, \ |
381 | ec245e21 | Juan Quintela | .offset = offsetof(_state, _field) \ |
382 | ec245e21 | Juan Quintela | + type_check(_type,typeof_field(_state, _field)) \ |
383 | ec245e21 | Juan Quintela | } |
384 | ec245e21 | Juan Quintela | |
385 | 79c451b9 | Juan Quintela | #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) { \
|
386 | 79c451b9 | Juan Quintela | .name = (stringify(_field)), \ |
387 | 79c451b9 | Juan Quintela | .num = (_num), \ |
388 | 79c451b9 | Juan Quintela | .version_id = (_version), \ |
389 | 79c451b9 | Juan Quintela | .vmsd = &(_vmsd), \ |
390 | 79c451b9 | Juan Quintela | .size = sizeof(_type), \
|
391 | 79c451b9 | Juan Quintela | .flags = VMS_STRUCT|VMS_ARRAY, \ |
392 | 79c451b9 | Juan Quintela | .offset = offsetof(_state, _field) \ |
393 | 79c451b9 | Juan Quintela | + type_check_array(_type,typeof_field(_state, _field),_num) \ |
394 | 79c451b9 | Juan Quintela | } |
395 | 79c451b9 | Juan Quintela | |
396 | 6f67c50f | Juan Quintela | #define VMSTATE_STATIC_BUFFER(_field, _state, _version) { \
|
397 | 6f67c50f | Juan Quintela | .name = (stringify(_field)), \ |
398 | 6f67c50f | Juan Quintela | .version_id = (_version), \ |
399 | 6f67c50f | Juan Quintela | .size = sizeof(typeof_field(_state,_field)), \
|
400 | 6f67c50f | Juan Quintela | .info = &vmstate_info_buffer, \ |
401 | 6f67c50f | Juan Quintela | .flags = VMS_BUFFER, \ |
402 | 6f67c50f | Juan Quintela | .offset = offsetof(_state, _field) \ |
403 | 6f67c50f | Juan Quintela | + type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \
|
404 | 6f67c50f | Juan Quintela | } |
405 | 6f67c50f | Juan Quintela | |
406 | 73534f2f | Juan Quintela | extern const VMStateDescription vmstate_pci_device; |
407 | 73534f2f | Juan Quintela | |
408 | 73534f2f | Juan Quintela | #define VMSTATE_PCI_DEVICE(_field, _state) { \
|
409 | 73534f2f | Juan Quintela | .name = (stringify(_field)), \ |
410 | 73534f2f | Juan Quintela | .version_id = 2, \
|
411 | 73534f2f | Juan Quintela | .size = sizeof(PCIDevice), \
|
412 | 73534f2f | Juan Quintela | .vmsd = &vmstate_pci_device, \ |
413 | 73534f2f | Juan Quintela | .flags = VMS_STRUCT, \ |
414 | 73534f2f | Juan Quintela | .offset = offsetof(_state, _field) \ |
415 | 73534f2f | Juan Quintela | + type_check(PCIDevice,typeof_field(_state, _field)) \ |
416 | 73534f2f | Juan Quintela | } |
417 | 73534f2f | Juan Quintela | |
418 | 9ed7d6ae | Juan Quintela | /* _f : field name
|
419 | b00319a9 | Juan Quintela | _f_n : num of elements field_name
|
420 | f752a6aa | Juan Quintela | _n : num of elements
|
421 | 9ed7d6ae | Juan Quintela | _s : struct state name
|
422 | 9ed7d6ae | Juan Quintela | _v : version
|
423 | 9ed7d6ae | Juan Quintela | */
|
424 | 9ed7d6ae | Juan Quintela | |
425 | 9ed7d6ae | Juan Quintela | #define VMSTATE_INT8_V(_f, _s, _v) \
|
426 | 9ed7d6ae | Juan Quintela | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) |
427 | 9ed7d6ae | Juan Quintela | #define VMSTATE_INT16_V(_f, _s, _v) \
|
428 | 9ed7d6ae | Juan Quintela | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t) |
429 | 9ed7d6ae | Juan Quintela | #define VMSTATE_INT32_V(_f, _s, _v) \
|
430 | 9ed7d6ae | Juan Quintela | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t) |
431 | 9ed7d6ae | Juan Quintela | #define VMSTATE_INT64_V(_f, _s, _v) \
|
432 | 9ed7d6ae | Juan Quintela | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t) |
433 | 9ed7d6ae | Juan Quintela | |
434 | 9ed7d6ae | Juan Quintela | #define VMSTATE_UINT8_V(_f, _s, _v) \
|
435 | 9ed7d6ae | Juan Quintela | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t) |
436 | 9ed7d6ae | Juan Quintela | #define VMSTATE_UINT16_V(_f, _s, _v) \
|
437 | 9ed7d6ae | Juan Quintela | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t) |
438 | 9ed7d6ae | Juan Quintela | #define VMSTATE_UINT32_V(_f, _s, _v) \
|
439 | 9ed7d6ae | Juan Quintela | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t) |
440 | 9ed7d6ae | Juan Quintela | #define VMSTATE_UINT64_V(_f, _s, _v) \
|
441 | 9ed7d6ae | Juan Quintela | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) |
442 | 9ed7d6ae | Juan Quintela | |
443 | 9ed7d6ae | Juan Quintela | #define VMSTATE_INT8(_f, _s) \
|
444 | 9ed7d6ae | Juan Quintela | VMSTATE_INT8_V(_f, _s, 0)
|
445 | 9ed7d6ae | Juan Quintela | #define VMSTATE_INT16(_f, _s) \
|
446 | 9ed7d6ae | Juan Quintela | VMSTATE_INT16_V(_f, _s, 0)
|
447 | 9ed7d6ae | Juan Quintela | #define VMSTATE_INT32(_f, _s) \
|
448 | 9ed7d6ae | Juan Quintela | VMSTATE_INT32_V(_f, _s, 0)
|
449 | 9ed7d6ae | Juan Quintela | #define VMSTATE_INT64(_f, _s) \
|
450 | 9ed7d6ae | Juan Quintela | VMSTATE_INT64_V(_f, _s, 0)
|
451 | 9ed7d6ae | Juan Quintela | |
452 | 9ed7d6ae | Juan Quintela | #define VMSTATE_UINT8(_f, _s) \
|
453 | 9ed7d6ae | Juan Quintela | VMSTATE_UINT8_V(_f, _s, 0)
|
454 | 9ed7d6ae | Juan Quintela | #define VMSTATE_UINT16(_f, _s) \
|
455 | 9ed7d6ae | Juan Quintela | VMSTATE_UINT16_V(_f, _s, 0)
|
456 | 9ed7d6ae | Juan Quintela | #define VMSTATE_UINT32(_f, _s) \
|
457 | 9ed7d6ae | Juan Quintela | VMSTATE_UINT32_V(_f, _s, 0)
|
458 | 9ed7d6ae | Juan Quintela | #define VMSTATE_UINT64(_f, _s) \
|
459 | 9ed7d6ae | Juan Quintela | VMSTATE_UINT64_V(_f, _s, 0)
|
460 | 9ed7d6ae | Juan Quintela | |
461 | 82501660 | Juan Quintela | #define VMSTATE_INT32_EQUAL(_f, _s) \
|
462 | 82501660 | Juan Quintela | VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
|
463 | 82501660 | Juan Quintela | |
464 | 0a031e0a | Juan Quintela | #define VMSTATE_INT32_LE(_f, _s) \
|
465 | 0a031e0a | Juan Quintela | VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
|
466 | 0a031e0a | Juan Quintela | |
467 | dde0463b | Juan Quintela | #define VMSTATE_TIMER_V(_f, _s, _v) \
|
468 | dde0463b | Juan Quintela | VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) |
469 | dde0463b | Juan Quintela | |
470 | dde0463b | Juan Quintela | #define VMSTATE_TIMER(_f, _s) \
|
471 | dde0463b | Juan Quintela | VMSTATE_TIMER_V(_f, _s, 0)
|
472 | dde0463b | Juan Quintela | |
473 | f752a6aa | Juan Quintela | #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
|
474 | f752a6aa | Juan Quintela | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t) |
475 | f752a6aa | Juan Quintela | |
476 | f752a6aa | Juan Quintela | #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
|
477 | f752a6aa | Juan Quintela | VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
|
478 | f752a6aa | Juan Quintela | |
479 | f752a6aa | Juan Quintela | #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
|
480 | f752a6aa | Juan Quintela | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t) |
481 | f752a6aa | Juan Quintela | |
482 | f752a6aa | Juan Quintela | #define VMSTATE_INT32_ARRAY(_f, _s, _n) \
|
483 | f752a6aa | Juan Quintela | VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
|
484 | f752a6aa | Juan Quintela | |
485 | b00319a9 | Juan Quintela | #define VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, _v) \
|
486 | b00319a9 | Juan Quintela | VMSTATE_VARRAY(_f, _s, _f_n, _v, vmstate_info_int32, int32_t) |
487 | b00319a9 | Juan Quintela | |
488 | b00319a9 | Juan Quintela | #define VMSTATE_INT32_VARRAY(_f, _s, _f_n) \
|
489 | b00319a9 | Juan Quintela | VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, 0)
|
490 | b00319a9 | Juan Quintela | |
491 | 6f67c50f | Juan Quintela | #define VMSTATE_BUFFER_V(_f, _s, _v) \
|
492 | 6f67c50f | Juan Quintela | VMSTATE_STATIC_BUFFER(_f, _s, _v) |
493 | 6f67c50f | Juan Quintela | |
494 | 6f67c50f | Juan Quintela | #define VMSTATE_BUFFER(_f, _s) \
|
495 | 6f67c50f | Juan Quintela | VMSTATE_STATIC_BUFFER(_f, _s, 0)
|
496 | 6f67c50f | Juan Quintela | |
497 | 9ed7d6ae | Juan Quintela | #define VMSTATE_END_OF_LIST() \
|
498 | 9ed7d6ae | Juan Quintela | {} |
499 | 9ed7d6ae | Juan Quintela | |
500 | 9ed7d6ae | Juan Quintela | extern int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, |
501 | 9ed7d6ae | Juan Quintela | void *opaque, int version_id); |
502 | 9ed7d6ae | Juan Quintela | extern void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, |
503 | 9ed7d6ae | Juan Quintela | const void *opaque); |
504 | 9ed7d6ae | Juan Quintela | extern int vmstate_register(int instance_id, const VMStateDescription *vmsd, |
505 | 9ed7d6ae | Juan Quintela | void *base);
|
506 | 9ed7d6ae | Juan Quintela | extern void vmstate_unregister(const char *idstr, void *opaque); |
507 | 87ecb68b | pbrook | #endif |