Interrupt Forwarding #22

Merged
koniifer merged 8 commits from kodin/ableos-idl:kold/interrupts into master 2024-11-26 15:53:52 -06:00
2 changed files with 16 additions and 4 deletions
Showing only changes of commit 5a9fe9a0bd - Show all commits

View file

@ -242,6 +242,14 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
vm.registers[3] = x vm.registers[3] = x
} }
} }
6 => { // Wait till interrupt
use crate::kmain::EXECUTOR;
let interrupt_type = vm.registers[3].cast::<u8>();
unsafe{
EXECUTOR.pause(pid.clone());
LazyCell::<Executor>::get_mut(&mut EXECUTOR).unwrap().interrupt_subscribe(pid.clone(), interrupt_type);
}
}
_ => { _ => {
log::error!("Syscall unknown {:?}{:?}", ecall_number, vm.registers); log::error!("Syscall unknown {:?}{:?}", ecall_number, vm.registers);
} }

View file

@ -1,5 +1,5 @@
use { use {
alloc::{boxed::Box, sync::Arc, vec::Vec}, alloc::{boxed::Box, sync::Arc},
core::{ core::{
future::Future, future::Future,
pin::Pin, pin::Pin,
@ -35,7 +35,7 @@ impl<T: Future<Output = ()> + Send> Process for T {}
pub struct Executor { pub struct Executor {
tasks: Slab<Task>, tasks: Slab<Task>,
task_queue: Arc<SegQueue<usize>>, task_queue: Arc<SegQueue<usize>>,
interrupt_lookup: [Option<usize>; u8::MAX as usize], interrupt_lookup: Box<[Option<usize>; u8::MAX as usize]>,
} }
impl Executor { impl Executor {
@ -54,19 +54,23 @@ impl Executor {
id id
} }
pub fn pause(&mut self, id: usize) { pub fn pause(&self, id: usize) {
if let Some(task) = self.tasks.get(id) { if let Some(task) = self.tasks.get(id) {
task.set_paused(true); 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) { if let Some(task) = self.tasks.get(id) {
task.set_paused(false); task.set_paused(false);
self.task_queue.push(id); 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) { pub fn run(&mut self) {
let mut task_batch = [0; 32]; let mut task_batch = [0; 32];
loop { loop {