ableos/kernel/src/kmain.rs
2023-08-22 15:52:30 +02:00

72 lines
1.7 KiB
Rust

//! AbleOS Kernel Entrypoint
use hbvm::mem::Address;
use crate::holeybytes::ExecThread;
// use crate::arch::sloop;
use {
crate::{
bootmodules::{build_cmd, BootModules},
device_tree::DeviceTree,
},
alloc::format,
log::{debug, info, trace},
spin::{Lazy, Mutex},
xml::XMLElement,
};
pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
debug!("Entered kmain");
let kcmd = build_cmd("Kernel Command Line", cmdline);
trace!("Cmdline: {kcmd:?}");
for (i, bm) in boot_modules.iter().enumerate() {
let name = format!("module-{}", i);
let _bmcmd: XMLElement;
if bm.cmd.len() >= 2 {
// TODO: pass into the program
_bmcmd = build_cmd(name, bm.cmd.clone());
}
}
let dt = DEVICE_TREE.lock();
info!("Device Tree: {}", dt);
info!("Boot complete. Moving to init_system");
// TODO: schedule the disk driver from the initramfs
// TODO: schedule the filesystem driver from the initramfs
// TODO: schedule the init system from the initramfs
// capabilities::example();
let mut executor = crate::task::Executor::default();
unsafe {
for module in boot_modules.into_iter().take(2) {
executor.spawn(async move {
if let Err(e) = ExecThread::new(&module.bytes, Address::new(4)).await {
log::error!("{e:?}");
}
});
}
executor.run();
};
crate::arch::spin_loop()
}
pub static DEVICE_TREE: Lazy<Mutex<DeviceTree>> = Lazy::new(|| {
let dt = DeviceTree::new();
Mutex::new(dt)
});
#[test_case]
fn trivial_assertion() {
trace!("trivial assertion... ");
assert_eq!(1, 1);
info!("[ok]");
}