mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
68 lines
1.6 KiB
Rust
68 lines
1.6 KiB
Rust
// Copyright 2015 Philipp Oppermann. See the README.md
|
|
// file at the top-level directory of this distribution.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
pub use self::area_frame_allocator::AreaFrameAllocator;
|
|
pub use self::paging::remap_the_kernel;
|
|
use self::paging::PhysicalAddress;
|
|
|
|
mod area_frame_allocator;
|
|
mod paging;
|
|
|
|
pub const PAGE_SIZE: usize = 4096;
|
|
|
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub struct Frame {
|
|
number: usize,
|
|
}
|
|
|
|
impl Frame {
|
|
fn containing_address(address: usize) -> Frame {
|
|
Frame { number: address / PAGE_SIZE }
|
|
}
|
|
|
|
fn start_address(&self) -> PhysicalAddress {
|
|
self.number * PAGE_SIZE
|
|
}
|
|
|
|
fn clone(&self) -> Frame {
|
|
Frame { number: self.number }
|
|
}
|
|
|
|
fn range_inclusive(start: Frame, end: Frame) -> FrameIter {
|
|
FrameIter {
|
|
start: start,
|
|
end: end,
|
|
}
|
|
}
|
|
}
|
|
|
|
struct FrameIter {
|
|
start: Frame,
|
|
end: Frame,
|
|
}
|
|
|
|
impl Iterator for FrameIter {
|
|
type Item = Frame;
|
|
|
|
fn next(&mut self) -> Option<Frame> {
|
|
if self.start <= self.end {
|
|
let frame = self.start.clone();
|
|
self.start.number += 1;
|
|
Some(frame)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait FrameAllocator {
|
|
fn allocate_frame(&mut self) -> Option<Frame>;
|
|
fn deallocate_frame(&mut self, frame: Frame);
|
|
}
|