From 68caeb67f1acca5077f1cc92f20d2826237efa67 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 18 Sep 2017 22:37:03 -0500 Subject: [PATCH] memory::init(): map memory for the kheap --- src/arch/x86_64/memory/mod.rs | 20 +++++++++++++++++--- src/lib.rs | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/arch/x86_64/memory/mod.rs b/src/arch/x86_64/memory/mod.rs index 23d6d05..69c6652 100644 --- a/src/arch/x86_64/memory/mod.rs +++ b/src/arch/x86_64/memory/mod.rs @@ -7,8 +7,10 @@ mod paging; use multiboot2::BootInformation; use arch::x86_64; +use ::alloca; pub use self::area_frame_allocator::AreaFrameAllocator; +use self::paging::Page; /// The physical size of each frame. pub const PAGE_SIZE: usize = 4096; @@ -88,7 +90,7 @@ pub fn init(boot_info: &BootInformation) { info!("memory areas:"); for area in memory_map_tag.memory_areas() { - info!(" start: 0x{:x}, length: 0x{:x}", + info!(" start: {:#x}, length: {:#x}", area.base_addr, area.length); } @@ -110,6 +112,18 @@ pub fn init(boot_info: &BootInformation) { x86_64::enable_nxe_bit(); // Enable NO_EXECUTE pages x86_64::enable_wrprot_bit(); // Disable writing to non-WRITABLE pages - paging::remap_kernel(&mut frame_allocator, boot_info); - info!("-- kernel remapped --"); + let mut active_table = paging::remap_kernel(&mut frame_allocator, boot_info); + info!("kernel remapped"); + + use ::alloca::{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); + + // TODO: map these pages lazily + for page in Page::range_inclusive(heap_start_page, heap_end_page) { + active_table.map(page, paging::WRITABLE, &mut frame_allocator); + } + + alloca::heap_init(HEAP_START, HEAP_SIZE); + info!("kheap: initialized"); } diff --git a/src/lib.rs b/src/lib.rs index 76c4d2c..789326d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,7 @@ pub extern fn kernel_main(multiboot_info_pointer: usize) { let boot_info = unsafe {multiboot2::load(multiboot_info_pointer)}; memory::init(boot_info); + info!("* memory::init(): success! *"); loop {} }