From 7a390c2a1d24b2302f22f2277b572aa2ecc97485 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 1 Aug 2022 08:25:33 -0600 Subject: [PATCH] Sync some paging code for aarch64 with x86_64 --- src/arch/aarch64/paging/mod.rs | 2 +- src/arch/aarch64/rmm.rs | 45 ++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/arch/aarch64/paging/mod.rs b/src/arch/aarch64/paging/mod.rs index c80d610..b1e3aed 100644 --- a/src/arch/aarch64/paging/mod.rs +++ b/src/arch/aarch64/paging/mod.rs @@ -9,7 +9,6 @@ use self::entry::EntryFlags; use self::mapper::PageFlushAll; pub use rmm::{ - AArch64Arch as RmmA, Arch as RmmArch, Flusher, PageFlags, @@ -17,6 +16,7 @@ pub use rmm::{ TableKind, VirtualAddress, }; +pub use super::CurrentRmmArch as RmmA; pub type PageMapper = rmm::PageMapper; pub use crate::rmm::KernelMapper; diff --git a/src/arch/aarch64/rmm.rs b/src/arch/aarch64/rmm.rs index 3643554..522267a 100644 --- a/src/arch/aarch64/rmm.rs +++ b/src/arch/aarch64/rmm.rs @@ -7,7 +7,6 @@ use core::{ use rmm::{ KILOBYTE, MEGABYTE, - AArch64Arch as RmmA, Arch, BuddyAllocator, BumpAllocator, @@ -20,8 +19,9 @@ use rmm::{ PhysicalAddress, VirtualAddress, }; +use spin::Mutex; -use spin::{Mutex, MutexGuard}; +use super::CurrentRmmArch as RmmA; extern "C" { /// The starting byte of the text (code) data segment. @@ -140,8 +140,8 @@ unsafe fn inner( } let mut identity_map = |base, size_aligned| { - // Map stack with identity mapping - for i in 0..size / A::PAGE_SIZE { + // Map with identity mapping + for i in 0..size_aligned / A::PAGE_SIZE { let phys = PhysicalAddress::new(base + i * A::PAGE_SIZE); let virt = A::phys_to_virt(phys); let flags = page_flags::(virt); @@ -154,13 +154,11 @@ unsafe fn inner( } }; - identity_map(stack_base, stack_size_aligned); identity_map(env_base, env_size_aligned); identity_map(acpi_base, acpi_size_aligned); identity_map(initfs_base, initfs_size_aligned); - //TODO: this is another hack to map our UART match crate::device::serial::COM1.lock().as_ref().map(|x| x.base()) { Some(serial_base) => { @@ -174,8 +172,39 @@ unsafe fn inner( None => (), } + // Ensure graphical debug region remains paged + #[cfg(feature = "graphical_debug")] + { + use crate::devices::graphical_debug::DEBUG_DISPLAY; + use super::paging::entry::EntryFlags; + + let (base, size) = if let Some(debug_display) = &*DEBUG_DISPLAY.lock() { + let data = &debug_display.display.onscreen; + ( + data.as_ptr() as usize - crate::PHYS_OFFSET, + data.len() * 4 + ) + } else { + (0, 0) + }; + + let pages = (size + A::PAGE_SIZE - 1) / A::PAGE_SIZE; + for i in 0..pages { + let phys = PhysicalAddress::new(base + i * A::PAGE_SIZE); + let virt = A::phys_to_virt(phys); + let flags = PageFlags::new().write(true) + .custom_flag(EntryFlags::HUGE_PAGE.bits(), true); + let flush = mapper.map_phys( + virt, + phys, + flags + ).expect("failed to map frame"); + flush.ignore(); // Not the active table + } + } + log::debug!("Table: {:X}", mapper.table().phys().data()); - for i in 0..512 { + for i in 0..A::PAGE_ENTRIES { if let Some(entry) = mapper.table().entry(i) { if entry.present() { log::debug!("{}: {:X}", i, entry.data()); @@ -348,7 +377,7 @@ pub unsafe fn init( // Copy memory map from bootloader location, and page align it let mut area_i = 0; for bootloader_area in bootloader_areas.iter() { - if bootloader_area.kind != BootloaderMemoryKind::Free { + if { bootloader_area.kind } != BootloaderMemoryKind::Free { // Not a free area continue; }