SCHEDULER: cut out deadcode and added ifguard

This commit is contained in:
able 2023-07-12 12:22:13 -05:00
parent d1a6e627ef
commit 2f24089938
3 changed files with 22 additions and 79 deletions

View file

@ -1,15 +1,12 @@
//! AbleOS Kernel Entrypoint //! AbleOS Kernel Entrypoint
use crate::capabilities;
// use crate::arch::sloop; // use crate::arch::sloop;
use { use {
crate::{ crate::{
arch::logging::SERIAL_CONSOLE,
bootmodules::{build_cmd, BootModules}, bootmodules::{build_cmd, BootModules},
capabilities,
device_tree::DeviceTree, device_tree::DeviceTree,
scheduler::Scheduler, scheduler::Scheduler,
}, },
alloc::format, alloc::format,
log::{debug, info, trace}, log::{debug, info, trace},
@ -43,69 +40,11 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
capabilities::example(); capabilities::example();
// TODO: change this to a driver let mut sched = Scheduler::new();
{ // AHEM that isn't a valid HBVM program
let mut prog = alloc::vec![]; sched.new_process(boot_modules[0].bytes.clone());
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);
}
}
}
}
sched.run();
// sloop(); // sloop();
} }

View file

@ -16,16 +16,17 @@ impl log::Log for Logger {
fn log(&self, record: &log::Record) { fn log(&self, record: &log::Record) {
let lvl = record.level(); 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!( crate::arch::log(format_args!(
"\x1b[38;5;{}m{lvl}\x1b[0m [{}]: {}\r\n", "\x1b[38;5;{lvl_color}m{lvl}\x1b[0m [{module}:{line}]: {}\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(),
record.args(), record.args(),
)) ))
.expect("write to serial console"); .expect("write to serial console");

View file

@ -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 // NOTE: This is a very simple schduler and it sucks and should be replaced with a better one
// Written By Yours Truly: Munir // Written By Yours Truly: Munir
impl Scheduler<'_> { impl Scheduler<'_> {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
data: VecDeque::new(), data: VecDeque::new(),
} }
} }
pub fn new_process(&mut self, program: Vec<u8>) { pub fn new_process(&mut self, program: Vec<u8>) {
@ -41,8 +38,14 @@ impl Scheduler<'_> {
} }
} }
pub fn scheduler_run(&mut self) -> Option<u32> { pub fn run(&mut self) -> ! {
loop { 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(); let mut prog = self.data.pop_front().unwrap();
prog.run().unwrap(); prog.run().unwrap();
self.data.push_back(prog); self.data.push_back(prog);