mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Merge branch 'post-10' into post-11
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
||||
use x86_64::{
|
||||
structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB},
|
||||
PhysAddr, VirtAddr,
|
||||
structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB},
|
||||
};
|
||||
|
||||
/// Initialize a new OffsetPageTable.
|
||||
@@ -11,8 +11,10 @@ use x86_64::{
|
||||
/// `physical_memory_offset`. Also, this function must be only called once
|
||||
/// to avoid aliasing `&mut` references (which is undefined behavior).
|
||||
pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static> {
|
||||
unsafe {
|
||||
let level_4_table = active_level_4_table(physical_memory_offset);
|
||||
OffsetPageTable::new(level_4_table, physical_memory_offset)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the active level 4 table.
|
||||
@@ -30,7 +32,7 @@ unsafe fn active_level_4_table(physical_memory_offset: VirtAddr) -> &'static mut
|
||||
let virt = physical_memory_offset + phys.as_u64();
|
||||
let page_table_ptr: *mut PageTable = virt.as_mut_ptr();
|
||||
|
||||
&mut *page_table_ptr // unsafe
|
||||
unsafe { &mut *page_table_ptr }
|
||||
}
|
||||
|
||||
/// A FrameAllocator that always returns `None`.
|
||||
|
||||
Reference in New Issue
Block a user