forked from AbleOS/ableos
91 lines
2.3 KiB
Rust
91 lines
2.3 KiB
Rust
//! AbleOS Kernel Entrypoint
|
|
|
|
use {hashbrown::HashMap, hbvm::mem::Address};
|
|
|
|
use crate::{
|
|
capabilities,
|
|
holeybytes::ExecThread,
|
|
ipc::buffer::{self, IpcBuffer},
|
|
};
|
|
// 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
|
|
// Pass CMDLine into an IPCBuffer and put the ptr to the IPCBuffer in r200
|
|
_bmcmd = build_cmd(name, bm.cmd.clone());
|
|
}
|
|
}
|
|
|
|
let dt = DEVICE_TREE.lock();
|
|
|
|
// TODO(Able): This line causes a deadlock
|
|
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 VFS from initramfs
|
|
// TODO: schedule the init system from the initramfs
|
|
|
|
let mut executor = crate::task::Executor::default();
|
|
let bm_take = boot_modules.len();
|
|
unsafe {
|
|
for module in boot_modules.into_iter().take(bm_take) {
|
|
executor.spawn(async move {
|
|
if let Err(e) = ExecThread::new(&module.bytes, Address::new(0)).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)
|
|
});
|
|
|
|
use alloc::vec::Vec;
|
|
pub type IpcBuffers = HashMap<u64, IpcBuffer>;
|
|
pub static IPC_BUFFERS: Lazy<Mutex<IpcBuffers>> = Lazy::new(|| {
|
|
let mut bufs = HashMap::new();
|
|
let log_buffer = IpcBuffer::new(false, 0);
|
|
let file_buffer = IpcBuffer::new(false, 0);
|
|
|
|
bufs.insert(1, log_buffer);
|
|
bufs.insert(2, file_buffer);
|
|
|
|
Mutex::new(bufs)
|
|
});
|
|
|
|
#[test_case]
|
|
fn trivial_assertion() {
|
|
trace!("trivial assertion... ");
|
|
assert_eq!(1, 1);
|
|
info!("[ok]");
|
|
}
|