diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 2a69e800..aca8153d 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -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 { diff --git a/kernel/src/holeybytes/kernel_services/logging_service.rs b/kernel/src/holeybytes/kernel_services/logging_service.rs new file mode 100644 index 00000000..27392dfa --- /dev/null +++ b/kernel/src/holeybytes/kernel_services/logging_service.rs @@ -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(()) +} diff --git a/kernel/src/holeybytes/kernel_services/mem_serve.rs b/kernel/src/holeybytes/kernel_services/mem_serve.rs index 16ecbe80..d8332225 100644 --- a/kernel/src/holeybytes/kernel_services/mem_serve.rs +++ b/kernel/src/holeybytes/kernel_services/mem_serve.rs @@ -1,6 +1,5 @@ use { crate::holeybytes::{ - ecah::LogError, kernel_services::{block_read, mem_serve}, Vm, }, diff --git a/kernel/src/holeybytes/kernel_services/mod.rs b/kernel/src/holeybytes/kernel_services/mod.rs index 9d0b9fcf..58eef2d1 100644 --- a/kernel/src/holeybytes/kernel_services/mod.rs +++ b/kernel/src/holeybytes/kernel_services/mod.rs @@ -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; diff --git a/kernel/src/holeybytes/kernel_services/service_definition_service.rs b/kernel/src/holeybytes/kernel_services/service_definition_service.rs index 1a12447b..0f26960f 100644 --- a/kernel/src/holeybytes/kernel_services/service_definition_service.rs +++ b/kernel/src/holeybytes/kernel_services/service_definition_service.rs @@ -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> = 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); diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 90f4ee3b..d45fe5b1 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -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"