Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializes zone_ctor #1231

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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