aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / uefi / tests / memory_map.rs
| 1 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | |
| 3 | //! Memory map API testing. |
| 4 | |
| 5 | use uefi::mem::memory_map::*; |
| 6 | |
| 7 | /// This test imitates a kernel that receives the UEFI memory map as boot |
| 8 | /// information. |
| 9 | #[test] |
| 10 | fn parse_boot_information_efi_mmap() { |
| 11 | let desc_size = size_of::<MemoryDescriptor>(); |
| 12 | let mut mmap_source = [ |
| 13 | MemoryDescriptor { |
| 14 | ty: MemoryType::CONVENTIONAL, |
| 15 | padding: 0, |
| 16 | phys_start: 0x3000, |
| 17 | virt_start: 0x3000, |
| 18 | page_count: 1, |
| 19 | att: MemoryAttribute::WRITE_BACK, |
| 20 | }, |
| 21 | MemoryDescriptor { |
| 22 | ty: MemoryType::CONVENTIONAL, |
| 23 | padding: 0, |
| 24 | phys_start: 0x2000, |
| 25 | virt_start: 0x2000, |
| 26 | page_count: 1, |
| 27 | att: MemoryAttribute::WRITE_BACK, |
| 28 | }, |
| 29 | MemoryDescriptor { |
| 30 | ty: MemoryType::CONVENTIONAL, |
| 31 | padding: 0, |
| 32 | phys_start: 0x1000, |
| 33 | virt_start: 0x1000, |
| 34 | page_count: 1, |
| 35 | att: MemoryAttribute::WRITE_BACK, |
| 36 | }, |
| 37 | ]; |
| 38 | let map_size = mmap_source.len() * desc_size; |
| 39 | let meta = MemoryMapMeta { |
| 40 | map_size, |
| 41 | desc_size, |
| 42 | map_key: Default::default(), |
| 43 | desc_version: MemoryDescriptor::VERSION, |
| 44 | }; |
| 45 | let mmap = |
| 46 | unsafe { core::slice::from_raw_parts_mut(mmap_source.as_mut_ptr().cast::<u8>(), map_size) }; |
| 47 | |
| 48 | // BOOT INFORMATION END |
| 49 | // |
| 50 | // BEGIN PARSING |
| 51 | // This scenario is similar to what a kernel parsing a boot information |
| 52 | // would do. |
| 53 | |
| 54 | let mmap = MemoryMapRefMut::new(mmap, meta).unwrap(); |
| 55 | assert_eq!(mmap.entries().copied().collect::<Vec<_>>(), mmap_source); |
| 56 | } |