From 5ba9d28f5d0224cf2a78c6849a725e00e8e1cd1d Mon Sep 17 00:00:00 2001 From: Able Date: Fri, 24 Dec 2021 07:03:15 -0600 Subject: [PATCH] integrating logging fully --- ableos/src/arch/x86_64/init.rs | 6 +-- ableos/src/experiments/clip.rs | 7 ++- ableos/src/experiments/mail.rs | 69 ++++++++++++++++++++++-------- ableos/src/experiments/mod.rs | 1 + ableos/src/experiments/schedule.rs | 2 + ableos/src/kmain.rs | 41 +----------------- ableos/src/log.rs | 38 +++++++++++++--- ableos/src/panic.rs | 12 +++--- ableos/src/print.rs | 2 +- ableos/src/scheduler.rs | 7 +-- 10 files changed, 101 insertions(+), 84 deletions(-) diff --git a/ableos/src/arch/x86_64/init.rs b/ableos/src/arch/x86_64/init.rs index e19df2bb..a0319a94 100644 --- a/ableos/src/arch/x86_64/init.rs +++ b/ableos/src/arch/x86_64/init.rs @@ -1,11 +1,7 @@ #![allow(clippy::print_literal)] use { super::{gdt, interrupts}, - crate::{ - info, - log::{self, Log}, - println, - }, + crate::{info, println}, }; pub fn init() { diff --git a/ableos/src/experiments/clip.rs b/ableos/src/experiments/clip.rs index 5f63ffd4..f5f72846 100644 --- a/ableos/src/experiments/clip.rs +++ b/ableos/src/experiments/clip.rs @@ -1,6 +1,6 @@ -use crate::alloc::vec; -use crate::String; -use crate::Vec; +use alloc::{string::String, vec, vec::Vec}; +// use crate::String; +// use crate::Vec; use lazy_static::lazy_static; #[derive(Debug)] pub enum Mime { @@ -11,7 +11,6 @@ pub enum Mime { lazy_static! { pub static ref CLIPBOARD: spin::Mutex = { let clipboard = Clipboard::new(); - spin::Mutex::new(clipboard) }; } diff --git a/ableos/src/experiments/mail.rs b/ableos/src/experiments/mail.rs index 63e5b972..43f486eb 100644 --- a/ableos/src/experiments/mail.rs +++ b/ableos/src/experiments/mail.rs @@ -1,8 +1,9 @@ #![allow(dead_code)] -use crate::serial_println; +use crate::trace; + pub struct MailBoxes { - flags: u8, - mailboxes: [u64; 4], + flags: u8, + mailboxes: [u64; 4], } impl MailBoxes { pub fn new() -> Self { @@ -51,22 +52,52 @@ impl MailBoxes { } } pub fn dump_flags(&self) { - serial_println!("Flag 0: {:08b}", self.flags & 0b0000_0001); - serial_println!("Flag 1: {:08b}", self.flags & 0b0000_0010); - serial_println!("Flag 2: {:08b}", self.flags & 0b0000_0100); - serial_println!("Flag 3: {:08b}", self.flags & 0b0000_1000); - serial_println!("Flag 4: {:08b}", self.flags & 0b0001_0000); - serial_println!("Flag 5: {:08b}", self.flags & 0b0010_0000); - serial_println!("Flag 6: {:08b}", self.flags & 0b0100_0000); - serial_println!("Flag 7: {:08b}", self.flags & 0b1000_0000); + trace!( + "Flag 0: {:08b} | {}", + self.flags & 0b0000_0001, + self.flags & 0b0000_0001 + ); - serial_println!("Flag 0: {}", self.flags & 0b0000_0001); - serial_println!("Flag 1: {}", self.flags >> 1 & 0b0000_0001); - serial_println!("Flag 2: {}", self.flags >> 2 & 0b0000_0001); - serial_println!("Flag 3: {}", self.flags >> 3 & 0b0000_0001); - serial_println!("Flag 4: {}", self.flags >> 4 & 0b0000_0001); - serial_println!("Flag 5: {}", self.flags >> 5 & 0b0000_0001); - serial_println!("Flag 6: {}", self.flags >> 6 & 0b0000_0001); - serial_println!("Flag 7: {}", self.flags >> 7 & 0b0000_0001); + trace!( + "Flag 1: {:08b} | {}", + self.flags & 0b0000_0010, + self.flags >> 1 & 0b0000_0001 + ); + + trace!( + "Flag 2: {:08b} | {}", + self.flags & 0b0000_0100, + self.flags >> 2 & 0b0000_0001 + ); + + trace!( + "Flag 3: {:08b} | {}", + self.flags & 0b0000_1000, + self.flags >> 3 & 0b0000_0001 + ); + + trace!( + "Flag 4: {:08b} | {}", + self.flags & 0b0001_0000, + self.flags >> 4 & 0b0000_0001 + ); + + trace!( + "Flag 5: {:08b} | {}", + self.flags & 0b0010_0000, + self.flags >> 5 & 0b0000_0001 + ); + + trace!( + "Flag 6: {:08b} | {}", + self.flags & 0b0100_0000, + self.flags >> 6 & 0b0000_0001 + ); + + trace!( + "Flag 7: {:08b} | {}", + self.flags & 0b1000_0000, + self.flags >> 7 & 0b0000_0001 + ); } } diff --git a/ableos/src/experiments/mod.rs b/ableos/src/experiments/mod.rs index d8bf70f7..75686028 100644 --- a/ableos/src/experiments/mod.rs +++ b/ableos/src/experiments/mod.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] +pub mod clip; pub mod server; pub mod systeminfo; pub mod virtual_memory; diff --git a/ableos/src/experiments/schedule.rs b/ableos/src/experiments/schedule.rs index 0384d48f..e168f4d4 100644 --- a/ableos/src/experiments/schedule.rs +++ b/ableos/src/experiments/schedule.rs @@ -1,3 +1,5 @@ +// Deprecated + pub type Priority = [Process; 512]; pub struct VirtualMemoryTable {} diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 7329ae7a..d43055b0 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -11,7 +11,7 @@ use { relib::math::rand::RAND_HANDLE, scheduler::{test_fn, Thread, ThreadList}, }, - alloc::{boxed::Box, rc::Rc, vec, vec::Vec}, + alloc::vec, lazy_static::lazy_static, }; @@ -30,7 +30,6 @@ lazy_static! { pub static ref TICK: spin::Mutex = spin::Mutex::new(0); } -use crate::log::{self, Log}; #[no_mangle] pub fn kernel_main() -> ! { init::init(); @@ -44,20 +43,10 @@ pub fn kernel_main() -> ! { GraphicsBuffer::draw(); GraphicsBuffer::hide_cursor(); GraphicsBuffer::show_cursor(); - if false { - test_alloc(); - } // crate::wasm::evaluate(); println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); - { - use crate::experiments::mail::MailBoxes; - let mut x = MailBoxes::new(); - x.set_flag(1); - x.set_flag(2); - // x.dump_flags(); - } // stack_overflow(); // crate::arch::shutdown(); @@ -74,31 +63,3 @@ pub fn tick() { pub fn key_entropy(key: u8) { RAND_HANDLE.lock().seed_entropy_keyboard(key); } - -fn test_alloc() { - let x: Vec = vec![1]; - println!("{:?}", x); - - let heap_value = Box::new(41); - println!("heap_value at {:p}", heap_value); - - // create a dynamically sized vector - let mut vec = Vec::new(); - for i in 0..500 { - vec.push(i); - } - println!("vec at {:p}", vec.as_slice()); - - // create a reference counted vector -> will be freed when count reaches 0 - let reference_counted = Rc::new(vec![1, 2, 3]); - let cloned_reference = reference_counted.clone(); - println!( - "current reference count is {}", - Rc::strong_count(&cloned_reference) - ); - core::mem::drop(reference_counted); - println!( - "reference count is {} now", - Rc::strong_count(&cloned_reference) - ); -} diff --git a/ableos/src/log.rs b/ableos/src/log.rs index ccfd3347..99330512 100644 --- a/ableos/src/log.rs +++ b/ableos/src/log.rs @@ -4,6 +4,21 @@ pub trait Log { fn info(val: &str); fn trace(val: &str); } +pub struct LogState { + pub debug: bool, + pub error: bool, + pub info: bool, + pub trace: bool, +} + +lazy_static::lazy_static! { + pub static ref LOG_STATE: LogState = LogState { + debug: true, + error: true, + info: true, + trace: true, + }; +} use crate::serial_print; use lliw::{Fg, Reset}; @@ -26,27 +41,40 @@ impl Log for ANSISerialLogger { #[macro_export] macro_rules! debug { ($($arg:tt)*) => ({ - let _ = &log::ANSISerialLogger::debug(&alloc::format!($($arg)*)); + if $crate::log::LOG_STATE.debug{ + use crate::log::Log; + + let _ = &log::ANSISerialLogger::debug(&alloc::format!($($arg)*)); + } }) } #[macro_export] macro_rules! error { ($($arg:tt)*) => ({ - log::ANSISerialLogger::error(&alloc::format!($($arg)*)); - }) + if $crate::log::LOG_STATE.error{ + use crate::log::Log; + crate::log::ANSISerialLogger::error(&alloc::format!($($arg)*)); + } + }); } #[macro_export] macro_rules! info { ($($arg:tt)*) => ({ - log::ANSISerialLogger::info(&alloc::format!($($arg)*)); + if $crate::log::LOG_STATE.info{ + use crate::log::Log; + crate::log::ANSISerialLogger::info(&alloc::format!($($arg)*)); + } }) } #[macro_export] macro_rules! trace { ($($arg:tt)*) => ({ - log::ANSISerialLogger::trace(&alloc::format!($($arg)*)); + if $crate::log::LOG_STATE.trace{ + use crate::log::Log; + crate::log::ANSISerialLogger::trace(&alloc::format!($($arg)*)); + } }) } diff --git a/ableos/src/panic.rs b/ableos/src/panic.rs index 794139a6..ef857b6d 100644 --- a/ableos/src/panic.rs +++ b/ableos/src/panic.rs @@ -1,9 +1,11 @@ -use crate::{arch::sloop, println, serial_println}; -use core::panic::PanicInfo; +use { + crate::{arch::sloop, println}, + core::panic::PanicInfo, +}; #[panic_handler] fn panic(info: &PanicInfo) -> ! { - println!("{}", info); - serial_println!("{}", info); - sloop() + println!("{}", info); + error!("{}", info); + sloop() } diff --git a/ableos/src/print.rs b/ableos/src/print.rs index 76a2013e..f1ee4fc1 100644 --- a/ableos/src/print.rs +++ b/ableos/src/print.rs @@ -3,7 +3,7 @@ use core::fmt::{Arguments, Error}; impl Stdout { pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */ { - core::fmt::Write::write_fmt(self, arg); + let _ = core::fmt::Write::write_fmt(self, arg); // Ok(()) } } diff --git a/ableos/src/scheduler.rs b/ableos/src/scheduler.rs index 1fe3ca28..9800031c 100644 --- a/ableos/src/scheduler.rs +++ b/ableos/src/scheduler.rs @@ -1,8 +1,5 @@ use { - crate::{ - kmain::THREAD_LIST, - log::{self, Log}, - }, + crate::{kmain::THREAD_LIST, log}, alloc::{vec, vec::Vec}, core::cmp::Ordering, }; @@ -12,6 +9,7 @@ pub type ThreadID = u64; pub type TaskID = u64; pub type ThreadList = Vec; +#[allow(dead_code)] #[derive(Eq, Debug)] pub struct Task { id: TaskID, @@ -32,7 +30,6 @@ impl Task { } } } - impl Ord for Task { fn cmp(&self, other: &Self) -> Ordering { self.id.cmp(&other.id)