Skip to content

Commit 9e38b08

Browse files
committed
style(msr): address cosmetic changes
1 parent 753388d commit 9e38b08

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/registers/model_specific.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ pub struct SCet;
7272
pub struct Pat;
7373

7474
/// IA32_APIC_BASE: status and location of the local APIC
75+
///
76+
/// IA32_APIC_BASE must be supported on the CPU, otherwise, a general protection exception will occur. Support can be detected using the `cpuid` instruction.
7577
#[derive(Debug)]
76-
pub struct Apic;
78+
pub struct ApicBase;
7779

7880
impl Efer {
7981
/// The underlying model specific register.
@@ -136,7 +138,7 @@ impl Pat {
136138
];
137139
}
138140

139-
impl Apic {
141+
impl ApicBase {
140142
/// The underlying model specific register.
141143
pub const MSR: Msr = Msr(0x1B);
142144
}
@@ -231,7 +233,7 @@ bitflags! {
231233
/// Flags for the Advanced Programmable Interrupt Controler Base Register.
232234
#[repr(transparent)]
233235
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
234-
pub struct ApicFlags: u64 {
236+
pub struct ApicBaseFlags: u64 {
235237
// bits 0 - 7 are reserved.
236238
/// Indicates whether the current processor is the bootstrap processor
237239
const BSP = 1 << 8;
@@ -754,58 +756,46 @@ mod x86_64 {
754756
}
755757
}
756758

757-
impl Apic {
758-
/// Reads the IA32_APIC_BASE.
759-
///
760-
/// The APIC_BASE must be supported on the CPU, otherwise a general protection exception will
761-
/// occur. Support can be detected using the `cpuid` instruction.
759+
impl ApicBase {
760+
/// Reads the IA32_APIC_BASE MSR.
762761
#[inline]
763-
pub fn read() -> (PhysFrame, ApicFlags) {
762+
pub fn read() -> (PhysFrame, ApicBaseFlags) {
764763
let (frame, flags) = Self::read_raw();
765-
(frame, ApicFlags::from_bits_truncate(flags))
764+
(frame, ApicBaseFlags::from_bits_truncate(flags))
766765
}
767766

768-
/// Reads the raw IA32_APIC_BASE.
769-
///
770-
/// The APIC_BASE must be supported on the CPU, otherwise a general protection exception will
771-
/// occur. Support can be detected using the `cpuid` instruction.
767+
/// Reads the raw IA32_APIC_BASE MSR.
772768
#[inline]
773769
pub fn read_raw() -> (PhysFrame, u64) {
774770
let raw = unsafe { Self::MSR.read() };
775-
// extract bits 32 - 51 (incl.)
776-
let addr = PhysAddr::new(raw & 0x_000F_FFFF_FFFF_F000);
771+
// extract bits 12 - 51 (incl.)
772+
let addr = PhysAddr::new_truncate(raw);
777773
let frame = PhysFrame::containing_address(addr);
778774
(frame, raw)
779775
}
780776

781-
/// Writes the IA32_APIC_BASE preserving reserved values.
777+
/// Writes the IA32_APIC_BASE MSR preserving reserved values.
782778
///
783779
/// Preserves the value of reserved fields.
784780
///
785-
/// The APIC_BASE must be supported on the CPU, otherwise a general protection exception will
786-
/// occur. Support can be detected using the `cpuid` instruction.
787-
///
788781
/// ## Safety
789782
///
790783
/// Unsafe because changing the APIC base address allows hijacking a page of physical memory space in ways that would violate Rust's memory rules.
791784
#[inline]
792-
pub unsafe fn write(frame: PhysFrame, flags: ApicFlags) {
785+
pub unsafe fn write(frame: PhysFrame, flags: ApicBaseFlags) {
793786
let (_, old_flags) = Self::read_raw();
794-
let reserved = old_flags & !(ApicFlags::all().bits());
787+
let reserved = old_flags & !(ApicBaseFlags::all().bits());
795788
let new_flags = reserved | flags.bits();
796789

797790
unsafe {
798791
Self::write_raw(frame, new_flags);
799792
}
800793
}
801794

802-
/// Writes the IA32_APIC_BASE flags.
795+
/// Writes the IA32_APIC_BASE MSR flags.
803796
///
804797
/// Does not preserve any bits, including reserved fields.
805798
///
806-
/// The APIC_BASE must be supported on the CPU, otherwise a general protection exception will
807-
/// occur. Support can be detected using the `cpuid` instruction.
808-
///
809799
/// ## Safety
810800
///
811801
/// Unsafe because it's possible to set reserved bits to `1` and changing the APIC base address allows hijacking a page of physical memory space in ways that would violate Rust's memory rules.

0 commit comments

Comments
 (0)