1 /*
2  * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
3  *                    VA Linux Systems Japan K.K.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #ifndef XC_CORE_H
21 #define XC_CORE_H
22 
23 #include "xen/version.h"
24 #include "xg_private.h"
25 #include "xen/libelf/elfstructs.h"
26 
27 /* section names */
28 #define XEN_DUMPCORE_SEC_NOTE                   ".note.Xen"
29 #define XEN_DUMPCORE_SEC_PRSTATUS               ".xen_prstatus"
30 #define XEN_DUMPCORE_SEC_SHARED_INFO            ".xen_shared_info"
31 #define XEN_DUMPCORE_SEC_P2M                    ".xen_p2m"
32 #define XEN_DUMPCORE_SEC_PFN                    ".xen_pfn"
33 #define XEN_DUMPCORE_SEC_PAGES                  ".xen_pages"
34 
35 /* elf note name */
36 #define XEN_DUMPCORE_ELFNOTE_NAME               "Xen"
37 /* note numbers are defined in xen/elfnote.h */
38 
39 struct elfnote {
40     uint32_t    namesz; /* Elf_Note note; */
41     uint32_t    descsz;
42     uint32_t    type;
43     char        name[4]; /* sizeof("Xen") = 4
44                           * Fotunately this is 64bit aligned so that
45                           * we can use same structore for both 32/64bit
46                           */
47 };
48 
49 struct xen_dumpcore_elfnote_none_desc {
50     /* nothing */
51 };
52 
53 struct xen_dumpcore_elfnote_header_desc {
54     uint64_t    xch_magic;
55     uint64_t    xch_nr_vcpus;
56     uint64_t    xch_nr_pages;
57     uint64_t    xch_page_size;
58 };
59 
60 struct xen_dumpcore_elfnote_xen_version_desc {
61     uint64_t                    major_version;
62     uint64_t                    minor_version;
63     xen_extraversion_t          extra_version;
64     xen_compile_info_t          compile_info;
65     xen_capabilities_info_t     capabilities;
66     xen_changeset_info_t        changeset;
67     xen_platform_parameters_t   platform_parameters;
68     uint64_t                    pagesize;
69 };
70 
71 #define XEN_DUMPCORE_FORMAT_VERSION(major, minor)  \
72     ((major) << 32) | ((minor) & 0xffffffff)
73 #define XEN_DUMPCORE_FORMAT_MAJOR(version)      ((major) >> 32)
74 #define XEN_DUMPCORE_FORMAT_MINOR(version)      ((minor) & 0xffffffff)
75 
76 #define XEN_DUMPCORE_FORMAT_MAJOR_CURRENT       ((uint64_t)0)
77 #define XEN_DUMPCORE_FORMAT_MINOR_CURRENT       ((uint64_t)1)
78 #define XEN_DUMPCORE_FORMAT_VERSION_CURRENT                         \
79     XEN_DUMPCORE_FORMAT_VERSION(XEN_DUMPCORE_FORMAT_MAJOR_CURRENT,  \
80                                 XEN_DUMPCORE_FORMAT_MINOR_CURRENT)
81 
82 struct xen_dumpcore_elfnote_format_version_desc {
83     uint64_t    version;
84 };
85 
86 
87 struct xen_dumpcore_elfnote_none {
88     struct elfnote                              elfnote;
89     struct xen_dumpcore_elfnote_none_desc       none;
90 };
91 
92 struct xen_dumpcore_elfnote_header {
93     struct elfnote                              elfnote;
94     struct xen_dumpcore_elfnote_header_desc     header;
95 };
96 
97 struct xen_dumpcore_elfnote_xen_version {
98     struct elfnote                                     elfnote;
99     struct xen_dumpcore_elfnote_xen_version_desc        xen_version;
100 };
101 
102 struct xen_dumpcore_elfnote_format_version {
103     struct elfnote                                      elfnote;
104     struct xen_dumpcore_elfnote_format_version_desc     format_version;
105 };
106 
107 #define XC_CORE_INVALID_PFN     (~(uint64_t)0)
108 #define XC_CORE_INVALID_GMFN    (~(uint64_t)0)
109 struct xen_dumpcore_p2m {
110     uint64_t    pfn;
111     uint64_t    gmfn;
112 };
113 
114 
115 struct xc_core_strtab;
116 struct xc_core_section_headers;
117 
118 Elf64_Shdr*
119 xc_core_shdr_get(xc_interface *xch,
120                  struct xc_core_section_headers *sheaders);
121 int
122 xc_core_shdr_set(xc_interface *xch,
123                  Elf64_Shdr *shdr,
124                  struct xc_core_strtab *strtab,
125                  const char *name, uint32_t type,
126                  uint64_t offset, uint64_t size,
127                  uint64_t addralign, uint64_t entsize);
128 
129 struct xc_core_memory_map {
130     uint64_t    addr;
131     uint64_t    size;
132 };
133 typedef struct xc_core_memory_map xc_core_memory_map_t;
134 int xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info);
135 struct xc_core_arch_context;
136 int xc_core_arch_memory_map_get(xc_interface *xch,
137                                 struct xc_core_arch_context *arch_ctxt,
138                                 xc_dominfo_t *info, shared_info_any_t *live_shinfo,
139                                 xc_core_memory_map_t **mapp,
140                                 unsigned int *nr_entries);
141 int xc_core_arch_map_p2m(xc_interface *xch, unsigned int guest_width,
142                          xc_dominfo_t *info, shared_info_any_t *live_shinfo,
143                          xen_pfn_t **live_p2m, unsigned long *pfnp);
144 
145 int xc_core_arch_map_p2m_writable(xc_interface *xch, unsigned int guest_width,
146                                   xc_dominfo_t *info,
147                                   shared_info_any_t *live_shinfo,
148                                   xen_pfn_t **live_p2m, unsigned long *pfnp);
149 
150 int xc_core_arch_get_scratch_gpfn(xc_interface *xch, uint32_t domid,
151                                   xen_pfn_t *gpfn);
152 
153 
154 #if defined (__i386__) || defined (__x86_64__)
155 # include "xc_core_x86.h"
156 #elif defined (__arm__) || defined(__aarch64__)
157 # include "xc_core_arm.h"
158 #else
159 # error "unsupported architecture"
160 #endif
161 
162 #ifndef ELF_CORE_EFLAGS
163 # define ELF_CORE_EFLAGS 0
164 #endif
165 
166 #endif /* XC_CORE_H */
167 
168 /*
169  * Local variables:
170  * mode: C
171  * c-file-style: "BSD"
172  * c-basic-offset: 4
173  * tab-width: 4
174  * indent-tabs-mode: nil
175  * End:
176  */
177