2023-03-30 16:43:04 -05:00
|
|
|
//! AbleOS Kernel Entrypoint
|
|
|
|
|
2023-05-06 06:50:24 -05:00
|
|
|
use {
|
2023-05-25 07:04:19 -05:00
|
|
|
crate::{alloc::string::ToString, arch::logging::SERIAL_CONSOLE, device_tree::DeviceTree},
|
2023-06-16 05:20:37 -05:00
|
|
|
clparse::Arguments,
|
2023-05-25 07:04:19 -05:00
|
|
|
hbvm::engine::Engine,
|
2023-05-26 06:30:17 -05:00
|
|
|
log::{debug, 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-03-30 16:43:04 -05:00
|
|
|
pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
|
2023-05-25 07:04:19 -05:00
|
|
|
debug!("Entered kmain");
|
2023-03-30 16:43:04 -05:00
|
|
|
|
2023-04-05 12:29:20 -05:00
|
|
|
let mut cmdline = cmdline.to_string();
|
|
|
|
cmdline.pop();
|
|
|
|
cmdline.remove(0);
|
|
|
|
|
2023-06-16 05:20:37 -05:00
|
|
|
let kcmd = Arguments::parse(cmdline.to_string()).unwrap();
|
2023-05-26 06:30:17 -05:00
|
|
|
trace!("Cmdline: {kcmd:?}");
|
2023-03-30 16:43:04 -05:00
|
|
|
|
2023-06-16 05:20:37 -05:00
|
|
|
let mut kcl = XMLElement::new("Kernel Command Line");
|
2023-05-25 07:04:19 -05:00
|
|
|
for (key, value) in kcmd.arguments {
|
|
|
|
kcl.set_attribute(key, value);
|
2023-05-06 06:50:24 -05:00
|
|
|
}
|
2023-05-26 06:30:17 -05:00
|
|
|
debug!("kernel command line object: {:?}", kcl);
|
2023-04-07 16:44:33 -05:00
|
|
|
|
2023-04-05 12:29:20 -05:00
|
|
|
let bootstrap = bootstrap/*.expect("no bootstrap found")*/;
|
|
|
|
match bootstrap {
|
2023-05-26 06:30:17 -05:00
|
|
|
Some(bootstrap_mod) => {
|
|
|
|
debug!("Bootstrap Module: {:?}", bootstrap_mod);
|
|
|
|
}
|
2023-04-05 12:29:20 -05:00
|
|
|
None => {
|
2023-05-26 06:30:17 -05:00
|
|
|
debug!("No bootstrap module loaded.")
|
2023-04-05 12:29:20 -05:00
|
|
|
}
|
|
|
|
}
|
2023-05-23 05:16:14 -05:00
|
|
|
let dt = DEVICE_TREE.lock();
|
2023-04-05 12:29:20 -05:00
|
|
|
|
2023-06-16 05:20:37 -05:00
|
|
|
log::info!("Device Tree{}", dt);
|
2023-05-15 02:19:34 -05:00
|
|
|
|
|
|
|
let bytes = alloc::vec![0];
|
|
|
|
let mut prog = Engine::new(bytes);
|
|
|
|
// prog.enviroment_call_table[0] = read_device_tree;
|
2023-05-23 05:16:14 -05:00
|
|
|
let _ = prog.run();
|
2023-05-15 02:19:34 -05:00
|
|
|
prog.dump();
|
|
|
|
|
|
|
|
// TODO: change this to a driver
|
|
|
|
{
|
2023-05-23 05:16:14 -05:00
|
|
|
let _buf = [8; 128 * 4];
|
2023-05-15 02:19:34 -05:00
|
|
|
|
|
|
|
let mut sc = SERIAL_CONSOLE.lock();
|
|
|
|
loop {
|
2023-05-28 04:51:51 -05:00
|
|
|
// TODO: Implement an API for sending and recieving serial stuff
|
|
|
|
{
|
|
|
|
fn read_ipc_buff() {}
|
|
|
|
fn write_ipc_buff() {}
|
|
|
|
// TODO: read from the IPC buffer and push to serial stream
|
|
|
|
let _msg = read_ipc_buff();
|
|
|
|
for byte in 0..0 {
|
|
|
|
sc.send(byte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 17:16:22 -05:00
|
|
|
match sc.receive() {
|
|
|
|
b'\r' => {
|
|
|
|
sc.send(b'\n');
|
|
|
|
}
|
|
|
|
byte => {
|
|
|
|
sc.send(byte);
|
|
|
|
}
|
2023-05-15 02:19:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
#[test_case]
|
|
|
|
fn trivial_assertion() {
|
|
|
|
trace!("trivial assertion... ");
|
|
|
|
assert_eq!(1, 1);
|
|
|
|
info!("[ok]");
|
|
|
|
}
|