1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/kernel/src/kmain.rs
2023-05-23 05:16:14 -05:00

83 lines
1.9 KiB
Rust

//! AbleOS Kernel Entrypoint
// use std::collections::HashMap;
use {
log::info,
spin::{Lazy, Mutex},
};
use hbvm::engine::Engine;
use crate::{
arch::logging::SERIAL_CONSOLE,
device_tree::DeviceTree,
// host_functions::read_device_tree,
};
use crate::alloc::string::ToString;
pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
log::debug!("Entered kmain");
let mut cmdline = cmdline.to_string();
cmdline.pop();
cmdline.remove(0);
let kcmd = clparse::Arguments::parse(cmdline.to_string()).unwrap();
log::info!("Cmdline: {kcmd:?}");
if kcmd.arguments.get("baka") == Some(&"true".to_string()) {
let _ = crate::arch::log(format_args!(include_str!("../data/⑨. バカ")));
}
if kcmd.arguments.get("foobles") == Some(&"true".to_string()) {
let _ = crate::arch::log(format_args!("foobles\n\r"));
}
let bootstrap = bootstrap/*.expect("no bootstrap found")*/;
match bootstrap {
Some(_bootstrap_mod) => {}
None => {
info!("No bootstrap module loaded.")
}
}
let dt = DEVICE_TREE.lock();
info!("Device Tree {}", &dt);
let bytes = alloc::vec![0];
let mut prog = Engine::new(bytes);
// prog.enviroment_call_table[0] = read_device_tree;
let _ = prog.run();
prog.dump();
// TODO: change this to a driver
{
let _buf = [8; 128 * 4];
let mut sc = SERIAL_CONSOLE.lock();
loop {
let byte = sc.receive();
if byte == b'\r' {
sc.send(b'\n');
}
sc.send(byte);
}
}
// crate::arch::sloop()
}
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]");
}