|
27 | 27 | //! This example shows how to prepare a VM for booting with an ELF kernel, following the PVH
|
28 | 28 | //! boot protocol.
|
29 | 29 | //!
|
30 |
| -//! ```rust,ignore |
| 30 | +//! ```rust |
| 31 | +//! |
31 | 32 | //! # extern crate linux_loader;
|
32 | 33 | //! # extern crate vm_memory;
|
33 |
| -//! # use std::io::Cursor; |
| 34 | +//! # use std::{io::{Cursor, Read}, fs::File}; |
34 | 35 | //! # use linux_loader::configurator::{BootConfigurator, BootParams};
|
| 36 | +//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
35 | 37 | //! # use linux_loader::configurator::pvh::PvhBootConfigurator;
|
| 38 | +//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
36 | 39 | //! # use linux_loader::loader::elf::start_info::{hvm_memmap_table_entry, hvm_start_info};
|
| 40 | +//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
37 | 41 | //! # use linux_loader::loader::elf::Elf;
|
38 | 42 | //! # use linux_loader::loader::KernelLoader;
|
39 | 43 | //! # use vm_memory::{Address, GuestAddress, GuestMemoryMmap};
|
40 | 44 | //! # const E820_RAM: u32 = 1;
|
41 | 45 | //! # const MEM_SIZE: usize = 0x100_0000;
|
42 | 46 | //! # const XEN_HVM_START_MAGIC_VALUE: u32 = 0x336ec578;
|
43 |
| -//! # fn create_guest_memory() -> GuestMemoryMmap { |
44 |
| -//! # GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), MEM_SIZE)]).unwrap() |
45 |
| -//! # } |
46 |
| -//! # fn create_elf_pvh_image() -> Vec<u8> { |
47 |
| -//! # include_bytes!(concat!( |
48 |
| -//! # env!("CARGO_MANIFEST_DIR"), "/src/loader/x86_64/elf/test_elfnote.bin" |
49 |
| -//! # )).to_vec() |
50 |
| -//! # } |
| 47 | +//! |
| 48 | +//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
51 | 49 | //! fn build_boot_params() -> (hvm_start_info, Vec<hvm_memmap_table_entry>) {
|
52 | 50 | //! let mut start_info = hvm_start_info::default();
|
53 | 51 | //! let memmap_entry = hvm_memmap_table_entry {
|
|
63 | 61 | //! (start_info, vec![memmap_entry])
|
64 | 62 | //! }
|
65 | 63 | //!
|
| 64 | +//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
66 | 65 | //! fn main() {
|
67 |
| -//! let guest_mem = create_guest_memory(); |
68 |
| -//! let elf_pvh_image = create_elf_pvh_image(); |
| 66 | +//! let guest_mem = |
| 67 | +//! GuestMemoryMmap::from_ranges( &[(GuestAddress(0x0), MEM_SIZE)]) .unwrap(); |
| 68 | +//! |
| 69 | +//! let mut elf_pvh_image = Vec::new(); |
| 70 | +//! let path = concat!(env!("CARGO_MANIFEST_DIR"), "/src/loader/x86_64/elf/test_elfnote.bin"); |
| 71 | +//! let mut file = File::open(path).unwrap(); |
| 72 | +//! file.read_to_end(&mut elf_pvh_image).unwrap(); |
| 73 | +//! |
69 | 74 | //! // Load the kernel image.
|
70 | 75 | //! let loader_result = Elf::load(
|
71 | 76 | //! &guest_mem, None, &mut Cursor::new(&elf_pvh_image), None
|
|
82 | 87 | //! // Write boot parameters in guest memory.
|
83 | 88 | //! let mut boot_params = BootParams::new::<hvm_start_info>(&start_info, start_info_addr);
|
84 | 89 | //! boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
|
85 |
| -//! PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(boot_params, &guest_mem).unwrap(); |
| 90 | +//! PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_mem).unwrap(); |
86 | 91 | //! }
|
| 92 | +//! |
| 93 | +//! # #[cfg(target_arch = "aarch64")] |
| 94 | +//! # fn main() {} |
| 95 | +//! |
87 | 96 | //! ```
|
88 | 97 | //!
|
89 | 98 | //! [`BootConfigurator`]: trait.BootConfigurator.html
|
|
0 commit comments