mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Map the heap pages to physical frames
This commit is contained in:
@@ -36,7 +36,18 @@ pub fn init(boot_info: &BootInformation) {
|
|||||||
boot_info.start_address(), boot_info.end_address(),
|
boot_info.start_address(), boot_info.end_address(),
|
||||||
memory_map_tag.memory_areas());
|
memory_map_tag.memory_areas());
|
||||||
|
|
||||||
paging::remap_the_kernel(&mut frame_allocator, boot_info);
|
let mut active_table = paging::remap_the_kernel(&mut frame_allocator,
|
||||||
|
boot_info);
|
||||||
|
|
||||||
|
use self::paging::Page;
|
||||||
|
use {HEAP_START, HEAP_SIZE};
|
||||||
|
|
||||||
|
let heap_start_page = Page::containing_address(HEAP_START);
|
||||||
|
let heap_end_page = Page::containing_address(HEAP_START + HEAP_SIZE-1);
|
||||||
|
|
||||||
|
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
||||||
|
active_table.map(page, paging::WRITABLE, &mut frame_allocator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const ENTRY_COUNT: usize = 512;
|
|||||||
pub type PhysicalAddress = usize;
|
pub type PhysicalAddress = usize;
|
||||||
pub type VirtualAddress = usize;
|
pub type VirtualAddress = usize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
number: usize,
|
number: usize,
|
||||||
}
|
}
|
||||||
@@ -46,6 +46,32 @@ impl Page {
|
|||||||
fn p1_index(&self) -> usize {
|
fn p1_index(&self) -> usize {
|
||||||
(self.number >> 0) & 0o777
|
(self.number >> 0) & 0o777
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn range_inclusive(start: Page, end: Page) -> PageIter {
|
||||||
|
PageIter {
|
||||||
|
start: start,
|
||||||
|
end: end,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PageIter {
|
||||||
|
start: Page,
|
||||||
|
end: Page,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for PageIter {
|
||||||
|
type Item = Page;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Page> {
|
||||||
|
if self.start <= self.end {
|
||||||
|
let page = self.start;
|
||||||
|
self.start.number += 1;
|
||||||
|
Some(page)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ActivePageTable {
|
pub struct ActivePageTable {
|
||||||
@@ -145,6 +171,7 @@ impl InactivePageTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
|
pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
|
||||||
|
-> ActivePageTable
|
||||||
where A: FrameAllocator
|
where A: FrameAllocator
|
||||||
{
|
{
|
||||||
let mut temporary_page = TemporaryPage::new(Page { number: 0xcafebabe },
|
let mut temporary_page = TemporaryPage::new(Page { number: 0xcafebabe },
|
||||||
@@ -203,4 +230,6 @@ pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
|
|||||||
);
|
);
|
||||||
active_table.unmap(old_p4_page, allocator);
|
active_table.unmap(old_p4_page, allocator);
|
||||||
println!("guard page at {:#x}", old_p4_page.start_address());
|
println!("guard page at {:#x}", old_p4_page.start_address());
|
||||||
|
|
||||||
|
active_table
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user