1 /*
2 * hvm/save.h
3 *
4 * Structure definitions for HVM state that is held by Xen and must
5 * be saved along with the domain's memory and device-model state.
6 *
7 * Copyright (c) 2007 XenSource Ltd.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to
11 * deal in the Software without restriction, including without limitation the
12 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 * sell copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 */
27
28 #ifndef __XEN_PUBLIC_HVM_SAVE_H__
29 #define __XEN_PUBLIC_HVM_SAVE_H__
30
31 /*
32 * Structures in this header *must* have the same layout in 32bit
33 * and 64bit environments: this means that all fields must be explicitly
34 * sized types and aligned to their sizes, and the structs must be
35 * a multiple of eight bytes long.
36 *
37 * Only the state necessary for saving and restoring (i.e. fields
38 * that are analogous to actual hardware state) should go in this file.
39 * Internal mechanisms should be kept in Xen-private headers.
40 */
41
42 #if !defined(__GNUC__) || defined(__STRICT_ANSI__)
43 #error "Anonymous structs/unions are a GNU extension."
44 #endif
45
46 /*
47 * Each entry is preceded by a descriptor giving its type and length
48 */
49 struct hvm_save_descriptor {
50 uint16_t typecode; /* Used to demux the various types below */
51 uint16_t instance; /* Further demux within a type */
52 uint32_t length; /* In bytes, *not* including this descriptor */
53 };
54
55
56 /*
57 * Each entry has a datatype associated with it: for example, the CPU state
58 * is saved as a HVM_SAVE_TYPE(CPU), which has HVM_SAVE_LENGTH(CPU),
59 * and is identified by a descriptor with typecode HVM_SAVE_CODE(CPU).
60 * DECLARE_HVM_SAVE_TYPE binds these things together with some type-system
61 * ugliness.
62 */
63
64 #ifdef __XEN__
65 # define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix) \
66 static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h) { return _fix(h); } \
67 struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];}; \
68 struct __HVM_SAVE_TYPE_COMPAT_##_x { _ctype t; }
69
70 # include <xen/lib.h> /* BUG() */
71 # define DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \
72 static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h) { BUG(); return -1; } \
73 struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}; \
74 struct __HVM_SAVE_TYPE_COMPAT_##_x { _type t; }
75 #else
76 # define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix) \
77 struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];}
78
79 # define DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \
80 struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}
81 #endif
82
83 #define HVM_SAVE_TYPE(_x) typeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->t)
84 #define HVM_SAVE_LENGTH(_x) (sizeof (HVM_SAVE_TYPE(_x)))
85 #define HVM_SAVE_CODE(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->c))
86
87 #ifdef __XEN__
88 # define HVM_SAVE_TYPE_COMPAT(_x) typeof (((struct __HVM_SAVE_TYPE_COMPAT_##_x *)(0))->t)
89 # define HVM_SAVE_LENGTH_COMPAT(_x) (sizeof (HVM_SAVE_TYPE_COMPAT(_x)))
90
91 # define HVM_SAVE_HAS_COMPAT(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->cpt)-1)
92 # define HVM_SAVE_FIX_COMPAT(_x, _dst) __HVM_SAVE_FIX_COMPAT_##_x(_dst)
93 #endif
94
95 /*
96 * The series of save records is teminated by a zero-type, zero-length
97 * descriptor.
98 */
99
100 struct hvm_save_end {};
101 DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);
102
103 #if defined(__i386__) || defined(__x86_64__)
104 #include "../arch-x86/hvm/save.h"
105 #elif defined(__ia64__)
106 #include "../arch-ia64/hvm/save.h"
107 #elif defined(__arm__)
108 #include "../arch-arm/hvm/save.h"
109 #else
110 #error "unsupported architecture"
111 #endif
112
113 #endif /* __XEN_PUBLIC_HVM_SAVE_H__ */
Cache object: a34590e4f45b66b126d26dc11c493009
|