From 491889a237013af8dee0accff0f034c3e4b09fd8 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 20 May 2020 14:29:36 +0200 Subject: [PATCH] Update paging code for x86_64 v0.11.0 --- src/memory.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/memory.rs b/src/memory.rs index e9380203..c64b72d4 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -2,7 +2,6 @@ use bootloader::bootinfo::{MemoryMap, MemoryRegionType}; use x86_64::{ structures::paging::{ FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB, - UnusedPhysFrame, }, PhysAddr, VirtAddr, }; @@ -45,11 +44,12 @@ pub fn create_example_mapping( use x86_64::structures::paging::PageTableFlags as Flags; let frame = PhysFrame::containing_address(PhysAddr::new(0xb8000)); - // FIXME: ONLY FOR TEMPORARY TESTING - let unused_frame = unsafe { UnusedPhysFrame::new(frame) }; let flags = Flags::PRESENT | Flags::WRITABLE; - let map_to_result = mapper.map_to(page, unused_frame, flags, frame_allocator); + let map_to_result = unsafe { + // FIXME: this is not safe, we do it only for testing + mapper.map_to(page, frame, flags, frame_allocator) + }; map_to_result.expect("map_to failed").flush(); } @@ -57,7 +57,7 @@ pub fn create_example_mapping( pub struct EmptyFrameAllocator; unsafe impl FrameAllocator for EmptyFrameAllocator { - fn allocate_frame(&mut self) -> Option { + fn allocate_frame(&mut self) -> Option { None } } @@ -82,7 +82,7 @@ impl BootInfoFrameAllocator { } /// Returns an iterator over the usable frames specified in the memory map. - fn usable_frames(&self) -> impl Iterator { + fn usable_frames(&self) -> impl Iterator { // get usable regions from memory map let regions = self.memory_map.iter(); let usable_regions = regions.filter(|r| r.region_type == MemoryRegionType::Usable); @@ -91,14 +91,12 @@ impl BootInfoFrameAllocator { // 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 frames = frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr))); - // we know that the frames are really unused - frames.map(|f| unsafe { UnusedPhysFrame::new(f) }) + frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr))) } } unsafe impl FrameAllocator for BootInfoFrameAllocator { - fn allocate_frame(&mut self) -> Option { + fn allocate_frame(&mut self) -> Option { let frame = self.usable_frames().nth(self.next); self.next += 1; frame