Skip to content

Commit

Permalink
Initializes vm_page_alloc (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Feb 7, 2025
1 parent 9780405 commit dfea04a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod signal;
mod subsystem;
mod trap;
mod uma;
mod vm;

extern crate alloc;

Expand Down
3 changes: 3 additions & 0 deletions kernel/src/uma/aarch64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn small_alloc() {
todo!()
}
24 changes: 21 additions & 3 deletions kernel/src/uma/keg.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -9,6 +10,7 @@ use core::num::NonZero;
pub struct UmaKeg {
size: NonZero<usize>, // uk_size
ipers: usize, // uk_ipers
alloc: fn(), // uk_allocf
max_pages: u32, // uk_maxpages
pages: u32, // uk_pages
free: u32, // uk_free
Expand Down Expand Up @@ -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!()
Expand All @@ -159,6 +165,7 @@ impl UmaKeg {
Self {
size,
ipers,
alloc,
max_pages: 0,
pages: 0,
free: 0,
Expand Down Expand Up @@ -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!()
}
}
3 changes: 3 additions & 0 deletions kernel/src/uma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions kernel/src/uma/x86_64.rs
Original file line number Diff line number Diff line change
@@ -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!()
}
9 changes: 9 additions & 0 deletions kernel/src/vm/mod.rs
Original file line number Diff line number Diff line change
@@ -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!()
}

0 comments on commit dfea04a

Please sign in to comment.