2022-01-16 19:42:11 -06:00
|
|
|
use crate::arch::drivers::allocator;
|
2021-11-28 14:50:14 -06:00
|
|
|
use bootloader::{entry_point, BootInfo};
|
2021-11-23 06:01:42 -06:00
|
|
|
use x86_64::{
|
|
|
|
instructions::hlt,
|
|
|
|
{structures::paging::Page, VirtAddr},
|
|
|
|
};
|
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub mod drivers;
|
|
|
|
pub mod gdt;
|
|
|
|
pub mod init;
|
|
|
|
pub mod interrupts;
|
2021-11-22 03:51:11 -06:00
|
|
|
pub mod memory;
|
2021-11-23 06:01:42 -06:00
|
|
|
|
|
|
|
entry_point![start];
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn start(boot_info: &'static BootInfo) -> ! {
|
|
|
|
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 { memory::BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
2022-01-13 08:54:33 -06:00
|
|
|
if false {
|
|
|
|
let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000));
|
|
|
|
memory::create_example_mapping(page, &mut mapper, &mut frame_allocator);
|
2021-11-23 06:01:42 -06:00
|
|
|
|
2022-01-13 08:54:33 -06:00
|
|
|
let page_ptr: *mut u64 = page.start_address().as_mut_ptr();
|
|
|
|
unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) };
|
|
|
|
}
|
2021-11-23 06:01:42 -06:00
|
|
|
|
2021-11-28 14:50:14 -06:00
|
|
|
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
|
2022-01-13 08:54:33 -06:00
|
|
|
// info!("{:?}", boot_info);
|
2021-11-23 06:01:42 -06:00
|
|
|
crate::kmain::kernel_main();
|
|
|
|
}
|
2021-11-16 00:09:27 -06:00
|
|
|
|
|
|
|
#[allow(unused)]
|
|
|
|
pub fn shutdown() -> ! {
|
2022-01-13 08:54:33 -06:00
|
|
|
info!("Shutting down");
|
2021-11-17 08:42:54 -06:00
|
|
|
unsafe {
|
|
|
|
cpuio::outw(0x2000, 0x604);
|
|
|
|
}
|
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
sloop();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sloop() -> ! {
|
|
|
|
loop {
|
|
|
|
hlt();
|
|
|
|
}
|
|
|
|
}
|