Browse Source

memory::init(): map memory for the kheap

master
3moon 8 years ago
parent
commit
68caeb67f1
2 changed files with 18 additions and 3 deletions
  1. +17
    -3
      src/arch/x86_64/memory/mod.rs
  2. +1
    -0
      src/lib.rs

+ 17
- 3
src/arch/x86_64/memory/mod.rs View File

@ -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");
}

+ 1
- 0
src/lib.rs View File

@ -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 {}
}


Loading…
Cancel
Save