|
4 | 4 | use crate::memory_descriptor::MemoryRegion; |
5 | 5 | use bootloader_api::info::{FrameBufferInfo, PixelFormat}; |
6 | 6 | use bootloader_boot_config::{BootConfig, LevelFilter}; |
7 | | -use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, E820MemoryRegion}; |
| 7 | +use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, E820MemoryRegion, Region}; |
| 8 | +use bootloader_x86_64_common::legacy_memory_region::UsedMemorySlice; |
8 | 9 | use bootloader_x86_64_common::RawFrameBufferInfo; |
9 | 10 | use bootloader_x86_64_common::{ |
10 | 11 | legacy_memory_region::LegacyFrameAllocator, load_and_switch_to_kernel, Kernel, PageTables, |
@@ -55,9 +56,10 @@ pub extern "C" fn _start(info: &mut BiosInfo) -> ! { |
55 | 56 | }; |
56 | 57 | let kernel_size = info.kernel.len; |
57 | 58 | let next_free_frame = PhysFrame::containing_address(PhysAddr::new(info.last_used_addr)) + 1; |
58 | | - let mut frame_allocator = LegacyFrameAllocator::new_starting_at( |
| 59 | + let mut frame_allocator = LegacyFrameAllocator::new_with_used_slices( |
59 | 60 | next_free_frame, |
60 | 61 | memory_map.iter().copied().map(MemoryRegion), |
| 62 | + used_memory_slices(info), |
61 | 63 | ); |
62 | 64 |
|
63 | 65 | // We identity-mapped all memory, so the offset between physical and virtual addresses is 0 |
@@ -216,6 +218,17 @@ fn init_logger( |
216 | 218 | framebuffer_info |
217 | 219 | } |
218 | 220 |
|
| 221 | +fn used_memory_slices(info: &BiosInfo) -> impl Iterator<Item = UsedMemorySlice> + Clone { |
| 222 | + // skip kernel and ramdisk because they are handled individually by the |
| 223 | + // uefi/bios common code |
| 224 | + [info.stage_3, info.stage_4, info.config_file] |
| 225 | + .into_iter() |
| 226 | + .map(|region| UsedMemorySlice { |
| 227 | + start: PhysAddr::new(region.start).as_u64(), |
| 228 | + len: region.len, |
| 229 | + }) |
| 230 | +} |
| 231 | + |
219 | 232 | /// Creates page table abstraction types for both the bootloader and kernel page tables. |
220 | 233 | fn create_page_tables(frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> PageTables { |
221 | 234 | // We identity-mapped all memory, so the offset between physical and virtual addresses is 0 |
|
0 commit comments