diff --git a/framework/jinux-frame/src/arch/x86/boot/linux_boot/mod.rs b/framework/jinux-frame/src/arch/x86/boot/linux_boot/mod.rs index 297e095d2..0716da811 100644 --- a/framework/jinux-frame/src/arch/x86/boot/linux_boot/mod.rs +++ b/framework/jinux-frame/src/arch/x86/boot/linux_boot/mod.rs @@ -111,9 +111,10 @@ impl From for MemoryRegionType { } fn init_memory_regions(memory_regions: &'static Once>) { - let boot_params = &BOOT_PARAMS.get().unwrap(); - let num_entries = boot_params.e820_entries as usize; let mut regions = Vec::::new(); + + let boot_params = BOOT_PARAMS.get().unwrap(); + let num_entries = boot_params.e820_entries as usize; for e820_entry in &boot_params.e820_table[0..num_entries] { regions.push(MemoryRegion::new( e820_entry.addr as usize, @@ -121,6 +122,7 @@ fn init_memory_regions(memory_regions: &'static Once>) { e820_entry.typ.into(), )); } + memory_regions.call_once(|| regions); } diff --git a/framework/jinux-frame/src/arch/x86/boot/multiboot/mod.rs b/framework/jinux-frame/src/arch/x86/boot/multiboot/mod.rs index 5276426b3..4247b3e5c 100644 --- a/framework/jinux-frame/src/arch/x86/boot/multiboot/mod.rs +++ b/framework/jinux-frame/src/arch/x86/boot/multiboot/mod.rs @@ -103,12 +103,12 @@ fn init_framebuffer_info(framebuffer_arg: &'static Once>) { let mut regions = Vec::::new(); - // Add the regions in the multiboot protocol. let info = MB1_INFO.get().unwrap(); + + // Add the regions in the multiboot protocol. let start = info.memory_map_addr as usize; let length = info.memory_map_len as usize; let mut current = start; - while current < start + length { let entry = unsafe { &*(paddr_to_vaddr(current) as *const MemoryEntry) }; let start = entry.base_addr; @@ -134,6 +134,7 @@ fn init_memory_regions(memory_regions: &'static Once>) { (fb.width * fb.height * fb.bpp + 7) / 8, // round up when divide with 8 (bits/Byte) MemoryRegionType::Framebuffer, )); + // Add the kernel region. // These are physical addresses provided by the linker script. extern "C" { diff --git a/framework/jinux-frame/src/arch/x86/boot/multiboot2/mod.rs b/framework/jinux-frame/src/arch/x86/boot/multiboot2/mod.rs index 2a94e0e70..6f437e5eb 100644 --- a/framework/jinux-frame/src/arch/x86/boot/multiboot2/mod.rs +++ b/framework/jinux-frame/src/arch/x86/boot/multiboot2/mod.rs @@ -106,10 +106,10 @@ impl From for MemoryRegionType { fn init_memory_regions(memory_regions: &'static Once>) { let mut regions = Vec::::new(); + let mb2_info = MB2_INFO.get().unwrap(); + // Add the regions returned by Grub. - let memory_regions_tag = MB2_INFO - .get() - .unwrap() + let memory_regions_tag = mb2_info .memory_map_tag() .expect("Memory region not found from the Multiboot2 header!"); let num_memory_regions = memory_regions_tag.memory_areas().len(); @@ -124,7 +124,8 @@ fn init_memory_regions(memory_regions: &'static Once>) { ); regions.push(region); } - if let Some(Ok(fb_tag)) = MB2_INFO.get().unwrap().framebuffer_tag() { + + if let Some(Ok(fb_tag)) = mb2_info.framebuffer_tag() { // Add the framebuffer region since Grub does not specify it. let fb = BootloaderFramebufferArg { address: fb_tag.address() as usize, @@ -138,6 +139,7 @@ fn init_memory_regions(memory_regions: &'static Once>) { MemoryRegionType::Framebuffer, )); } + // Add the kernel region since Grub does not specify it. // These are physical addresses provided by the linker script. extern "C" { @@ -149,12 +151,13 @@ fn init_memory_regions(memory_regions: &'static Once>) { __kernel_end as usize - __kernel_start as usize, MemoryRegionType::Kernel, )); + // Add the boot module region since Grub does not specify it. - let mb2_module_tag = MB2_INFO.get().unwrap().module_tags(); - for m in mb2_module_tag { + let mb2_module_tag = mb2_info.module_tags(); + for module in mb2_module_tag { regions.push(MemoryRegion::new( - m.start_address() as usize, - m.module_size() as usize, + module.start_address() as usize, + module.module_size() as usize, MemoryRegionType::Module, )); }