From 1ae1d2ceac766013b25697c702e1c260b0ac2a8f Mon Sep 17 00:00:00 2001 From: able Date: Sat, 28 Oct 2023 23:14:36 -0500 Subject: [PATCH] Logging works enough. Still unstructured however. --- kernel/src/holeybytes/ecah.rs | 52 +++++++++++++---------------------- repbuild/hblib/std.rhai | 2 +- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 73bfb7c..45683ea 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -9,8 +9,8 @@ use { pub fn handler(vm: &mut Vm) { let r1 = vm.registers[1].cast::(); - debug!("Ecall number {:?}", r1); - trace!("Register dump: {:?}", vm.registers); + // debug!("Ecall number {:?}", r1); + // trace!("Register dump: {:?}", vm.registers); match r1 { 0 => { @@ -66,7 +66,7 @@ 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") + // error!("Logging via IPC isn't quite ready") } buffer_id => { info!("Message has been sent to {}", buffer_id) @@ -82,42 +82,28 @@ 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 message_length = 8 + 8 + 8; let mut msg_vec = vec![]; - for x in 0..(message_length as isize) { + + for x in 0..(length as isize) { let xyz = mem_addr as *const u8; let value = unsafe { xyz.offset(x).read() }; - info!("{} - {:x?} - {}", value, value, value as char); + // info!("{} - {:x?} - {}", value, value, value as char); msg_vec.push(value); } + let log_level = msg_vec.pop().unwrap(); + let strr = String::from_utf8(msg_vec).unwrap(); + // info!("{}", strr); // 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); + let ll = match log_level { + 48 => error!("{}", strr), + 49 => warn!("{}", strr), + 50 => info!("{}", strr), + 51 => debug!("{}", strr), + 52 => trace!("{}", strr), + _ => return Err(LogError::InvalidLogFormat), + }; Ok(()) } @@ -125,4 +111,4 @@ fn log_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogE pub enum LogError { InvalidLogFormat, } -use alloc::vec; +use {alloc::vec, log::Record}; diff --git a/repbuild/hblib/std.rhai b/repbuild/hblib/std.rhai index 82814cf..1d64a83 100644 --- a/repbuild/hblib/std.rhai +++ b/repbuild/hblib/std.rhai @@ -12,7 +12,7 @@ fn ipc_send(buffer_id, mem_addr, length){ } private fn log(log_level, string){ - let str = data::str(string); + let str = data::str(string + log_level); ipc_send(1, str, str.len); }