integrating logging fully
This commit is contained in:
parent
750f4e71b8
commit
5ba9d28f5d
|
@ -1,11 +1,7 @@
|
|||
#![allow(clippy::print_literal)]
|
||||
use {
|
||||
super::{gdt, interrupts},
|
||||
crate::{
|
||||
info,
|
||||
log::{self, Log},
|
||||
println,
|
||||
},
|
||||
crate::{info, println},
|
||||
};
|
||||
|
||||
pub fn init() {
|
||||
|
|
|
@ -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<Clipboard> = {
|
||||
let clipboard = Clipboard::new();
|
||||
|
||||
spin::Mutex::new(clipboard)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
pub mod clip;
|
||||
pub mod server;
|
||||
pub mod systeminfo;
|
||||
pub mod virtual_memory;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// Deprecated
|
||||
|
||||
pub type Priority = [Process; 512];
|
||||
|
||||
pub struct VirtualMemoryTable {}
|
||||
|
|
|
@ -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<u64> = 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<u8> = 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)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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)*));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Thread>;
|
||||
|
||||
#[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)
|
||||
|
|
Loading…
Reference in a new issue