1
0
Fork 0
forked from koniifer/ableos

update on the logger

Further changes pending on the IDL
This commit is contained in:
Able 2024-09-13 20:50:12 -05:00
parent 1b5cb54a2b
commit ec25c0f207
6 changed files with 70 additions and 46 deletions

View file

@ -7,6 +7,7 @@ use crate::{
holeybytes::kernel_services::{
block_read,
dt_msg_handler::dt_msg_handler,
logging_service::log_msg_handler,
service_definition_service::{sds_msg_handler, SERVICES},
},
};
@ -145,6 +146,7 @@ pub fn handler(vm: &mut Vm) {
let mut buffs = IPC_BUFFERS.lock();
match buffs.get_mut(&buffer_id) {
Some(buff) => {
use alloc::vec;
let mut msg_vec = vec![];
for x in 0..(length as isize) {
@ -222,40 +224,6 @@ 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 = block_read(mem_addr, length);
let log_level = msg_vec.pop().unwrap();
match String::from_utf8(msg_vec) {
Ok(strr) => {
// use LogLevel::*;
let ll = match log_level {
0 | 48 => error!("{}", strr),
1 | 49 => warn!("{}", strr),
2 | 50 => info!("{}", strr),
3 | 51 => debug!("{}", strr),
4 | 52 => trace!("{}", strr),
_ => {
return Err(LogError::InvalidLogFormat);
}
};
}
Err(e) => {
error!("{:?}", e);
}
}
Ok(())
}
#[derive(Debug)]
pub enum LogError {
InvalidLogFormat,
}
use {alloc::vec, log::Record};
// fn memory_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> {
// let mut val = alloc::vec::Vec::new();
// for _ in 0..4096 {

View file

@ -0,0 +1,54 @@
use crate::logger::TermLogger;
use {
crate::holeybytes::{kernel_services::block_read, Vm},
alloc::string::String,
};
#[derive(Debug)]
pub enum LogError {
InvalidLogFormat,
}
use {alloc::vec, log::Record};
pub fn log_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> {
let mut msg_vec = block_read(mem_addr, length);
let log_level = msg_vec.pop().unwrap();
let file_name = "None";
let line_number = 0;
match String::from_utf8(msg_vec) {
Ok(strr) => {
use log::Level::*;
let log_level = match log_level {
0 | 48 => Error,
1 | 49 => Warn,
2 | 50 => Info,
3 | 51 => Debug,
4 | 52 => Trace,
_ => {
return Err(LogError::InvalidLogFormat);
}
};
log::logger().log(
&Record::builder()
.args(format_args!("{}", strr))
.level(log_level)
.target("Userspace")
.file(Some(file_name))
.line(Some(line_number))
.module_path(Some(&file_name))
.build(),
);
}
Err(e) => {
log::error!("{:?}", e);
}
}
Ok(())
}

View file

@ -1,6 +1,5 @@
use {
crate::holeybytes::{
ecah::LogError,
kernel_services::{block_read, mem_serve},
Vm,
},

View file

@ -1,6 +1,7 @@
use alloc::{vec, vec::Vec};
pub mod dt_msg_handler;
pub mod logging_service;
pub mod mem_serve;
pub mod service_definition_service;

View file

@ -2,7 +2,7 @@ use {
crate::{
alloc::string::ToString,
arch::hardware_random_u64,
holeybytes::{ecah::LogError, kernel_services::block_read, Vm},
holeybytes::{kernel_services::block_read, Vm},
ipc::{
buffer::IpcBuffer,
protocol::{self, Protocol},
@ -20,8 +20,10 @@ pub static SERVICES: Lazy<Mutex<Services>> = Lazy::new(|| {
dt.0.insert(0, Protocol::void());
Mutex::new(dt)
});
pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> {
pub enum ServiceError {
InvalidFormat,
}
pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), ServiceError> {
let mut msg_vec = block_read(mem_addr, length);
let sds_event_type: ServiceEventType = msg_vec[0].into();
msg_vec.remove(0);

View file

@ -19,19 +19,19 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.tests]
# path = "boot:///tests.hbf"
[boot.limine.ableos.modules.a_serial_driver]
path = "boot:///a_serial_driver.hbf"
# [boot.limine.ableos.modules.a_serial_driver]
# path = "boot:///a_serial_driver.hbf"
[boot.limine.ableos.modules.diskio_driver]
path = "boot:///diskio_driver.hbf"
# [boot.limine.ableos.modules.diskio_driver]
# path = "boot:///diskio_driver.hbf"
[boot.limine.ableos.modules.fb_driver]
path = "boot:///fb_driver.hbf"
[boot.limine.ableos.modules.serial_driver_test]
path = "boot:///serial_driver_test.hbf"
# [boot.limine.ableos.modules.serial_driver_test]
# path = "boot:///serial_driver_test.hbf"
[boot.limine.ableos.modules.horizon]
@ -41,5 +41,5 @@ path = "boot:///horizon.hbf"
path = "boot:///horizon_testing_program.hbf"
[boot.limine.ableos.modules.dt_buffer_test]
path = "boot:///dt_buffer_test.hbf"
# [boot.limine.ableos.modules.dt_buffer_test]
# path = "boot:///dt_buffer_test.hbf"