diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 2a4d2e1..ab540d6 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -80,6 +80,10 @@ pub fn handler(vm: &mut Vm, pid: &usize) { let length = vm.registers[5].cast::() as usize; trace!("IPC address: {:?}", mem_addr); + unsafe { LazyCell::::get_mut(&mut EXECUTOR) } + .unwrap() + .send_buffer(buffer_id as usize); + match buffer_id { 0 => match sds_msg_handler(vm, mem_addr, length) { Ok(()) => {} @@ -246,12 +250,22 @@ pub fn handler(vm: &mut Vm, pid: &usize) { // Wait till interrupt use crate::kmain::EXECUTOR; let interrupt_type = vm.registers[3].cast::(); - info!("Interrupt subscribled: {}", interrupt_type); + debug!("Interrupt subscribed: {}", interrupt_type); unsafe { - EXECUTOR.pause(pid.clone()); LazyCell::::get_mut(&mut EXECUTOR) .unwrap() - .interrupt_subscribe(pid.clone(), interrupt_type); + .interrupt_subscribe(*pid, interrupt_type); + } + } + 7 => { + // Wait till buffer + use crate::kmain::EXECUTOR; + let buffer_id = vm.registers[3].cast::() as usize; + debug!("Buffer subscribed: {}", buffer_id); + unsafe { + LazyCell::::get_mut(&mut EXECUTOR) + .unwrap() + .buffer_subscribe(*pid, buffer_id); } } _ => { diff --git a/kernel/src/task.rs b/kernel/src/task.rs index 1040fb9..8807505 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -1,5 +1,9 @@ use { - alloc::{boxed::Box, sync::Arc}, + alloc::{ + boxed::Box, + collections::{BTreeMap, BTreeSet}, + sync::Arc, + }, core::{ future::Future, pin::Pin, @@ -36,6 +40,7 @@ pub struct Executor { tasks: Slab, task_queue: Arc>, interrupt_lookup: [Option; u8::MAX as usize], + buffer_lookup: BTreeMap>, } impl Executor { @@ -44,6 +49,7 @@ impl Executor { tasks: Slab::new(), task_queue: Arc::new(SegQueue::new()), interrupt_lookup: [None; u8::MAX as usize], + buffer_lookup: BTreeMap::new(), } } @@ -68,9 +74,19 @@ impl Executor { } pub fn interrupt_subscribe(&mut self, pid: usize, interrupt_type: u8) { + self.pause(pid); self.interrupt_lookup[interrupt_type as usize] = Some(pid); } + pub fn buffer_subscribe(&mut self, pid: usize, buffer_id: usize) { + self.pause(pid); + if let Some(buf) = self.buffer_lookup.get_mut(&buffer_id) { + buf.insert(pid); + } else { + self.buffer_lookup.insert(buffer_id, BTreeSet::from([pid])); + } + } + pub fn run(&mut self) { let mut task_batch = [0; 32]; loop { @@ -108,6 +124,9 @@ impl Executor { } return pid; }); + self.buffer_lookup.iter_mut().for_each(|(_, pid_set)| { + pid_set.remove(&id); + }); } } } @@ -120,6 +139,11 @@ impl Executor { self.unpause(id); } } + pub fn send_buffer(&self, id: usize) { + if let Some(buf) = self.buffer_lookup.get(&id) { + buf.iter().for_each(|pid| self.unpause(*pid)); + } + } } struct Task { diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 17f5a3f..495f53a 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -1,5 +1,9 @@ string := @use("string.hb") +$await := fn(buffer_id: uint): void { + return @eca(7, buffer_id) +} + $recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void { return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) } diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index f75dfb2..6191960 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -48,6 +48,8 @@ await_channel := fn(): Channel { await_message := fn($Expr: type, buffer_id: uint): Message(Expr) { response := @as(?Message(Expr), null) loop { + // awaiting here causes flickering... idk why + buffer.await(buffer_id) buffer.recv(?Message(Expr), buffer_id, &response) if response != null { return @as(Message(Expr), response) @@ -58,9 +60,11 @@ await_message := fn($Expr: type, buffer_id: uint): Message(Expr) { await_header := fn(buffer_id: uint): MessageHeader { response := @as(?MessageHeader, null) loop { + // awaiting here causes flickering... idk why + buffer.await(buffer_id) buffer.recv(?MessageHeader, buffer_id, &response) if response != null { - return @as(?MessageHeader, response) + return @as(MessageHeader, response) } } } diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index fa109c6..9f438d7 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -91,8 +91,8 @@ main := fn(): int { // Mouse cursor { - render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR_DARKER) - render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR) + render.put_filled_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER) + render.put_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR) } render.sync(screen) diff --git a/sysdata/programs/test/src/main.hb b/sysdata/programs/test/src/main.hb index 3b3bc21..debec4e 100644 --- a/sysdata/programs/test/src/main.hb +++ b/sysdata/programs/test/src/main.hb @@ -3,5 +3,5 @@ serial_driver := @use("./tests/serial_driver.hb") main := fn(): uint { // return serial_driver.test() - return stn.process.test() + return stn.sleep.test() } \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 72ef8b4..297b1b3 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -34,14 +34,14 @@ path = "boot:///ps2_mouse_driver.hbf" # [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] +path = "boot:///sunset_client.hbf" -# [boot.limine.ableos.modules.sunset_client_2] -# path = "boot:///sunset_client_2.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.sdoom] +# path = "boot:///sdoom.hbf" [boot.limine.ableos.modules.sunset_server] path = "boot:///sunset_server.hbf"