Skip to content

Commit 2486164

Browse files
committed
Fixes
1 parent 0ba90da commit 2486164

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

src/registers/model_specific.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ impl Pat {
123123
pub const DEFAULT: [PatMemoryType; 8] = [
124124
PatMemoryType::WriteBack,
125125
PatMemoryType::WriteThrough,
126-
PatMemoryType::Uncached,
127126
PatMemoryType::Uncacheable,
127+
PatMemoryType::StrongUncacheable,
128128
PatMemoryType::WriteBack,
129129
PatMemoryType::WriteThrough,
130-
PatMemoryType::Uncached,
131130
PatMemoryType::Uncacheable,
131+
PatMemoryType::StrongUncacheable,
132132
];
133133
}
134134

@@ -185,29 +185,29 @@ bitflags! {
185185
/// Memory types used in the [PAT](Pat).
186186
#[repr(u8)]
187187
pub enum PatMemoryType {
188-
/// Disables caching.
189-
Uncacheable = 0x00,
190-
/// Uses a write combining cache policy.
188+
/// Uncacheable (UC).
189+
StrongUncacheable = 0x00,
190+
/// Uses a write combining (WC) cache policy.
191191
WriteCombining = 0x01,
192-
/// Uses a write through cache policy.
192+
/// Uses a write through (WT) cache policy.
193193
WriteThrough = 0x04,
194-
/// Uses a write protected cache policy.
194+
/// Uses a write protected (WP) cache policy.
195195
WriteProtected = 0x05,
196-
/// Uses a write back cache policy.
196+
/// Uses a write back (WB) cache policy.
197197
WriteBack = 0x06,
198-
/// Same as uncacheable, but can be overridden by MTRRs.
199-
Uncached = 0x07,
198+
/// Same as strong uncacheable, but can be overridden to be write combining by MTRRs (UC-).
199+
Uncacheable = 0x07,
200200
}
201201
impl PatMemoryType {
202202
/// Converts from bits, returning `None` if the value is invalid.
203203
pub const fn from_bits(bits: u8) -> Option<Self> {
204204
match bits {
205-
0x00 => Some(Self::Uncacheable),
205+
0x00 => Some(Self::StrongUncacheable),
206206
0x01 => Some(Self::WriteCombining),
207207
0x04 => Some(Self::WriteThrough),
208208
0x05 => Some(Self::WriteProtected),
209209
0x06 => Some(Self::WriteBack),
210-
0x07 => Some(Self::Uncached),
210+
0x07 => Some(Self::Uncacheable),
211211
_ => None,
212212
}
213213
}
@@ -701,12 +701,9 @@ mod x86_64 {
701701
/// occur. Support can be detected using the `cpuid` instruction.
702702
#[inline]
703703
pub fn read() -> [PatMemoryType; 8] {
704-
let bits = unsafe { Self::MSR.read() };
705-
let mut flags = [PatMemoryType::Uncacheable; 8];
706-
for (i, flag) in flags.iter_mut().enumerate() {
707-
*flag = PatMemoryType::from_bits((bits >> (8 * i)) as u8).unwrap();
708-
}
709-
flags
704+
unsafe { Self::MSR.read() }
705+
.to_ne_bytes()
706+
.map(|bits| PatMemoryType::from_bits(bits).unwrap())
710707
}
711708

712709
/// Writes IA32_PAT.
@@ -721,10 +718,7 @@ mod x86_64 {
721718
/// type.
722719
#[inline]
723720
pub unsafe fn write(table: [PatMemoryType; 8]) {
724-
let mut bits = 0u64;
725-
for (i, flag) in table.iter().enumerate() {
726-
bits |= (flag.bits() as u64) << (8 * i);
727-
}
721+
let bits = u64::from_ne_bytes(table.map(PatMemoryType::bits));
728722
let mut msr = Self::MSR;
729723
unsafe {
730724
msr.write(bits);

src/structures/paging/mapper/recursive_page_table.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl Mapper<Size1GiB> for RecursivePageTable<'_> {
325325
if p4_entry.flags().contains(PageTableFlags::HUGE_PAGE) {
326326
return Err(UnmapError::ParentEntryHugePage);
327327
}
328-
p4_entry.frame::<Size4KiB>().map_err(|err| match err {
328+
p4_entry.frame().map_err(|err| match err {
329329
FrameError::FrameNotPresent => UnmapError::PageNotMapped,
330330
#[allow(deprecated)]
331331
FrameError::HugeFrame => unreachable!(),
@@ -448,7 +448,7 @@ impl Mapper<Size2MiB> for RecursivePageTable<'_> {
448448
if p4_entry.flags().contains(PageTableFlags::HUGE_PAGE) {
449449
return Err(UnmapError::ParentEntryHugePage);
450450
}
451-
p4_entry.frame::<Size4KiB>().map_err(|err| match err {
451+
p4_entry.frame().map_err(|err| match err {
452452
FrameError::FrameNotPresent => UnmapError::PageNotMapped,
453453
#[allow(deprecated)]
454454
FrameError::HugeFrame => unreachable!(),
@@ -459,7 +459,7 @@ impl Mapper<Size2MiB> for RecursivePageTable<'_> {
459459
if p3_entry.flags().contains(PageTableFlags::HUGE_PAGE) {
460460
return Err(UnmapError::ParentEntryHugePage);
461461
}
462-
p3_entry.frame::<Size4KiB>().map_err(|err| match err {
462+
p3_entry.frame().map_err(|err| match err {
463463
FrameError::FrameNotPresent => UnmapError::PageNotMapped,
464464
#[allow(deprecated)]
465465
FrameError::HugeFrame => unreachable!(),
@@ -611,7 +611,7 @@ impl Mapper<Size4KiB> for RecursivePageTable<'_> {
611611
if p4_entry.flags().contains(PageTableFlags::HUGE_PAGE) {
612612
return Err(UnmapError::ParentEntryHugePage);
613613
}
614-
p4_entry.frame::<Size4KiB>().map_err(|err| match err {
614+
p4_entry.frame().map_err(|err| match err {
615615
FrameError::FrameNotPresent => UnmapError::PageNotMapped,
616616
#[allow(deprecated)]
617617
FrameError::HugeFrame => unreachable!(),
@@ -622,7 +622,7 @@ impl Mapper<Size4KiB> for RecursivePageTable<'_> {
622622
if p3_entry.flags().contains(PageTableFlags::HUGE_PAGE) {
623623
return Err(UnmapError::ParentEntryHugePage);
624624
}
625-
p3_entry.frame::<Size4KiB>().map_err(|err| match err {
625+
p3_entry.frame().map_err(|err| match err {
626626
FrameError::FrameNotPresent => UnmapError::PageNotMapped,
627627
#[allow(deprecated)]
628628
FrameError::HugeFrame => unreachable!(),
@@ -633,7 +633,7 @@ impl Mapper<Size4KiB> for RecursivePageTable<'_> {
633633
if p2_entry.flags().contains(PageTableFlags::HUGE_PAGE) {
634634
return Err(UnmapError::ParentEntryHugePage);
635635
}
636-
p2_entry.frame::<Size4KiB>().map_err(|err| match err {
636+
p2_entry.frame().map_err(|err| match err {
637637
FrameError::FrameNotPresent => UnmapError::PageNotMapped,
638638
#[allow(deprecated)]
639639
FrameError::HugeFrame => unreachable!(),

src/structures/paging/page_table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bitflags::bitflags;
1515
pub enum FrameError {
1616
/// The entry does not have the `PRESENT` flag set, so it isn't currently mapped to a frame.
1717
FrameNotPresent,
18-
#[deprecated = "`HugeFrame` is no longer returned by the `frame` method, as it can now return huge pages"]
18+
#[deprecated = "`HugeFrame` is no longer returned by the `frame` method"]
1919
/// The entry does have the `HUGE_PAGE` flag set.
2020
HugeFrame,
2121
}
@@ -64,7 +64,7 @@ impl PageTableEntry {
6464
///
6565
/// - `FrameError::FrameNotPresent` if the entry doesn't have the `PRESENT` flag set.
6666
#[inline]
67-
pub fn frame<S: PageSize>(&self) -> Result<PhysFrame<S>, FrameError> {
67+
pub fn frame(&self) -> Result<PhysFrame, FrameError> {
6868
if self.flags().contains(PageTableFlags::PRESENT) {
6969
Ok(PhysFrame::containing_address(self.addr()))
7070
} else {

0 commit comments

Comments
 (0)