mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
move SwapAlloc to the swap module
This commit is contained in:
parent
c6d4d8ebc8
commit
dcef549099
2 changed files with 44 additions and 48 deletions
|
|
@ -7,6 +7,8 @@ use xous_kernel::{MemoryFlags, MemoryRange, PID};
|
|||
|
||||
pub use crate::arch::mem::{MemoryMapping, PAGE_SIZE};
|
||||
use crate::arch::process::Process;
|
||||
#[cfg(feature = "swap")]
|
||||
use crate::swap::SwapAlloc;
|
||||
|
||||
#[derive(Debug)]
|
||||
// below suppresses warning from unused Move argument in hosted mode
|
||||
|
|
@ -55,51 +57,6 @@ impl Default for MemoryManager {
|
|||
fn default() -> Self { Self::default_hack() }
|
||||
}
|
||||
|
||||
#[cfg(feature = "swap")]
|
||||
use loader::swap::SWAP_FLG_WIRED;
|
||||
|
||||
#[cfg(feature = "swap")]
|
||||
pub struct SwapAlloc {
|
||||
timestamp: u32,
|
||||
/// virtual_page_number[19:0] | flags[3:0] | pid[7:0]
|
||||
vpn: u32,
|
||||
}
|
||||
#[cfg(feature = "swap")]
|
||||
impl SwapAlloc {
|
||||
pub fn is_pid(&self, pid: PID) -> bool { self.vpn as u8 == pid.get() }
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_some(&self) -> bool { self.vpn as u8 != 0 }
|
||||
|
||||
pub fn is_none(&self) -> bool { self.vpn as u8 == 0 }
|
||||
|
||||
pub fn get_pid(&self) -> Option<PID> {
|
||||
if self.vpn as u8 == 0 { None } else { Some(PID::new(self.vpn as u8).unwrap()) }
|
||||
}
|
||||
|
||||
pub unsafe fn update(&mut self, pid: Option<PID>, vaddr: Option<usize>) {
|
||||
crate::swap::Swap::with_mut(|s| {
|
||||
self.timestamp = s.next_epoch();
|
||||
if let Some(pid) = pid {
|
||||
s.track_alloc(true);
|
||||
if let Some(va) = vaddr {
|
||||
self.vpn = (va as u32) & !0xFFF | pid.get() as u32;
|
||||
} else {
|
||||
self.vpn = SWAP_FLG_WIRED | pid.get() as u32;
|
||||
}
|
||||
} else {
|
||||
s.track_alloc(false);
|
||||
self.vpn = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub unsafe fn reparent(&mut self, pid: PID) {
|
||||
self.timestamp = crate::swap::Swap::with_mut(|s| s.next_epoch());
|
||||
self.vpn = self.vpn & !&0xFFu32 | pid.get() as u32;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(baremetal))]
|
||||
std::thread_local!(static MEMORY_MANAGER: core::cell::RefCell<MemoryManager> = core::cell::RefCell::new(MemoryManager::default()));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,55 @@
|
|||
use loader::swap::SWAP_FLG_WIRED;
|
||||
use loader::swap::SWAP_RPT_VADDR;
|
||||
use xous_kernel::SWAPPER_PID;
|
||||
use xous_kernel::{SysCallResult, PID, SID, TID};
|
||||
|
||||
/* for non-blocking calls
|
||||
use xous_Kernel::{try_send_message, MemoryFlags, Message, MessageEnvelope, SysCallResult, TID};
|
||||
use crate::server::SenderID; */
|
||||
use crate::arch::current_pid;
|
||||
use crate::arch::mem::MMUFlags;
|
||||
use crate::arch::mem::PAGE_SIZE;
|
||||
use crate::mem::MemoryManager;
|
||||
use crate::services::SystemServices;
|
||||
|
||||
pub struct SwapAlloc {
|
||||
timestamp: u32,
|
||||
/// virtual_page_number[19:0] | flags[3:0] | pid[7:0]
|
||||
vpn: u32,
|
||||
}
|
||||
|
||||
impl SwapAlloc {
|
||||
pub fn is_pid(&self, pid: PID) -> bool { self.vpn as u8 == pid.get() }
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_some(&self) -> bool { self.vpn as u8 != 0 }
|
||||
|
||||
pub fn is_none(&self) -> bool { self.vpn as u8 == 0 }
|
||||
|
||||
pub fn get_pid(&self) -> Option<PID> {
|
||||
if self.vpn as u8 == 0 { None } else { Some(PID::new(self.vpn as u8).unwrap()) }
|
||||
}
|
||||
|
||||
pub unsafe fn update(&mut self, pid: Option<PID>, vaddr: Option<usize>) {
|
||||
crate::swap::Swap::with_mut(|s| {
|
||||
self.timestamp = s.next_epoch();
|
||||
if let Some(pid) = pid {
|
||||
s.track_alloc(true);
|
||||
if let Some(va) = vaddr {
|
||||
self.vpn = (va as u32) & !0xFFF | pid.get() as u32;
|
||||
} else {
|
||||
self.vpn = SWAP_FLG_WIRED | pid.get() as u32;
|
||||
}
|
||||
} else {
|
||||
s.track_alloc(false);
|
||||
self.vpn = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub unsafe fn reparent(&mut self, pid: PID) {
|
||||
self.timestamp = crate::swap::Swap::with_mut(|s| s.next_epoch());
|
||||
self.vpn = self.vpn & !&0xFFu32 | pid.get() as u32;
|
||||
}
|
||||
}
|
||||
|
||||
/// This ABI is copy-paste synchronized with what's in the userspace handler. It's left out of
|
||||
/// xous-rs so that we can change it without having to push crates to crates.io.
|
||||
/// Since there is only one place the ABI could be used, we're going to stick with
|
||||
|
|
|
|||
Loading…
Reference in a new issue