absorb ABI changes

This commit is contained in:
bunnie 2024-05-07 00:56:35 +08:00
parent 73414ff9d5
commit b1cc676345
2 changed files with 36 additions and 6 deletions

View file

@ -10,6 +10,21 @@ use crate::arch::mem::PAGE_SIZE;
use crate::mem::MemoryManager; use crate::mem::MemoryManager;
use crate::services::SystemServices; use crate::services::SystemServices;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum SwapAbi {
Invalid = 0,
Evict = 1,
}
impl SwapAbi {
pub fn from(val: usize) -> SwapAbi {
use SwapAbi::*;
match val {
1 => Evict,
_ => Invalid,
}
}
}
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum BlockingSwapOp { pub enum BlockingSwapOp {
/// PID of source, vaddr of source, vaddr in swap space (block must already be mapped into swap space) /// PID of source, vaddr of source, vaddr in swap space (block must already be mapped into swap space)
@ -310,14 +325,20 @@ impl Swap {
} }
} }
pub fn evict_page(&mut self, target_pid: PID, vaddr: usize) -> ! { pub fn evict_page(&mut self, target_pid: usize, vaddr: usize) -> SysCallResult {
let evicted_ptr = crate::arch::mem::evict_page_inner(target_pid, vaddr).expect("couldn't evict page"); let evicted_ptr =
crate::arch::mem::evict_page_inner(PID::new(target_pid as u8).expect("Invalid PID"), vaddr)
.expect("couldn't evict page");
// this is safe because evict_page() leaves us in the swapper memory context // this is safe because evict_page() leaves us in the swapper memory context
#[cfg(feature = "debug-swap")] #[cfg(feature = "debug-swap")]
println!("evict_page - swapper activate, PC: {:08x}", self.pc); println!("evict_page - swapper activate, PC: {:08x}", self.pc);
unsafe { unsafe {
self.blocking_activate_swapper(BlockingSwapOp::WriteToSwap(target_pid, vaddr, evicted_ptr)); self.blocking_activate_swapper(BlockingSwapOp::WriteToSwap(
PID::new(target_pid as u8).expect("Invalid PID"),
vaddr,
evicted_ptr,
));
} }
} }

View file

@ -12,7 +12,7 @@ use crate::mem::{MemoryManager, PAGE_SIZE};
use crate::server::{SenderID, WaitingMessage}; use crate::server::{SenderID, WaitingMessage};
use crate::services::SystemServices; use crate::services::SystemServices;
#[cfg(feature = "swap")] #[cfg(feature = "swap")]
use crate::swap::Swap; use crate::swap::{Swap, SwapAbi};
/* Quoth Xobs: /* Quoth Xobs:
The idea behind SWITCHTO_CALLER was that you'd have a process act as a scheduler, The idea behind SWITCHTO_CALLER was that you'd have a process act as a scheduler,
@ -1022,12 +1022,21 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
Swap::with_mut(|swap| swap.register_handler(s0, s1, s2, s3, handler, state)) Swap::with_mut(|swap| swap.register_handler(s0, s1, s2, s3, handler, state))
} }
#[cfg(feature = "swap")] #[cfg(feature = "swap")]
SysCall::EvictPage(target_pid, vaddr) => { SysCall::SwapOp(op, a1, a2, a3, a4, a5, a6) => {
if pid.get() != xous_kernel::SWAPPER_PID { if pid.get() != xous_kernel::SWAPPER_PID {
klog!("Illegal caller"); // only PID 2 can call this klog!("Illegal caller"); // only PID 2 can call this
return Err(xous_kernel::Error::AccessDenied); return Err(xous_kernel::Error::AccessDenied);
} }
Swap::with_mut(|swap| swap.evict_page(target_pid, vaddr)) match SwapAbi::from(op) {
SwapAbi::Evict => Swap::with_mut(|swap| swap.evict_page(a1, a2)),
SwapAbi::Invalid => {
println!(
"Invalid SwapOp: {:x} {:x} {:x} {:x} {:x} {:x} {:x}",
op, a1, a2, a3, a4, a5, a6
);
Err(xous_kernel::Error::UnhandledSyscall)
}
}
} }
/* https://github.com/betrusted-io/xous-core/issues/90 /* https://github.com/betrusted-io/xous-core/issues/90