More work on the psuedo STD lib and IPC

This commit is contained in:
able 2023-10-29 07:27:10 -05:00
parent 1ae1d2ceac
commit 080bb8b188
10 changed files with 132 additions and 14 deletions

View file

@ -47,6 +47,7 @@ pub fn handler(vm: &mut Vm) {
let buff_id = arch::hardware_random_u64();
buffs.insert(buff_id, abc);
debug!("Buffer ID: {}", buff_id);
vm.registers[1] = hbvm::value::Value(buff_id);
}
2 => {
// Delete buffer
@ -66,14 +67,31 @@ pub fn handler(vm: &mut Vm) {
match buffer_id {
1 => {
log_msg_handler(vm, mem_addr, length);
// error!("Logging via IPC isn't quite ready")
}
buffer_id => {
info!("Message has been sent to {}", buffer_id)
let mut buffs = IPC_BUFFERS.lock();
let mut buff = buffs.get_mut(&buffer_id).unwrap();
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);
}
buff.push(msg_vec.clone());
info!("Message {:?} has been sent to {}", msg_vec, buffer_id);
drop(buffs);
}
}
}
// 4
4 => {
let r2 = vm.registers[2].cast::<u64>();
let mut buffs = IPC_BUFFERS.lock();
let mut buff = buffs.get_mut(&r2).unwrap();
let msg = buff.pop();
info!("Recieve {:?} from Buffer({})", msg, r2);
}
// 5
_ => {
log::error!("Syscall unknown {:?}", r1);
@ -108,6 +126,7 @@ fn log_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogE
Ok(())
}
#[derive(Debug)]
pub enum LogError {
InvalidLogFormat,
}

View file

@ -11,8 +11,8 @@ pub enum BufferTypes {
}
/// Interproccess buffer
pub struct IpcBuffer {
protocol: Protocol,
buffer: BufferTypes,
pub protocol: Protocol,
pub buffer: BufferTypes,
}
impl IpcBuffer {
@ -48,6 +48,24 @@ impl IpcBuffer {
pub fn validate_messages(&mut self) -> Result<(), IpcError> {
Ok(())
}
pub fn push(&mut self, msg: Message) {
match &self.buffer {
BufferTypes::Unbound(buff) => buff.push(msg.clone()),
BufferTypes::Bound(buff) => {
let _ = buff.push(msg.clone());
}
};
}
pub fn pop(&mut self) -> Message {
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!"),
}
}
}
/// Interprocess Communication Errors
pub enum IpcError {

View file

@ -2,7 +2,11 @@
use {hashbrown::HashMap, hbvm::mem::Address};
use crate::{capabilities, holeybytes::ExecThread, ipc::buffer::IpcBuffer};
use crate::{
capabilities,
holeybytes::ExecThread,
ipc::buffer::{self, IpcBuffer},
};
// use crate::arch::sloop;
use {
crate::{
@ -68,7 +72,13 @@ pub static DEVICE_TREE: Lazy<Mutex<DeviceTree>> = Lazy::new(|| {
use alloc::vec::Vec;
pub type IpcBuffers = HashMap<u64, IpcBuffer>;
pub static IPC_BUFFERS: Lazy<Mutex<IpcBuffers>> = Lazy::new(|| {
let bufs = HashMap::new();
let mut bufs = HashMap::new();
let log_buffer = IpcBuffer::new(false, 0);
let file_buffer = IpcBuffer::new(false, 0);
bufs.insert(1, log_buffer);
bufs.insert(2, file_buffer);
Mutex::new(bufs)
});

View file

@ -1,4 +1,3 @@
fn ipc_send(buffer_id, mem_addr, length){
// set the ecall
li8(r1, 3);
@ -8,11 +7,33 @@ fn ipc_send(buffer_id, mem_addr, length){
// set the length
li64(r4, length);
// ecall
eca();
eca();
}
fn ipc_recv(buffer_id){
li8(r1, 4);
eca();
}
fn ipc_make_bound_buffer(length) {
li8(r1, 1);
li8(r2, 1);
li64(r3, length);
eca();
// The ipc buffer id is in r1
}
private fn log(log_level, string){
// This is NOT the final format
let str = data::str(string + log_level);
// 1 byte for the log level
// 8 bytes for the length to the message
// 8 bytes for the pointer to the string
ipc_send(1, str, str.len);
}
@ -23,3 +44,10 @@ fn Info(string) {log(2, string);}
// because of this all of the log levels are upper case
fn Debug(string) {log(3, string);}
fn Trace(string) {log(4, string);}
fn open(string_path){
let file_path = data::str("Meow meow meow bark bark bark");
ipc_send(2, file_path, file_path.len);
}
fn write(){}

View file

@ -1,3 +1,3 @@
li8 (r1, 0x69);
// eca ();
li8 (r1, 2);
eca ();
tx ();

View file

@ -2,10 +2,13 @@ import "repbuild/hblib/std" as std;
fn main(){
std::Error(":+)");
std::Debug("ABC");
std::Info("Hello, world!");
std::Trace("Trace Deez");
std::Warn("Your mom fell in a well!");
std::Info("Hello, world!");
std::Debug("XYZ");
std::Trace("Trace Deez");
// let ret = std::open("/file.hbf");
// std::Info("" + ret);
tx();
}

View file

@ -0,0 +1,13 @@
/// Act as a shim of a virtual file system that recieves one message from buffer 2
import "repbuild/hblib/std" as std;
fn main() {
// jmp here
}
main();
tx();

View file

@ -0,0 +1,19 @@
import "repbuild/hblib/std" as std;
fn main(){
std::Info("Trying to open a file.");
// let ret = std::open("/file.hbf");
// std::Info("File return " + ret);
std::ipc_make_bound_buffer(1000);
let str = data::str("ABC XYZ");
std::ipc_send(2, str, str.len);
std::ipc_recv(2);
tx();
}
main();

View file

@ -26,3 +26,6 @@ TERM_BACKDROP=008080
MODULE_PATH=boot:///main.hbf
MODULE_CMDLINE=""
MODULE_PATH=boot:///vfs_test.hbf
MODULE_CMDLINE=""

View file

@ -162,6 +162,11 @@ fn get_fs() -> Result<FileSystem<impl ReadWriteSeek>, io::Error> {
&mut fs.root_dir().create_file("main.hbf")?,
)?;
io::copy(
&mut File::open("target/holeybytes/vfs_test.hbf")?,
&mut fs.root_dir().create_file("vfs_test.hbf")?,
)?;
drop(bootdir);
Ok(fs)
}