forked from AbleOS/ableos
117 lines
3.5 KiB
Rust
117 lines
3.5 KiB
Rust
//! AbleOS Kernel Entrypoint
|
|
|
|
use crate::capabilities;
|
|
|
|
// use crate::arch::sloop;
|
|
use {
|
|
crate::{
|
|
arch::logging::SERIAL_CONSOLE,
|
|
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();
|
|
|
|
// TODO: change this to a driver
|
|
{
|
|
let mut prog = alloc::vec![];
|
|
let mut code = alloc::string::String::new();
|
|
|
|
let mut sc = SERIAL_CONSOLE.lock();
|
|
loop {
|
|
match sc.receive() {
|
|
b'\r' => {
|
|
code.push('\n');
|
|
|
|
sc.send(b'\r');
|
|
sc.send(b'\n');
|
|
|
|
match hbasm::assembly(&code, &mut prog) {
|
|
Ok(_) => {
|
|
use hbvm::validate::validate;
|
|
match validate(&prog) {
|
|
Err(_e) => {
|
|
// log::error!("Program validation error: {e:?}");
|
|
}
|
|
Ok(_) => {
|
|
// log::info!("valid program");
|
|
use {crate::host::TrapHandler, hbvm::vm::Vm};
|
|
let mut vm;
|
|
unsafe {
|
|
vm = Vm::new_unchecked(&prog, TrapHandler);
|
|
vm.memory.insert_test_page();
|
|
}
|
|
// log::info!("Program interrupt: {:?}", vm.run());
|
|
// log::debug!("{:?}", vm.registers);
|
|
}
|
|
}
|
|
|
|
sc.send(b'>');
|
|
}
|
|
Err(_e) => {
|
|
// log::error!(
|
|
// "Error {:?} at {:?} (`{}`)",
|
|
// e.kind,
|
|
// e.span.clone(),
|
|
// &code[e.span],
|
|
// );
|
|
for x in "err".as_bytes() {
|
|
sc.send(*x);
|
|
}
|
|
}
|
|
}
|
|
code = alloc::string::String::new();
|
|
}
|
|
byte => {
|
|
code.push(byte as char);
|
|
|
|
sc.send(byte);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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]");
|
|
}
|