summaryrefslogtreecommitdiff
path: root/kernel/src/mm.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2026-09-06 18:06:51 +0800
committerlittleblack111 <littleblack11111@gmail.com>2026-09-06 18:06:51 +0800
commitf303e7596367dc77d539f36f8c4e68ad51914337 (patch)
tree09bb2a66d517e23dc60eb569f59c3e31fdf42bd1 /kernel/src/mm.rs
parent02ea0327f11f6715ae0d34c597cc8095884f2216 (diff)
refactor(mm): seperate addr
Diffstat (limited to 'kernel/src/mm.rs')
-rw-r--r--kernel/src/mm.rs112
1 files changed, 4 insertions, 108 deletions
diff --git a/kernel/src/mm.rs b/kernel/src/mm.rs
index 4f9004d..e7ade30 100644
--- a/kernel/src/mm.rs
+++ b/kernel/src/mm.rs
@@ -1,111 +1,7 @@
-use core::{ops::Deref, sync::atomic::Ordering};
+use crate::mm::addr::PhysicalMemoryAddress;
-use atomic::Atomic;
-use bytemuck::{Pod, Zeroable};
+pub mod addr;
-static KERNEL_VIRTUAL_BASE: Atomic<PhysicalMemoryAddress> = Atomic::new(PhysicalMemoryAddress(0));
-
-#[derive(Clone, Copy, Pod, Zeroable)]
-#[repr(transparent)]
-pub struct VirtualMemoryAddress(pub usize);
-
-impl Deref for VirtualMemoryAddress {
- type Target = usize;
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-impl From<usize> for VirtualMemoryAddress {
- fn from(value: usize) -> Self {
- Self(value)
- }
-}
-
-impl From<VirtualMemoryAddress> for usize {
- fn from(value: VirtualMemoryAddress) -> Self {
- *value
- }
-}
-
-impl From<PhysicalMemoryAddress> for VirtualMemoryAddress {
- fn from(value: PhysicalMemoryAddress) -> Self {
- VirtualMemoryAddress(*value + *KERNEL_VIRTUAL_BASE.load(Ordering::Relaxed))
- }
-}
-
-#[derive(Clone, Copy, Pod, Zeroable)]
-#[repr(transparent)]
-pub struct PhysicalMemoryAddress(pub usize);
-
-impl Deref for PhysicalMemoryAddress {
- type Target = usize;
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-impl From<usize> for PhysicalMemoryAddress {
- fn from(value: usize) -> Self {
- PhysicalMemoryAddress(value)
- }
-}
-
-impl From<PhysicalMemoryAddress> for usize {
- fn from(value: PhysicalMemoryAddress) -> Self {
- *value
- }
-}
-
-impl From<VirtualMemoryAddress> for PhysicalMemoryAddress {
- fn from(value: VirtualMemoryAddress) -> Self {
- PhysicalMemoryAddress(*value - *KERNEL_VIRTUAL_BASE.load(Ordering::Relaxed))
- }
-}
-
-#[derive(Clone, Copy)]
-pub enum MemoryAddress {
- Virtual(VirtualMemoryAddress),
- Physical(PhysicalMemoryAddress),
-}
-
-impl From<VirtualMemoryAddress> for MemoryAddress {
- fn from(value: VirtualMemoryAddress) -> Self {
- MemoryAddress::Virtual(value)
- }
-}
-
-impl From<PhysicalMemoryAddress> for MemoryAddress {
- fn from(value: PhysicalMemoryAddress) -> Self {
- MemoryAddress::Physical(value)
- }
-}
-
-impl From<MemoryAddress> for usize {
- fn from(value: MemoryAddress) -> Self {
- match value {
- MemoryAddress::Virtual(v) => *v,
- MemoryAddress::Physical(p) => *p,
- }
- }
-}
-
-impl From<MemoryAddress> for VirtualMemoryAddress {
- fn from(value: MemoryAddress) -> Self {
- match value {
- MemoryAddress::Virtual(v) => v,
- MemoryAddress::Physical(p) => p.into(),
- }
- }
-}
-
-impl From<MemoryAddress> for PhysicalMemoryAddress {
- fn from(value: MemoryAddress) -> Self {
- match value {
- MemoryAddress::Virtual(v) => v.into(),
- MemoryAddress::Physical(p) => p,
- }
- }
+pub fn init(kernel_virtual_base: PhysicalMemoryAddress) {
+ addr::init(kernel_virtual_base);
}