A nice stopping point so I can lament work

This commit is contained in:
able 2023-10-28 08:43:32 -05:00
parent c8f500470e
commit 707528ef86
2 changed files with 56 additions and 9 deletions

View file

@ -1,8 +1,8 @@
//! Environment call handling routines //! Environment call handling routines
use { use {
super::{mem::Memory, Vm}, super::{mem::Memory, Vm},
crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS}, crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS},
alloc::string::String,
log::{debug, error, info, trace, warn}, log::{debug, error, info, trace, warn},
}; };
@ -53,18 +53,19 @@ pub fn handler(vm: &mut Vm) {
} }
3 => { 3 => {
// Send a message to a buffer // Send a message to a buffer
let r254 = vm.registers[254].cast::<u64>(); let r2 = vm.registers[2].cast::<u64>();
let r253 = vm.registers[253].cast::<u64>(); let r3 = vm.registers[3].cast::<u64>();
let r252 = vm.registers[252].cast::<u64>(); let r4 = vm.registers[4].cast::<u64>();
let buffer_id = r254; let buffer_id = r2;
let mem_addr = r253; let mem_addr = r3;
let length = r252 as usize; let length = r4 as usize;
trace!("IPC address: {:?}", mem_addr); trace!("IPC address: {:?}", mem_addr);
use alloc::vec::Vec; use alloc::vec::Vec;
match buffer_id { match buffer_id {
1 => { 1 => {
log_msg_handler(vm, mem_addr, length);
error!("Logging via IPC isn't quite ready") error!("Logging via IPC isn't quite ready")
} }
buffer_id => { buffer_id => {
@ -79,3 +80,49 @@ 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;
let mut msg_vec = vec![];
for x in 0..(message_length as isize) {
let xyz = mem_addr as *const u8;
let value = unsafe { xyz.offset(x).read() };
info!("{} - {:x?} - {}", value, value, value as char);
msg_vec.push(value);
}
// use LogLevel::*;
// let log_level = match bytes[0] {
// 0 => Error,
// 2 => Info,
// _ => return Err(LogError::InvalidLogFormat),
// };
// println!("Log Level {:?}", log_level);
// let mut msg_ptr_arr = [0u8; 8];
// msg_ptr_arr.copy_from_slice(&bytes[8..=15]);
// let msg_ptr = u64::from_le_bytes(msg_ptr_arr) as *const u8;
// info!("bytes ptr: {:?}", msg_ptr);
// let mut msg_len_arr = [0u8; 8];
// msg_len_arr.copy_from_slice(&bytes[16..=23]);
// let msg_len = usize::from_le_bytes(msg_len_arr);
// info!("MSG Len: {}", msg_len);
// let mut str_vec = vec![];
// for offset in 0..(msg_len as isize) {
// let value = unsafe { msg_ptr.offset(offset).read() };
// info!("{} - {}", value, value as char);
// str_vec.push(value);
// }
// let log_message = String::from_utf8(str_vec).unwrap();
// info!("{}", log_message);
Ok(())
}
pub enum LogError {
InvalidLogFormat,
}
use alloc::vec;

View file

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