From 2b33a65e6b3f10bbf0347b9a190cc2ae8f99744c Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Mon, 25 Nov 2024 23:59:37 +0500 Subject: [PATCH 1/8] Removed programs temporarily for testing purposes --- sysdata/system_config.toml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index a63f170..e5a2a8e 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -28,23 +28,23 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" -[boot.limine.ableos.modules.ps2_mouse_driver] -path = "boot:///ps2_mouse_driver.hbf" +# path = "boot:///ps2_mouse_driver.hbf" +# [boot.limine.ableos.modules.ps2_mouse_driver] # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -[boot.limine.ableos.modules.sunset_client] -path = "boot:///sunset_client.hbf" - -[boot.limine.ableos.modules.sunset_client_2] -path = "boot:///sunset_client_2.hbf" - -[boot.limine.ableos.modules.sdoom] -path = "boot:///sdoom.hbf" - -[boot.limine.ableos.modules.sunset_server] -path = "boot:///sunset_server.hbf" +# [boot.limine.ableos.modules.sunset_client] +# path = "boot:///sunset_client.hbf" +# +# [boot.limine.ableos.modules.sunset_client_2] +# path = "boot:///sunset_client_2.hbf" +# +# [boot.limine.ableos.modules.sdoom] +# path = "boot:///sdoom.hbf" +# +# [boot.limine.ableos.modules.sunset_server] +# path = "boot:///sunset_server.hbf" # [boot.limine.ableos.modules.pcspkr] # path = "boot:///pcspkr.hbf" -- 2.44.1 From f65a5bd79c8f3ce820cab356d35fa7857f5ecc99 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 00:14:01 +0500 Subject: [PATCH 2/8] Added interrupt lookup to executor --- kernel/src/task.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/src/task.rs b/kernel/src/task.rs index 01c6688..33eceb2 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -1,5 +1,5 @@ use { - alloc::{boxed::Box, sync::Arc}, + alloc::{boxed::Box, sync::Arc, vec::Vec}, core::{ future::Future, pin::Pin, @@ -35,6 +35,7 @@ impl + Send> Process for T {} pub struct Executor { tasks: Slab, task_queue: Arc>, + interrupt_lookup: [Option; u8::MAX as usize], } impl Executor { @@ -42,6 +43,7 @@ impl Executor { Self { tasks: Slab::new(), task_queue: Arc::new(SegQueue::new()), + interrupt_lookup: [None; u8::MAX as usize], } } @@ -98,6 +100,14 @@ 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); + } + } } struct Task { -- 2.44.1 From 4a45c929a1de934b10a35911acc5eacc50279bbf Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 00:19:42 +0500 Subject: [PATCH 3/8] Added the sending of the interrupt to subscribed processes --- kernel/src/arch/x86_64/interrupts.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/src/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs index 4bd3c8a..28b432c 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -62,7 +62,7 @@ extern "x86-interrupt" fn page_fault( } extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) { - // interrupt(Interrupt::Timer); + interrupt(Interrupt::Timer); unsafe { LAPIC.end_of_interrupt(); @@ -85,6 +85,7 @@ extern "x86-interrupt" fn spurious(_: InterruptStackFrame) { fn interrupt(interrupt_type: Interrupt) { use crate::arch::INTERRUPT_LIST; + use crate::kmain::EXECUTOR; let il = INTERRUPT_LIST.lock(); let val = il.list.get(&interrupt_type).unwrap(); @@ -107,4 +108,8 @@ fn interrupt(interrupt_type: Interrupt) { // log::info!("{}", buffer); } + + unsafe{ + EXECUTOR.send_interrupt(interrupt_type as u8); + } } -- 2.44.1 From 5a9fe9a0bd3c958161da06ea97873311b72f8a10 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 01:05:18 +0500 Subject: [PATCH 4/8] 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 { -- 2.44.1 From 6534340a86daa34a2fd1afbd3ec9ea9d4adc1da9 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 01:13:29 +0500 Subject: [PATCH 5/8] stn sleep_till_interrupt function --- sysdata/libraries/stn/src/sleep.hb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysdata/libraries/stn/src/sleep.hb b/sysdata/libraries/stn/src/sleep.hb index d323267..470b137 100644 --- a/sysdata/libraries/stn/src/sleep.hb +++ b/sysdata/libraries/stn/src/sleep.hb @@ -3,4 +3,5 @@ subscribe_to_interrupt := fn(interrupt_number: u8): bool { } // Pauses execution until the interrupt occures sleep_until_interrupt := fn(interrupt_number: u8): void { -} \ No newline at end of file + @eca(6, 32); +} -- 2.44.1 From 4b9107c4d604ea6e8c9aa465d59952f0c08baf86 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 02:10:42 +0500 Subject: [PATCH 6/8] 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" # -- 2.44.1 From a658189efe12202e3cdad5c1c17e2996d120add5 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 02:29:43 +0500 Subject: [PATCH 7/8] Cleaning of interrupt lookup after process end --- kernel/src/task.rs | 8 ++++++++ sysdata/programs/timer_test/src/main.hb | 10 ++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/kernel/src/task.rs b/kernel/src/task.rs index 9aa67f8..7cf5c10 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -100,6 +100,14 @@ impl Executor { if let Poll::Ready(()) = task.poll(&mut cx) { self.tasks.remove(id); + self.interrupt_lookup.map(move |pid|{ + if let Some(pid) = pid{ + if pid == id { + return None; + } + } + return pid; + }); } } } diff --git a/sysdata/programs/timer_test/src/main.hb b/sysdata/programs/timer_test/src/main.hb index d359f3c..b2142ea 100644 --- a/sysdata/programs/timer_test/src/main.hb +++ b/sysdata/programs/timer_test/src/main.hb @@ -2,9 +2,7 @@ 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") - } -} + log.info("BEFORE\0") + sleep.sleep_until_interrupt(32) + log.info("AFTER\0") +} \ No newline at end of file -- 2.44.1 From 7acf2a869f4635ddf55eac789bf4196019b7fe56 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Wed, 27 Nov 2024 02:44:23 +0500 Subject: [PATCH 8/8] Got rid of move for konii's PTSD --- kernel/src/task.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/src/task.rs b/kernel/src/task.rs index 7cf5c10..c79140f 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -100,7 +100,7 @@ impl Executor { if let Poll::Ready(()) = task.poll(&mut cx) { self.tasks.remove(id); - self.interrupt_lookup.map(move |pid|{ + self.interrupt_lookup.map(|pid|{ if let Some(pid) = pid{ if pid == id { return None; -- 2.44.1