forked from AbleOS/ableos
integrating logging fully
This commit is contained in:
parent
750f4e71b8
commit
5ba9d28f5d
|
@ -1,11 +1,7 @@
|
||||||
#![allow(clippy::print_literal)]
|
#![allow(clippy::print_literal)]
|
||||||
use {
|
use {
|
||||||
super::{gdt, interrupts},
|
super::{gdt, interrupts},
|
||||||
crate::{
|
crate::{info, println},
|
||||||
info,
|
|
||||||
log::{self, Log},
|
|
||||||
println,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::alloc::vec;
|
use alloc::{string::String, vec, vec::Vec};
|
||||||
use crate::String;
|
// use crate::String;
|
||||||
use crate::Vec;
|
// use crate::Vec;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Mime {
|
pub enum Mime {
|
||||||
|
@ -11,7 +11,6 @@ pub enum Mime {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref CLIPBOARD: spin::Mutex<Clipboard> = {
|
pub static ref CLIPBOARD: spin::Mutex<Clipboard> = {
|
||||||
let clipboard = Clipboard::new();
|
let clipboard = Clipboard::new();
|
||||||
|
|
||||||
spin::Mutex::new(clipboard)
|
spin::Mutex::new(clipboard)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
use crate::serial_println;
|
use crate::trace;
|
||||||
|
|
||||||
pub struct MailBoxes {
|
pub struct MailBoxes {
|
||||||
flags: u8,
|
flags: u8,
|
||||||
mailboxes: [u64; 4],
|
mailboxes: [u64; 4],
|
||||||
}
|
}
|
||||||
impl MailBoxes {
|
impl MailBoxes {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
@ -51,22 +52,52 @@ impl MailBoxes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn dump_flags(&self) {
|
pub fn dump_flags(&self) {
|
||||||
serial_println!("Flag 0: {:08b}", self.flags & 0b0000_0001);
|
trace!(
|
||||||
serial_println!("Flag 1: {:08b}", self.flags & 0b0000_0010);
|
"Flag 0: {:08b} | {}",
|
||||||
serial_println!("Flag 2: {:08b}", self.flags & 0b0000_0100);
|
self.flags & 0b0000_0001,
|
||||||
serial_println!("Flag 3: {:08b}", self.flags & 0b0000_1000);
|
self.flags & 0b0000_0001
|
||||||
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);
|
|
||||||
|
|
||||||
serial_println!("Flag 0: {}", self.flags & 0b0000_0001);
|
trace!(
|
||||||
serial_println!("Flag 1: {}", self.flags >> 1 & 0b0000_0001);
|
"Flag 1: {:08b} | {}",
|
||||||
serial_println!("Flag 2: {}", self.flags >> 2 & 0b0000_0001);
|
self.flags & 0b0000_0010,
|
||||||
serial_println!("Flag 3: {}", self.flags >> 3 & 0b0000_0001);
|
self.flags >> 1 & 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);
|
trace!(
|
||||||
serial_println!("Flag 7: {}", self.flags >> 7 & 0b0000_0001);
|
"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)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
pub mod clip;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod systeminfo;
|
pub mod systeminfo;
|
||||||
pub mod virtual_memory;
|
pub mod virtual_memory;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// Deprecated
|
||||||
|
|
||||||
pub type Priority = [Process; 512];
|
pub type Priority = [Process; 512];
|
||||||
|
|
||||||
pub struct VirtualMemoryTable {}
|
pub struct VirtualMemoryTable {}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use {
|
||||||
relib::math::rand::RAND_HANDLE,
|
relib::math::rand::RAND_HANDLE,
|
||||||
scheduler::{test_fn, Thread, ThreadList},
|
scheduler::{test_fn, Thread, ThreadList},
|
||||||
},
|
},
|
||||||
alloc::{boxed::Box, rc::Rc, vec, vec::Vec},
|
alloc::vec,
|
||||||
lazy_static::lazy_static,
|
lazy_static::lazy_static,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ lazy_static! {
|
||||||
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
|
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::log::{self, Log};
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn kernel_main() -> ! {
|
pub fn kernel_main() -> ! {
|
||||||
init::init();
|
init::init();
|
||||||
|
@ -44,20 +43,10 @@ pub fn kernel_main() -> ! {
|
||||||
GraphicsBuffer::draw();
|
GraphicsBuffer::draw();
|
||||||
GraphicsBuffer::hide_cursor();
|
GraphicsBuffer::hide_cursor();
|
||||||
GraphicsBuffer::show_cursor();
|
GraphicsBuffer::show_cursor();
|
||||||
if false {
|
|
||||||
test_alloc();
|
|
||||||
}
|
|
||||||
// crate::wasm::evaluate();
|
// crate::wasm::evaluate();
|
||||||
|
|
||||||
println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||||
info!("{} 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();
|
// stack_overflow();
|
||||||
// crate::arch::shutdown();
|
// crate::arch::shutdown();
|
||||||
|
@ -74,31 +63,3 @@ pub fn tick() {
|
||||||
pub fn key_entropy(key: u8) {
|
pub fn key_entropy(key: u8) {
|
||||||
RAND_HANDLE.lock().seed_entropy_keyboard(key);
|
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 info(val: &str);
|
||||||
fn trace(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 crate::serial_print;
|
||||||
use lliw::{Fg, Reset};
|
use lliw::{Fg, Reset};
|
||||||
|
@ -26,27 +41,40 @@ impl Log for ANSISerialLogger {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! debug {
|
macro_rules! debug {
|
||||||
($($arg:tt)*) => ({
|
($($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_export]
|
||||||
macro_rules! error {
|
macro_rules! error {
|
||||||
($($arg:tt)*) => ({
|
($($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_export]
|
||||||
macro_rules! info {
|
macro_rules! info {
|
||||||
($($arg:tt)*) => ({
|
($($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_export]
|
||||||
macro_rules! trace {
|
macro_rules! trace {
|
||||||
($($arg:tt)*) => ({
|
($($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 {
|
||||||
use core::panic::PanicInfo;
|
crate::{arch::sloop, println},
|
||||||
|
core::panic::PanicInfo,
|
||||||
|
};
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
println!("{}", info);
|
println!("{}", info);
|
||||||
serial_println!("{}", info);
|
error!("{}", info);
|
||||||
sloop()
|
sloop()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use core::fmt::{Arguments, Error};
|
||||||
impl Stdout {
|
impl Stdout {
|
||||||
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
|
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(())
|
// Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{kmain::THREAD_LIST, log},
|
||||||
kmain::THREAD_LIST,
|
|
||||||
log::{self, Log},
|
|
||||||
},
|
|
||||||
alloc::{vec, vec::Vec},
|
alloc::{vec, vec::Vec},
|
||||||
core::cmp::Ordering,
|
core::cmp::Ordering,
|
||||||
};
|
};
|
||||||
|
@ -12,6 +9,7 @@ pub type ThreadID = u64;
|
||||||
pub type TaskID = u64;
|
pub type TaskID = u64;
|
||||||
pub type ThreadList = Vec<Thread>;
|
pub type ThreadList = Vec<Thread>;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Eq, Debug)]
|
#[derive(Eq, Debug)]
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
id: TaskID,
|
id: TaskID,
|
||||||
|
@ -32,7 +30,6 @@ impl Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ord for Task {
|
impl Ord for Task {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
self.id.cmp(&other.id)
|
self.id.cmp(&other.id)
|
||||||
|
|
Loading…
Reference in a new issue