11use alloc:: borrow:: ToOwned ;
22use core:: ptr:: write_bytes;
3- use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
3+ use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
44use core:: { mem, ptr, slice} ;
55
66use align_address:: Align ;
@@ -9,7 +9,7 @@ use hermit_entry::boot_info::{
99} ;
1010use hermit_entry:: elf:: LoadedKernel ;
1111use log:: info;
12- use multiboot:: information:: { MemoryManagement , Multiboot , PAddr } ;
12+ use multiboot:: information:: { MemoryManagement , Multiboot , MultibootInfo , PAddr } ;
1313use vm_fdt:: FdtWriterResult ;
1414use x86_64:: structures:: paging:: { PageSize , PageTableFlags , Size2MiB , Size4KiB } ;
1515
@@ -36,9 +36,9 @@ mod entry {
3636 ) ;
3737}
3838
39- static MB_INFO : AtomicUsize = AtomicUsize :: new ( 0 ) ;
39+ static MB_INFO : AtomicPtr < MultibootInfo > = AtomicPtr :: new ( ptr :: null_mut ( ) ) ;
4040
41- unsafe extern "C" fn rust_start ( mb_info : usize ) -> ! {
41+ unsafe extern "C" fn rust_start ( mb_info : * mut MultibootInfo ) -> ! {
4242 MB_INFO . store ( mb_info, Ordering :: Relaxed ) ;
4343 unsafe {
4444 crate :: os:: loader_main ( ) ;
@@ -95,13 +95,18 @@ pub fn find_kernel() -> &'static [u8] {
9595 paging:: clean_up ( ) ;
9696 // Identity-map the Multiboot information.
9797 let mb_info = MB_INFO . load ( Ordering :: Relaxed ) ;
98- assert ! ( mb_info > 0 , "Could not find Multiboot information" ) ;
99- info ! ( "Found Multiboot information at {mb_info:#x}" ) ;
100- paging:: map :: < Size4KiB > ( mb_info, mb_info, 1 , PageTableFlags :: empty ( ) ) ;
98+ assert ! ( !mb_info. is_null( ) , "Could not find Multiboot information" ) ;
99+ info ! ( "Found Multiboot information at {mb_info:p}" ) ;
100+ paging:: map :: < Size4KiB > (
101+ mb_info. expose_provenance ( ) ,
102+ mb_info. expose_provenance ( ) ,
103+ 1 ,
104+ PageTableFlags :: empty ( ) ,
105+ ) ;
101106
102107 let mut mem = Mem ;
103108 // Load the Multiboot information and identity-map the modules information.
104- let multiboot = unsafe { Multiboot :: from_ptr ( mb_info as u64 , & mut mem) . unwrap ( ) } ;
109+ let multiboot = unsafe { Multiboot :: from_ref ( & mut * mb_info , & mut mem) } ;
105110
106111 // Iterate through all modules.
107112 // Collect the start address of the first module and the highest end address of all modules.
@@ -170,9 +175,9 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
170175 . addr ( )
171176 . align_up ( Size4KiB :: SIZE as usize ) ;
172177
173- if new_stack + KERNEL_STACK_SIZE as usize > mb_info {
174- new_stack =
175- ( mb_info + mem :: size_of :: < Multiboot < ' _ , ' _ > > ( ) ) . align_up ( Size4KiB :: SIZE as usize ) ;
178+ if new_stack + KERNEL_STACK_SIZE as usize > mb_info. addr ( ) {
179+ new_stack = ( mb_info . addr ( ) + mem :: size_of :: < Multiboot < ' _ , ' _ > > ( ) )
180+ . align_up ( Size4KiB :: SIZE as usize ) ;
176181 }
177182
178183 let command_line = multiboot. command_line ( ) ;
0 commit comments