#![cfg_attr(not(feature = "std"), no_std)] pub use crate::{allocator::*, arch::*, page::*}; mod allocator; mod arch; mod page; pub const KILOBYTE: usize = 1024; pub const MEGABYTE: usize = KILOBYTE * 1024; pub const GIGABYTE: usize = MEGABYTE * 1024; #[cfg(target_pointer_width = "64")] pub const TERABYTE: usize = GIGABYTE * 1024; /// Specific table to be used, needed on some architectures //TODO: Use this throughout the code #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] pub enum TableKind { /// Userspace page table User, /// Kernel page table Kernel, } /// Physical memory address #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] #[repr(transparent)] pub struct PhysicalAddress(usize); impl PhysicalAddress { #[inline(always)] pub const fn new(address: usize) -> Self { Self(address) } #[inline(always)] pub fn data(&self) -> usize { self.0 } #[inline(always)] pub fn add(self, offset: usize) -> Self { Self(self.0 + offset) } } /// Virtual memory address #[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] #[repr(transparent)] pub struct VirtualAddress(usize); impl VirtualAddress { #[inline(always)] pub const fn new(address: usize) -> Self { Self(address) } #[inline(always)] pub fn data(&self) -> usize { self.0 } #[inline(always)] pub fn add(self, offset: usize) -> Self { Self(self.0 + offset) } #[inline(always)] pub fn kind(&self) -> TableKind { if (self.0 as isize) < 0 { TableKind::Kernel } else { TableKind::User } } } impl core::fmt::Debug for VirtualAddress { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "[virt {:#0x}]", self.data()) } } #[derive(Clone, Copy, Debug)] pub struct MemoryArea { pub base: PhysicalAddress, pub size: usize, }