mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add a memory::create_example_mapping function
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
use x86_64::{
|
use x86_64::{
|
||||||
structures::paging::{MappedPageTable, MapperAllSizes, PageTable, PhysFrame},
|
structures::paging::{
|
||||||
VirtAddr,
|
FrameAllocator, MappedPageTable, Mapper, MapperAllSizes, Page, PageTable, PhysFrame,
|
||||||
|
Size4KiB,
|
||||||
|
},
|
||||||
|
PhysAddr, VirtAddr,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Initialize a new MappedPageTable.
|
/// 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
|
&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();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user