• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _QEMU_FILE_H
2 #define _QEMU_FILE_H
3 
4 #include "hw/hw.h"
5 
6 typedef enum {
7     Q_FIELD_END,          /* mark end of field list */
8     Q_FIELD_BYTE,         /* for 1-byte fields */
9     Q_FIELD_INT16,        /* for 2-byte fields */
10     Q_FIELD_INT32,        /* for 4-byte fields */
11     Q_FIELD_INT64,        /* for 8-byte fields */
12     Q_FIELD_BUFFER,       /* for buffer fields */
13     Q_FIELD_BUFFER_SIZE,  /* to specify the size of buffers */
14 
15 #if TARGET_LONG_BITS == 64
16     Q_FIELD_TL = Q_FIELD_INT64,           /* target long, either 4 or 8 bytes */
17 #else
18     Q_FIELD_TL = Q_FIELD_INT32
19 #endif
20 
21 } QFieldType;
22 
23 typedef struct {
24     QFieldType  type : 16; /* field type */
25     uint16_t    offset;    /* offset of field in structure */
26 } QField;
27 
28 #define  QFIELD_BEGIN(name)  \
29     static const QField    name[] = {
30 
31 #define  _QFIELD_(t, f)    { t, offsetof(QFIELD_STRUCT,f) }
32 #define  QFIELD_BYTE(f)   _QFIELD_(Q_FIELD_BYTE, f)
33 #define  QFIELD_INT16(f)  _QFIELD_(Q_FIELD_INT16, f)
34 #define  QFIELD_INT32(f)  _QFIELD_(Q_FIELD_INT32, f)
35 #define  QFIELD_INT64(f)  _QFIELD_(Q_FIELD_INT64, f)
36 #define  QFIELD_TL(f)     _QFIELD_(Q_FIELD_TL, f)
37 
38 #define  _QFIELD_SIZEOF(f)   sizeof(((QFIELD_STRUCT*)0)->f)
39 
40 #define  QFIELD_BUFFER(f)  \
41     _QFIELD_(Q_FIELD_BUFFER, f), \
42     { Q_FIELD_BUFFER_SIZE, (uint16_t)(_QFIELD_SIZEOF(f) >> 16) }, \
43     { Q_FIELD_BUFFER_SIZE, (uint16_t) _QFIELD_SIZEOF(f) }
44 
45 #define  QFIELD_END           \
46         { Q_FIELD_END, 0 },   \
47     };
48 
49 extern void  qemu_put_struct(QEMUFile*  f, const QField*  fields, const void*  s);
50 extern int   qemu_get_struct(QEMUFile*  f, const QField*  fields, void*  s);
51 
52 #endif /* _QEMU_FILE_H */
53