forked from AbleOS/ableos
update on the logger
Further changes pending on the IDL
This commit is contained in:
parent
1b5cb54a2b
commit
ec25c0f207
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
holeybytes::kernel_services::{
|
holeybytes::kernel_services::{
|
||||||
block_read,
|
block_read,
|
||||||
dt_msg_handler::dt_msg_handler,
|
dt_msg_handler::dt_msg_handler,
|
||||||
|
logging_service::log_msg_handler,
|
||||||
service_definition_service::{sds_msg_handler, SERVICES},
|
service_definition_service::{sds_msg_handler, SERVICES},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -145,6 +146,7 @@ pub fn handler(vm: &mut Vm) {
|
||||||
let mut buffs = IPC_BUFFERS.lock();
|
let mut buffs = IPC_BUFFERS.lock();
|
||||||
match buffs.get_mut(&buffer_id) {
|
match buffs.get_mut(&buffer_id) {
|
||||||
Some(buff) => {
|
Some(buff) => {
|
||||||
|
use alloc::vec;
|
||||||
let mut msg_vec = vec![];
|
let mut msg_vec = vec![];
|
||||||
|
|
||||||
for x in 0..(length as isize) {
|
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> {
|
// fn memory_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> {
|
||||||
// let mut val = alloc::vec::Vec::new();
|
// let mut val = alloc::vec::Vec::new();
|
||||||
// for _ in 0..4096 {
|
// for _ in 0..4096 {
|
||||||
|
|
54
kernel/src/holeybytes/kernel_services/logging_service.rs
Normal file
54
kernel/src/holeybytes/kernel_services/logging_service.rs
Normal 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(())
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
use {
|
use {
|
||||||
crate::holeybytes::{
|
crate::holeybytes::{
|
||||||
ecah::LogError,
|
|
||||||
kernel_services::{block_read, mem_serve},
|
kernel_services::{block_read, mem_serve},
|
||||||
Vm,
|
Vm,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use alloc::{vec, vec::Vec};
|
use alloc::{vec, vec::Vec};
|
||||||
|
|
||||||
pub mod dt_msg_handler;
|
pub mod dt_msg_handler;
|
||||||
|
pub mod logging_service;
|
||||||
pub mod mem_serve;
|
pub mod mem_serve;
|
||||||
pub mod service_definition_service;
|
pub mod service_definition_service;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
alloc::string::ToString,
|
alloc::string::ToString,
|
||||||
arch::hardware_random_u64,
|
arch::hardware_random_u64,
|
||||||
holeybytes::{ecah::LogError, kernel_services::block_read, Vm},
|
holeybytes::{kernel_services::block_read, Vm},
|
||||||
ipc::{
|
ipc::{
|
||||||
buffer::IpcBuffer,
|
buffer::IpcBuffer,
|
||||||
protocol::{self, Protocol},
|
protocol::{self, Protocol},
|
||||||
|
@ -20,8 +20,10 @@ pub static SERVICES: Lazy<Mutex<Services>> = Lazy::new(|| {
|
||||||
dt.0.insert(0, Protocol::void());
|
dt.0.insert(0, Protocol::void());
|
||||||
Mutex::new(dt)
|
Mutex::new(dt)
|
||||||
});
|
});
|
||||||
|
pub enum ServiceError {
|
||||||
pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> {
|
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 mut msg_vec = block_read(mem_addr, length);
|
||||||
let sds_event_type: ServiceEventType = msg_vec[0].into();
|
let sds_event_type: ServiceEventType = msg_vec[0].into();
|
||||||
msg_vec.remove(0);
|
msg_vec.remove(0);
|
||||||
|
|
|
@ -19,19 +19,19 @@ resolution = "1024x768x24"
|
||||||
|
|
||||||
# [boot.limine.ableos.modules.tests]
|
# [boot.limine.ableos.modules.tests]
|
||||||
# path = "boot:///tests.hbf"
|
# path = "boot:///tests.hbf"
|
||||||
[boot.limine.ableos.modules.a_serial_driver]
|
# [boot.limine.ableos.modules.a_serial_driver]
|
||||||
path = "boot:///a_serial_driver.hbf"
|
# path = "boot:///a_serial_driver.hbf"
|
||||||
|
|
||||||
|
|
||||||
[boot.limine.ableos.modules.diskio_driver]
|
# [boot.limine.ableos.modules.diskio_driver]
|
||||||
path = "boot:///diskio_driver.hbf"
|
# path = "boot:///diskio_driver.hbf"
|
||||||
|
|
||||||
[boot.limine.ableos.modules.fb_driver]
|
[boot.limine.ableos.modules.fb_driver]
|
||||||
path = "boot:///fb_driver.hbf"
|
path = "boot:///fb_driver.hbf"
|
||||||
|
|
||||||
|
|
||||||
[boot.limine.ableos.modules.serial_driver_test]
|
# [boot.limine.ableos.modules.serial_driver_test]
|
||||||
path = "boot:///serial_driver_test.hbf"
|
# path = "boot:///serial_driver_test.hbf"
|
||||||
|
|
||||||
|
|
||||||
[boot.limine.ableos.modules.horizon]
|
[boot.limine.ableos.modules.horizon]
|
||||||
|
@ -41,5 +41,5 @@ path = "boot:///horizon.hbf"
|
||||||
path = "boot:///horizon_testing_program.hbf"
|
path = "boot:///horizon_testing_program.hbf"
|
||||||
|
|
||||||
|
|
||||||
[boot.limine.ableos.modules.dt_buffer_test]
|
# [boot.limine.ableos.modules.dt_buffer_test]
|
||||||
path = "boot:///dt_buffer_test.hbf"
|
# path = "boot:///dt_buffer_test.hbf"
|
||||||
|
|
Loading…
Reference in a new issue