From 4b9107c4d604ea6e8c9aa465d59952f0c08baf86 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 02:10:42 +0500 Subject: [PATCH] THE FORWARDED INTERRUPT --- kernel/src/holeybytes/ecah.rs | 3 +++ kernel/src/task.rs | 10 +++++----- sysdata/libraries/stn/src/sleep.hb | 4 ++-- sysdata/programs/timer_test/meta.toml | 11 +++++++++++ sysdata/programs/timer_test/src/main.hb | 10 ++++++++++ sysdata/system_config.toml | 3 +++ 6 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 sysdata/programs/timer_test/meta.toml create mode 100644 sysdata/programs/timer_test/src/main.hb diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 7b00893..b1561f9 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -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::(); + info!("Interrupt subscribled: {}", interrupt_type); unsafe{ EXECUTOR.pause(pid.clone()); LazyCell::::get_mut(&mut EXECUTOR).unwrap().interrupt_subscribe(pid.clone(), interrupt_type); diff --git a/kernel/src/task.rs b/kernel/src/task.rs index b815f2c..9aa67f8 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -35,7 +35,7 @@ impl + Send> Process for T {} pub struct Executor { tasks: Slab, task_queue: Arc>, - interrupt_lookup: Box<[Option; u8::MAX as usize]>, + interrupt_lookup: [Option; 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); } } } diff --git a/sysdata/libraries/stn/src/sleep.hb b/sysdata/libraries/stn/src/sleep.hb index 470b137..5aeaf14 100644 --- a/sysdata/libraries/stn/src/sleep.hb +++ b/sysdata/libraries/stn/src/sleep.hb @@ -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) +} \ No newline at end of file diff --git a/sysdata/programs/timer_test/meta.toml b/sysdata/programs/timer_test/meta.toml new file mode 100644 index 0000000..c05908d --- /dev/null +++ b/sysdata/programs/timer_test/meta.toml @@ -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" diff --git a/sysdata/programs/timer_test/src/main.hb b/sysdata/programs/timer_test/src/main.hb new file mode 100644 index 0000000..d359f3c --- /dev/null +++ b/sysdata/programs/timer_test/src/main.hb @@ -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") + } +} diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index e5a2a8e..34ab790 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -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" #