diff --git a/kernel/src/init.rs b/kernel/src/init.rs index 694278b2f..50870ff39 100644 --- a/kernel/src/init.rs +++ b/kernel/src/init.rs @@ -5,7 +5,6 @@ use component::InitStage; use ostd::{ arch::qemu::{exit_qemu, QemuExitCode}, - boot::boot_info, cpu::CpuId, util::id_set::Id, }; @@ -145,7 +144,7 @@ fn first_kthread() { print_banner(); INIT_PROCESS.call_once(|| { - let karg: KCmdlineArg = boot_info().kernel_cmdline.as_str().into(); + let karg = KCmdlineArg::singleton(); spawn_init_process( karg.get_initproc_path().unwrap(), karg.get_initproc_argv().to_vec(), diff --git a/kernel/src/kcmdline.rs b/kernel/src/kcmdline.rs index fe9162631..8bf2e7ffe 100644 --- a/kernel/src/kcmdline.rs +++ b/kernel/src/kcmdline.rs @@ -18,6 +18,9 @@ use alloc::{ vec::Vec, }; +use ostd::boot::boot_info; +use spin::Once; + #[derive(PartialEq, Debug)] struct InitprocArgs { path: Option, @@ -38,23 +41,39 @@ pub enum ModuleArg { #[derive(Debug)] pub struct KCmdlineArg { initproc: InitprocArgs, + console_names: Vec, module_args: BTreeMap>, } // Define get APIs. impl KCmdlineArg { + /// Gets the singleton instance of `KCmdlineArg`. + pub fn singleton() -> &'static KCmdlineArg { + static INSTANCE: Once = Once::new(); + + INSTANCE.call_once(|| KCmdlineArg::from(boot_info().kernel_cmdline.as_str())) + } + /// Gets the path of the initprocess. pub fn get_initproc_path(&self) -> Option<&str> { self.initproc.path.as_deref() } + /// Gets the argument vector(argv) of the initprocess. pub fn get_initproc_argv(&self) -> &Vec { &self.initproc.argv } + /// Gets the environment vector(envp) of the initprocess. pub fn get_initproc_envp(&self) -> &Vec { &self.initproc.envp } + + /// Gets the vector of system console names specified in the command line. + pub fn get_console_names(&self) -> &Vec { + &self.console_names + } + /// Gets the argument vector of a kernel module. #[expect(dead_code)] pub fn get_module_args(&self, module: &str) -> Option<&Vec> { @@ -86,6 +105,7 @@ impl From<&str> for KCmdlineArg { argv: Vec::new(), envp: Vec::new(), }, + console_names: Vec::new(), module_args: BTreeMap::new(), }; @@ -162,6 +182,9 @@ impl From<&str> for KCmdlineArg { } result.initproc.path = Some(value.to_string()); } + "console" => { + result.console_names.push(value.to_string()); + } _ => { // If the option is not recognized, it is passed to the initproc. // Pattern 'option=value' is treated as the init environment.