From f4246ae38757137280b660173d442b7693878783 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 12 Aug 2024 08:15:50 -0500 Subject: [PATCH] SEARCHING for dynamically created buffers now works using buffer.create / buffer.search --- kernel/src/holeybytes/ecah.rs | 6 ++-- .../service_definition_service.rs | 32 ++++++++++++++--- kernel/src/ipc/buffer.rs | 1 - kernel/src/ipc/protocol.rs | 12 +++---- sysdata/libraries/stn/src/buffer.hb | 12 +++++-- sysdata/programs/serial_driver/meta.toml | 11 ++++++ sysdata/programs/serial_driver/src/main.hb | 34 ++++++++++++++++--- sysdata/programs/time_driver/src/main.hb | 1 - sysdata/system_config.toml | 6 ++-- 9 files changed, 88 insertions(+), 27 deletions(-) create mode 100644 sysdata/programs/serial_driver/meta.toml diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 59eb329..cd1493a 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -68,7 +68,7 @@ pub fn handler(vm: &mut Vm) { let buffer_id = vm.registers[3].cast::(); let mem_addr = vm.registers[4].cast::(); let length = vm.registers[5].cast::() as usize; - debug!("IPC address: {:?}", mem_addr); + trace!("IPC address: {:?}", mem_addr); use alloc::vec::Vec; match buffer_id { @@ -111,7 +111,7 @@ pub fn handler(vm: &mut Vm) { let value = unsafe { x86_in(addr) }; - info!("Read the value {} from address {}", value, addr); + trace!("Read the value {} from address {}", value, addr); vm.registers[1] = hbvm::value::Value(value as u64); } 1 => { @@ -125,7 +125,7 @@ pub fn handler(vm: &mut Vm) { let value = msg_vec[0]; msg_vec.remove(0); - info!("Setting the address {} to {}", addr, value); + trace!("Setting the address {} to {}", addr, value); unsafe { x86_out(addr, value) }; } _ => {} diff --git a/kernel/src/holeybytes/kernel_services/service_definition_service.rs b/kernel/src/holeybytes/kernel_services/service_definition_service.rs index 7a79bee..a7497bc 100644 --- a/kernel/src/holeybytes/kernel_services/service_definition_service.rs +++ b/kernel/src/holeybytes/kernel_services/service_definition_service.rs @@ -22,14 +22,21 @@ 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()); + use ServiceEventType::*; match sds_event_type { CreateService => { let string = String::from_utf8(msg_vec).expect("Our bytes should be valid utf8"); - sds_create_service(string); + let ret = sds_create_service(string); + vm.registers[1] = hbvm::value::Value(ret as u64); } DeleteService => todo!(), - SearchServices => todo!(), + SearchServices => { + let string = String::from_utf8(msg_vec).expect("Our bytes should be valid utf8"); + let ret = sds_search_service(string); + vm.registers[1] = hbvm::value::Value(ret as u64); + } } // let buffer_id_raw = &msg_vec[0..8]; // let mut arr = [0u8; 8]; @@ -67,8 +74,23 @@ impl From for ServiceEventType { fn sds_create_service(protocol: String) -> u64 { let buff_id = hardware_random_u64(); let mut services = SERVICES.lock(); - services.0.insert(buff_id, protocol.clone().into()); - info!("BufferID({}) => {}", buff_id, protocol); - let a: protocol::Protocol = protocol.into(); + + let protocol_ = Protocol::from(protocol.clone()); + + services.0.insert(buff_id, protocol_); + trace!("BufferID({}) => {}", buff_id, protocol); + // let a: protocol::Protocol = protocol.into(); buff_id } + +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 { + if protocol_canidate == &compare { + trace!("BufferID({}) => {}", bid, protocol.clone()); + return *bid; + } + } + 0 +} diff --git a/kernel/src/ipc/buffer.rs b/kernel/src/ipc/buffer.rs index 596a0c6..6eb47ce 100644 --- a/kernel/src/ipc/buffer.rs +++ b/kernel/src/ipc/buffer.rs @@ -23,7 +23,6 @@ impl IpcBuffer { bounded, length ); - match (bounded, length) { (false, a) => { let buftype = BufferTypes::Unbound(SegQueue::new()); diff --git a/kernel/src/ipc/protocol.rs b/kernel/src/ipc/protocol.rs index bd1c3e0..70b3028 100644 --- a/kernel/src/ipc/protocol.rs +++ b/kernel/src/ipc/protocol.rs @@ -3,13 +3,14 @@ use { hashbrown::HashMap, log::info, }; - +#[derive(PartialEq)] pub struct Type {} +#[derive(PartialEq)] pub struct Funct { takes: Vec, gives: Vec, } - +#[derive(PartialEq)] pub struct Protocol { types: HashMap, fns: HashMap, @@ -29,11 +30,10 @@ impl Protocol { impl From for Protocol { fn from(value: alloc::string::String) -> Self { - if value.starts_with("protocol") { - info!("ABC"); - } + let mut hm_t = HashMap::new(); + hm_t.insert(value, Type {}); Self { - types: HashMap::new(), + types: hm_t, fns: HashMap::new(), } } diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index f252b07..1f5bb17 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -11,9 +11,15 @@ send_message := fn(buffer_id: int): void { return } -create := fn(): int { - msg := "\{01}Number\0" +create := fn(msg: ^u8): int { msg_length := string.length(msg); *msg = 0 - return @eca(int, 1, 0, msg, msg_length) + return @eca(int, 3, 0, msg, msg_length) +} + +search := fn(msg: ^u8): int { + msg_length := string.length(msg); + *msg = 3 + + return @eca(int, 3, 0, msg, msg_length) } \ No newline at end of file diff --git a/sysdata/programs/serial_driver/meta.toml b/sysdata/programs/serial_driver/meta.toml new file mode 100644 index 0000000..33de705 --- /dev/null +++ b/sysdata/programs/serial_driver/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "serial_driver" +authors = ["Able"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/serial_driver/src/main.hb b/sysdata/programs/serial_driver/src/main.hb index db85d0b..c4854b2 100644 --- a/sysdata/programs/serial_driver/src/main.hb +++ b/sysdata/programs/serial_driver/src/main.hb @@ -1,7 +1,31 @@ +stn := @use("../../../libraries/stn/src/lib.hb"); +.{log, string, memory, buffer} := stn -main:= fn(): int { - arch := "Arm"; - ADDR := 0x09000000; - loop { } - return 0; +serial_print := fn(ptr: ^u8): void { + letter := 0 + loop if *ptr == 0 break else { + letter = *ptr + memory.outb(3, 248, letter) + ptr += 1 + } + return +} + +serial_println := fn(ptr: ^u8): void { + serial_print(ptr) + memory.outb(3, 248, 12) + memory.outb(3, 248, 13) + return +} + +main := fn(): int { + serial_println("Starting Serial Driver.\0") + // Note that the first byte is reserved, pad accordingly. + a := buffer.create("XNumber\0") + 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/time_driver/src/main.hb b/sysdata/programs/time_driver/src/main.hb index c388403..45e752b 100644 --- a/sysdata/programs/time_driver/src/main.hb +++ b/sysdata/programs/time_driver/src/main.hb @@ -5,7 +5,6 @@ s := stn.string page := 0 main := fn(): void { - page += mem.request_page(1) port_str := "\0\0\{47}\0" a := @eca(u8, 3, 3, port_str, 4) diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index eaad34b..624b1ed 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -19,12 +19,12 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.tests] # path = "boot:///tests.hbf" +[boot.limine.ableos.modules.serial_driver] +path = "boot:///serial_driver.hbf" + [boot.limine.ableos.modules.diskio_driver] path = "boot:///diskio_driver.hbf" [boot.limine.ableos.modules.fb_driver] path = "boot:///fb_driver.hbf" - -# [boot.limine.ableos.modules.time_driver] -# path = "boot:///time_driver.hbf"