From 359d62c1b012db43e3b553aabdce4b83480842a9 Mon Sep 17 00:00:00 2001 From: MunirG05 Date: Mon, 10 Jul 2023 17:14:11 +0530 Subject: [PATCH] i pushed so i can work on it in windows thanks --- kernel/src/kmain.rs | 20 +++++++++------ kernel/src/scheduler.rs | 55 +++++++++++++++++++++++++++++------------ repbuild/src/main.rs | 2 +- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 5a3fd52c..72cb2e33 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -6,6 +6,8 @@ use { arch::logging::SERIAL_CONSOLE, bootmodules::{build_cmd, BootModules}, device_tree::DeviceTree, + scheduler::Scheduler, + }, alloc::format, log::{debug, info, trace}, @@ -30,7 +32,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { let dt = DEVICE_TREE.lock(); - info!("Device Tree{}", dt); + info!("Device Tree: {}", dt); info!("Boot complete. Moving to init_system"); // TODO: schedule the disk driver from the initramfs @@ -59,13 +61,17 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { // 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(); - } + // use {crate::host::TrapHandler, hbvm::vm::Vm}; + let mut sched = Scheduler::new(); + sched.new_process(prog.clone()); + sched.scheduler_loop(); + // 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); } diff --git a/kernel/src/scheduler.rs b/kernel/src/scheduler.rs index 6543e6c7..8af7bfa3 100644 --- a/kernel/src/scheduler.rs +++ b/kernel/src/scheduler.rs @@ -1,22 +1,45 @@ -use {crate::host::TrapHandler, alloc::vec::Vec, hbvm::vm::Vm}; +use alloc::{collections::VecDeque, vec::Vec, rc::Rc, slice}; +use hbvm::validate::validate; + +use {crate::host::TrapHandler, hbvm::vm::Vm}; pub struct Scheduler<'a> { - data: Vec>, + data: VecDeque>, } impl Scheduler<'_> { - // fn new_process(&mut self, program: Vec) { - // let prog = program.clone(); - // #[allow(clippy::redundant_else)] - // if let Err(e) = validate(&prog) { - // log::error!("Program validation error: {e:?}"); - // } else { - // log::info!("valid program"); - // unsafe { - // let mut vm = Vm::new_unchecked(&prog, TrapHandler); - // vm.memory.insert_test_page(); - // self.data.push(vm); - // } - // } - // } + pub fn new() -> Self { + Self { + data: VecDeque::new(), + } + } + pub fn new_process(&mut self, program: Vec) { + let prog = program.clone(); + let prog_arc = Rc::new(prog); + + 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_loop(&mut self){ + loop { + let mut prog = self.data.pop_front().unwrap(); + prog.run().unwrap(); + self.data.push_back(prog); + } + } } diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 1424038d..68ebe26a 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -187,7 +187,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> { #[cfg(target_os = "linux")] { - // com.args(["-enable-kvm", "-cpu", "host"]); + //com.args(["-enable-kvm", "-cpu", "host"]); } }