1#[no_mangle]
8pub static mb_magic: u64 = 0;
9#[no_mangle]
13pub static mb_info_pm_addr: u64 = 0;
14
15#[inline]
16pub fn roundup_4k(addr: u64) -> u64 { (addr + 0xfff) & !0xfff }
17
18#[inline]
19pub fn rounddown_4k(addr: u64) -> u64 { addr & !0xfff }
20
21#[inline]
22pub fn is_aligned_4k(addr: u64) -> bool { (addr & 0xfff) == 0 }
23
24pub mod Mem {
26	pub const K: u64 = 1024;
28	pub const M: u64 = 1024 * K;
29	pub const G: u64 = 1024 * M;
30	pub const PAGE_SIZE: u64 = 0x1000;
32	pub const PAGE_SHIFT: u64 = 12;
33	pub const PAGE_MASK: u64 = 0xfff;
34	pub const MAX_PHY_MEM: u64 = 0x1000000000;
36	pub const MIN_PHY_MEM: u64 = 64 * M;
38	pub const ID_MAP_START: u64 = 0xffff_8000_0000_0000;
39	pub const ID_MAP_END: u64 = 0xffff_8010_0000_0000;
40	pub const KERNEL_OFFSET: u64 = 0xffff_8020_0000_0000;
42	pub const KERNEL_HEAP_START: u64 = 0xffff_8030_0000_0000;
45	pub const KERNEL_HEAP_END: u64 = 0xffff_8040_0000_0000;
46	pub const KERNEL_STACK_SIZE: u64 = 0x4000;
49	pub const KERNEL_STACK_MASK: u64 = KERNEL_STACK_SIZE - 1;
50	pub const KERNEL_STACK_TASK_MAGIC: u64 = 0x1A2B3C4D5E6F6969;
51	pub const USER_STACK_START: u64 = 0x0000_7000_0000_0000;
53	pub const USER_STACK_SIZE: u64 = 8 * M;
54}
55
56pub mod ExternSyms {
58	extern "C" {
59		pub fn ___KERNEL_PM_START__();
60		pub fn ___KERNEL_PM_END__();
61		pub fn ___BSS_START__();
62		pub fn ___BSS_END__();
63		pub fn ___RAMFS_START__();
64		pub fn ___RAMFS_END__();
65		pub fn ___FREE_PAGE_STACK__();
70	}
71	#[cfg(target_arch = "x86_64")]
72	pub use crate::arch::x86_64::ExternSyms::*;
73}
74
75#[cfg(target_arch = "x86_64")]
76pub mod HWDefs {
77	pub const IDT_CAPACITY: usize = 256;
79	pub const IDT_VALID: usize = 48;
81	pub const VECTOR_SIZE: usize = 16;
83}
84
85pub mod Limits {
86	pub const SEM_WAIT_QUEUE_MIN_CAP: usize = 16;
89	pub const SCHED_RUN_QUEUE_MIN_CAP: usize = 24;
90}
91
92#[allow(non_snake_case)]
96#[inline]
97pub const fn V2P(va: u64) -> Option<u64> {
98	if va >= Mem::ID_MAP_END || va < Mem::ID_MAP_START {
99		return None;
100	}
101	return Some(va - Mem::ID_MAP_START);
102}
103
104#[allow(non_snake_case)]
106#[inline]
107pub const fn P2V(pa: u64) -> Option<u64> {
108	if pa >= Mem::MAX_PHY_MEM {
109		return None;
110	}
111	return Some(pa + Mem::ID_MAP_START);
112}
113
114pub struct IntNumber {}
117impl IntNumber {
118	pub const PAGEFAULT: u16 = 0xe;
119	pub const TIMER: u16 = 0x20;
120	pub const KEYBOARD: u16 = 0x21;
121	pub const SYSCALL: u16 = 0x80;
122}