mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
move AllocAdvice record to externally visible xous-rs definitions
this structure moves between swapper and userland.
This commit is contained in:
parent
a2e6a75b2d
commit
b62a639031
1 changed files with 42 additions and 0 deletions
|
|
@ -587,3 +587,45 @@ macro_rules! msg_blocking_scalar_unpack {
|
|||
}
|
||||
}};
|
||||
}
|
||||
|
||||
#[cfg(feature = "swap")]
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum AllocAdvice {
|
||||
/// the PID of the allocation, virtual address in PID space, physical address
|
||||
Allocate(PID, usize, usize),
|
||||
/// the PID of the page freed, virtuall address in PID space, physical address
|
||||
Free(PID, usize, usize),
|
||||
/// not yet initialized record
|
||||
Uninit,
|
||||
}
|
||||
#[cfg(feature = "swap")]
|
||||
impl AllocAdvice {
|
||||
pub fn serialize(&self) -> (usize, usize) {
|
||||
match self {
|
||||
AllocAdvice::Allocate(pid, vaddr, paddr) => {
|
||||
(
|
||||
(pid.get() as usize) << 24 | (vaddr >> 12),
|
||||
(1 << 24) | (paddr >> 12), // 1 indicates an alloc
|
||||
)
|
||||
}
|
||||
AllocAdvice::Free(pid, vaddr, paddr) => {
|
||||
(
|
||||
(pid.get() as usize) << 24 | (vaddr >> 12),
|
||||
(0 << 24) | (paddr >> 12), // 0 indicates a free
|
||||
)
|
||||
}
|
||||
AllocAdvice::Uninit => (0, 0),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize(a0: usize, a1: usize) -> Self {
|
||||
if a0 == 0 && a1 == 0 {
|
||||
AllocAdvice::Uninit
|
||||
} else if (a1 & (1 << 24)) == 0 {
|
||||
// don't have to mask a0 or a1 high bits because << 12 shifts the high flag byte out
|
||||
AllocAdvice::Free(NonZeroU8::new((a0 >> 24) as u8).unwrap(), a0 << 12, a1 << 12)
|
||||
} else {
|
||||
AllocAdvice::Allocate(NonZeroU8::new((a0 >> 24) as u8).unwrap(), a0 << 12, a1 << 12)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue