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