1
0
Fork 0
forked from koniifer/ableos

Merge pull request 'master' (#5) from IntoTheNight/ableos:master into master

Reviewed-on: https://git.ablecorp.us/AbleOS/ableos/pulls/5
This commit is contained in:
able 2023-07-12 16:48:02 +00:00
commit 1455f1712c
3 changed files with 58 additions and 23 deletions

0
a.out Normal file
View file

View file

@ -8,6 +8,8 @@ use {
arch::logging::SERIAL_CONSOLE, arch::logging::SERIAL_CONSOLE,
bootmodules::{build_cmd, BootModules}, bootmodules::{build_cmd, BootModules},
device_tree::DeviceTree, device_tree::DeviceTree,
scheduler::Scheduler,
}, },
alloc::format, alloc::format,
log::{debug, info, trace}, log::{debug, info, trace},
@ -32,7 +34,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
let dt = DEVICE_TREE.lock(); let dt = DEVICE_TREE.lock();
info!("Device Tree{}", dt); info!("Device Tree: {}", dt);
info!("Boot complete. Moving to init_system"); info!("Boot complete. Moving to init_system");
// TODO: schedule the disk driver from the initramfs // TODO: schedule the disk driver from the initramfs
@ -63,13 +65,17 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
// log::error!("Program validation error: {e:?}"); // log::error!("Program validation error: {e:?}");
} }
Ok(_) => { Ok(_) => {
// log::info!("valid program"); // log::info!("valid program");
use {crate::host::TrapHandler, hbvm::vm::Vm}; // use {crate::host::TrapHandler, hbvm::vm::Vm};
let mut vm; let mut sched = Scheduler::new();
unsafe { sched.new_process(prog.clone());
vm = Vm::new_unchecked(&prog, TrapHandler); sched.scheduler_run();
vm.memory.insert_test_page(); // let mut vm;
} // unsafe {
// vm = Vm::new_unchecked(&prog, TrapHandler);
// vm.memory.insert_test_page();
// }
// log::info!("Program interrupt: {:?}", vm.run()); // log::info!("Program interrupt: {:?}", vm.run());
// log::debug!("{:?}", vm.registers); // log::debug!("{:?}", vm.registers);
} }

View file

@ -1,22 +1,51 @@
use {crate::host::TrapHandler, alloc::vec::Vec, hbvm::vm::Vm}; use {
alloc::{collections::VecDeque, rc::Rc, slice, vec::Vec},
hbvm::validate::validate,
};
use {crate::host::TrapHandler, hbvm::vm::Vm};
pub struct Scheduler<'a> { pub struct Scheduler<'a> {
data: Vec<Vm<'a, TrapHandler>>, data: VecDeque<Vm<'a, TrapHandler>>,
} }
// 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<'_> { impl Scheduler<'_> {
// fn new_process(&mut self, program: Vec<u8>) { pub fn new() -> Self {
// let prog = program.clone(); Self {
// #[allow(clippy::redundant_else)] data: VecDeque::new(),
// if let Err(e) = validate(&prog) {
// log::error!("Program validation error: {e:?}"); }
// } else { }
// log::info!("valid program"); pub fn new_process(&mut self, program: Vec<u8>) {
// unsafe { let prog = program.clone();
// let mut vm = Vm::new_unchecked(&prog, TrapHandler); let prog_arc = Rc::new(prog);
// vm.memory.insert_test_page();
// self.data.push(vm); let binding = Rc::try_unwrap(prog_arc).ok().unwrap();
// }
// } #[allow(clippy::redundant_else)]
// } if let Err(e) = validate(&program.as_slice()) {
log::error!("Program validation error: {e:?}");
} else {
log::info!("valid program");
unsafe {
let slice = slice::from_raw_parts(binding.as_ptr(), binding.len());
let mut vm = Vm::new_unchecked(&*slice, TrapHandler);
vm.memory.insert_test_page();
self.data.push_front(vm);
}
}
}
pub fn scheduler_run(&mut self) -> Option<u32> {
loop {
let mut prog = self.data.pop_front().unwrap();
prog.run().unwrap();
self.data.push_back(prog);
}
}
} }