Create example mapping for page 0x1000

This commit is contained in:
Philipp Oppermann
2019-01-28 11:19:46 +01:00
parent 5d807ee622
commit f272785861
2 changed files with 31 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
use x86_64::structures::paging::{Mapper, Page, PageTable, RecursivePageTable};
use x86_64::{VirtAddr, PhysAddr};
use x86_64::structures::paging::{
FrameAllocator, Mapper, Page, PageTable, PhysFrame, RecursivePageTable, Size4KiB,
};
use x86_64::{PhysAddr, VirtAddr};
/// Creates a RecursivePageTable instance from the level 4 address.
///
@@ -28,3 +30,26 @@ pub fn translate_addr(addr: u64, recursive_page_table: &RecursivePageTable) -> O
let frame = recursive_page_table.translate_page(page);
frame.map(|frame| frame.start_address() + u64::from(addr.page_offset()))
}
pub fn create_example_mapping(
recursive_page_table: &mut RecursivePageTable,
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
) {
use x86_64::structures::paging::PageTableFlags as Flags;
let page: Page = Page::containing_address(VirtAddr::new(0x1000));
let frame = PhysFrame::containing_address(PhysAddr::new(0xb8000));
let flags = Flags::PRESENT | Flags::WRITABLE;
let map_to_result = unsafe { recursive_page_table.map_to(page, frame, flags, frame_allocator) };
map_to_result.expect("map_to failed").flush();
}
/// A FrameAllocator that always returns `None`.
pub struct EmptyFrameAllocator;
impl FrameAllocator<Size4KiB> for EmptyFrameAllocator {
fn allocate_frame(&mut self) -> Option<PhysFrame> {
None
}
}