From cc4de4ab5e299cb5d466288268db606b5d89dcc1 Mon Sep 17 00:00:00 2001 From: able Date: Fri, 22 Mar 2024 03:58:59 -0500 Subject: [PATCH] sds prelim work --- kernel/src/holeybytes/ecah.rs | 22 +++++++++----- .../holeybytes/kernel_services/mem_serve.rs | 19 ++++-------- kernel/src/holeybytes/kernel_services/mod.rs | 14 +++++++++ .../service_definition_service.rs | 30 +++++++++++++++++++ kernel/src/holeybytes/mem.rs | 3 +- kernel/src/kmain.rs | 2 +- repbuild/src/main.rs | 1 + sysdata/protocol.idl | 5 ++++ sysdata/system_config.toml | 4 +++ sysdata/test-programs/sds_test.rhai | 16 ++++++++++ 10 files changed, 92 insertions(+), 24 deletions(-) create mode 100644 kernel/src/holeybytes/kernel_services/service_definition_service.rs create mode 100644 sysdata/protocol.idl create mode 100644 sysdata/test-programs/sds_test.rhai diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index e5808a2e7..ab0b1ff86 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -1,6 +1,14 @@ //! Environment call handling routines -use crate::allocator; +use core::borrow::Borrow; + +use crate::{ + allocator, + holeybytes::kernel_services::{ + block_read, + service_definition_service::{sds_msg_handler, SERVICES}, + }, +}; use { super::{mem::Memory, Vm}, @@ -68,6 +76,10 @@ pub fn handler(vm: &mut Vm) { use alloc::vec::Vec; match buffer_id { + 0 => match sds_msg_handler(vm, mem_addr, length) { + Ok(()) => {} + Err(err) => log::error!("Improper sds format"), + }, 1 => match log_msg_handler(vm, mem_addr, length) { Ok(()) => {} Err(err) => log::error!("Improper log format"), @@ -137,14 +149,8 @@ pub fn handler(vm: &mut Vm) { fn log_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> { // let message_length = 8 + 8 + 8; // log::info!("Mem Addr 0x{:x?} length {}", mem_addr, length); - let mut msg_vec = vec![]; + let mut msg_vec = block_read(mem_addr, length); - for x in 0..(length as isize) { - let xyz = mem_addr as *const u8; - let value = unsafe { xyz.offset(x).read() }; - // info!("{} - 0x{:x?} - {}", value, value, value as char); - msg_vec.push(value); - } let log_level = msg_vec.pop().unwrap(); match String::from_utf8(msg_vec) { Ok(strr) => { diff --git a/kernel/src/holeybytes/kernel_services/mem_serve.rs b/kernel/src/holeybytes/kernel_services/mem_serve.rs index 8f144803f..30be84504 100644 --- a/kernel/src/holeybytes/kernel_services/mem_serve.rs +++ b/kernel/src/holeybytes/kernel_services/mem_serve.rs @@ -1,5 +1,9 @@ use { - crate::holeybytes::{ecah::LogError, kernel_services::mem_serve, Vm}, + crate::holeybytes::{ + ecah::LogError, + kernel_services::{block_read, mem_serve}, + Vm, + }, log::info, }; @@ -23,19 +27,8 @@ pub fn memory_msg_handler( mem_addr: u64, length: usize, ) -> Result<(), MemoryServiceError> { - let msg_type = (mem_addr) as *const u8; - // info!("memory message type {:?}", unsafe { msg_type.read() }); + let mut msg_vec = block_read(mem_addr, length); - let ptr = (mem_addr + 1) as *const u64; - // info!("ptr: {:x?}", unsafe { ptr.read() }); - - let page_count_addr = (mem_addr + 9) as *const u8; - // let page_count = unsafe { page_count_addr.read() }; - // info!("page count {}", page_count); - // if page_count > 16 { - // use log::error; - // error!("Map less pages at a time"); - // } Ok(()) } diff --git a/kernel/src/holeybytes/kernel_services/mod.rs b/kernel/src/holeybytes/kernel_services/mod.rs index 6e454bcb5..23908efb7 100644 --- a/kernel/src/holeybytes/kernel_services/mod.rs +++ b/kernel/src/holeybytes/kernel_services/mod.rs @@ -1 +1,15 @@ +use alloc::{vec, vec::Vec}; + pub mod mem_serve; +pub mod service_definition_service; + +pub fn block_read(mem_addr: u64, length: usize) -> Vec { + let mut msg_vec = vec![]; + + for x in 0..(length as isize) { + let xyz = mem_addr as *const u8; + let value = unsafe { xyz.offset(x).read() }; + msg_vec.push(value); + } + msg_vec +} diff --git a/kernel/src/holeybytes/kernel_services/service_definition_service.rs b/kernel/src/holeybytes/kernel_services/service_definition_service.rs new file mode 100644 index 000000000..0866c3989 --- /dev/null +++ b/kernel/src/holeybytes/kernel_services/service_definition_service.rs @@ -0,0 +1,30 @@ +use { + crate::{ + alloc::string::ToString, + holeybytes::{ecah::LogError, kernel_services::block_read, Vm}, + }, + alloc::string::String, + hashbrown::HashMap, + log::info, + spin::{lazy::Lazy, Mutex}, +}; + +pub struct Services(HashMap); + +pub static SERVICES: Lazy> = Lazy::new(|| { + let mut dt = Services(HashMap::new()); + dt.0.insert(0, "SDS".to_string()); + info!("test"); + Mutex::new(dt) +}); + +pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> { + let mut msg_vec = block_read(mem_addr, length); + let buffer_id_raw = &msg_vec[0..8]; + let mut arr = [0u8; 8]; + arr.copy_from_slice(&buffer_id_raw); + let buffer_id = u64::from_le_bytes(arr); + info!("BufferID({:x?})", buffer_id); + + Ok(()) +} diff --git a/kernel/src/holeybytes/mem.rs b/kernel/src/holeybytes/mem.rs index e3f66a286..a53d66a39 100644 --- a/kernel/src/holeybytes/mem.rs +++ b/kernel/src/holeybytes/mem.rs @@ -39,6 +39,7 @@ impl hbvm::mem::Memory for Memory { ) -> Result<(), hbvm::mem::LoadError> { use log::{error, info}; if addr.get() % 4096 == 0 {} + info!("a"); core::ptr::copy(addr.get() as *const u8, target, count); Ok(()) } @@ -50,8 +51,6 @@ impl hbvm::mem::Memory for Memory { source: *const u8, count: usize, ) -> Result<(), hbvm::mem::StoreError> { - // log::info!("Storing memory"); - core::ptr::copy(source, addr.get() as *mut u8, count); Ok(()) } diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 93380a879..c016f310e 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -2,7 +2,7 @@ use { crate::{ - arch::hardware_random_u64, + arch::{hardware_random_u64, logging::SERIAL_CONSOLE}, bootmodules::{build_cmd, BootModules}, capabilities, device_tree::DeviceTree, diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index ea49725fc..d9aceea88 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -268,6 +268,7 @@ TERM_BACKDROP={} "target/test-programs/main.hbf", "target/test-programs/serial_driver.hbf", "target/test-programs/vfs_test.hbf", + "target/test-programs/sds_test.hbf", "target/test-programs/limine_framebuffer_driver.hbf", "target/test-programs/keyboard_driver.hbf", ] { diff --git a/sysdata/protocol.idl b/sysdata/protocol.idl new file mode 100644 index 000000000..cf7b25f15 --- /dev/null +++ b/sysdata/protocol.idl @@ -0,0 +1,5 @@ +type BufferID = u64; + +protocol SDS { + fn register_protocol(BufferID, String) -> bool; +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 01ac2d54f..f6ddc760a 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -25,6 +25,10 @@ cmd_line = "" path = "boot:///ecall.hbf" cmd_line = "" +[boot.limine.ableos.modules.sds_test] +path = "boot:///sds_test.hbf" +cmd_line = "" + [boot.limine.ableos.modules.main] path = "boot:///main.hbf" cmd_line = "" diff --git a/sysdata/test-programs/sds_test.rhai b/sysdata/test-programs/sds_test.rhai new file mode 100644 index 000000000..8889eabcb --- /dev/null +++ b/sysdata/test-programs/sds_test.rhai @@ -0,0 +1,16 @@ +fn set_buffer_protocol(buffer_id, string) { + let str = data::str("01234567" + string); + li64(r10, buffer_id); + str(r10, r0, str, 8); + + li64(r1, 3); + li64(r2, 0); + lra(r3, r0, str); + li64(r4, str.len); + eca(); +} + + +set_buffer_protocol(1, "string"); + +tx(); \ No newline at end of file