1use core::sync::atomic::AtomicU64;
2
3pub const CUSTOM_USERSPACE_REGION_START: u64 = (1_u64 << 45) + (1_u64 << 40);
7pub const CUSTOM_USERSPACE_REGION_END: u64 = CUSTOM_USERSPACE_REGION_START + (1_u64 << 40);
8
9#[repr(C)]
13pub struct KernelStaticPage {
14 pub version: u64,
15
16 pub tsc_shift: i8,
19 pub tsc_mul: u32,
20 pub tsc_in_sec: u64,
21 pub tsc_ts: u64,
22 pub system_time: u64,
23
24 pub base_nsec: u64, pub system_start_time_tsc: u64,
30
31 pub num_cpus: u32,
32}
33
34impl KernelStaticPage {
35 pub const PAGE_SIZE: u64 = 4096;
36 pub const VADDR: u64 = 0x3F7FFFE00000; #[cfg(feature = "userspace")]
39 pub fn get() -> &'static Self {
40 unsafe {
42 (Self::VADDR as usize as *const KernelStaticPage)
43 .as_ref()
44 .unwrap_unchecked()
45 }
46 }
47}
48const _: () =
49 assert!(core::mem::size_of::<KernelStaticPage>() as u64 <= KernelStaticPage::PAGE_SIZE);
50
51#[derive(Debug)]
54#[repr(C)]
55pub struct ProcessStaticPage {
56 pub version: u64,
57
58 pub capabilities: u64,
60
61 pub max_memory: AtomicU64,
64
65 pub kernel_memory_used: AtomicU64,
66 pub user_memory_used: AtomicU64,
67}
68
69impl ProcessStaticPage {
70 pub const PAGE_SIZE: u64 = 4096;
71 pub const VADDR: u64 = (1_u64 << 46) - (2 * super::syscalls::SysMem::PAGE_SIZE_MID); #[cfg(feature = "userspace")]
74 pub fn get() -> &'static Self {
75 unsafe {
77 (Self::VADDR as usize as *const ProcessStaticPage)
78 .as_ref()
79 .unwrap_unchecked()
80 }
81 }
82}
83const _: () =
84 assert!(core::mem::size_of::<ProcessStaticPage>() as u64 <= ProcessStaticPage::PAGE_SIZE);
85
86#[derive(Debug)]
90#[repr(C)]
91pub struct UserThreadControlBlock {
92 pub guard: u64, pub kernel_version: u32, pub user_version: u32, pub self_handle: u64, pub tls: usize, pub current_cpu: u32,
98 pub reserved0: u32,
99}
100
101impl UserThreadControlBlock {
102 #[cfg(feature = "userspace")]
103 pub fn get_mut() -> &'static mut Self {
104 unsafe {
107 let mut fsbase: u64;
108 core::arch::asm!("rdfsbase {}", out(reg) fsbase, options(nostack, preserves_flags));
109 (fsbase as usize as *mut Self).as_mut().unwrap()
110 }
111 }
112
113 #[cfg(feature = "userspace")]
114 pub fn get() -> &'static Self {
115 Self::get_mut()
116 }
117
118 #[cfg(feature = "userspace")]
120 pub fn __utid() -> u64 {
121 u64::MAX - Self::get().self_handle
122 }
123}