use core::sync::atomic::AtomicU64;
pub const CUSTOM_USERSPACE_REGION_START: u64 = (1_u64 << 45) + (1_u64 << 40);
pub const CUSTOM_USERSPACE_REGION_END: u64 = CUSTOM_USERSPACE_REGION_START + (1_u64 << 40);
#[repr(C)]
pub struct KernelStaticPage {
pub version: u64,
pub tsc_shift: i8,
pub tsc_mul: u32,
pub tsc_in_sec: u64,
pub tsc_ts: u64,
pub system_time: u64,
pub base_nsec: u64,
pub system_start_time_tsc: u64,
pub num_cpus: u32,
}
impl KernelStaticPage {
pub const PAGE_SIZE: u64 = 4096;
pub const VADDR: u64 = 0x3F7FFFE00000;
#[cfg(feature = "userspace")]
pub fn get() -> &'static Self {
unsafe {
(Self::VADDR as usize as *const KernelStaticPage)
.as_ref()
.unwrap_unchecked()
}
}
}
const _: () =
assert!(core::mem::size_of::<KernelStaticPage>() as u64 <= KernelStaticPage::PAGE_SIZE);
#[derive(Debug)]
#[repr(C)]
pub struct ProcessStaticPage {
pub version: u64,
pub capabilities: u64,
pub max_memory: AtomicU64,
pub kernel_memory_used: AtomicU64,
pub user_memory_used: AtomicU64,
}
impl ProcessStaticPage {
pub const PAGE_SIZE: u64 = 4096;
pub const VADDR: u64 = (1_u64 << 46) - (2 * super::syscalls::SysMem::PAGE_SIZE_MID);
#[cfg(feature = "userspace")]
pub fn get() -> &'static Self {
unsafe {
(Self::VADDR as usize as *const ProcessStaticPage)
.as_ref()
.unwrap_unchecked()
}
}
}
const _: () =
assert!(core::mem::size_of::<ProcessStaticPage>() as u64 <= ProcessStaticPage::PAGE_SIZE);
#[derive(Debug)]
#[repr(C)]
pub struct UserThreadControlBlock {
pub guard: u64, pub kernel_version: u32, pub user_version: u32, pub self_handle: u64, pub tls: usize, pub current_cpu: u32,
pub reserved0: u32,
}
impl UserThreadControlBlock {
#[cfg(feature = "userspace")]
pub fn get_mut() -> &'static mut Self {
unsafe {
let mut fsbase: u64;
core::arch::asm!("rdfsbase {}", out(reg) fsbase, options(nostack, preserves_flags));
(fsbase as usize as *mut Self).as_mut().unwrap()
}
}
#[cfg(feature = "userspace")]
pub fn get() -> &'static Self {
Self::get_mut()
}
#[cfg(feature = "userspace")]
pub fn __utid() -> u64 {
u64::MAX - Self::get().self_handle
}
}