diff --git a/kernel/lds/aarch64-qemu.ld b/kernel/lds/aarch64-qemu.ld index 9aa4702..dbcbacf 100644 --- a/kernel/lds/aarch64-qemu.ld +++ b/kernel/lds/aarch64-qemu.ld @@ -7,8 +7,17 @@ SECTIONS .text : { *(.text) } .data : { *(.data) } .rodata : { *(.rodata) } - .bss : { *(.bss) } + .bss : { + *(COMMON) + *(.bss .bss.*) + /* Align initial kernel heap to page boundary */ + . = ALIGN(4K); + PROVIDE(_initial_kernel_heap_start = .); + /* PROVIDE(_initial_kernel_heap_size = 1024 * 1024); */ + PROVIDE(_initial_kernel_heap_size = 1024 * 4096 * 100); + . += _initial_kernel_heap_size; + } :data . = ALIGN(8); . = . + 0x4000; LD_STACK_PTR = .; diff --git a/kernel/src/arch/aarch64/mod.rs b/kernel/src/arch/aarch64/mod.rs index 0aad2c7..a6e359c 100644 --- a/kernel/src/arch/aarch64/mod.rs +++ b/kernel/src/arch/aarch64/mod.rs @@ -1,7 +1,17 @@ -use {core::arch::asm, limine::FramebufferRequest}; - -pub mod logging; pub use logging::log; +use { + crate::{allocator, bootmodules::BootModule, kmain::kmain}, + core::arch::asm, + limine::FramebufferRequest, +}; +pub mod logging; +use limine::HhdmRequest; +extern "C" { + fn _initial_kernel_heap_start(); + fn _initial_kernel_heap_size(); +} +const INITIAL_KERNEL_HEAP_START: *mut u8 = _initial_kernel_heap_start as _; +const INITIAL_KERNEL_HEAP_SIZE: *const () = _initial_kernel_heap_size as _; pub const PAGE_SIZE: usize = 4096; @@ -20,6 +30,80 @@ unsafe extern "C" fn _kernel_start() -> ! { } } + static HDHM_REQ: HhdmRequest = HhdmRequest::new(0); + // memory::init_pt(VirtAddr::new( + // HDHM_REQ + // .get_response() + // .get() + // .expect("tried to get physical memory mapping offset from Limine") + // .offset, + // )); + allocator::init(INITIAL_KERNEL_HEAP_START, INITIAL_KERNEL_HEAP_SIZE as _); + + let bm = MOD_REQ.get_response().get(); + use limine::{KernelFileRequest, ModuleRequest}; + static KFILE_REQ: KernelFileRequest = KernelFileRequest::new(0); + static MOD_REQ: ModuleRequest = ModuleRequest::new(0); + + let mut bootmodules = alloc::vec::Vec::new(); + + if bm.is_some() { + let bm = bm.unwrap(); + for x in 0..bm.module_count { + let file = bm.modules().get(x as usize); + if file.is_some() { + let file = file.unwrap(); + let raw_bytes = core::slice::from_raw_parts( + file.base.as_ptr().expect("invalid initrd"), + file.length as usize, + ) + .to_vec(); + + let file_path = alloc::string::String::from_utf8( + file.path.to_str().unwrap().to_bytes().to_vec(), + ); + if file_path.is_err() { + panic!("invalid file path: {:?}", file_path); + } + let file_cmd = alloc::string::String::from_utf8( + file.cmdline.to_str().unwrap().to_bytes().to_vec(), + ); + if file_cmd.is_err() { + panic!("invalid module cmd: {:?}", file_cmd); + } + + log::trace!("module path: {:?}", file_path); + log::trace!("module cmd: {:?}", file_cmd); + + bootmodules.push(BootModule::new( + file_path.unwrap(), + raw_bytes, + file_cmd.unwrap(), + )); + } else { + log::error!("You should not be here"); + break; + } + } + log::info!("Boot module count: {:?}", bootmodules.len()); + assert_eq!(bm.module_count, bootmodules.len() as u64); + } + + crate::kmain::kmain( + KFILE_REQ + .get_response() + .get() + .and_then(|r| r.kernel_file.get()) + .expect("failed to get kernel file from Limine") + .cmdline + .to_str() + .map(core::ffi::CStr::to_str) + .transpose() + .expect("expected valid cmdline string") + .unwrap_or_default(), + bootmodules, + ); + spin_loop(); } @@ -34,3 +118,5 @@ pub fn hardware_random_u64() -> u64 { } pub fn register_dump() {} +#[no_mangle] +pub fn fmod() {} diff --git a/kernel/src/logger.rs b/kernel/src/logger.rs index 5f5ae65..486a368 100644 --- a/kernel/src/logger.rs +++ b/kernel/src/logger.rs @@ -4,7 +4,7 @@ use log::{Level, SetLoggerError}; pub fn init() -> Result<(), SetLoggerError> { log::set_logger(&crate::logger::Logger)?; - log::set_max_level(log::LevelFilter::Trace); + log::set_max_level(log::LevelFilter::Debug); Ok(()) }