diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index a4481629..cb043f82 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -1,15 +1,12 @@ //! AbleOS Kernel Entrypoint -use crate::capabilities; - // use crate::arch::sloop; use { crate::{ - arch::logging::SERIAL_CONSOLE, bootmodules::{build_cmd, BootModules}, + capabilities, device_tree::DeviceTree, scheduler::Scheduler, - }, alloc::format, log::{debug, info, trace}, @@ -43,69 +40,11 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { 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 sched = Scheduler::new(); - sched.new_process(prog.clone()); - sched.scheduler_run(); - // 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); - } - } - } - } + let mut sched = Scheduler::new(); + // AHEM that isn't a valid HBVM program + sched.new_process(boot_modules[0].bytes.clone()); + sched.run(); // sloop(); } diff --git a/kernel/src/logger.rs b/kernel/src/logger.rs index 2fe17a4a..486a3688 100644 --- a/kernel/src/logger.rs +++ b/kernel/src/logger.rs @@ -16,16 +16,17 @@ impl log::Log for Logger { fn log(&self, record: &log::Record) { let lvl = record.level(); + let lvl_color = match lvl { + Level::Error => "160", + Level::Warn => "172", + Level::Info => "47", + Level::Debug => "25", + Level::Trace => "103", + }; + let module = record.module_path().unwrap_or_default(); + let line = record.line().unwrap_or_default(); crate::arch::log(format_args!( - "\x1b[38;5;{}m{lvl}\x1b[0m [{}]: {}\r\n", - match lvl { - Level::Error => "160", - Level::Warn => "172", - Level::Info => "47", - Level::Debug => "25", - Level::Trace => "103", - }, - record.module_path().unwrap_or_default(), + "\x1b[38;5;{lvl_color}m{lvl}\x1b[0m [{module}:{line}]: {}\r\n", record.args(), )) .expect("write to serial console"); diff --git a/kernel/src/scheduler.rs b/kernel/src/scheduler.rs index d7724fd8..7803975c 100644 --- a/kernel/src/scheduler.rs +++ b/kernel/src/scheduler.rs @@ -12,13 +12,10 @@ pub struct Scheduler<'a> { // NOTE: This is a very simple schduler and it sucks and should be replaced with a better one // Written By Yours Truly: Munir - - impl Scheduler<'_> { pub fn new() -> Self { Self { data: VecDeque::new(), - } } pub fn new_process(&mut self, program: Vec) { @@ -41,8 +38,14 @@ impl Scheduler<'_> { } } - pub fn scheduler_run(&mut self) -> Option { + pub fn run(&mut self) -> ! { loop { + // If there are no programs to run sleep + if self.data.is_empty() { + use crate::arch::sloop; + sloop(); + } + let mut prog = self.data.pop_front().unwrap(); prog.run().unwrap(); self.data.push_back(prog);