Skip to content
Snippets Groups Projects
Commit a4829d2d authored by Martin Kröning's avatar Martin Kröning :crab:
Browse files

Paging: Rework identity_map

parent 65dd01f9
No related branches found
No related tags found
No related merge requests found
use x86_64::structures::paging::PhysFrame;
use crate::arch::x86_64::kernel::processor;
use crate::arch::x86_64::mm::paging::{
BasePageSize, PageSize, PageTableEntryFlags, PageTableEntryFlagsExt,
......@@ -255,10 +257,10 @@ fn detect_rsdp(start_address: PhysAddr, end_address: PhysAddr) -> Result<&'stati
// Have we crossed a page boundary in the last iteration?
if current_address / BasePageSize::SIZE as usize > current_page {
// Identity-map this possible page of the RSDP.
paging::identity_map(
PhysAddr::from(current_address),
PhysAddr::from(current_address),
);
let frame = PhysFrame::<BasePageSize>::containing_address(x86_64::PhysAddr::new(
current_address as u64,
));
paging::identity_map(frame);
current_page = current_address / BasePageSize::SIZE as usize;
}
......@@ -304,7 +306,9 @@ fn detect_rsdp(start_address: PhysAddr, end_address: PhysAddr) -> Result<&'stati
/// Returns a reference to the ACPI RSDP within the Ok() if successful or an empty Err() on failure.
fn detect_acpi() -> Result<&'static AcpiRsdp, ()> {
// Get the address of the EBDA.
paging::identity_map(EBDA_PTR_LOCATION, EBDA_PTR_LOCATION);
let frame =
PhysFrame::<BasePageSize>::containing_address(x86_64::PhysAddr::new(EBDA_PTR_LOCATION.0));
paging::identity_map(frame);
let ebda_ptr_location: &u16 =
unsafe { &*(VirtAddr::from(EBDA_PTR_LOCATION.as_u64()).as_ptr()) };
let ebda_address = PhysAddr((*ebda_ptr_location as u64) << 4);
......
......@@ -239,28 +239,27 @@ pub fn unmap<S: PageSize>(virtual_address: VirtAddr, count: usize) {
}
#[cfg(feature = "acpi")]
pub fn identity_map(start_address: PhysAddr, end_address: PhysAddr) {
let first_page =
Page::<BasePageSize>::containing_address(x86_64::VirtAddr::new(start_address.as_u64()));
let last_page =
Page::<BasePageSize>::containing_address(x86_64::VirtAddr::new(end_address.as_u64()));
pub fn identity_map<S>(frame: PhysFrame<S>)
where
S: PageSize + core::fmt::Debug,
RecursivePageTable<'static>: Mapper<S>,
{
assert!(
last_page.start_address().as_u64() < mm::kernel_start_address().0,
frame.start_address().as_u64() < mm::kernel_start_address().0,
"Address {:#X} to be identity-mapped is not below Kernel start address",
last_page.start_address()
frame.start_address()
);
let mut flags = PageTableEntryFlags::empty();
flags.normal().read_only().execute_disable();
let count = (last_page.start_address().as_u64() - first_page.start_address().as_u64())
/ BasePageSize::SIZE
+ 1;
map::<BasePageSize>(
VirtAddr(first_page.start_address().as_u64()),
PhysAddr(first_page.start_address().as_u64()),
count as usize,
flags,
);
unsafe {
recursive_page_table()
.identity_map(
frame,
PageTableEntryFlags::PRESENT | PageTableEntryFlags::NO_EXECUTE,
&mut physicalmem::FrameAlloc,
)
.unwrap()
.flush();
}
}
#[inline]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment