linux_loader/loader_gen/x86_64/
start_info.rs

1/*
2 * Permission is hereby granted, free of charge, to any person obtaining a copy
3 * of this software and associated documentation files (the "Software"), to
4 * deal in the Software without restriction, including without limitation the
5 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6 * sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 * DEALINGS IN THE SOFTWARE.
19 *
20 * Copyright (c) 2016, Citrix Systems, Inc.
21 */
22
23/*
24 * automatically generated by rust-bindgen using:
25 *
26 * # bindgen start_info.h -- -include stdint.h > start_info.rs
27 *
28 * From the canonical version in upstream Xen repository
29 * xen/include/public/arch-x86/hvm/start_info.h
30 * at commit:
31 * b4642c32c4d079916d5607ddda0232aae5e1690e
32 *
33 * The generated file has been edited to eliminate unnecessary
34 * definitions, add comments, and relocate definitions and tests for clarity.
35 * Added Default to the list of traits that are automatically derived.
36 *
37 * The definitions in this file are intended to be exported and used by a particular
38 * VMM implementation in order to boot a Linux guest using the PVH entry point as
39 * specified in the x86/HVM direct boot ABI.
40 * These structures contain all the required information (cmdline address, ACPI RSDP,
41 * memory maps, etc) that must be written to guest memory before starting guest
42 * execution by jumping to the PVH entry point address.
43 * A comparable set of definitions to hvm_start_info and hvm_memmap_table_entry in this
44 * file would be the boot_params and boot_e820_entry definitions used by the Linux
45 * 64-bit boot protocol.
46 *
47 * Start of day structure passed to PVH guests and to HVM guests in %ebx.
48 *
49 * NOTE: nothing will be loaded at physical address 0, so a 0 value in any
50 * of the address fields should be treated as not present.
51 *
52 *  0 +----------------+
53 *    | magic          | Contains the magic value XEN_HVM_START_MAGIC_VALUE
54 *    |                | ("xEn3" with the 0x80 bit of the "E" set).
55 *  4 +----------------+
56 *    | version        | Version of this structure. Current version is 1. New
57 *    |                | versions are guaranteed to be backwards-compatible.
58 *  8 +----------------+
59 *    | flags          | SIF_xxx flags.
60 * 12 +----------------+
61 *    | nr_modules     | Number of modules passed to the kernel.
62 * 16 +----------------+
63 *    | modlist_paddr  | Physical address of an array of modules
64 *    |                | (layout of the structure below).
65 * 24 +----------------+
66 *    | cmdline_paddr  | Physical address of the command line,
67 *    |                | a zero-terminated ASCII string.
68 * 32 +----------------+
69 *    | rsdp_paddr     | Physical address of the RSDP ACPI data structure.
70 * 40 +----------------+
71 *    | memmap_paddr   | Physical address of the (optional) memory map. Only
72 *    |                | present in version 1 and newer of the structure.
73 * 48 +----------------+
74 *    | memmap_entries | Number of entries in the memory map table. Zero
75 *    |                | if there is no memory map being provided. Only
76 *    |                | present in version 1 and newer of the structure.
77 * 52 +----------------+
78 *    | reserved       | Version 1 and newer only.
79 * 56 +----------------+
80 *
81 * The layout of each entry in the module structure is the following:
82 *
83 *  0 +----------------+
84 *    | paddr          | Physical address of the module.
85 *  8 +----------------+
86 *    | size           | Size of the module in bytes.
87 * 16 +----------------+
88 *    | cmdline_paddr  | Physical address of the command line,
89 *    |                | a zero-terminated ASCII string.
90 * 24 +----------------+
91 *    | reserved       |
92 * 32 +----------------+
93 *
94 * The layout of each entry in the memory map table is as follows:
95 *
96 *  0 +----------------+
97 *    | addr           | Base address
98 *  8 +----------------+
99 *    | size           | Size of mapping in bytes
100 * 16 +----------------+
101 *    | type           | Type of mapping as defined between the hypervisor
102 *    |                | and guest. See XEN_HVM_MEMMAP_TYPE_* values below.
103 * 20 +----------------|
104 *    | reserved       |
105 * 24 +----------------+
106 *
107 * The address and sizes are always a 64bit little endian unsigned integer.
108 *
109 * NB: Xen on x86 will always try to place all the data below the 4GiB
110 * boundary.
111 *
112 * Version numbers of the hvm_start_info structure have evolved like this:
113 *
114 * Version 0:  Initial implementation.
115 *
116 * Version 1:  Added the memmap_paddr/memmap_entries fields (plus 4 bytes of
117 *             padding) to the end of the hvm_start_info struct. These new
118 *             fields can be used to pass a memory map to the guest. The
119 *             memory map is optional and so guests that understand version 1
120 *             of the structure must check that memmap_entries is non-zero
121 *             before trying to read the memory map.
122 */
123
124#[repr(C)]
125#[derive(Debug, Copy, Clone, Default)]
126pub struct hvm_start_info {
127    pub magic: u32,
128    pub version: u32,
129    pub flags: u32,
130    pub nr_modules: u32,
131    pub modlist_paddr: u64,
132    pub cmdline_paddr: u64,
133    pub rsdp_paddr: u64,
134    pub memmap_paddr: u64,
135    pub memmap_entries: u32,
136    pub reserved: u32,
137}
138
139#[repr(C)]
140#[derive(Debug, Copy, Clone, Default)]
141pub struct hvm_modlist_entry {
142    pub paddr: u64,
143    pub size: u64,
144    pub cmdline_paddr: u64,
145    pub reserved: u64,
146}
147
148#[repr(C)]
149#[derive(Debug, Copy, Clone, Default)]
150pub struct hvm_memmap_table_entry {
151    pub addr: u64,
152    pub size: u64,
153    pub type_: u32,
154    pub reserved: u32,
155}
156
157#[cfg(test)]
158mod tests {
159    use super::*;
160
161    #[test]
162    fn bindgen_test_layout_hvm_start_info() {
163        const UNINIT: ::std::mem::MaybeUninit<hvm_start_info> = ::std::mem::MaybeUninit::uninit();
164        let ptr = UNINIT.as_ptr();
165        assert_eq!(
166            ::std::mem::size_of::<hvm_start_info>(),
167            56usize,
168            concat!("Size of: ", stringify!(hvm_start_info))
169        );
170        assert_eq!(
171            ::std::mem::align_of::<hvm_start_info>(),
172            8usize,
173            concat!("Alignment of ", stringify!(hvm_start_info))
174        );
175        assert_eq!(
176            unsafe { ::std::ptr::addr_of!((*ptr).magic) as usize - ptr as usize },
177            0usize,
178            concat!(
179                "Offset of field: ",
180                stringify!(hvm_start_info),
181                "::",
182                stringify!(magic)
183            )
184        );
185        assert_eq!(
186            unsafe { ::std::ptr::addr_of!((*ptr).version) as usize - ptr as usize },
187            4usize,
188            concat!(
189                "Offset of field: ",
190                stringify!(hvm_start_info),
191                "::",
192                stringify!(version)
193            )
194        );
195        assert_eq!(
196            unsafe { ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize },
197            8usize,
198            concat!(
199                "Offset of field: ",
200                stringify!(hvm_start_info),
201                "::",
202                stringify!(flags)
203            )
204        );
205        assert_eq!(
206            unsafe { ::std::ptr::addr_of!((*ptr).nr_modules) as usize - ptr as usize },
207            12usize,
208            concat!(
209                "Offset of field: ",
210                stringify!(hvm_start_info),
211                "::",
212                stringify!(nr_modules)
213            )
214        );
215        assert_eq!(
216            unsafe { ::std::ptr::addr_of!((*ptr).modlist_paddr) as usize - ptr as usize },
217            16usize,
218            concat!(
219                "Offset of field: ",
220                stringify!(hvm_start_info),
221                "::",
222                stringify!(modlist_paddr)
223            )
224        );
225        assert_eq!(
226            unsafe { ::std::ptr::addr_of!((*ptr).cmdline_paddr) as usize - ptr as usize },
227            24usize,
228            concat!(
229                "Offset of field: ",
230                stringify!(hvm_start_info),
231                "::",
232                stringify!(cmdline_paddr)
233            )
234        );
235        assert_eq!(
236            unsafe { ::std::ptr::addr_of!((*ptr).rsdp_paddr) as usize - ptr as usize },
237            32usize,
238            concat!(
239                "Offset of field: ",
240                stringify!(hvm_start_info),
241                "::",
242                stringify!(rsdp_paddr)
243            )
244        );
245        assert_eq!(
246            unsafe { ::std::ptr::addr_of!((*ptr).memmap_paddr) as usize - ptr as usize },
247            40usize,
248            concat!(
249                "Offset of field: ",
250                stringify!(hvm_start_info),
251                "::",
252                stringify!(memmap_paddr)
253            )
254        );
255        assert_eq!(
256            unsafe { ::std::ptr::addr_of!((*ptr).memmap_entries) as usize - ptr as usize },
257            48usize,
258            concat!(
259                "Offset of field: ",
260                stringify!(hvm_start_info),
261                "::",
262                stringify!(memmap_entries)
263            )
264        );
265        assert_eq!(
266            unsafe { ::std::ptr::addr_of!((*ptr).reserved) as usize - ptr as usize },
267            52usize,
268            concat!(
269                "Offset of field: ",
270                stringify!(hvm_start_info),
271                "::",
272                stringify!(reserved)
273            )
274        );
275    }
276
277    #[test]
278    fn bindgen_test_layout_hvm_modlist_entry() {
279        const UNINIT: ::std::mem::MaybeUninit<hvm_modlist_entry> =
280            ::std::mem::MaybeUninit::uninit();
281        let ptr = UNINIT.as_ptr();
282        assert_eq!(
283            ::std::mem::size_of::<hvm_modlist_entry>(),
284            32usize,
285            concat!("Size of: ", stringify!(hvm_modlist_entry))
286        );
287        assert_eq!(
288            ::std::mem::align_of::<hvm_modlist_entry>(),
289            8usize,
290            concat!("Alignment of ", stringify!(hvm_modlist_entry))
291        );
292        assert_eq!(
293            unsafe { ::std::ptr::addr_of!((*ptr).paddr) as usize - ptr as usize },
294            0usize,
295            concat!(
296                "Offset of field: ",
297                stringify!(hvm_modlist_entry),
298                "::",
299                stringify!(paddr)
300            )
301        );
302        assert_eq!(
303            unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize },
304            8usize,
305            concat!(
306                "Offset of field: ",
307                stringify!(hvm_modlist_entry),
308                "::",
309                stringify!(size)
310            )
311        );
312        assert_eq!(
313            unsafe { ::std::ptr::addr_of!((*ptr).cmdline_paddr) as usize - ptr as usize },
314            16usize,
315            concat!(
316                "Offset of field: ",
317                stringify!(hvm_modlist_entry),
318                "::",
319                stringify!(cmdline_paddr)
320            )
321        );
322        assert_eq!(
323            unsafe { ::std::ptr::addr_of!((*ptr).reserved) as usize - ptr as usize },
324            24usize,
325            concat!(
326                "Offset of field: ",
327                stringify!(hvm_modlist_entry),
328                "::",
329                stringify!(reserved)
330            )
331        );
332    }
333
334    #[test]
335    fn bindgen_test_layout_hvm_memmap_table_entry() {
336        const UNINIT: ::std::mem::MaybeUninit<hvm_memmap_table_entry> =
337            ::std::mem::MaybeUninit::uninit();
338        let ptr = UNINIT.as_ptr();
339        assert_eq!(
340            ::std::mem::size_of::<hvm_memmap_table_entry>(),
341            24usize,
342            concat!("Size of: ", stringify!(hvm_memmap_table_entry))
343        );
344        assert_eq!(
345            ::std::mem::align_of::<hvm_memmap_table_entry>(),
346            8usize,
347            concat!("Alignment of ", stringify!(hvm_memmap_table_entry))
348        );
349        assert_eq!(
350            unsafe { ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize },
351            0usize,
352            concat!(
353                "Offset of field: ",
354                stringify!(hvm_memmap_table_entry),
355                "::",
356                stringify!(addr)
357            )
358        );
359        assert_eq!(
360            unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize },
361            8usize,
362            concat!(
363                "Offset of field: ",
364                stringify!(hvm_memmap_table_entry),
365                "::",
366                stringify!(size)
367            )
368        );
369        assert_eq!(
370            unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize },
371            16usize,
372            concat!(
373                "Offset of field: ",
374                stringify!(hvm_memmap_table_entry),
375                "::",
376                stringify!(type_)
377            )
378        );
379        assert_eq!(
380            unsafe { ::std::ptr::addr_of!((*ptr).reserved) as usize - ptr as usize },
381            20usize,
382            concat!(
383                "Offset of field: ",
384                stringify!(hvm_memmap_table_entry),
385                "::",
386                stringify!(reserved)
387            )
388        );
389    }
390}