summaryrefslogtreecommitdiff
path: root/kernel/src/allocators/mod.rs
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-08-27 00:20:19 -0500
committerNathan Ringo <nathan@remexre.com>2024-08-27 00:20:19 -0500
commit251ea035fa2338db7b001af338d65875a9bc65ad (patch)
treef260a8da1b5bfef4337f06ff1567de30ad1d4c70 /kernel/src/allocators/mod.rs
parentf988949d7e57f005fba0dbc14491ed9b065c2e36 (diff)
Adds a free-list for physical memory.
Diffstat (limited to 'kernel/src/allocators/mod.rs')
-rw-r--r--kernel/src/allocators/mod.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/kernel/src/allocators/mod.rs b/kernel/src/allocators/mod.rs
index e69de29..76d85e6 100644
--- a/kernel/src/allocators/mod.rs
+++ b/kernel/src/allocators/mod.rs
@@ -0,0 +1,23 @@
+use core::{ffi::c_void, ops::Range, ptr::addr_of};
+
+pub mod physical_memory_free_list;
+
+/// The number of bits in the offset in a page.
+pub const PAGE_SIZE_BITS: usize = 12;
+
+/// The size of a page, in bytes.
+pub const PAGE_SIZE: usize = 1 << PAGE_SIZE_BITS;
+
+/// Returns the physical address range the kernel is in.
+pub fn kernel_boundaries() -> Range<usize> {
+ extern "C" {
+ static kernel_start: c_void;
+ static kernel_end: c_void;
+ }
+
+ // SAFETY: We only use these as addresses, we never dereference them.
+ let (kernel_start_addr, kernel_end_addr) =
+ unsafe { (addr_of!(kernel_start), addr_of!(kernel_end)) };
+
+ kernel_start_addr as usize..kernel_end_addr as usize
+}