1
0
Fork 0
forked from AbleOS/ableos

Logging works enough. Still unstructured however.

This commit is contained in:
able 2023-10-28 23:14:36 -05:00
parent 707528ef86
commit 1ae1d2ceac
2 changed files with 20 additions and 34 deletions

View file

@ -9,8 +9,8 @@ use {
pub fn handler(vm: &mut Vm) {
let r1 = vm.registers[1].cast::<u64>();
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};

View file

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