From 0249353a6b84bd63771a24b6646aca11007c24af Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 8 Dec 2022 22:21:21 +0100 Subject: [PATCH] Added kernel cmdline support and retrieval of initrd --- base/boot/{initramfs.tar => initrd.tar} | Bin base/boot/limine.cfg | 2 +- kernel/src/arch/x86_64/mod.rs | 26 ++++++++++++++++++++++-- kernel/src/kmain.rs | 7 +++++-- kernel/src/lib.rs | 11 +++++----- 5 files changed, 36 insertions(+), 10 deletions(-) rename base/boot/{initramfs.tar => initrd.tar} (100%) diff --git a/base/boot/initramfs.tar b/base/boot/initrd.tar similarity index 100% rename from base/boot/initramfs.tar rename to base/boot/initrd.tar diff --git a/base/boot/limine.cfg b/base/boot/limine.cfg index f058d07..a26657e 100644 --- a/base/boot/limine.cfg +++ b/base/boot/limine.cfg @@ -18,5 +18,5 @@ TERM_BACKDROP=008080 # Setting a default resolution for the framebuffer RESOLUTION=800x600x24 - MODULE_PATH=boot:///boot/initramfs.tar + MODULE_PATH=boot:///boot/initrd.tar MODULE_CMDLINE=This is the first module. diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index b5a6cce..f094ed0 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -1,4 +1,4 @@ -use limine::{LimineHhdmRequest, LimineMmapRequest}; +use limine::{LimineHhdmRequest, LimineKernelFileRequest, LimineMmapRequest, LimineModuleRequest}; use spin::Mutex; use uart_16550::SerialPort; use x86_64::VirtAddr; @@ -14,6 +14,8 @@ static SERIAL_CONSOLE: Mutex = Mutex::new(unsafe { SerialPort::new(0 unsafe extern "C" fn _kernel_start() -> ! { static HDHM_REQ: LimineHhdmRequest = LimineHhdmRequest::new(0); static MMAP_REQ: LimineMmapRequest = LimineMmapRequest::new(0); + static KFILE_REQ: LimineKernelFileRequest = LimineKernelFileRequest::new(0); + static MOD_REQ: LimineModuleRequest = LimineModuleRequest::new(0); SERIAL_CONSOLE.lock().init(); crate::logger::init().expect("failed to set logger"); @@ -39,7 +41,27 @@ unsafe extern "C" fn _kernel_start() -> ! { gdt::init(); interrupts::init(); - crate::kmain::kmain() + 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_string() + .unwrap_or_default(), + MOD_REQ + .get_response() + .get() + .and_then(|r| r.modules()) + .and_then(|m| m.get(0)) + .map(|file| unsafe { + core::slice::from_raw_parts( + file.base.as_ptr().expect("invalid initrd"), + file.length as usize, + ) + }), + ) } /// Format args to serial console diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index b898fb8..a61ebef 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -1,6 +1,9 @@ //! AbleOS Kernel Entrypoint -pub fn kmain() -> ! { - log::trace!("Entered kmain"); +pub fn kmain(cmdline: &str, initrd: Option<&'static [u8]>) -> ! { + log::debug!("Entered kmain"); + log::info!("Cmdline: \"{cmdline}\""); + let initrd = initrd.expect("no initrd found"); + crate::arch::sloop() } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index cb20735..3862e44 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -10,11 +10,12 @@ extern crate alloc; -pub mod allocator; -pub mod arch; -pub mod kmain; -pub mod logger; -pub mod task; +mod allocator; +mod arch; +mod kmain; +mod logger; +mod syscalls; +mod task; use versioning::Version;