1
0
Fork 0
forked from AbleOS/ableos

fixed logging

This commit is contained in:
Able 2021-12-24 04:05:23 -06:00
parent 387d3f2bae
commit 750f4e71b8
5 changed files with 33 additions and 41 deletions

View file

@ -1,6 +1,12 @@
#![allow(clippy::print_literal)] #![allow(clippy::print_literal)]
use super::{gdt, interrupts}; use {
use crate::{println, serial_println}; super::{gdt, interrupts},
crate::{
info,
log::{self, Log},
println,
},
};
pub fn init() { pub fn init() {
gdt::init(); gdt::init();
@ -8,5 +14,5 @@ pub fn init() {
unsafe { interrupts::PICS.lock().initialize() }; unsafe { interrupts::PICS.lock().initialize() };
x86_64::instructions::interrupts::enable(); x86_64::instructions::interrupts::enable();
println!("Initialized"); println!("Initialized");
serial_println!("Initialized"); info!("Initialized");
} }

View file

@ -29,7 +29,6 @@ lazy_static! {
pub static ref THREAD_LIST: spin::Mutex<ThreadList> = spin::Mutex::new(vec![]); pub static ref THREAD_LIST: spin::Mutex<ThreadList> = spin::Mutex::new(vec![]);
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0); pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
} }
use alloc::format;
use crate::log::{self, Log}; use crate::log::{self, Log};
#[no_mangle] #[no_mangle]
@ -51,8 +50,7 @@ pub fn kernel_main() -> ! {
// crate::wasm::evaluate(); // crate::wasm::evaluate();
println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
log::ANSISerialLogger::info(&format!("{} v{}", RELEASE_TYPE, KERNEL_VERSION)); info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
{ {
use crate::experiments::mail::MailBoxes; use crate::experiments::mail::MailBoxes;
let mut x = MailBoxes::new(); let mut x = MailBoxes::new();

View file

@ -27,13 +27,14 @@ pub mod arch;
#[macro_use] #[macro_use]
pub mod print; pub mod print;
#[macro_use]
pub mod log;
pub mod allocator; pub mod allocator;
pub mod driver_traits; pub mod driver_traits;
pub mod experiments; pub mod experiments;
pub mod keyboard; pub mod keyboard;
pub mod kmain; pub mod kmain;
pub mod log;
pub mod panic; pub mod panic;
pub mod relib; pub mod relib;
pub mod scheduler; pub mod scheduler;

View file

@ -1,22 +1,14 @@
pub trait Log { pub trait Log {
<<<<<<< HEAD
fn debug(val: &str); fn debug(val: &str);
fn error(val: &str); fn error(val: &str);
fn info(val: &str); fn info(val: &str);
fn trace(val: &str); fn trace(val: &str);
=======
fn debug(val: &str);
fn error();
fn info(val: &str);
fn trace();
>>>>>>> 6a61fb8a9ede4d1a04da38100c4f7728e721b2d4
} }
use crate::serial_print; use crate::serial_print;
use lliw::{Fg, Reset}; use lliw::{Fg, Reset};
pub struct ANSISerialLogger; pub struct ANSISerialLogger;
impl Log for ANSISerialLogger { impl Log for ANSISerialLogger {
<<<<<<< HEAD
fn debug(val: &str) { fn debug(val: &str) {
serial_print!("[{}Debug{}] {}\n", Fg::Blue, Reset, val); serial_print!("[{}Debug{}] {}\n", Fg::Blue, Reset, val);
} }
@ -29,46 +21,32 @@ impl Log for ANSISerialLogger {
fn trace(val: &str) { fn trace(val: &str) {
serial_print!("[{}Trace{}] {}\n", Fg::Yellow, Reset, val); serial_print!("[{}Trace{}] {}\n", Fg::Yellow, Reset, val);
} }
=======
fn debug(val: &str) {
serial_print!("[{}Debug{}] {}\n", Fg::Blue, Reset, val);
}
fn error() {
todo!();
}
fn info(val: &str) {
serial_print!("[{}Info{}] {}\n", Fg::Blue, Reset, val);
}
fn trace() {
todo!();
}
} }
#[macro_export] #[macro_export]
macro_rules! debug { macro_rules! debug {
($($arg:tt)*) => ({ ($($arg:tt)*) => ({
log::ANSISerialLogger::debug(&format!($($arg)*)); let _ = &log::ANSISerialLogger::debug(&alloc::format!($($arg)*));
}) })
} }
#[macro_export] #[macro_export]
macro_rules! error { macro_rules! error {
($($arg:tt)*) => ({ ($($arg:tt)*) => ({
log::ANSISerialLogger::error(&format!($($arg)*)); log::ANSISerialLogger::error(&alloc::format!($($arg)*));
}) })
} }
#[macro_export] #[macro_export]
macro_rules! info { macro_rules! info {
($($arg:tt)*) => ({ ($($arg:tt)*) => ({
log::ANSISerialLogger::info(&format!($($arg)*)); log::ANSISerialLogger::info(&alloc::format!($($arg)*));
}) })
} }
#[macro_export] #[macro_export]
macro_rules! trace { macro_rules! trace {
($($arg:tt)*) => ({ ($($arg:tt)*) => ({
log::ANSISerialLogger::trace(&format!($($arg)*)); log::ANSISerialLogger::trace(&alloc::format!($($arg)*));
}) })
>>>>>>> 6a61fb8a9ede4d1a04da38100c4f7728e721b2d4
} }

View file

@ -1,9 +1,11 @@
use core::cmp::Ordering; use {
crate::{
use alloc::vec; kmain::THREAD_LIST,
use alloc::vec::Vec; log::{self, Log},
},
use crate::kmain::THREAD_LIST; alloc::{vec, vec::Vec},
core::cmp::Ordering,
};
pub type Pointer = fn(); pub type Pointer = fn();
pub type ThreadID = u64; pub type ThreadID = u64;
@ -18,6 +20,11 @@ pub struct Task {
} }
impl Task { impl Task {
fn new(parent_thread: ThreadID, task_id: u64, function_pointer: fn()) -> Self { fn new(parent_thread: ThreadID, task_id: u64, function_pointer: fn()) -> Self {
debug!(
"New task with TaskID: {} | Parent ThreadID: {}",
task_id, parent_thread
);
Self { Self {
id: task_id, id: task_id,
parent_thread, parent_thread,
@ -56,7 +63,7 @@ impl Thread {
Some(last_thread) => final_threadid = last_thread.id + 1, Some(last_thread) => final_threadid = last_thread.id + 1,
None => {} None => {}
} }
debug!("New thread with ThreadID: {}", final_threadid);
Self { Self {
id: final_threadid, id: final_threadid,
tasks: vec![], tasks: vec![],
@ -66,7 +73,9 @@ impl Thread {
self.tasks.sort(); self.tasks.sort();
} }
pub fn new_task_id(&self) -> TaskID { pub fn new_task_id(&self) -> TaskID {
self.tasks.len().try_into().unwrap() let task_id = self.tasks.len().try_into().unwrap();
trace!("New TaskID: {}", task_id);
task_id
} }
pub fn new_task(&mut self, function_pointer: fn()) { pub fn new_task(&mut self, function_pointer: fn()) {
let x = Task::new(self.id, self.new_task_id(), function_pointer); let x = Task::new(self.id, self.new_task_id(), function_pointer);