@@ -32,11 +32,23 @@ pub unsafe fn load(address: usize) -> BootInformation {
32
32
let multiboot = & * ( address as * const BootInformationInner ) ;
33
33
assert_eq ! ( 0 , multiboot. total_size & 0b111 ) ;
34
34
assert ! ( multiboot. has_valid_end_tag( ) ) ;
35
- BootInformation { inner : multiboot }
35
+ BootInformation { inner : multiboot, offset : 0 }
36
+ }
37
+
38
+ pub unsafe fn load_with_offset ( address : usize , offset : usize ) -> BootInformation {
39
+ if !cfg ! ( test) {
40
+ assert_eq ! ( 0 , address & 0b111 ) ;
41
+ assert_eq ! ( 0 , offset & 0b111 ) ;
42
+ }
43
+ let multiboot = & * ( ( address + offset) as * const BootInformationInner ) ;
44
+ assert_eq ! ( 0 , multiboot. total_size & 0b111 ) ;
45
+ assert ! ( multiboot. has_valid_end_tag( ) ) ;
46
+ BootInformation { inner : multiboot, offset : offset }
36
47
}
37
48
38
49
pub struct BootInformation {
39
50
inner : * const BootInformationInner ,
51
+ offset : usize ,
40
52
}
41
53
42
54
#[ repr( C , packed) ]
@@ -59,7 +71,9 @@ impl BootInformation {
59
71
}
60
72
61
73
pub fn elf_sections_tag ( & self ) -> Option < ElfSectionsTag > {
62
- self . get_tag ( 9 ) . map ( |tag| elf_sections:: elf_sections_tag ( tag) )
74
+ self . get_tag ( 9 ) . map ( |tag| unsafe {
75
+ elf_sections:: elf_sections_tag ( tag, self . offset )
76
+ } )
63
77
}
64
78
65
79
pub fn memory_map_tag ( & self ) -> Option < & ' static MemoryMapTag > {
@@ -196,8 +210,8 @@ impl Reader {
196
210
197
211
#[ cfg( test) ]
198
212
mod tests {
199
- use super :: load;
200
- use super :: { ElfSectionFlags , ElfSectionType } ;
213
+ use super :: { load, load_with_offset } ;
214
+ use super :: { BootInformation , ElfSectionFlags , ElfSectionType } ;
201
215
use super :: FramebufferType ;
202
216
203
217
#[ test]
@@ -646,10 +660,43 @@ mod tests {
646
660
bytes[ 796 + i] = ( string_addr >> ( i * 8 ) ) as u8 ;
647
661
}
648
662
let addr = bytes. as_ptr ( ) as usize ;
649
- let bi = unsafe { load ( addr) } ;
663
+ test_grub2_boot_info (
664
+ unsafe { load ( addr) } ,
665
+ addr,
666
+ string_addr,
667
+ & bytes,
668
+ & string_bytes,
669
+ ) ;
670
+ test_grub2_boot_info (
671
+ unsafe { load_with_offset ( addr, 0 ) } ,
672
+ addr,
673
+ string_addr,
674
+ & bytes,
675
+ & string_bytes,
676
+ ) ;
677
+ let offset = 8usize ;
678
+ for i in 0 ..8 {
679
+ bytes[ 796 + i] = ( ( string_addr - offset as u64 ) >> ( i * 8 ) ) as u8 ;
680
+ }
681
+ test_grub2_boot_info (
682
+ unsafe { load_with_offset ( addr - offset, offset) } ,
683
+ addr,
684
+ string_addr - offset as u64 ,
685
+ & bytes,
686
+ & string_bytes,
687
+ ) ;
688
+ }
689
+
690
+ fn test_grub2_boot_info (
691
+ bi : BootInformation ,
692
+ addr : usize ,
693
+ string_addr : u64 ,
694
+ bytes : & [ u8 ] ,
695
+ string_bytes : & [ u8 ] ,
696
+ ) {
650
697
assert_eq ! ( addr, bi. start_address( ) ) ;
651
698
assert_eq ! ( addr + bytes. len( ) , bi. end_address( ) ) ;
652
- assert_eq ! ( bytes. len( ) , bi. total_size( ) as usize ) ;
699
+ assert_eq ! ( bytes. len( ) , bi. total_size( ) ) ;
653
700
let es = bi. elf_sections_tag ( ) . unwrap ( ) ;
654
701
let mut s = es. sections ( ) ;
655
702
let s1 = s. next ( ) . unwrap ( ) ;
0 commit comments