From b1cc6763455081446d52f59a2d4c8e8698ad393d Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 7 May 2024 00:56:35 +0800 Subject: [PATCH] absorb ABI changes --- kernel/src/swap.rs | 27 ++++++++++++++++++++++++--- kernel/src/syscall.rs | 15 ++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/kernel/src/swap.rs b/kernel/src/swap.rs index 6162ee884..9a053380e 100644 --- a/kernel/src/swap.rs +++ b/kernel/src/swap.rs @@ -10,6 +10,21 @@ use crate::arch::mem::PAGE_SIZE; use crate::mem::MemoryManager; 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)] pub enum BlockingSwapOp { /// 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) -> ! { - let evicted_ptr = crate::arch::mem::evict_page_inner(target_pid, vaddr).expect("couldn't evict page"); + pub fn evict_page(&mut self, target_pid: usize, vaddr: usize) -> SysCallResult { + 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 #[cfg(feature = "debug-swap")] println!("evict_page - swapper activate, PC: {:08x}", self.pc); 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, + )); } } diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 557023f68..320480f9a 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -12,7 +12,7 @@ use crate::mem::{MemoryManager, PAGE_SIZE}; use crate::server::{SenderID, WaitingMessage}; use crate::services::SystemServices; #[cfg(feature = "swap")] -use crate::swap::Swap; +use crate::swap::{Swap, SwapAbi}; /* Quoth Xobs: 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)) } #[cfg(feature = "swap")] - SysCall::EvictPage(target_pid, vaddr) => { + SysCall::SwapOp(op, a1, a2, a3, a4, a5, a6) => { if pid.get() != xous_kernel::SWAPPER_PID { klog!("Illegal caller"); // only PID 2 can call this 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