1
0
Fork 0
forked from koniifer/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)]
use super::{gdt, interrupts};
use crate::{println, serial_println};
use {
super::{gdt, interrupts},
crate::{
info,
log::{self, Log},
println,
},
};
pub fn init() {
gdt::init();
@ -8,5 +14,5 @@ pub fn init() {
unsafe { interrupts::PICS.lock().initialize() };
x86_64::instructions::interrupts::enable();
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 TICK: spin::Mutex<u64> = spin::Mutex::new(0);
}
use alloc::format;
use crate::log::{self, Log};
#[no_mangle]
@ -51,8 +50,7 @@ pub fn kernel_main() -> ! {
// crate::wasm::evaluate();
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;
let mut x = MailBoxes::new();

View file

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

View file

@ -1,22 +1,14 @@
pub trait Log {
<<<<<<< HEAD
fn debug(val: &str);
fn error(val: &str);
fn info(val: &str);
fn trace(val: &str);
=======
fn debug(val: &str);
fn error();
fn info(val: &str);
fn trace();
>>>>>>> 6a61fb8a9ede4d1a04da38100c4f7728e721b2d4
}
use crate::serial_print;
use lliw::{Fg, Reset};
pub struct ANSISerialLogger;
impl Log for ANSISerialLogger {
<<<<<<< HEAD
fn debug(val: &str) {
serial_print!("[{}Debug{}] {}\n", Fg::Blue, Reset, val);
}
@ -29,46 +21,32 @@ impl Log for ANSISerialLogger {
fn trace(val: &str) {
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_rules! debug {
($($arg:tt)*) => ({
log::ANSISerialLogger::debug(&format!($($arg)*));
let _ = &log::ANSISerialLogger::debug(&alloc::format!($($arg)*));
})
}
#[macro_export]
macro_rules! error {
($($arg:tt)*) => ({
log::ANSISerialLogger::error(&format!($($arg)*));
log::ANSISerialLogger::error(&alloc::format!($($arg)*));
})
}
#[macro_export]
macro_rules! info {
($($arg:tt)*) => ({
log::ANSISerialLogger::info(&format!($($arg)*));
log::ANSISerialLogger::info(&alloc::format!($($arg)*));
})
}
#[macro_export]
macro_rules! trace {
($($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 alloc::vec;
use alloc::vec::Vec;
use crate::kmain::THREAD_LIST;
use {
crate::{
kmain::THREAD_LIST,
log::{self, Log},
},
alloc::{vec, vec::Vec},
core::cmp::Ordering,
};
pub type Pointer = fn();
pub type ThreadID = u64;
@ -18,6 +20,11 @@ pub struct Task {
}
impl Task {
fn new(parent_thread: ThreadID, task_id: u64, function_pointer: fn()) -> Self {
debug!(
"New task with TaskID: {} | Parent ThreadID: {}",
task_id, parent_thread
);
Self {
id: task_id,
parent_thread,
@ -56,7 +63,7 @@ impl Thread {
Some(last_thread) => final_threadid = last_thread.id + 1,
None => {}
}
debug!("New thread with ThreadID: {}", final_threadid);
Self {
id: final_threadid,
tasks: vec![],
@ -66,7 +73,9 @@ impl Thread {
self.tasks.sort();
}
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()) {
let x = Task::new(self.id, self.new_task_id(), function_pointer);