mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Return a memory controller from memory::init
This commit is contained in:
@@ -11,8 +11,7 @@ mod stack_allocator;
|
|||||||
|
|
||||||
pub const PAGE_SIZE: usize = 4096;
|
pub const PAGE_SIZE: usize = 4096;
|
||||||
|
|
||||||
|
pub fn init(boot_info: &BootInformation) -> MemoryController {
|
||||||
pub fn init(boot_info: &BootInformation) {
|
|
||||||
assert_has_not_been_called!("memory::init must be called only once");
|
assert_has_not_been_called!("memory::init must be called only once");
|
||||||
|
|
||||||
let memory_map_tag = boot_info.memory_map_tag().expect(
|
let memory_map_tag = boot_info.memory_map_tag().expect(
|
||||||
@@ -50,6 +49,20 @@ pub fn init(boot_info: &BootInformation) {
|
|||||||
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
||||||
active_table.map(page, paging::WRITABLE, &mut frame_allocator);
|
active_table.map(page, paging::WRITABLE, &mut frame_allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let stack_allocator = {
|
||||||
|
let stack_alloc_start = heap_end_page + 1;
|
||||||
|
let stack_alloc_end = stack_alloc_start + 100;
|
||||||
|
let stack_alloc_range = Page::range_inclusive(stack_alloc_start,
|
||||||
|
stack_alloc_end);
|
||||||
|
stack_allocator::StackAllocator::new(stack_alloc_range)
|
||||||
|
};
|
||||||
|
|
||||||
|
MemoryController {
|
||||||
|
active_table: active_table,
|
||||||
|
frame_allocator: frame_allocator,
|
||||||
|
stack_allocator: stack_allocator,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
pub use self::entry::*;
|
pub use self::entry::*;
|
||||||
pub use self::mapper::Mapper;
|
pub use self::mapper::Mapper;
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut, Add};
|
||||||
use core::ptr::Unique;
|
use core::ptr::Unique;
|
||||||
use memory::{PAGE_SIZE, Frame, FrameAllocator};
|
use memory::{PAGE_SIZE, Frame, FrameAllocator};
|
||||||
use multiboot2::BootInformation;
|
use multiboot2::BootInformation;
|
||||||
@@ -55,6 +55,15 @@ impl Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Add<usize> for Page {
|
||||||
|
type Output = Page;
|
||||||
|
|
||||||
|
fn add(self, rhs: usize) -> Page {
|
||||||
|
Page { number: self.number + rhs }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PageIter {
|
pub struct PageIter {
|
||||||
start: Page,
|
start: Page,
|
||||||
|
|||||||
Reference in New Issue
Block a user