From b631d71c7ca7e59cf4d0450a8809944d8a942129 Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Fri, 7 Feb 2025 19:45:35 +0700 Subject: [PATCH] Initializes vm_page_alloc --- kernel/src/main.rs | 1 + kernel/src/uma/aarch64.rs | 3 +++ kernel/src/uma/keg.rs | 24 +++++++++++++++++++++--- kernel/src/uma/mod.rs | 3 +++ kernel/src/uma/x86_64.rs | 14 ++++++++++++++ kernel/src/vm/mod.rs | 9 +++++++++ 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 kernel/src/uma/aarch64.rs create mode 100644 kernel/src/uma/x86_64.rs create mode 100644 kernel/src/vm/mod.rs diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 1afff83f3..315d205dd 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -27,6 +27,7 @@ mod signal; mod subsystem; mod trap; mod uma; +mod vm; extern crate alloc; diff --git a/kernel/src/uma/aarch64.rs b/kernel/src/uma/aarch64.rs new file mode 100644 index 000000000..409d98107 --- /dev/null +++ b/kernel/src/uma/aarch64.rs @@ -0,0 +1,3 @@ +pub fn small_alloc() { + todo!() +} diff --git a/kernel/src/uma/keg.rs b/kernel/src/uma/keg.rs index 5ac8b5ffb..ef8291857 100644 --- a/kernel/src/uma/keg.rs +++ b/kernel/src/uma/keg.rs @@ -1,3 +1,4 @@ +use super::arch::small_alloc; use super::slab::{Free, RcFree, Slab}; use super::{Alloc, Uma, UmaFlags, UmaZone}; use crate::config::{PAGE_MASK, PAGE_SHIFT, PAGE_SIZE}; @@ -9,6 +10,7 @@ use core::num::NonZero; pub struct UmaKeg { size: NonZero, // uk_size ipers: usize, // uk_ipers + alloc: fn(), // uk_allocf max_pages: u32, // uk_maxpages pages: u32, // uk_pages free: u32, // uk_free @@ -132,9 +134,13 @@ impl UmaKeg { } } - if ppera == 1 { - // TODO: Set uk_allocf and uk_freef. - } + // Get allocator. + let alloc = if ppera == 1 { + // TODO: Get uk_freef. + small_alloc + } else { + Self::page_alloc + }; if flags.has(UmaFlags::MtxClass) { todo!() @@ -159,6 +165,7 @@ impl UmaKeg { Self { size, ipers, + alloc, max_pages: 0, pages: 0, free: 0, @@ -220,7 +227,18 @@ impl UmaKeg { if self.flags.has(UmaFlags::Offpage) { todo!() } else { + (self.alloc)(); todo!() } } + + /// See `page_alloc` on the Orbis for a reference. + /// + /// # Reference offsets + /// | Version | Offset | + /// |---------|--------| + /// |PS4 11.00|0x1402F0| + fn page_alloc() { + todo!() + } } diff --git a/kernel/src/uma/mod.rs b/kernel/src/uma/mod.rs index 107b36118..0400dbaf7 100644 --- a/kernel/src/uma/mod.rs +++ b/kernel/src/uma/mod.rs @@ -12,6 +12,9 @@ use core::num::NonZero; use core::sync::atomic::AtomicBool; use macros::bitflag; +#[cfg_attr(target_arch = "aarch64", path = "aarch64.rs")] +#[cfg_attr(target_arch = "x86_64", path = "x86_64.rs")] +mod arch; mod boxed; mod bucket; mod keg; diff --git a/kernel/src/uma/x86_64.rs b/kernel/src/uma/x86_64.rs new file mode 100644 index 000000000..ea60085f1 --- /dev/null +++ b/kernel/src/uma/x86_64.rs @@ -0,0 +1,14 @@ +use crate::vm::alloc_page; + +/// See `uma_small_alloc` on the Orbis for a reference. +/// +/// # Reference offsets +/// | Version | Offset | +/// |---------|--------| +/// |PS4 11.00|0x22FD70| +pub fn small_alloc() { + // TODO: There are an increment on an unknown variable on the Orbis. + alloc_page(); + + todo!() +} diff --git a/kernel/src/vm/mod.rs b/kernel/src/vm/mod.rs new file mode 100644 index 000000000..0d58f0705 --- /dev/null +++ b/kernel/src/vm/mod.rs @@ -0,0 +1,9 @@ +/// See `vm_page_alloc` on the Orbis for a reference. +/// +/// # Reference offsets +/// | Version | Offset | +/// |---------|--------| +/// |PS4 11.00|0x02B030| +pub fn alloc_page() { + todo!() +}