/*1* hvm/save.h2*3* Structure definitions for HVM state that is held by Xen and must4* be saved along with the domain's memory and device-model state.5*6* Copyright (c) 2007 XenSource Ltd.7*8* Permission is hereby granted, free of charge, to any person obtaining a copy9* of this software and associated documentation files (the "Software"), to10* deal in the Software without restriction, including without limitation the11* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or12* sell copies of the Software, and to permit persons to whom the Software is13* furnished to do so, subject to the following conditions:14*15* The above copyright notice and this permission notice shall be included in16* all copies or substantial portions of the Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR19* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,20* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE21* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER22* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING23* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER24* DEALINGS IN THE SOFTWARE.25*/2627#ifndef __XEN_PUBLIC_HVM_SAVE_H__28#define __XEN_PUBLIC_HVM_SAVE_H__2930/*31* Structures in this header *must* have the same layout in 32bit32* and 64bit environments: this means that all fields must be explicitly33* sized types and aligned to their sizes, and the structs must be34* a multiple of eight bytes long.35*36* Only the state necessary for saving and restoring (i.e. fields37* that are analogous to actual hardware state) should go in this file.38* Internal mechanisms should be kept in Xen-private headers.39*/4041#if !defined(__GNUC__) || defined(__STRICT_ANSI__)42#error "Anonymous structs/unions are a GNU extension."43#endif4445/*46* Each entry is preceded by a descriptor giving its type and length47*/48struct hvm_save_descriptor {49uint16_t typecode; /* Used to demux the various types below */50uint16_t instance; /* Further demux within a type */51uint32_t length; /* In bytes, *not* including this descriptor */52};535455/*56* Each entry has a datatype associated with it: for example, the CPU state57* is saved as a HVM_SAVE_TYPE(CPU), which has HVM_SAVE_LENGTH(CPU),58* and is identified by a descriptor with typecode HVM_SAVE_CODE(CPU).59* DECLARE_HVM_SAVE_TYPE binds these things together with some type-system60* ugliness.61*/6263#ifdef __XEN__64# define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix) \65static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h, uint32_t size) \66{ return _fix(h, size); } \67struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];}; \68struct __HVM_SAVE_TYPE_COMPAT_##_x { _ctype t; }6970# include <xen/lib.h> /* BUG() */71# define DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \72static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h, uint32_t size) \73{ BUG(); return -1; } \74struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}; \75struct __HVM_SAVE_TYPE_COMPAT_##_x { _type t; }76#else77# define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix) \78struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];}7980# define DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \81struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}82#endif8384#define HVM_SAVE_TYPE(_x) __typeof__ (((struct __HVM_SAVE_TYPE_##_x *)(0))->t)85#define HVM_SAVE_LENGTH(_x) (sizeof (HVM_SAVE_TYPE(_x)))86#define HVM_SAVE_CODE(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->c))8788#ifdef __XEN__89# define HVM_SAVE_TYPE_COMPAT(_x) __typeof__ (((struct __HVM_SAVE_TYPE_COMPAT_##_x *)(0))->t)90# define HVM_SAVE_LENGTH_COMPAT(_x) (sizeof (HVM_SAVE_TYPE_COMPAT(_x)))9192# define HVM_SAVE_HAS_COMPAT(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->cpt)-1)93# define HVM_SAVE_FIX_COMPAT(_x, _dst, _size) __HVM_SAVE_FIX_COMPAT_##_x(_dst, _size)94#endif9596/*97* The series of save records is teminated by a zero-type, zero-length98* descriptor.99*/100101struct hvm_save_end {};102DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);103104#if defined(__i386__) || defined(__x86_64__)105#include "../arch-x86/hvm/save.h"106#elif defined(__arm__) || defined(__aarch64__)107#include "../arch-arm/hvm/save.h"108#else109#error "unsupported architecture"110#endif111112#endif /* __XEN_PUBLIC_HVM_SAVE_H__ */113114115