64 lines
1.5 KiB
Rust
64 lines
1.5 KiB
Rust
//! Kernel main process implementation: filesystem initialization and userspace init start
|
|
|
|
use abi::error::Error;
|
|
use alloc::borrow::ToOwned;
|
|
use kernel_fs::devfs;
|
|
use kernel_util::runtime;
|
|
use memfs::MemoryFilesystem;
|
|
use vfs::{IoContext, NodeRef};
|
|
|
|
use crate::{
|
|
device::input,
|
|
fs::{FileBlockAllocator, INITRD_DATA},
|
|
proc::{self, random},
|
|
};
|
|
|
|
fn setup_root() -> Result<NodeRef, Error> {
|
|
let initrd_data = INITRD_DATA.get();
|
|
let fs = MemoryFilesystem::<FileBlockAllocator>::from_slice(initrd_data.data).unwrap();
|
|
fs.root()
|
|
}
|
|
|
|
/// Kernel's "main" process function.
|
|
///
|
|
/// # Note
|
|
///
|
|
/// This function is meant to be used as a kernel-space process after all the platform-specific
|
|
/// initialization has finished.
|
|
pub fn kinit() -> Result<(), Error> {
|
|
infoln!("In main");
|
|
|
|
ygg_driver_net_core::start_network_tasks()?;
|
|
|
|
#[cfg(feature = "fb_console")]
|
|
{
|
|
use crate::device::display::console::update_consoles_task;
|
|
|
|
runtime::spawn(async move {
|
|
update_consoles_task().await;
|
|
})?;
|
|
}
|
|
|
|
// Add keyboard device
|
|
devfs::add_named_char_device(&input::KEYBOARD_DEVICE, "kbd".to_owned())?;
|
|
|
|
random::init();
|
|
|
|
let root = setup_root()?;
|
|
|
|
let mut ioctx = IoContext::new(root);
|
|
|
|
{
|
|
let (user_init, user_init_main) =
|
|
proc::exec::load(&mut ioctx, "/init", &["/init", "xxx"], &[])?;
|
|
|
|
let mut io = user_init.io.lock();
|
|
io.set_ioctx(ioctx);
|
|
drop(io);
|
|
|
|
user_init_main.enqueue();
|
|
}
|
|
|
|
Ok(())
|
|
}
|