sds prelim work

This commit is contained in:
able 2024-03-22 03:58:59 -05:00
parent 634d05acea
commit cc4de4ab5e
10 changed files with 92 additions and 24 deletions

View file

@ -1,6 +1,14 @@
//! Environment call handling routines //! 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 { use {
super::{mem::Memory, Vm}, super::{mem::Memory, Vm},
@ -68,6 +76,10 @@ pub fn handler(vm: &mut Vm) {
use alloc::vec::Vec; use alloc::vec::Vec;
match buffer_id { 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) { 1 => match log_msg_handler(vm, mem_addr, length) {
Ok(()) => {} Ok(()) => {}
Err(err) => log::error!("Improper log format"), 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> { fn log_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> {
// let message_length = 8 + 8 + 8; // let message_length = 8 + 8 + 8;
// log::info!("Mem Addr 0x{:x?} length {}", mem_addr, length); // 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(); let log_level = msg_vec.pop().unwrap();
match String::from_utf8(msg_vec) { match String::from_utf8(msg_vec) {
Ok(strr) => { Ok(strr) => {

View file

@ -1,5 +1,9 @@
use { use {
crate::holeybytes::{ecah::LogError, kernel_services::mem_serve, Vm}, crate::holeybytes::{
ecah::LogError,
kernel_services::{block_read, mem_serve},
Vm,
},
log::info, log::info,
}; };
@ -23,19 +27,8 @@ pub fn memory_msg_handler(
mem_addr: u64, mem_addr: u64,
length: usize, length: usize,
) -> Result<(), MemoryServiceError> { ) -> Result<(), MemoryServiceError> {
let msg_type = (mem_addr) as *const u8; let mut msg_vec = block_read(mem_addr, length);
// info!("memory message type {:?}", unsafe { msg_type.read() });
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(()) Ok(())
} }

View file

@ -1 +1,15 @@
use alloc::{vec, vec::Vec};
pub mod mem_serve; pub mod mem_serve;
pub mod service_definition_service;
pub fn block_read(mem_addr: u64, length: usize) -> Vec<u8> {
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
}

View file

@ -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<u64, String>);
pub static SERVICES: Lazy<Mutex<Services>> = 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(())
}

View file

@ -39,6 +39,7 @@ impl hbvm::mem::Memory for Memory {
) -> Result<(), hbvm::mem::LoadError> { ) -> Result<(), hbvm::mem::LoadError> {
use log::{error, info}; use log::{error, info};
if addr.get() % 4096 == 0 {} if addr.get() % 4096 == 0 {}
info!("a");
core::ptr::copy(addr.get() as *const u8, target, count); core::ptr::copy(addr.get() as *const u8, target, count);
Ok(()) Ok(())
} }
@ -50,8 +51,6 @@ impl hbvm::mem::Memory for Memory {
source: *const u8, source: *const u8,
count: usize, count: usize,
) -> Result<(), hbvm::mem::StoreError> { ) -> Result<(), hbvm::mem::StoreError> {
// log::info!("Storing memory");
core::ptr::copy(source, addr.get() as *mut u8, count); core::ptr::copy(source, addr.get() as *mut u8, count);
Ok(()) Ok(())
} }

View file

@ -2,7 +2,7 @@
use { use {
crate::{ crate::{
arch::hardware_random_u64, arch::{hardware_random_u64, logging::SERIAL_CONSOLE},
bootmodules::{build_cmd, BootModules}, bootmodules::{build_cmd, BootModules},
capabilities, capabilities,
device_tree::DeviceTree, device_tree::DeviceTree,

View file

@ -268,6 +268,7 @@ TERM_BACKDROP={}
"target/test-programs/main.hbf", "target/test-programs/main.hbf",
"target/test-programs/serial_driver.hbf", "target/test-programs/serial_driver.hbf",
"target/test-programs/vfs_test.hbf", "target/test-programs/vfs_test.hbf",
"target/test-programs/sds_test.hbf",
"target/test-programs/limine_framebuffer_driver.hbf", "target/test-programs/limine_framebuffer_driver.hbf",
"target/test-programs/keyboard_driver.hbf", "target/test-programs/keyboard_driver.hbf",
] { ] {

5
sysdata/protocol.idl Normal file
View file

@ -0,0 +1,5 @@
type BufferID = u64;
protocol SDS {
fn register_protocol(BufferID, String) -> bool;
}

View file

@ -25,6 +25,10 @@ cmd_line = ""
path = "boot:///ecall.hbf" path = "boot:///ecall.hbf"
cmd_line = "" cmd_line = ""
[boot.limine.ableos.modules.sds_test]
path = "boot:///sds_test.hbf"
cmd_line = ""
[boot.limine.ableos.modules.main] [boot.limine.ableos.modules.main]
path = "boot:///main.hbf" path = "boot:///main.hbf"
cmd_line = "" cmd_line = ""

View file

@ -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();