Add unmap function

This commit is contained in:
Jeremy Soller
2020-09-08 19:59:13 -06:00
parent e6d93d5743
commit fb88d1669f
2 changed files with 33 additions and 0 deletions
+10
View File
@@ -228,6 +228,16 @@ unsafe fn new_tables<A: Arch>(areas: &'static [MemoryArea]) {
flush_all.consume(flush);
}
flush_all.flush();
let flush_all = PageFlushAll::new();
for i in 0..16 {
let virt = VirtualAddress::new(MEGABYTE + i * A::PAGE_SIZE);
let flush = mapper.unmap(
virt,
).expect("failed to unmap page");
flush_all.consume(flush);
}
flush_all.flush();
}
unsafe fn inner<A: Arch>() {
+23
View File
@@ -78,4 +78,27 @@ impl<'f, A: Arch, F: FrameAllocator> PageMapper<'f, A, F> {
}
}
}
pub unsafe fn unmap(&mut self, virt: VirtualAddress) -> Option<PageFlush<A>> {
let (old, flush) = self.unmap_phys(virt)?;
self.allocator.free_one(old.address());
Some(flush)
}
pub unsafe fn unmap_phys(&mut self, virt: VirtualAddress) -> Option<(PageEntry<A>, PageFlush<A>)> {
//TODO: verify virt is aligned
let mut table = self.table();
//TODO: unmap parents
loop {
let i = table.index_of(virt)?;
if table.level() == 0 {
let entry_opt = table.entry(i);
table.set_entry(i, PageEntry::new(0));
let entry = entry_opt?;
return Some((entry, PageFlush::new(virt)));
} else {
table = table.next(i)?;
}
}
}
}