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

refac(hal-x86_64): move pit and tsc into time #356

Merged
merged 3 commits into from
Oct 22, 2022
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
4 changes: 1 addition & 3 deletions hal-x86_64/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use mycelium_util::bits;
pub mod entropy;
pub mod intrinsics;
mod msr;
mod tsc;
pub use self::msr::Msr;
pub use self::tsc::Rdtsc;

#[repr(transparent)]
pub struct Port {
Expand Down Expand Up @@ -246,7 +244,7 @@ impl FeatureNotSupported {
self.0
}

pub(in crate::cpu) fn new(feature_name: &'static str) -> Self {
pub(crate) fn new(feature_name: &'static str) -> Self {
Self(feature_name)
}
}
2 changes: 1 addition & 1 deletion hal-x86_64/src/cpu/entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use mycelium_util::sync::spin;
use raw_cpuid::CpuId;

#[cfg(feature = "rand_core")]
use super::Rdtsc;
use crate::time::Rdtsc;
#[cfg(feature = "rand_core")]
use mycelium_util::sync::Lazy;
#[cfg(feature = "rand_core")]
Expand Down
4 changes: 1 addition & 3 deletions hal-x86_64/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use mycelium_util::{bits, fmt};

pub mod idt;
pub mod pic;
pub mod pit;

pub use idt::Idt;
pub use pic::CascadedPic;
pub use pit::PIT;

pub type Control = &'static mut Idt;

Expand Down Expand Up @@ -227,7 +225,7 @@ impl hal_core::interrupt::Control for Idt {
use core::sync::atomic::Ordering;
// if we weren't trying to do a PIT sleep, handle the timer tick
// instead.
let was_sleeping = pit::SLEEPING
let was_sleeping = crate::time::pit::SLEEPING
.compare_exchange(true, false, Ordering::AcqRel, Ordering::Acquire)
.is_ok();
if !was_sleeping {
Expand Down
1 change: 1 addition & 0 deletions hal-x86_64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod mm;
pub mod segment;
pub mod serial;
pub mod task;
pub mod time;
pub mod vga;

pub const NAME: &str = "x86_64";
38 changes: 38 additions & 0 deletions hal-x86_64/src/time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! x86 hardware timers and timekeeping functionality.
pub(crate) mod pit;
mod tsc;
pub use self::{
pit::{Pit, PIT},
tsc::Rdtsc,
};
use core::fmt;
pub use core::time::Duration;

/// Error indicating that a [`Duration`] was invalid for a particular use.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct InvalidDuration {
duration: Duration,
message: &'static str,
}

// === impl InvalidDuration ===

impl fmt::Display for InvalidDuration {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { duration, message } = self;
write!(f, "invalid duration {duration:?}: {message}")
}
}

impl InvalidDuration {
/// Returns the [`Duration`] that was invalid.
#[must_use]
pub fn duration(self) -> Duration {
self.duration
}

#[must_use]
pub(crate) fn new(duration: Duration, message: &'static str) -> Self {
Self { duration, message }
}
}
Loading