Skip to content

Commit

Permalink
Apply formatter on page_table
Browse files Browse the repository at this point in the history
  • Loading branch information
yodalee committed May 17, 2023
1 parent 5094a2d commit 7964af0
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/vm/page_table.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! riscv page table
use core::ops::{Index, IndexMut};
use super::page_flag::PteFlag;
use core::ops::{Index, IndexMut};

// 4096 bytes / 8 bytes per entry = 512 entries
const ENTRY_COUNT: usize = 512;
Expand All @@ -14,7 +14,7 @@ impl PageTableIndex {
/// Will crash if the input > 512
pub fn new(index: u16) -> Self {
assert!((index as usize) < ENTRY_COUNT);
Self (index)
Self(index)
}

/// Create a PageTableIndex from u16
Expand Down Expand Up @@ -42,25 +42,23 @@ impl PageTableLevel {
pub const fn next_level(self) -> Option<Self> {
match self {
PageTableLevel::Three => Some(PageTableLevel::Two),
PageTableLevel::Two => Some(PageTableLevel::One),
PageTableLevel::One => Some(PageTableLevel::Zero),
PageTableLevel::Zero => None,
PageTableLevel::Two => Some(PageTableLevel::One),
PageTableLevel::One => Some(PageTableLevel::Zero),
PageTableLevel::Zero => None,
}
}
}

#[derive(Clone,Default)]
#[derive(Clone, Default)]
pub struct PageTableEntry {
entry: u64
entry: u64,
}

impl PageTableEntry {
// Create empty page table entry
#[inline]
pub const fn new() -> Self {
Self {
entry: 0
}
Self { entry: 0 }
}

// true if page is zero (unused)
Expand Down Expand Up @@ -92,7 +90,7 @@ impl PageTableEntry {
}

pub struct PageTable {
entries: [PageTableEntry;ENTRY_COUNT]
entries: [PageTableEntry; ENTRY_COUNT],
}

impl PageTable {
Expand All @@ -101,7 +99,7 @@ impl PageTable {
pub const fn new() -> Self {
const EMPTY: PageTableEntry = PageTableEntry::new();
Self {
entries: [EMPTY;ENTRY_COUNT]
entries: [EMPTY; ENTRY_COUNT],
}
}
}
Expand Down

0 comments on commit 7964af0

Please sign in to comment.