diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index cd1493aac..2937205ad 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -21,7 +21,7 @@ pub fn handler(vm: &mut Vm) { let ecall_number = vm.registers[2].cast::(); // debug!("Ecall number {:?}", ecall_number); - // trace!("Register dump: {:?}", vm.registers); + //info!("Register dump: {:?}", vm.registers); match ecall_number { 0 => { @@ -57,7 +57,7 @@ pub fn handler(vm: &mut Vm) { }; let buff_id = arch::hardware_random_u64(); buffs.insert(buff_id, abc); - debug!("Buffer ID: {}", buff_id); + info!("Buffer ID: {}", buff_id); vm.registers[1] = hbvm::value::Value(buff_id); } 2 => { @@ -133,7 +133,6 @@ pub fn handler(vm: &mut Vm) { } buffer_id => { let mut buffs = IPC_BUFFERS.lock(); - match buffs.get_mut(&buffer_id) { Some(buff) => { let mut msg_vec = vec![]; @@ -163,8 +162,20 @@ pub fn handler(vm: &mut Vm) { let max_length = vm.registers[5].cast::(); let mut buffs = IPC_BUFFERS.lock(); - let mut buff = buffs.get_mut(&buffer_id).unwrap(); - let msg = buff.pop(); + let mut buff: &mut IpcBuffer; + + if buffs.get_mut(&buffer_id).is_some() { + buff = buffs.get_mut(&buffer_id).unwrap(); + } else { + info!("AHHH"); + vm.registers[1] = hbvm::value::Value(0); + return; + } + let pop = buff.pop(); + if pop.is_err() { + return; + } + let msg = pop.unwrap(); if msg.len() > max_length.try_into().unwrap() { info!("{}", max_length); error!("Message is too long to map in."); diff --git a/kernel/src/holeybytes/kernel_services/service_definition_service.rs b/kernel/src/holeybytes/kernel_services/service_definition_service.rs index 02f7c3aef..1a12447b8 100644 --- a/kernel/src/holeybytes/kernel_services/service_definition_service.rs +++ b/kernel/src/holeybytes/kernel_services/service_definition_service.rs @@ -3,7 +3,11 @@ use { alloc::string::ToString, arch::hardware_random_u64, holeybytes::{ecah::LogError, kernel_services::block_read, Vm}, - ipc::{protocol, protocol::Protocol}, + ipc::{ + buffer::IpcBuffer, + protocol::{self, Protocol}, + }, + kmain::IPC_BUFFERS, }, alloc::string::String, hashbrown::HashMap, @@ -22,7 +26,7 @@ pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), let sds_event_type: ServiceEventType = msg_vec[0].into(); msg_vec.remove(0); - info!("Length {}", msg_vec.len()); + // info!("Length {}", msg_vec.len()); use ServiceEventType::*; match sds_event_type { @@ -66,6 +70,10 @@ impl From for ServiceEventType { // 1 => 2 => Self::DeleteService, 3 => Self::SearchServices, + 10 => { + info!("TEST"); + panic!() + } 1_u8 | 4_u8..=u8::MAX => todo!(), } } @@ -74,10 +82,15 @@ impl From for ServiceEventType { fn sds_create_service(protocol: String) -> u64 { let buff_id = hardware_random_u64(); let mut services = SERVICES.lock(); + let mut buffers = IPC_BUFFERS.lock(); let protocol_ = Protocol::from(protocol.clone()); + let mut buff = IpcBuffer::new(false, 0); + + services.0.insert(buff_id, protocol_.clone()); + buff.protocol = protocol_.clone(); + buffers.insert(buff_id, buff); - services.0.insert(buff_id, protocol_); trace!("BufferID({}) => {}", buff_id, protocol); // let a: protocol::Protocol = protocol.into(); buff_id @@ -87,6 +100,7 @@ fn sds_search_service(protocol: String) -> u64 { let mut services = SERVICES.lock(); let compare = Protocol::from(protocol.clone()); for (bid, protocol_canidate) in &services.0 { + trace!("BID-{bid} protocol_canidate {:?}", protocol_canidate); if protocol_canidate == &compare { trace!("BufferID({}) => {}", bid, protocol.clone()); return *bid; diff --git a/kernel/src/ipc/buffer.rs b/kernel/src/ipc/buffer.rs index 6eb47cec2..71756bb7a 100644 --- a/kernel/src/ipc/buffer.rs +++ b/kernel/src/ipc/buffer.rs @@ -54,19 +54,21 @@ impl IpcBuffer { } }; } - pub fn pop(&mut self) -> Message { + pub fn pop(&mut self) -> Result { let msg = match &self.buffer { BufferTypes::Unbound(buff) => buff.pop(), BufferTypes::Bound(buff) => buff.pop(), }; match msg { - Some(msg) => return msg, - None => panic!("Recieving msg error. No messages!"), + Some(msg) => return Ok(msg), + None => return Err(IpcError::NoMessagesInBuffer), } } } /// Interprocess Communication Errors +#[derive(Debug)] pub enum IpcError { /// An invalid message error returned to the sender InvalidMessage, + NoMessagesInBuffer, } diff --git a/kernel/src/ipc/protocol.rs b/kernel/src/ipc/protocol.rs index 70b302829..e8cead341 100644 --- a/kernel/src/ipc/protocol.rs +++ b/kernel/src/ipc/protocol.rs @@ -3,14 +3,14 @@ use { hashbrown::HashMap, log::info, }; -#[derive(PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Type {} -#[derive(PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Funct { takes: Vec, gives: Vec, } -#[derive(PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Protocol { types: HashMap, fns: HashMap, diff --git a/sysdata/libraries/stn/src/log.hb b/sysdata/libraries/stn/src/log.hb index f336c56bc..42cf4a666 100644 --- a/sysdata/libraries/stn/src/log.hb +++ b/sysdata/libraries/stn/src/log.hb @@ -1,4 +1,5 @@ string := @use("rel:string.hb") +buffer := @use("rel:buffer.hb") log := fn(message: ^u8, level: u8): void { message_length := string.length(message); diff --git a/sysdata/programs/a_serial_driver/src/main.hb b/sysdata/programs/a_serial_driver/src/main.hb index 80f877fd9..6ec614e19 100644 --- a/sysdata/programs/a_serial_driver/src/main.hb +++ b/sysdata/programs/a_serial_driver/src/main.hb @@ -23,11 +23,26 @@ main := fn(): int { a := buffer.create("XNumber\0") serial_println("Starting Serial Driver.\0") + mem := memory.request_page(1) + + loop { + ptr := @eca(int, 4, a, mem, 4096) + if ptr == 0 { + serial_println("No message\0") + } + if ptr > 0 { + serial_println("Yes message\0") + serial_println(mem) + break + } + } + // Note that the first byte is reserved, pad accordingly. b := buffer.search("XNumber\0") if a == b { serial_println("Stopping Serial Driver.\0") } + return 0 } \ No newline at end of file diff --git a/sysdata/programs/serial_driver_test/meta.toml b/sysdata/programs/serial_driver_test/meta.toml new file mode 100644 index 000000000..f8f995c92 --- /dev/null +++ b/sysdata/programs/serial_driver_test/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "serial_driver_test" +authors = ["able"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/serial_driver_test/src/main.hb b/sysdata/programs/serial_driver_test/src/main.hb new file mode 100644 index 000000000..c1f676189 --- /dev/null +++ b/sysdata/programs/serial_driver_test/src/main.hb @@ -0,0 +1,21 @@ +stn := @use("../../../libraries/stn/src/lib.hb"); +.{string, memory, buffer} := stn + +frame_buffer := @as(^u8, @bitcast(18446603339442421760)) + +log_info := fn(): void { + a := buffer.search("XNumber\0") + if a == 0 { + } else { + msg := "XABC\0" + msg_length := string.length(msg) + @eca(void, 3, a, msg, msg_length) + } + + return +} + +main := fn(): int { + log_info() + return 0 +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index f72427051..f0539ef83 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -28,3 +28,7 @@ path = "boot:///diskio_driver.hbf" [boot.limine.ableos.modules.fb_driver] path = "boot:///fb_driver.hbf" + + +[boot.limine.ableos.modules.serial_driver_test] +path = "boot:///serial_driver_test.hbf"