ableos/kernel/src/kmain.rs

77 lines
2 KiB
Rust
Raw Normal View History

2023-03-30 16:43:04 -05:00
//! AbleOS Kernel Entrypoint
2023-08-22 08:52:30 -05:00
use hbvm::mem::Address;
2023-09-09 02:35:16 -05:00
use crate::{capabilities, holeybytes::ExecThread, ipc::buffer::IpcBuffer};
2023-07-08 23:22:44 -05:00
// use crate::arch::sloop;
2023-05-06 06:50:24 -05:00
use {
2023-07-08 23:22:44 -05:00
crate::{
bootmodules::{build_cmd, BootModules},
device_tree::DeviceTree,
},
alloc::format,
log::{debug, info, trace},
2023-05-06 06:50:24 -05:00
spin::{Lazy, Mutex},
2023-06-16 05:20:37 -05:00
xml::XMLElement,
2023-05-06 06:50:24 -05:00
};
2023-04-05 12:29:20 -05:00
2023-07-08 23:22:44 -05:00
pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
2023-05-25 07:04:19 -05:00
debug!("Entered kmain");
2023-03-30 16:43:04 -05:00
2023-08-22 08:52:30 -05:00
let kcmd = build_cmd("Kernel Command Line", cmdline);
trace!("Cmdline: {kcmd:?}");
2023-03-30 16:43:04 -05:00
2023-07-08 23:22:44 -05:00
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
2023-09-09 02:35:16 -05:00
// Pass CMDLine into an IPCBuffer and put the ptr to the IPCBuffer in r200
2023-07-08 23:22:44 -05:00
_bmcmd = build_cmd(name, bm.cmd.clone());
2023-04-05 12:29:20 -05:00
}
}
2023-07-08 23:22:44 -05:00
2023-05-23 05:16:14 -05:00
let dt = DEVICE_TREE.lock();
2023-04-05 12:29:20 -05:00
info!("Device Tree: {}", dt);
2023-07-08 23:22:44 -05:00
info!("Boot complete. Moving to init_system");
2023-06-25 22:34:24 -05:00
// TODO: schedule the disk driver from the initramfs
// TODO: schedule the filesystem driver from the initramfs
// TODO: Schedule the VFS from initramfs
2023-06-25 22:34:24 -05:00
// TODO: schedule the init system from the initramfs
2023-05-15 02:19:34 -05:00
2023-08-22 08:52:30 -05:00
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:?}");
}
});
}
2023-08-22 08:52:30 -05:00
executor.run();
};
2023-07-08 23:22:44 -05:00
2023-08-22 08:52:30 -05:00
crate::arch::spin_loop()
2023-03-30 16:43:04 -05:00
}
2023-04-10 01:16:30 -05:00
2023-05-06 06:50:24 -05:00
pub static DEVICE_TREE: Lazy<Mutex<DeviceTree>> = Lazy::new(|| {
2023-05-23 05:16:14 -05:00
let dt = DeviceTree::new();
2023-05-06 06:50:24 -05:00
Mutex::new(dt)
});
2023-05-15 02:19:34 -05:00
2023-09-09 02:35:16 -05:00
use alloc::vec::Vec;
pub static IPC_BUFFERS: Lazy<Mutex<Vec<IpcBuffer>>> = Lazy::new(|| {
let bufs = Vec::new();
Mutex::new(bufs)
});
2023-05-15 02:19:34 -05:00
#[test_case]
fn trivial_assertion() {
trace!("trivial assertion... ");
assert_eq!(1, 1);
info!("[ok]");
}