|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
pub use self::area_frame_allocator::AreaFrameAllocator;
|
|
|
|
|
pub use self::paging::remap_the_kernel;
|
|
|
|
|
pub use self::stack_allocator::Stack;
|
|
|
|
|
use self::paging::PhysicalAddress;
|
|
|
|
|
use self::paging::{PhysicalAddress, FromToVirtualAddress};
|
|
|
|
|
use multiboot2::BootInformation;
|
|
|
|
|
use consts::KERNEL_OFFSET;
|
|
|
|
|
|
|
|
|
@ -20,26 +20,28 @@ pub fn init(boot_info: &BootInformation) -> MemoryController {
|
|
|
|
|
let elf_sections_tag = boot_info.elf_sections_tag().expect(
|
|
|
|
|
"Elf sections tag required");
|
|
|
|
|
|
|
|
|
|
let kernel_start = elf_sections_tag.sections()
|
|
|
|
|
.filter(|s| s.is_allocated()).map(|s| s.start_address()).min().unwrap() as usize;
|
|
|
|
|
let kernel_end = elf_sections_tag.sections()
|
|
|
|
|
.filter(|s| s.is_allocated()).map(|s| s.end_address()).max().unwrap() as usize
|
|
|
|
|
- KERNEL_OFFSET;
|
|
|
|
|
let kernel_start = PhysicalAddress(elf_sections_tag.sections()
|
|
|
|
|
.filter(|s| s.is_allocated()).map(|s| s.start_address()).min().unwrap() as u64);
|
|
|
|
|
let kernel_end = PhysicalAddress::from_kernel_virtual(elf_sections_tag.sections()
|
|
|
|
|
.filter(|s| s.is_allocated()).map(|s| s.end_address()).max().unwrap());
|
|
|
|
|
|
|
|
|
|
let boot_info_start = PhysicalAddress(boot_info.start_address() as u64);
|
|
|
|
|
let boot_info_end = PhysicalAddress(boot_info.end_address() as u64);
|
|
|
|
|
|
|
|
|
|
println!("kernel start: {:#x}, kernel end: {:#x}",
|
|
|
|
|
kernel_start,
|
|
|
|
|
kernel_end);
|
|
|
|
|
println!("multiboot start: {:#x}, multiboot end: {:#x}",
|
|
|
|
|
boot_info.start_address(),
|
|
|
|
|
boot_info.end_address());
|
|
|
|
|
boot_info_start,
|
|
|
|
|
boot_info_end);
|
|
|
|
|
println!("memory area:");
|
|
|
|
|
for area in memory_map_tag.memory_areas() {
|
|
|
|
|
println!(" addr: {:#x}, size: {:#x}", area.base_addr, area.length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut frame_allocator = AreaFrameAllocator::new(
|
|
|
|
|
kernel_start, kernel_end,
|
|
|
|
|
boot_info.start_address(), boot_info.end_address(),
|
|
|
|
|
boot_info_start, boot_info_end,
|
|
|
|
|
memory_map_tag.memory_areas());
|
|
|
|
|
|
|
|
|
|
let mut active_table = paging::remap_the_kernel(&mut frame_allocator,
|
|
|
|
@ -48,10 +50,10 @@ pub fn init(boot_info: &BootInformation) -> MemoryController {
|
|
|
|
|
println!("{:?}", active_table);
|
|
|
|
|
|
|
|
|
|
use self::paging::Page;
|
|
|
|
|
use {HEAP_START, HEAP_SIZE};
|
|
|
|
|
use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE};
|
|
|
|
|
|
|
|
|
|
let heap_start_page = Page::containing_address(HEAP_START);
|
|
|
|
|
let heap_end_page = Page::containing_address(HEAP_START + HEAP_SIZE-1);
|
|
|
|
|
let heap_start_page = Page::containing_address(KERNEL_HEAP_OFFSET);
|
|
|
|
|
let heap_end_page = Page::containing_address(KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE-1);
|
|
|
|
|
|
|
|
|
|
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
|
|
|
|
active_table.map(page, paging::WRITABLE, &mut frame_allocator);
|
|
|
|
@ -64,7 +66,7 @@ pub fn init(boot_info: &BootInformation) -> MemoryController {
|
|
|
|
|
stack_alloc_end);
|
|
|
|
|
stack_allocator::StackAllocator::new(stack_alloc_range)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MemoryController {
|
|
|
|
|
active_table: active_table,
|
|
|
|
|
frame_allocator: frame_allocator,
|
|
|
|
|