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

expose DEBUG_STR more directly #471

Merged
merged 1 commit into from
Mar 18, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/instructions/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ impl PortWrite for u32 {
}

/// A marker trait for access types which allow accessing port values.
pub trait PortAccess: Sealed {}
pub trait PortAccess: Sealed {
/// A string representation for debug output.
const DEBUG_STR: &'static str;
}

/// A marker trait for access types which allow reading port values.
pub trait PortReadAccess: PortAccess {}
Expand All @@ -80,30 +83,30 @@ pub trait PortWriteAccess: PortAccess {}
#[derive(Debug)]
pub struct ReadOnlyAccess(());

impl Sealed for ReadOnlyAccess {
impl Sealed for ReadOnlyAccess {}
impl PortAccess for ReadOnlyAccess {
const DEBUG_STR: &'static str = "ReadOnly";
}
impl PortAccess for ReadOnlyAccess {}
impl PortReadAccess for ReadOnlyAccess {}

/// An access marker type indicating that a port is only allowed to write values.
#[derive(Debug)]
pub struct WriteOnlyAccess(());

impl Sealed for WriteOnlyAccess {
impl Sealed for WriteOnlyAccess {}
impl PortAccess for WriteOnlyAccess {
const DEBUG_STR: &'static str = "WriteOnly";
}
impl PortAccess for WriteOnlyAccess {}
impl PortWriteAccess for WriteOnlyAccess {}

/// An access marker type indicating that a port is allowed to read or write values.
#[derive(Debug)]
pub struct ReadWriteAccess(());

impl Sealed for ReadWriteAccess {
impl Sealed for ReadWriteAccess {}
impl PortAccess for ReadWriteAccess {
const DEBUG_STR: &'static str = "ReadWrite";
}
impl PortAccess for ReadWriteAccess {}
impl PortReadAccess for ReadWriteAccess {}
impl PortWriteAccess for ReadWriteAccess {}

Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,5 @@ impl PrivilegeLevel {
}

pub(crate) mod sealed {
pub trait Sealed {
/// A string representation for debug output.
const DEBUG_STR: &'static str;
}
pub trait Sealed {}
}
18 changes: 9 additions & 9 deletions src/structures/paging/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
pub trait PageSize: Copy + Eq + PartialOrd + Ord + Sealed {
/// The page size in bytes.
const SIZE: u64;

/// A string representation of the page size for debug output.
const DEBUG_STR: &'static str;
}

/// This trait is implemented for 4KiB and 2MiB pages, but not for 1GiB pages.
Expand All @@ -35,32 +38,29 @@

impl PageSize for Size4KiB {
const SIZE: u64 = 4096;
const DEBUG_STR: &'static str = "4KiB";
}

impl NotGiantPageSize for Size4KiB {}

impl Sealed for super::Size4KiB {
const DEBUG_STR: &'static str = "4KiB";
}
impl Sealed for super::Size4KiB {}

impl PageSize for Size2MiB {
const SIZE: u64 = Size4KiB::SIZE * 512;
const DEBUG_STR: &'static str = "2MiB";
}

impl NotGiantPageSize for Size2MiB {}

impl Sealed for super::Size2MiB {
const DEBUG_STR: &'static str = "2MiB";
}
impl Sealed for super::Size2MiB {}

impl PageSize for Size1GiB {
const SIZE: u64 = Size2MiB::SIZE * 512;
}

impl Sealed for super::Size1GiB {
const DEBUG_STR: &'static str = "1GiB";
}

impl Sealed for super::Size1GiB {}

/// A virtual memory page.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
Expand Down Expand Up @@ -159,13 +159,13 @@
}

// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> Option<usize> {

Check warning on line 162 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `steps_between_impl`

Check warning on line 162 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `steps_between_impl`
VirtAddr::steps_between_impl(&start.start_address, &end.start_address)
.map(|steps| steps / S::SIZE as usize)
}

// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
pub(crate) fn forward_checked_impl(start: Self, count: usize) -> Option<Self> {

Check warning on line 168 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `forward_checked_impl`

Check warning on line 168 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `forward_checked_impl`
let count = count.checked_mul(S::SIZE as usize)?;
let start_address = VirtAddr::forward_checked_impl(start.start_address, count)?;
Some(Self {
Expand Down