mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
Add basic description for frame allocator methods
This commit is contained in:
@@ -43,27 +43,33 @@ impl AreaFrameAllocator {
|
||||
|
||||
impl FrameAllocator for AreaFrameAllocator {
|
||||
fn allocate_frame(&mut self) -> Option<Frame> {
|
||||
match self.current_area {
|
||||
None => None,
|
||||
Some(area) => {
|
||||
let frame = self.next_free_frame;
|
||||
let current_area_last_frame = {
|
||||
let address = area.base_addr + area.length - 1;
|
||||
Frame::containing_address(address as usize)
|
||||
};
|
||||
if let Some(area) = self.current_area {
|
||||
let frame = self.next_free_frame;
|
||||
|
||||
if frame > current_area_last_frame {
|
||||
self.choose_next_area()
|
||||
} else if frame >= self.kernel_start && frame <= self.kernel_end {
|
||||
self.next_free_frame = Frame{ number: self.kernel_end.number + 1 }
|
||||
} else if frame >= self.multiboot_start && frame <= self.multiboot_end {
|
||||
self.next_free_frame = Frame{ number: self.multiboot_end.number + 1 }
|
||||
} else {
|
||||
self.next_free_frame.number += 1;
|
||||
return Some(frame);
|
||||
}
|
||||
self.allocate_frame()
|
||||
// the last frame of the current area
|
||||
let current_area_last_frame = {
|
||||
let address = area.base_addr + area.length - 1;
|
||||
Frame::containing_address(address as usize)
|
||||
};
|
||||
|
||||
if frame > current_area_last_frame {
|
||||
// all frames of current area are used, switch to next area
|
||||
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 };
|
||||
} 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 };
|
||||
} else {
|
||||
// frame is unused, increment `next_free_frame` and return it
|
||||
self.next_free_frame.number += 1;
|
||||
return Some(frame);
|
||||
}
|
||||
// `frame` was not valid, try it again with the updated `next_free_frame`
|
||||
self.allocate_frame()
|
||||
} else {
|
||||
None // no free frames left
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user