Skip to content

Commit

Permalink
Initializes keg_ctor (#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Jan 9, 2025
1 parent e210f6f commit 21bef49
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion kernel/src/malloc/stage2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Stage2 {
let zone = Arc::new(uma.create_zone(
size.to_string(),
size,
align - 1,
Some(align - 1),
UmaFlags::new().with_malloc(true),
));

Expand Down
15 changes: 15 additions & 0 deletions kernel/src/uma/keg.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
/// Implementation of `uma_keg` structure.
pub struct UmaKeg {}

impl UmaKeg {
/// See `keg_ctor` on the Orbis for a reference.
///
/// # Context safety
/// This function does not require a CPU context on **stage 1** heap.
///
/// # Reference offsets
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x13CF40|
pub(super) fn new(_: usize) -> Self {
todo!()
}
}
16 changes: 10 additions & 6 deletions kernel/src/uma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Uma {
/// the CPU context due to this function can be called before context activation.
///
/// # Context safety
/// This function does not require a CPU context.
/// This function does not require a CPU context on **stage 1** heap.
///
/// # Reference offsets
/// | Version | Offset |
Expand All @@ -37,14 +37,14 @@ impl Uma {
/// |PS4 11.00|0x13DC80|
pub fn create_zone(
&mut self,
_: impl Into<String>,
_: NonZero<usize>,
_: usize,
name: impl Into<String>,
size: NonZero<usize>,
align: Option<usize>,
flags: UmaFlags,
) -> UmaZone {
// The Orbis will allocate a new zone from masterzone_z. We choose to remove this since it
// does not idomatic to Rust, which mean our uma_zone itself can live on the stack.
UmaZone::new(None, flags)
UmaZone::new(name, None, size, align, flags)
}
}

Expand All @@ -59,6 +59,10 @@ pub struct UmaFlags {
__: u8,
/// `UMA_ZONE_SECONDARY`.
pub secondary: bool,
#[bits(22)]
#[bits(19)]
__: u32,
/// `UMA_ZFLAG_INTERNAL`.
pub internal: bool,
__: bool,
__: bool,
}
21 changes: 16 additions & 5 deletions kernel/src/uma/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::UmaFlags;
use crate::context::{current_thread, CpuLocal};
use crate::lock::Gutex;
use alloc::collections::VecDeque;
use alloc::string::String;
use core::cell::RefCell;
use core::num::NonZero;
use core::ops::DerefMut;
Expand All @@ -20,6 +21,8 @@ pub struct UmaZone {
}

impl UmaZone {
const ALIGN_CACHE: usize = 63; // uma_align_cache

/// See `zone_ctor` on Orbis for a reference.
///
/// # Context safety
Expand All @@ -29,14 +32,22 @@ impl UmaZone {
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x13D490|
pub(super) fn new(keg: Option<UmaKeg>, flags: UmaFlags) -> Self {
pub(super) fn new(
_: impl Into<String>,
keg: Option<UmaKeg>,
_: NonZero<usize>,
align: Option<usize>,
flags: UmaFlags,
) -> Self {
if flags.secondary() {
todo!()
} else {
match keg {
Some(_) => todo!(),
None => todo!(),
}
// We use a different approach here to make it idiomatic to Rust. On Orbis it will
// construct a keg here if it is passed from the caller. If not it will allocate a new
// keg from masterzone_k.
keg.unwrap_or_else(|| UmaKeg::new(align.unwrap_or(Self::ALIGN_CACHE)));

todo!()
}
}

Expand Down

0 comments on commit 21bef49

Please sign in to comment.