Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ fn panic(_info: &PanicInfo) -> ! {
// entry point for kernel
entry_point!(kernel_main);
fn kernel_main(boot_info: &'static BootInfo) -> ! {
use kernel::memory::BootInfoFrameAllocator;
use kernel::{allocator, memory};
use x86_64::VirtAddr;
use kernel::allocator;
use kernel::memory::MapperFrameAllocaterInfo;

println!("Hello World{}", "!");
kernel::init();

let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
let mut mapper = unsafe { memory::init(phys_mem_offset) };
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };

allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
let mut mapper_frame_allocator = unsafe { MapperFrameAllocaterInfo::init(boot_info) };
allocator::init_heap(
&mut mapper_frame_allocator.mapper,
&mut mapper_frame_allocator.frame_allocator,
)
.expect("heap initialization failed");
// unsafe {
// syscalls::init_syscalls();
// }
Expand Down
16 changes: 15 additions & 1 deletion kernel/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn create_example_mapping(
map_to_result.expect("map_to failed").flush();
}

use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
use bootloader::bootinfo::{BootInfo, MemoryMap, MemoryRegionType};

pub struct BootInfoFrameAllocator {
memory_map: &'static MemoryMap,
Expand Down Expand Up @@ -71,3 +71,17 @@ unsafe impl FrameAllocator<Size4KiB> for BootInfoFrameAllocator {
frame
}
}

pub struct MapperFrameAllocaterInfo<'a> {
pub mapper: OffsetPageTable<'a>,
pub frame_allocator: BootInfoFrameAllocator,
}

impl MapperFrameAllocaterInfo<'_> {
pub unsafe fn init(boot_info: &'static BootInfo) -> Self {
MapperFrameAllocaterInfo {
mapper: unsafe { init(VirtAddr::new(boot_info.physical_memory_offset)) },
frame_allocator: unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) },
}
}
}