Add a memory::create_example_mapping function

This commit is contained in:
Philipp Oppermann
2019-03-13 14:23:28 +01:00
parent b0e1527a95
commit 6146ccba2d

View File

@@ -1,6 +1,9 @@
use x86_64::{
structures::paging::{MappedPageTable, MapperAllSizes, PageTable, PhysFrame},
VirtAddr,
structures::paging::{
FrameAllocator, MappedPageTable, Mapper, MapperAllSizes, Page, PageTable, PhysFrame,
Size4KiB,
},
PhysAddr, VirtAddr,
};
/// Initialize a new MappedPageTable.
@@ -36,3 +39,18 @@ unsafe fn active_level_4_table(physical_memory_offset: u64) -> &'static mut Page
&mut *page_table_ptr // unsafe
}
/// Creates an example mapping for the given page to frame `0xb8000`.
pub fn create_example_mapping(
page: Page,
mapper: &mut impl Mapper<Size4KiB>,
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
) {
use x86_64::structures::paging::PageTableFlags as Flags;
let frame = PhysFrame::containing_address(PhysAddr::new(0xb8000));
let flags = Flags::PRESENT | Flags::WRITABLE;
let map_to_result = unsafe { mapper.map_to(page, frame, flags, frame_allocator) };
map_to_result.expect("map_to failed").flush();
}