Logging stuff
This commit is contained in:
parent
32779a05bc
commit
f487ec2c0b
35
Cargo.lock
generated
35
Cargo.lock
generated
@ -41,6 +41,12 @@ version = "0.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e763eef8846b13b380f37dfecda401770b0ca4e56e95170237bd7c25c7db3582"
|
checksum = "e763eef8846b13b380f37dfecda401770b0ca4e56e95170237bd7c25c7db3582"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "critical-section"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flagset"
|
name = "flagset"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@ -55,25 +61,16 @@ checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gila"
|
name = "gila"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flagset",
|
"flagset",
|
||||||
"lazy_static",
|
|
||||||
"limine",
|
"limine",
|
||||||
|
"once_cell",
|
||||||
"spin",
|
"spin",
|
||||||
"talc",
|
"talc",
|
||||||
"vga",
|
"vga",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazy_static"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|
||||||
dependencies = [
|
|
||||||
"spin",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "limine"
|
name = "limine"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@ -102,6 +99,22 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.20.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
|
||||||
|
dependencies = [
|
||||||
|
"critical-section",
|
||||||
|
"portable-atomic",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic"
|
||||||
|
version = "1.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.19"
|
version = "1.0.19"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "gila"
|
name = "gila"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
flagset = "0.4.6"
|
flagset = "0.4.6"
|
||||||
lazy_static = { version = "1.5.0", features = ["spin_no_std"] }
|
|
||||||
limine = "0.3.1"
|
limine = "0.3.1"
|
||||||
|
once_cell = { version = "1.20.3", default-features = false, features = ["alloc", "critical-section"] }
|
||||||
spin = "0.9.8"
|
spin = "0.9.8"
|
||||||
talc = "4.4.2"
|
talc = "4.4.2"
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
# Gila v0.2.0 - a Rust Microkernel
|
# Gila v0.2.1 - a Rust Microkernel
|
||||||
|
|
||||||
Gila is a Rust microkernel OS, inspired by the Xinu embedded OS. It will
|
Gila is a Rust microkernel OS, inspired by the Xinu embedded OS. It will
|
||||||
hopefully be capable of multitasking some day. I do not intend for Gila to
|
hopefully be capable of multitasking some day. I do not intend for Gila to
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
/// Boot services, handled by the Limine boot protocol.
|
/// Boot services, handled by the Limine boot protocol.
|
||||||
pub mod boot;
|
pub mod boot;
|
||||||
|
/// Logger structure and trait.
|
||||||
|
pub mod log;
|
||||||
/// Memory regions, allocation, flags, and whatnot.
|
/// Memory regions, allocation, flags, and whatnot.
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
/// Panic handling function logic.
|
/// Panic handling function logic.
|
||||||
|
67
src/log.rs
Normal file
67
src/log.rs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
extern crate alloc;
|
||||||
|
use alloc::vec::*;
|
||||||
|
use spin::Mutex;
|
||||||
|
|
||||||
|
pub static LOGGER: Mutex<Logger> = Mutex::new(Logger::new());
|
||||||
|
|
||||||
|
pub struct EnumParseError {}
|
||||||
|
|
||||||
|
pub struct Logger {
|
||||||
|
pub level: LogLevel,
|
||||||
|
pub subscriber: Vec<alloc::boxed::Box<dyn LogSubscriber + Send + Sync>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait LogSubscriber {
|
||||||
|
fn write(&self, msg: &str);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Logger {
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Logger {
|
||||||
|
level: LogLevel::WARNING,
|
||||||
|
subscriber: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
pub fn log(&self, level: LogLevel, msg: &str) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum LogLevel {
|
||||||
|
DISABLED,
|
||||||
|
CRITICAL,
|
||||||
|
ERROR,
|
||||||
|
WARNING,
|
||||||
|
INFO,
|
||||||
|
TRACE,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<u8> for LogLevel {
|
||||||
|
type Error = EnumParseError;
|
||||||
|
fn try_from(from: u8) -> Result<Self, Self::Error> {
|
||||||
|
match from {
|
||||||
|
0 => Ok(Self::DISABLED),
|
||||||
|
1 => Ok(Self::CRITICAL),
|
||||||
|
2 => Ok(Self::ERROR),
|
||||||
|
3 => Ok(Self::WARNING),
|
||||||
|
4 => Ok(Self::INFO),
|
||||||
|
5 => Ok(Self::TRACE),
|
||||||
|
_ => Err(EnumParseError {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&str> for LogLevel {
|
||||||
|
type Error = EnumParseError;
|
||||||
|
fn try_from(from: &str) -> Result<Self, Self::Error> {
|
||||||
|
match from.to_ascii_lowercase().as_ref() {
|
||||||
|
"disabled" => Ok(Self::DISABLED),
|
||||||
|
"critical" => Ok(Self::CRITICAL),
|
||||||
|
"error" => Ok(Self::ERROR),
|
||||||
|
"warning" => Ok(Self::WARNING),
|
||||||
|
"info" => Ok(Self::INFO),
|
||||||
|
"trace" => Ok(Self::TRACE),
|
||||||
|
_ => Err(EnumParseError {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,8 +4,11 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
|
use core::ops::Deref;
|
||||||
|
|
||||||
use gila::arch::current::*;
|
use gila::arch::current::*;
|
||||||
use gila::boot::*;
|
use gila::boot::*;
|
||||||
|
use gila::log::*;
|
||||||
use gila::memory;
|
use gila::memory;
|
||||||
use gila::panic;
|
use gila::panic;
|
||||||
use gila::params;
|
use gila::params;
|
||||||
@ -21,6 +24,12 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
|
|
||||||
let _kernel_parameters = get_kernel_params(kernel_file_response.file().cmdline());
|
let _kernel_parameters = get_kernel_params(kernel_file_response.file().cmdline());
|
||||||
|
|
||||||
|
if let Some(level) = _kernel_parameters.get("-log") {
|
||||||
|
if let Ok(parsed_level) = LogLevel::try_from(level.as_str()) {
|
||||||
|
LOGGER.lock().level = parsed_level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let _smp_response = SMP_REQUEST.get_response();
|
let _smp_response = SMP_REQUEST.get_response();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
use crate::memory::MemoryRegion;
|
use crate::memory::MemoryRegion;
|
||||||
|
|
||||||
use lazy_static;
|
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
Loading…
Reference in New Issue
Block a user