From f3f7aad23c5bb1f48b10a716c10b1be8acf15e39 Mon Sep 17 00:00:00 2001 From: guillaume didier Date: Thu, 20 Feb 2020 09:19:40 +0100 Subject: [PATCH] Memory map dump --- src/main.rs | 2 ++ src/memory.rs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9667a70..a276038 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,6 +64,8 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { use x86_64::structures::paging::MapperAllSizes; use x86_64::VirtAddr; + serial_println!("Memory map: {:#?}", boot_info.memory_map); + let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset); // new: initialize a mapper let mut frame_allocator = diff --git a/src/memory.rs b/src/memory.rs index ce98eb5..93bfcaa 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -79,12 +79,14 @@ impl BootInfoFrameAllocator { // map each region to its address range let addr_ranges = usable_regions.map(|r| r.range.start_addr()..r.range.end_addr()); // transform to an iterator of frame start addresses - let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096)); - // create `PhysFrame` types from the start addresses + let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096)); // TODO Magic number, this is where 4k pages are enforced + // create `PhysFrame` types from the start addresses let frames = frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr))); frames } } + +// We only allocate 4k pages unsafe impl FrameAllocator for BootInfoFrameAllocator { fn allocate_frame(&mut self) -> Option { let frame = self.usable_frames().nth(self.next);