forked from AbleOS/ableos
SCHEDULER: cut out deadcode and added ifguard
This commit is contained in:
parent
d1a6e627ef
commit
2f24089938
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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<u8>) {
|
||||
|
@ -41,8 +38,14 @@ impl Scheduler<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn scheduler_run(&mut self) -> Option<u32> {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue