mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
Run rustfmt
This commit is contained in:
@@ -17,9 +17,12 @@ pub struct AreaFrameAllocator {
|
||||
}
|
||||
|
||||
impl AreaFrameAllocator {
|
||||
pub fn new(kernel_start: usize, kernel_end: usize, multiboot_start: usize, multiboot_end: usize,
|
||||
memory_areas: MemoryAreaIter) -> AreaFrameAllocator
|
||||
{
|
||||
pub fn new(kernel_start: usize,
|
||||
kernel_end: usize,
|
||||
multiboot_start: usize,
|
||||
multiboot_end: usize,
|
||||
memory_areas: MemoryAreaIter)
|
||||
-> AreaFrameAllocator {
|
||||
let mut allocator = AreaFrameAllocator {
|
||||
next_free_frame: Frame::containing_address(0),
|
||||
current_area: None,
|
||||
@@ -34,10 +37,14 @@ impl AreaFrameAllocator {
|
||||
}
|
||||
|
||||
fn choose_next_area(&mut self) {
|
||||
self.current_area = self.areas.clone().filter(|area| {
|
||||
let address = area.base_addr + area.length - 1;
|
||||
Frame::containing_address(address as usize) >= self.next_free_frame
|
||||
}).min_by_key(|area| area.base_addr);
|
||||
self.current_area = self.areas
|
||||
.clone()
|
||||
.filter(|area| {
|
||||
let address = area.base_addr + area.length - 1;
|
||||
Frame::containing_address(address as usize) >=
|
||||
self.next_free_frame
|
||||
})
|
||||
.min_by_key(|area| area.base_addr);
|
||||
|
||||
if let Some(area) = self.current_area {
|
||||
let start_frame = Frame::containing_address(area.base_addr as usize);
|
||||
@@ -53,7 +60,7 @@ impl FrameAllocator for AreaFrameAllocator {
|
||||
if let Some(area) = self.current_area {
|
||||
// "clone" the frame to return it if it's free. Frame doesn't
|
||||
// implement Clone, but we can construct an identical frame.
|
||||
let frame = Frame{ number: self.next_free_frame.number };
|
||||
let frame = Frame { number: self.next_free_frame.number };
|
||||
|
||||
// the last frame of the current area
|
||||
let current_area_last_frame = {
|
||||
@@ -66,10 +73,10 @@ impl FrameAllocator for AreaFrameAllocator {
|
||||
self.choose_next_area();
|
||||
} else if frame >= self.kernel_start && frame <= self.kernel_end {
|
||||
// `frame` is used by the kernel
|
||||
self.next_free_frame = Frame{ number: self.kernel_end.number + 1 };
|
||||
self.next_free_frame = Frame { number: self.kernel_end.number + 1 };
|
||||
} else if frame >= self.multiboot_start && frame <= self.multiboot_end {
|
||||
// `frame` is used by the multiboot information structure
|
||||
self.next_free_frame = Frame{ number: self.multiboot_end.number + 1 };
|
||||
self.next_free_frame = Frame { number: self.multiboot_end.number + 1 };
|
||||
} else {
|
||||
// frame is unused, increment `next_free_frame` and return it
|
||||
self.next_free_frame.number += 1;
|
||||
@@ -82,5 +89,7 @@ impl FrameAllocator for AreaFrameAllocator {
|
||||
}
|
||||
}
|
||||
|
||||
fn deallocate_frame(&mut self, _frame: Frame) {unimplemented!()}
|
||||
fn deallocate_frame(&mut self, _frame: Frame) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,9 +139,9 @@ impl RecursivePageTable {
|
||||
.expect("mapping code does not support huge pages");
|
||||
let frame = p1[page.p1_index()].pointed_frame().unwrap();
|
||||
p1[page.p1_index()].set_unused();
|
||||
unsafe { ::x86::tlb::flush(page.start_address() )};
|
||||
unsafe { ::x86::tlb::flush(page.start_address()) };
|
||||
// TODO free p(1,2,3) table if empty
|
||||
//allocator.deallocate_frame(frame);
|
||||
// allocator.deallocate_frame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,9 +170,8 @@ pub fn test_paging<A>(allocator: &mut A)
|
||||
println!("next free frame: {:?}", allocator.allocate_frame());
|
||||
|
||||
// test unmap
|
||||
println!("{:#x}", unsafe {
|
||||
*(Page::containing_address(addr).start_address() as *const u64)
|
||||
});
|
||||
println!("{:#x}",
|
||||
unsafe { *(Page::containing_address(addr).start_address() as *const u64) });
|
||||
page_table.unmap(Page::containing_address(addr), allocator);
|
||||
println!("None = {:?}", page_table.translate(addr));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user