Skip to content

Commit

Permalink
Initializes uma_keg (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Jan 8, 2025
1 parent d802635 commit e210f6f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 39 deletions.
57 changes: 27 additions & 30 deletions kernel/src/console/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::boot_env;
use anstyle::{AnsiColor, Color, Style};
use anstyle::{AnsiColor, Color, Effects, Style};
use core::fmt::{Display, Formatter};
use obconf::{BootEnv, ConsoleType};

Expand Down Expand Up @@ -30,49 +30,47 @@ macro_rules! info {
/// This function does not require a CPU context as long as [`Display`] implementation on `msg` does
/// not.
///
/// # Interupt safety
/// # Interrupt safety
/// This function is interupt safe as long as [`Display`] implementation on `msg` are interupt safe
/// (e.g. no heap allocation).
#[inline(never)]
pub fn info(file: &str, line: u32, msg: impl Display) {
print(
ConsoleType::Info,
Log {
style: Style::new().fg_color(Some(Color::Ansi(AnsiColor::BrightCyan))),
cat: 'I',
file,
line,
msg,
},
);
let msg = Log {
style: Style::new().effects(Effects::DIMMED),
cat: 'I',
file,
line,
msg,
};

print(ConsoleType::Info, msg);
}

/// # Context safety
/// This function does not require a CPU context as long as [`Display`] implementation on `msg` does
/// not.
///
/// # Interupt safety
/// # Interrupt safety
/// This function is interupt safe as long as [`Display`] implementation on `msg` are interupt safe
/// (e.g. no heap allocation).
#[inline(never)]
pub fn error(file: &str, line: u32, msg: impl Display) {
print(
ConsoleType::Error,
Log {
style: Style::new().fg_color(Some(Color::Ansi(AnsiColor::BrightRed))),
cat: 'E',
file,
line,
msg,
},
)
let msg = Log {
style: Style::new().fg_color(Some(Color::Ansi(AnsiColor::BrightRed))),
cat: 'E',
file,
line,
msg,
};

print(ConsoleType::Error, msg)
}

/// # Context safety
/// This function does not require a CPU context as long as [`Display`] implementation on `msg` does
/// not.
///
/// # Interupt safety
/// # Interrupt safety
/// This function is interupt safe as long as [`Display`] implementation on `msg` are interupt safe
/// (e.g. no heap allocation).
fn print(ty: ConsoleType, msg: impl Display) {
Expand All @@ -96,12 +94,11 @@ struct Log<'a, M: Display> {

impl<M: Display> Display for Log<'_, M> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
writeln!(
f,
"{}++++++++++++++++++ {} {}:{}{0:#}",
self.style, self.cat, self.file, self.line
)?;
self.msg.fmt(f)?;
let info = Style::new().effects(Effects::DIMMED);

writeln!(f, "{}[{}]:{0:#} {}", self.style, self.cat, self.msg)?;
write!(f, " {}{}:{}{0:#}", info, self.file, self.line)?;

Ok(())
}
}
2 changes: 1 addition & 1 deletion kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn panic(i: &PanicInfo) -> ! {
};

// Print the message.
crate::console::error(file, line, i.message());
crate::console::error(file, line, format_args!("Kernel panic - {}.", i.message()));
crate::panic::panic();
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/malloc/stage2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Stage2 {

// Create zone.
let zone = Arc::new(uma.create_zone(
size.to_string().into(),
size.to_string(),
size,
align - 1,
UmaFlags::new().with_malloc(true),
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/uma/keg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Implementation of `uma_keg` structure.
pub struct UmaKeg {}
16 changes: 11 additions & 5 deletions kernel/src/uma/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
pub use self::zone::*;
use alloc::borrow::Cow;

use alloc::string::String;
use bitfield_struct::bitfield;
use core::num::NonZero;

mod bucket;
mod keg;
mod zone;

/// Implementation of UMA system.
Expand Down Expand Up @@ -35,14 +37,14 @@ impl Uma {
/// |PS4 11.00|0x13DC80|
pub fn create_zone(
&mut self,
_: Cow<'static, str>,
_: impl Into<String>,
_: NonZero<usize>,
_: usize,
_: UmaFlags,
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()
UmaZone::new(None, flags)
}
}

Expand All @@ -53,6 +55,10 @@ pub struct UmaFlags {
__: u8,
/// `UMA_ZONE_MALLOC`.
pub malloc: bool,
#[bits(27)]
#[bits(4)]
__: u8,
/// `UMA_ZONE_SECONDARY`.
pub secondary: bool,
#[bits(22)]
__: u32,
}
13 changes: 11 additions & 2 deletions kernel/src/uma/zone.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::bucket::UmaBucket;
use super::keg::UmaKeg;
use super::UmaFlags;
use crate::context::{current_thread, CpuLocal};
use crate::lock::Gutex;
use alloc::collections::VecDeque;
Expand Down Expand Up @@ -27,8 +29,15 @@ impl UmaZone {
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x13D490|
pub(super) fn new() -> Self {
todo!()
pub(super) fn new(keg: Option<UmaKeg>, flags: UmaFlags) -> Self {
if flags.secondary() {
todo!()
} else {
match keg {
Some(_) => todo!(),
None => todo!(),
}
}
}

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

0 comments on commit e210f6f

Please sign in to comment.