#![no_std] #![feature(abi_x86_interrupt)] #![warn( clippy::correctness, clippy::nursery, clippy::unnecessary_cast, clippy::all, clippy::suspicious, clippy::perf, rustdoc::missing_errors_doc, rustdoc::missing_panics_doc )] extern crate alloc; // use arch::x86_64::apic::enable_apic; use core::arch::asm; // use libk::drivers::mem::pmm; use limine::BaseRevision; // use libk::drivers::alloc::allocator::init_heap; use libk::prelude::*; mod arch; /// Sets the base revision to the latest revision supported by the crate. /// See specification for further info. /// Be sure to mark all limine requests with #[used], otherwise they may be removed by the compiler. #[used] // The .requests section allows limine to find the requests faster and more safely. #[unsafe(link_section = ".requests")] static BASE_REVISION: BaseRevision = BaseRevision::new(); #[panic_handler] fn rust_panic(_info: &core::panic::PanicInfo) -> ! { println!("Kernel panic: {}", _info); serial_println!("Kernel panic: {}", _info); hcf(); } pub fn hcf() -> ! { loop { unsafe { #[cfg(target_arch = "x86_64")] asm!("hlt"); #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] asm!("wfi"); #[cfg(target_arch = "loongarch64")] asm!("idle 0"); } } } pub fn boot() -> Result<(), &'static str> { if !BASE_REVISION.is_supported() { return Err("base revision not supported"); } use arch::x86_64::{gdt, interrupts, mem::memmap}; let _memory_map = memmap::get_memory_map(); print_log!(" Initialising Serial... "); if libk::drivers::io::serial::init().is_err() { println_log!("[Not Detected]") } else { println_log!("[Success]"); } print_log!(" Setting Up Global Descriptor Table... "); gdt::init(); println_log!("[Success]"); print_log!(" Setting Up Interrupt Descriptor Table... "); interrupts::init_idt(); println_log!("[Success]"); print_log!(" Initialising Memory Subsystem... "); // let physical_memory_offset = VirtAddr::new(*memmap::PHYSICAL_MEMORY_OFFSET); // pmm::init_page_table(physical_memory_offset); println_log!("[Success]"); print_log!(" Setting Up Page Table... "); // pmm::init_frame_allocator(memory_map); println_log!("[Success]"); print_log!(" Initialising Heap... "); // TODO: Reenable the heap. // if init_heap().is_err() { // return Err("Failed to initialise heap: error"); // } println_log!("[Success]"); print_log!(" Enabling PICs... "); interrupts::enable_pic(); println_log!("[Success]"); // print_log!(" Disabling PICs... "); // interrupts::disable_pic(); // println_log!("[Success]"); // // print_log!(" Initialising APIC"); // enable_apic(&mut l4_table, &mut frame_allocator); // println_log!("[Success]"); print_log!(" Enabling Interrupts... "); x86_64::instructions::interrupts::enable(); println_log!("[Success]"); Ok(()) }