rut stable, going to do some assembly now

This commit is contained in:
Jack Halford 2018-03-05 13:29:44 +01:00
parent 5412334168
commit d491624274
3 changed files with 14 additions and 9 deletions

View file

@ -19,7 +19,7 @@ bitflags! {
impl Entry {
pub fn is_unused(&self) -> bool {
self.0 == 0;
self.0 == 0
}
pub fn set_unused(&mut self) {
@ -27,21 +27,21 @@ impl Entry {
}
pub fn flags(&self) -> EntryFlags {
EntryFlags::from_bits_truncate(self.0);
EntryFlags::from_bits_truncate(self.0)
}
pub fn pointed_frame(&self) -> Option<Frame> {
if self.flags().contains(PRESENT) {
if self.flags().contains(EntryFlags::PRESENT) {
Some(Frame::containing_address(
self.0 as usize & 0x000fffff_fffff000 // actual addr is bits 12-51
))
// actual addr is bits 12-51
self.0 as usize & 0x000fffff_fffff000))
} else {
None
}
}
pub fn set(&mut self, frame: Frame, flags: EntryFlags) {
assert!!(frame.start_address() & !0x000fffff_fffff000 == 0);
assert!(frame.start_address() & !0x000fffff_fffff000 == 0);
self.0 = (frame.start_address() as u64) | flags.bits();
}
}

View file

@ -1,3 +1,6 @@
mod entry;
mod table;
use memory::PAGE_SIZE;
const ENTRY_COUNT: usize = 512;

View file

@ -8,9 +8,11 @@ pub struct Table {
}
impl Table {
pub fn zero(&mut self) {
for entry in self.entries.iter_mut() {
entry.set_unused();
}
}
}
impl Index<usize> for Table {
@ -22,7 +24,7 @@ impl Index<usize> for Table {
}
impl IndexMut<usize> for Table {
fn index(&self, index: usize) -> &mut Entry {
fn index_mut(&mut self, index: usize) -> &mut Entry {
&mut self.entries[index]
}
}