feat: implement configure_protection and map_shared with real page mapping, remove dead context_switch from Platform trait
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
use domain::memory::MemoryRegion;
|
||||
use domain::process::MAX_PROCESSES;
|
||||
use domain::thread::SavedContext;
|
||||
use platform::Platform;
|
||||
use types::{
|
||||
address::{EntryPoint, PhysicalAddress, StackPointer},
|
||||
bounded::PageCount,
|
||||
id::{CoreId, IrqId, ProcessId},
|
||||
permission::PermissionSet,
|
||||
permission::{Permission, PermissionSet},
|
||||
time::{Ticks, TimerDuration},
|
||||
};
|
||||
|
||||
@@ -30,23 +29,28 @@ impl RiscVPlatform {
|
||||
pub fn page_table_for(&self, pid: ProcessId) -> usize {
|
||||
self.page_tables[pid.raw() as usize]
|
||||
}
|
||||
|
||||
fn ensure_page_table(&mut self, pid: ProcessId) -> &mut mmu::PageTable {
|
||||
let idx = pid.raw() as usize;
|
||||
if self.page_tables[idx] == 0 {
|
||||
let kernel_pt = unsafe { &*(self.page_tables[0] as *const mmu::PageTable) };
|
||||
let user_pt = mmu::create_user_page_table(kernel_pt, 0, 0, 0x10000);
|
||||
self.page_tables[idx] = user_pt as *const mmu::PageTable as usize;
|
||||
}
|
||||
unsafe { &mut *(self.page_tables[idx] as *mut mmu::PageTable) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Platform for RiscVPlatform {
|
||||
fn configure_protection(&mut self, process: ProcessId, _regions: &[MemoryRegion]) {
|
||||
if self.page_tables[process.raw() as usize] == 0 {
|
||||
let kernel_pt_addr = self.page_tables[0];
|
||||
let kernel_pt = unsafe { &*(kernel_pt_addr as *const mmu::PageTable) };
|
||||
let user_pt = mmu::create_user_page_table(kernel_pt, 0, 0, 0x10000);
|
||||
self.page_tables[process.raw() as usize] = user_pt as *const mmu::PageTable as usize;
|
||||
fn configure_protection(&mut self, process: ProcessId, regions: &[MemoryRegion]) {
|
||||
let pt = self.ensure_page_table(process);
|
||||
for region in regions {
|
||||
let base_pa = region.base().raw();
|
||||
let pages = region.size().value() as usize;
|
||||
mmu::map_range(pt, base_pa, base_pa, pages, true, true, true, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
fn context_switch(&mut self, from: &mut SavedContext, to: &SavedContext) {
|
||||
let _ = from;
|
||||
let _ = to;
|
||||
}
|
||||
|
||||
fn enable_user_mode(&mut self, entry: EntryPoint, stack: StackPointer) -> ! {
|
||||
let kernel_sp: usize;
|
||||
unsafe { core::arch::asm!("mv {0}, sp", out(reg) kernel_sp) };
|
||||
@@ -97,10 +101,17 @@ impl Platform for RiscVPlatform {
|
||||
|
||||
fn map_shared(
|
||||
&mut self,
|
||||
_process: ProcessId,
|
||||
_base: PhysicalAddress,
|
||||
_size: PageCount,
|
||||
_permissions: PermissionSet,
|
||||
process: ProcessId,
|
||||
base: PhysicalAddress,
|
||||
size: PageCount,
|
||||
permissions: PermissionSet,
|
||||
) {
|
||||
let pt = self.ensure_page_table(process);
|
||||
let pa = base.raw();
|
||||
let pages = size.value() as usize;
|
||||
let read = permissions.allows(Permission::Read);
|
||||
let write = permissions.allows(Permission::Write);
|
||||
let exec = permissions.allows(Permission::Execute);
|
||||
mmu::map_range(pt, pa, pa, pages, read, write, exec, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user