forked from koniifer/ableos
sds prelim work
This commit is contained in:
parent
634d05acea
commit
cc4de4ab5e
|
@ -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) => {
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
] {
|
||||
|
|
5
sysdata/protocol.idl
Normal file
5
sysdata/protocol.idl
Normal file
|
@ -0,0 +1,5 @@
|
|||
type BufferID = u64;
|
||||
|
||||
protocol SDS {
|
||||
fn register_protocol(BufferID, String) -> bool;
|
||||
}
|
|
@ -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 = ""
|
||||
|
|
16
sysdata/test-programs/sds_test.rhai
Normal file
16
sysdata/test-programs/sds_test.rhai
Normal 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();
|
Loading…
Reference in a new issue