File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ use uefi:: mem:: memory_map:: * ;
2
+
3
+ /// This test imitates a kernel that receives the UEFI memory map as boot
4
+ /// information.
5
+ #[ test]
6
+ fn parse_boot_information_efi_mmap ( ) {
7
+ let desc_size = size_of :: < MemoryDescriptor > ( ) ;
8
+ let mut mmap_source = [
9
+ MemoryDescriptor {
10
+ ty : MemoryType :: CONVENTIONAL ,
11
+ phys_start : 0x3000 ,
12
+ virt_start : 0x3000 ,
13
+ page_count : 1 ,
14
+ att : MemoryAttribute :: WRITE_BACK ,
15
+ } ,
16
+ MemoryDescriptor {
17
+ ty : MemoryType :: CONVENTIONAL ,
18
+ phys_start : 0x2000 ,
19
+ virt_start : 0x2000 ,
20
+ page_count : 1 ,
21
+ att : MemoryAttribute :: WRITE_BACK ,
22
+ } ,
23
+ MemoryDescriptor {
24
+ ty : MemoryType :: CONVENTIONAL ,
25
+ phys_start : 0x1000 ,
26
+ virt_start : 0x1000 ,
27
+ page_count : 1 ,
28
+ att : MemoryAttribute :: WRITE_BACK ,
29
+ } ,
30
+ ] ;
31
+ let map_size = mmap_source. len ( ) * desc_size;
32
+ let meta = MemoryMapMeta {
33
+ map_size,
34
+ desc_size,
35
+ map_key : Default :: default ( ) ,
36
+ desc_version : MemoryDescriptor :: VERSION ,
37
+ } ;
38
+ let mmap =
39
+ unsafe { core:: slice:: from_raw_parts_mut ( mmap_source. as_mut_ptr ( ) . cast :: < u8 > ( ) , map_size) } ;
40
+
41
+ // BOOT INFORMATION END
42
+ //
43
+ // BEGIN PARSING
44
+
45
+ let mmap = MemoryMapRefMut :: new ( mmap, meta) . unwrap ( ) ;
46
+ assert_eq ! ( mmap. entries( ) . copied( ) . collect:: <Vec <_>>( ) , mmap_source) ;
47
+ }
You can’t perform that action at this time.
0 commit comments