|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2/6] tools/libxc: Stream specification and some common code
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
tools/libxc/saverestore/common.c | 59 ++++++++++++++
tools/libxc/saverestore/common.h | 8 ++
tools/libxc/saverestore/stream_format.h | 130 +++++++++++++++++++++++++++++++
3 files changed, 197 insertions(+)
create mode 100644 tools/libxc/saverestore/common.c
create mode 100644 tools/libxc/saverestore/stream_format.h
diff --git a/tools/libxc/saverestore/common.c b/tools/libxc/saverestore/common.c
new file mode 100644
index 0000000..d2dfd5a
--- /dev/null
+++ b/tools/libxc/saverestore/common.c
@@ -0,0 +1,59 @@
+#include "common.h"
+
+static const char *dhdr_types[] =
+{
+ [DHDR_TYPE_x86_pv] = "x86 PV",
+ [DHDR_TYPE_x86_hvm] = "x86 HVM",
+ [DHDR_TYPE_x86_pvh] = "x86 PVH",
+ [DHDR_TYPE_arm] = "ARM",
+};
+
+const char *dhdr_type_to_str(uint32_t type)
+{
+ if ( type < ARRAY_SIZE(dhdr_types) && dhdr_types[type] )
+ return dhdr_types[type];
+
+ return "Reserved";
+}
+
+static const char *mandatory_rec_types[] =
+{
+ [REC_TYPE_end] = "End",
+ [REC_TYPE_page_data] = "Page data",
+ [REC_TYPE_x86_pv_info] = "x86 PV info",
+ [REC_TYPE_x86_pv_p2m_frames] = "x86 PV P2M frames",
+ [REC_TYPE_x86_pv_vcpu_basic] = "x86 PV vcpu basic",
+ [REC_TYPE_x86_pv_vcpu_extended] = "x86 PV vcpu extended",
+ [REC_TYPE_x86_pv_vcpu_xsave] = "x86 PV vcpu xsave",
+ [REC_TYPE_x86_pv_shared_info] = "x86 PV shared info",
+ [REC_TYPE_tsc_info] = "TSC info",
+};
+
+/*
+static const char *optional_rec_types[] =
+{
+};
+*/
+
+const char *rec_type_to_str(uint32_t type)
+{
+ if ( type & REC_TYPE_optional )
+ return "Reserved";
+
+ if ( ((type & REC_TYPE_optional) == 0 ) &&
+ (type < ARRAY_SIZE(mandatory_rec_types)) &&
+ (mandatory_rec_types[type]) )
+ return mandatory_rec_types[type];
+
+ return "Reserved";
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/saverestore/common.h b/tools/libxc/saverestore/common.h
index f1aff44..fff0a39 100644
--- a/tools/libxc/saverestore/common.h
+++ b/tools/libxc/saverestore/common.h
@@ -3,6 +3,14 @@
#include "../xg_private.h"
+#include "stream_format.h"
+
+// TODO: Find a better place to put this...
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+const char *dhdr_type_to_str(uint32_t type);
+const char *rec_type_to_str(uint32_t type);
+
#endif
/*
* Local variables:
diff --git a/tools/libxc/saverestore/stream_format.h
b/tools/libxc/saverestore/stream_format.h
new file mode 100644
index 0000000..6898c3c
--- /dev/null
+++ b/tools/libxc/saverestore/stream_format.h
@@ -0,0 +1,130 @@
+#ifndef __STREAM_FORMAT__H
+#define __STREAM_FORMAT__H
+
+#include <inttypes.h>
+
+/*
+ * Image Header
+ */
+struct ihdr
+{
+ uint64_t marker;
+ uint32_t id;
+ uint32_t version;
+ uint16_t options;
+ uint16_t _res1;
+ uint32_t _res2;
+};
+
+#define IHDR_MARKER 0xffffffffffffffffULL
+#define IHDR_ID 0x58454E46U
+#define IHDR_VERSION 1
+
+#define _IHDR_OPT_ENDIAN 0
+#define IHDR_OPT_LITTLE_ENDIAN (0 << _IHDR_OPT_ENDIAN)
+#define IHDR_OPT_BIG_ENDIAN (1 << _IHDR_OPT_ENDIAN)
+
+/*
+ * Domain Header
+ */
+struct dhdr
+{
+ uint32_t type;
+ uint16_t page_shift;
+ uint16_t _res1;
+ uint32_t xen_major;
+ uint32_t xen_minor;
+};
+
+#define DHDR_TYPE_x86_pv 0x00000001U
+#define DHDR_TYPE_x86_hvm 0x00000002U
+#define DHDR_TYPE_x86_pvh 0x00000003U
+#define DHDR_TYPE_arm 0x00000004U
+
+/*
+ * Record Header
+ */
+struct rhdr
+{
+ uint32_t type;
+ uint32_t length;
+};
+
+/* Somewhat arbitrary - 8MB */
+#define REC_LENGTH_MAX (8U << 20)
+
+#define REC_TYPE_end 0x00000000U
+#define REC_TYPE_page_data 0x00000001U
+#define REC_TYPE_x86_pv_info 0x00000002U
+#define REC_TYPE_x86_pv_p2m_frames 0x00000003U
+#define REC_TYPE_x86_pv_vcpu_basic 0x00000004U
+#define REC_TYPE_x86_pv_vcpu_extended 0x00000005U
+#define REC_TYPE_x86_pv_vcpu_xsave 0x00000006U
+#define REC_TYPE_x86_pv_shared_info 0x00000007U
+#define REC_TYPE_tsc_info 0x00000008U
+
+#define REC_TYPE_optional 0x80000000U
+
+/* PAGE_DATA */
+struct rec_page_data_header
+{
+ uint32_t count;
+ uint32_t _res1;
+ uint64_t pfn[0];
+};
+
+#define PAGE_DATA_PFN_MASK 0x000fffffffffffffULL
+#define PAGE_DATA_TYPE_MASK 0xf000000000000000ULL
+
+/* X86_PV_INFO */
+struct rec_x86_pv_info
+{
+ uint8_t guest_width;
+ uint8_t pt_levels;
+ uint8_t options;
+};
+
+/* X86_PV_P2M_FRAMES */
+struct rec_x86_pv_p2m_frames
+{
+ uint32_t start_pfn;
+ uint32_t end_pfn;
+ uint64_t p2m_pfns[0];
+};
+
+/* VCPU_CONTEXT_{basic,extended} */
+struct rec_x86_pv_vcpu
+{
+ uint32_t vcpu_id;
+ uint32_t _res1;
+ uint8_t context[0];
+};
+
+/* VCPU_CONTEXT_XSAVE */
+struct rec_x86_pv_vcpu_xsave
+{
+ uint32_t vcpu_id;
+ uint32_t _res1;
+ uint64_t xfeature_mask;
+ uint8_t context[0];
+};
+
+/* TSC_INFO */
+struct rec_tsc_info
+{
+ uint32_t mode;
+ uint32_t khz;
+ uint64_t nsec;
+ uint32_t incarnation;
+};
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
1.7.10.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |