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

WIP try to support hugepages #503

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
82 changes: 56 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ members = [
]
resolver = "2"

[workspace.dependencies]
thiserror = { version = "2.0.9", default_features = false }

[package]
name = "mycelium-kernel"
version = "0.0.1"
Expand Down Expand Up @@ -42,6 +45,7 @@ maitake = { path = "maitake", features = ["tracing-02"] }
mycelium-pci = { path = "pci" }
mycelium-util = { path = "util" }
mycelium-trace = { path = "trace", features = ["embedded-graphics"] }

rand_xoshiro = "0.6"
rand = { version = "0.8", default_features = false }
rlibc = "1.0"
Expand Down
10 changes: 5 additions & 5 deletions alloc/src/buddy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::{
};
use hal_core::{
mem::{
page::{self, AllocErr, PageRange, Size},
page::{self, AllocError, PageRange, Size},
Region, RegionKind,
},
Address, PAddr, VAddr,
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct Alloc<const FREE_LISTS: usize> {
free_lists: [Mutex<List<Free>>; FREE_LISTS],
}

type Result<T> = core::result::Result<T, AllocErr>;
type Result<T> = core::result::Result<T, AllocError>;

pub struct Free {
magic: usize,
Expand Down Expand Up @@ -317,7 +317,7 @@ impl<const FREE_LISTS: usize> Alloc<FREE_LISTS> {
// Find the order of the free list on which the freed range belongs.
let min_order = self.order_for(layout);
tracing::trace!(?min_order);
let min_order = min_order.ok_or_else(AllocErr::oom)?;
let min_order = min_order.ok_or_else(AllocError::oom)?;

let Some(size) = self.size_for(layout) else {
// XXX(eliza): is it better to just leak it?
Expand Down Expand Up @@ -523,7 +523,7 @@ where
// If the size of the page range would overflow, we *definitely*
// can't allocate that lol.
.checked_mul(actual_len)
.ok_or_else(AllocErr::oom)?;
.ok_or_else(AllocError::oom)?;

debug_assert!(
total_size.is_power_of_two(),
Expand All @@ -540,7 +540,7 @@ where
};

// Try to allocate the page range
let block = unsafe { self.alloc_inner(layout) }.ok_or_else(AllocErr::oom)?;
let block = unsafe { self.alloc_inner(layout) }.ok_or_else(AllocError::oom)?;

// Return the allocation!
let range = unsafe { block.as_ref() }.region().page_range(size);
Expand Down
2 changes: 2 additions & 0 deletions hal-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ version = "0.1.0"
authors = ["Eliza Weisman <[email protected]>", "iximeow <[email protected]>"]
edition = "2021"
license = "MIT"
rust-version = "1.81.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tracing = { git = "https://github.com/tokio-rs/tracing", default_features = false }
thiserror = { workspace = true }
maitake-sync = { path = "../maitake-sync", default-features = false }
mycelium-util = { path = "../util" }
embedded-graphics-core = { version = "0.3", optional = true }
16 changes: 2 additions & 14 deletions hal-core/src/addr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::{fmt, ops};
use mycelium_util::error::Error;

pub trait Address:
Copy
Expand Down Expand Up @@ -142,7 +141,8 @@ pub struct PAddr(usize);
#[repr(transparent)]
pub struct VAddr(usize);

#[derive(Clone, Debug)]
#[derive(Clone, Debug, thiserror::Error)]
#[error("invalid address {addr:#x} for target architecture: {msg}")]
pub struct InvalidAddress {
msg: &'static str,
addr: usize,
Expand Down Expand Up @@ -408,18 +408,6 @@ impl InvalidAddress {
Self { msg, addr }
}
}
impl fmt::Display for InvalidAddress {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"address {:#x} not valid for target architecture: {}",
self.addr, self.msg
)
}
}

impl Error for InvalidAddress {}

#[cfg(test)]
mod tests {
Expand Down
8 changes: 6 additions & 2 deletions hal-core/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ pub trait Handlers<R: fmt::Debug + fmt::Display> {
}

/// Errors that may occur while registering an interrupt handler.
#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq, thiserror::Error)]
#[error("{kind}")]
pub struct RegistrationError {
kind: RegistrationErrorKind,
}
Expand All @@ -78,10 +79,13 @@ pub struct CriticalGuard<'a, C: Control + ?Sized> {
ctrl: &'a mut C,
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)]
enum RegistrationErrorKind {
#[error("the provided interrupt vector does not exist")]
Nonexistant,
#[error("an interrupt handler is already registered for this vector")]
AlreadyRegistered,
#[error("{0}")]
Other(&'static str),
}

Expand Down
Loading
Loading