THE FORWARDED INTERRUPT

This commit is contained in:
Talha Qamar 2024-11-27 02:10:42 +05:00
parent 6534340a86
commit 4b9107c4d6
6 changed files with 34 additions and 7 deletions

View file

@ -1,5 +1,7 @@
//! Environment call handling routines
use log::log;
use {alloc::boxed::Box, core::cell::LazyCell, hbvm::mem::Address};
use crate::{
@ -245,6 +247,7 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
6 => { // Wait till interrupt
use crate::kmain::EXECUTOR;
let interrupt_type = vm.registers[3].cast::<u8>();
info!("Interrupt subscribled: {}", interrupt_type);
unsafe{
EXECUTOR.pause(pid.clone());
LazyCell::<Executor>::get_mut(&mut EXECUTOR).unwrap().interrupt_subscribe(pid.clone(), interrupt_type);

View file

@ -35,7 +35,7 @@ impl<T: Future<Output = ()> + Send> Process for T {}
pub struct Executor {
tasks: Slab<Task>,
task_queue: Arc<SegQueue<usize>>,
interrupt_lookup: Box<[Option<usize>; u8::MAX as usize]>,
interrupt_lookup: [Option<usize>; u8::MAX as usize],
}
impl Executor {
@ -60,7 +60,7 @@ impl Executor {
}
}
pub fn unpause(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);
@ -85,7 +85,8 @@ impl Executor {
}
if batch_len == 0 {
break;
//break;
continue;
}
for &(mut id) in &task_batch[..batch_len] {
@ -108,8 +109,7 @@ impl Executor {
pub fn send_interrupt(&self, interrupt : u8){
let id = self.interrupt_lookup[interrupt as usize];
if let Some(id) = id{
let task = &self.tasks[id];
task.set_paused(false);
self.unpause(id);
}
}
}

View file

@ -3,5 +3,5 @@ subscribe_to_interrupt := fn(interrupt_number: u8): bool {
}
// Pauses execution until the interrupt occures
sleep_until_interrupt := fn(interrupt_number: u8): void {
@eca(6, 32);
@eca(6, interrupt_number)
}

View file

@ -0,0 +1,11 @@
[package]
name = "timer_test"
authors = ["Talha Qamar"]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -0,0 +1,10 @@
sleep := @use("../../../libraries/stn/src/sleep.hb")
log := @use("../../../libraries/stn/src/log.hb")
main := fn(): int {
loop {
log.info("BEFORE\0")
sleep.sleep_until_interrupt(32)
log.info("AFTER\0")
}
}

View file

@ -34,6 +34,9 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.ps2_keyboard_driver]
# path = "boot:///ps2_keyboard_driver.hbf"
[boot.limine.ableos.modules.timer_test]
path = "boot:///timer_test.hbf"
# [boot.limine.ableos.modules.sunset_client]
# path = "boot:///sunset_client.hbf"
#