1
0
Fork 0
forked from AbleOS/ableos
ableos/kernel/src/kmain.rs

113 lines
3.5 KiB
Rust
Raw Normal View History

2023-03-30 16:43:04 -05:00
//! AbleOS Kernel Entrypoint
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::{
arch::logging::SERIAL_CONSOLE,
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-07-08 23:22:44 -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
_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
2023-07-08 23:22:44 -05:00
info!("Device Tree{}", dt);
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 init system from the initramfs
2023-05-15 02:19:34 -05:00
// TODO: change this to a driver
{
2023-07-08 23:22:44 -05:00
let mut prog = alloc::vec![];
let mut code = alloc::string::String::new();
2023-05-15 02:19:34 -05:00
let mut sc = SERIAL_CONSOLE.lock();
loop {
match sc.receive() {
b'\r' => {
2023-07-08 23:22:44 -05:00
code.push('\n');
sc.send(b'\r');
sc.send(b'\n');
2023-07-08 23:22:44 -05:00
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 => {
2023-07-08 23:22:44 -05:00
code.push(byte as char);
sc.send(byte);
}
2023-05-15 02:19:34 -05:00
}
}
}
2023-07-08 23:22:44 -05:00
// sloop();
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]");
}