diff --git a/Cargo.toml b/Cargo.toml index 89d5bf1ff..0fab6d505 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ members = [ "src/obconf", "src/tls", ] -default-members = ["gui"] [profile.dev] panic = "abort" diff --git a/kernel/src/malloc/stage2.rs b/kernel/src/malloc/stage2.rs index 168cec577..27d3ee381 100644 --- a/kernel/src/malloc/stage2.rs +++ b/kernel/src/malloc/stage2.rs @@ -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; @@ -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 @@ -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()); diff --git a/kernel/src/uma/mod.rs b/kernel/src/uma/mod.rs index c4a93b5f9..c00c7ce44 100644 --- a/kernel/src/uma/mod.rs +++ b/kernel/src/uma/mod.rs @@ -1,5 +1,6 @@ pub use self::zone::*; use alloc::borrow::Cow; +use bitfield_struct::bitfield; use core::num::NonZero; mod bucket; @@ -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) -> UmaZone { - todo!() + /// + /// # Reference offsets + /// | Version | Offset | + /// |---------|--------| + /// |PS4 11.00|0x13DC80| + pub fn create_zone( + &mut self, + _: Cow<'static, str>, + _: NonZero, + _: 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, +} diff --git a/kernel/src/uma/zone.rs b/kernel/src/uma/zone.rs index 73d8aeb39..107ab25aa 100644 --- a/kernel/src/uma/zone.rs +++ b/kernel/src/uma/zone.rs @@ -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 { self.size }