From 5a9fe9a0bd3c958161da06ea97873311b72f8a10 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 01:05:18 +0500 Subject: [PATCH] Interrupt Subscription syscall --- kernel/src/holeybytes/ecah.rs | 8 ++++++++ kernel/src/task.rs | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index a34f683..7b00893 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -242,6 +242,14 @@ pub fn handler(vm: &mut Vm, pid: &usize) { vm.registers[3] = x } } + 6 => { // Wait till interrupt + use crate::kmain::EXECUTOR; + let interrupt_type = vm.registers[3].cast::(); + unsafe{ + EXECUTOR.pause(pid.clone()); + LazyCell::::get_mut(&mut EXECUTOR).unwrap().interrupt_subscribe(pid.clone(), interrupt_type); + } + } _ => { log::error!("Syscall unknown {:?}{:?}", ecall_number, vm.registers); } diff --git a/kernel/src/task.rs b/kernel/src/task.rs index 33eceb2..b815f2c 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -1,5 +1,5 @@ use { - alloc::{boxed::Box, sync::Arc, vec::Vec}, + alloc::{boxed::Box, sync::Arc}, core::{ future::Future, pin::Pin, @@ -35,7 +35,7 @@ impl + Send> Process for T {} pub struct Executor { tasks: Slab, task_queue: Arc>, - interrupt_lookup: [Option; u8::MAX as usize], + interrupt_lookup: Box<[Option; u8::MAX as usize]>, } impl Executor { @@ -54,19 +54,23 @@ impl Executor { id } - pub fn pause(&mut self, id: usize) { + pub fn pause(&self, id: usize) { if let Some(task) = self.tasks.get(id) { task.set_paused(true); } } - pub fn unpause(&mut self, id: usize) { + pub fn unpause(self, id: usize) { if let Some(task) = self.tasks.get(id) { task.set_paused(false); self.task_queue.push(id); } } + pub fn interrupt_subscribe(&mut self, pid : usize, interrupt_type: u8){ + self.interrupt_lookup[interrupt_type as usize] = Some(pid); + } + pub fn run(&mut self) { let mut task_batch = [0; 32]; loop {