Skip to content
Snippets Groups Projects
Verified Commit 29460e0b authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Use RMM for some arch-specific paging functions

parent f90033e0
Branches
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
use crate::memory::Frame; use crate::memory::Frame;
use super::PhysicalAddress; use super::{PhysicalAddress, RmmA, RmmArch};
/// A page table entry /// A page table entry
#[repr(packed(8))] #[repr(packed(8))]
...@@ -11,16 +11,13 @@ pub struct Entry(u64); ...@@ -11,16 +11,13 @@ pub struct Entry(u64);
bitflags! { bitflags! {
pub struct EntryFlags: u64 { pub struct EntryFlags: u64 {
const PRESENT = 1; const PRESENT = RmmA::ENTRY_FLAG_PRESENT as u64;
const WRITABLE = 1 << 1; const WRITABLE = RmmA::ENTRY_FLAG_READWRITE as u64;
const USER_ACCESSIBLE = 1 << 2; const USER_ACCESSIBLE = RmmA::ENTRY_FLAG_USER as u64;
const WRITE_THROUGH = 1 << 3;
const NO_CACHE = 1 << 4; const NO_CACHE = 1 << 4;
const ACCESSED = 1 << 5;
const DIRTY = 1 << 6;
const HUGE_PAGE = 1 << 7; const HUGE_PAGE = 1 << 7;
const GLOBAL = 1 << 8; const GLOBAL = 1 << 8;
const NO_EXECUTE = 1 << 63; const NO_EXECUTE = RmmA::ENTRY_FLAG_NO_EXEC as u64;
} }
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
use core::ops::{Deref, DerefMut}; use core::ops::{Deref, DerefMut};
use core::{mem, ptr}; use core::{mem, ptr};
use spin::Mutex; use spin::Mutex;
use x86::{controlregs, msr, tlb}; use x86::msr;
use crate::memory::Frame; use crate::memory::Frame;
...@@ -12,7 +12,12 @@ use self::entry::EntryFlags; ...@@ -12,7 +12,12 @@ use self::entry::EntryFlags;
use self::mapper::{Mapper, MapperFlushAll}; use self::mapper::{Mapper, MapperFlushAll};
use self::temporary_page::TemporaryPage; use self::temporary_page::TemporaryPage;
pub use rmm::{PhysicalAddress, VirtualAddress}; pub use rmm::{
Arch as RmmArch,
PhysicalAddress,
VirtualAddress,
X8664Arch as RmmA,
};
pub mod entry; pub mod entry;
pub mod mapper; pub mod mapper;
...@@ -259,25 +264,25 @@ impl ActivePageTable { ...@@ -259,25 +264,25 @@ impl ActivePageTable {
pub fn switch(&mut self, new_table: InactivePageTable) -> InactivePageTable { pub fn switch(&mut self, new_table: InactivePageTable) -> InactivePageTable {
let old_table = InactivePageTable { let old_table = InactivePageTable {
p4_frame: Frame::containing_address(PhysicalAddress::new( frame: Frame::containing_address(unsafe {
unsafe { controlregs::cr3() } as usize, RmmA::table()
)), })
}; };
unsafe { unsafe {
controlregs::cr3_write(new_table.p4_frame.start_address().data() as u64); RmmA::set_table(new_table.frame.start_address());
} }
old_table old_table
} }
pub fn flush(&mut self, page: Page) { pub fn flush(&mut self, page: Page) {
unsafe { unsafe {
tlb::flush(page.start_address().data()); RmmA::invalidate(page.start_address());
} }
} }
pub fn flush_all(&mut self) { pub fn flush_all(&mut self) {
unsafe { unsafe {
tlb::flush_all(); RmmA::invalidate_all();
} }
} }
...@@ -290,9 +295,9 @@ impl ActivePageTable { ...@@ -290,9 +295,9 @@ impl ActivePageTable {
F: FnOnce(&mut Mapper), F: FnOnce(&mut Mapper),
{ {
{ {
let backup = Frame::containing_address(PhysicalAddress::new(unsafe { let backup = Frame::containing_address(unsafe {
controlregs::cr3() as usize RmmA::table()
})); });
// map temporary_page to current p4 table // map temporary_page to current p4 table
let p4_table = temporary_page.map_table_frame( let p4_table = temporary_page.map_table_frame(
...@@ -303,7 +308,7 @@ impl ActivePageTable { ...@@ -303,7 +308,7 @@ impl ActivePageTable {
// overwrite recursive mapping // overwrite recursive mapping
self.p4_mut()[crate::RECURSIVE_PAGE_PML4].set( self.p4_mut()[crate::RECURSIVE_PAGE_PML4].set(
table.p4_frame.clone(), table.frame.clone(),
EntryFlags::PRESENT | EntryFlags::WRITABLE | EntryFlags::NO_EXECUTE, EntryFlags::PRESENT | EntryFlags::WRITABLE | EntryFlags::NO_EXECUTE,
); );
self.flush_all(); self.flush_all();
...@@ -323,7 +328,7 @@ impl ActivePageTable { ...@@ -323,7 +328,7 @@ impl ActivePageTable {
} }
pub unsafe fn address(&self) -> usize { pub unsafe fn address(&self) -> usize {
controlregs::cr3() as usize RmmA::table().data()
} }
} }
...@@ -337,7 +342,7 @@ impl Drop for ActivePageTable { ...@@ -337,7 +342,7 @@ impl Drop for ActivePageTable {
} }
pub struct InactivePageTable { pub struct InactivePageTable {
p4_frame: Frame, frame: Frame,
} }
impl InactivePageTable { impl InactivePageTable {
...@@ -362,17 +367,17 @@ impl InactivePageTable { ...@@ -362,17 +367,17 @@ impl InactivePageTable {
} }
temporary_page.unmap(active_table); temporary_page.unmap(active_table);
InactivePageTable { p4_frame: frame } InactivePageTable { frame: frame }
} }
pub unsafe fn from_address(cr3: usize) -> InactivePageTable { pub unsafe fn from_address(cr3: usize) -> InactivePageTable {
InactivePageTable { InactivePageTable {
p4_frame: Frame::containing_address(PhysicalAddress::new(cr3)), frame: Frame::containing_address(PhysicalAddress::new(cr3)),
} }
} }
pub unsafe fn address(&self) -> usize { pub unsafe fn address(&self) -> usize {
self.p4_frame.start_address().data() self.frame.start_address().data()
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment