Skip to content

Commit

Permalink
Initializes zone_ctor (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Jan 7, 2025
1 parent ab581d0 commit d802635
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ members = [
"src/obconf",
"src/tls",
]
default-members = ["gui"]

[profile.dev]
panic = "abort"
Expand Down
16 changes: 13 additions & 3 deletions kernel/src/malloc/stage2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::config::PAGE_SIZE;
use crate::context::{current_thread, CpuLocal};
use crate::uma::{Uma, UmaZone};
use crate::uma::{Uma, UmaFlags, UmaZone};
use alloc::string::ToString;
use alloc::sync::Arc;
use alloc::vec::Vec;
Expand All @@ -23,7 +23,12 @@ impl Stage2 {
const KMEM_ZMASK: usize = Self::KMEM_ZBASE - 1;
const KMEM_ZSIZE: usize = PAGE_SIZE.get() >> Self::KMEM_ZSHIFT;

/// See `kmeminit` on the PS4 for a reference.
/// See `kmeminit` on the Orbis for a reference.
///
/// # Reference offsets
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x1A4B80|
pub fn new(uma: &mut Uma) -> Self {
// The possible of maximum alignment that Layout allowed is a bit before the most
// significant bit of isize (e.g. 0x4000000000000000 on 64 bit system). So we can use
Expand All @@ -46,7 +51,12 @@ impl Stage2 {
}

// Create zone.
let zone = Arc::new(uma.create_zone(size.to_string().into(), size, align - 1));
let zone = Arc::new(uma.create_zone(
size.to_string().into(),
size,
align - 1,
UmaFlags::new().with_malloc(true),
));

while last <= size.get() {
zones.push(zone.clone());
Expand Down
38 changes: 34 additions & 4 deletions kernel/src/uma/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub use self::zone::*;
use alloc::borrow::Cow;
use bitfield_struct::bitfield;
use core::num::NonZero;

mod bucket;
Expand All @@ -9,20 +10,49 @@ mod zone;
pub struct Uma {}

impl Uma {
/// See `uma_startup` on the PS4 for a reference. Beware that our implementation cannot access
/// See `uma_startup` on the Orbis for a reference. Beware that our implementation cannot access
/// the CPU context due to this function can be called before context activation.
///
/// # Context safety
/// This function does not require a CPU context.
///
/// # Reference offsets
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x13CA70|
pub fn new() -> Self {
Self {}
}

/// See `uma_zcreate` on the PS4 for a reference.
/// See `uma_zcreate` on the Orbis for a reference.
///
/// # Context safety
/// This function does not require a CPU context on **stage 1** heap.
pub fn create_zone(&mut self, _: Cow<'static, str>, _: NonZero<usize>, _: usize) -> UmaZone {
todo!()
///
/// # Reference offsets
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x13DC80|
pub fn create_zone(
&mut self,
_: Cow<'static, str>,
_: NonZero<usize>,
_: usize,
_: 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()
}
}

/// Flags for [`Uma::create_zone()`].
#[bitfield(u32)]
pub struct UmaFlags {
#[bits(4)]
__: u8,
/// `UMA_ZONE_MALLOC`.
pub malloc: bool,
#[bits(27)]
__: u32,
}
13 changes: 13 additions & 0 deletions kernel/src/uma/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ pub struct UmaZone {
}

impl UmaZone {
/// See `zone_ctor` on 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|0x13D490|
pub(super) fn new() -> Self {
todo!()
}

pub fn size(&self) -> NonZero<usize> {
self.size
}
Expand Down

0 comments on commit d802635

Please sign in to comment.