Improved logging stuff, cleanup
This commit is contained in:
parent
e007ba3e7f
commit
1d58152935
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -61,7 +61,7 @@ checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
|
||||
|
||||
[[package]]
|
||||
name = "gila"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"flagset",
|
||||
"limine",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "gila"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
4
Makefile
4
Makefile
@ -19,13 +19,11 @@ all: gila iso run
|
||||
# Prepare toolchain
|
||||
prepare:
|
||||
rustup install nightly
|
||||
rustup update
|
||||
rustup target add $(TARGET)
|
||||
|
||||
# Run the ISO in an emulator.
|
||||
run: build/gila.iso
|
||||
|
||||
echo $(qemu)
|
||||
|
||||
$(qemu) -drive file=build/gila.iso,format=raw,index=0,media=disk
|
||||
|
||||
# Build the bootable kernel image.
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
# Gila v0.2.1 - a Rust Microkernel
|
||||
# Gila v0.2.2 - a Rust Microkernel
|
||||
|
||||
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
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
/// Boot services, handled by the Limine boot protocol.
|
||||
pub mod boot;
|
||||
/// Logger structure and trait.
|
||||
/// Logger structure, static, and trait.
|
||||
pub mod log;
|
||||
/// Memory regions, allocation, flags, and whatnot.
|
||||
pub mod memory;
|
||||
|
26
src/log.rs
26
src/log.rs
@ -1,14 +1,20 @@
|
||||
extern crate alloc;
|
||||
use core::fmt::Write;
|
||||
|
||||
use crate::memory::alloc;
|
||||
|
||||
use alloc::boxed::*;
|
||||
use alloc::string::*;
|
||||
use alloc::vec::*;
|
||||
use spin::Mutex;
|
||||
|
||||
/// The logger exists for the entire lifetime of the kernel.
|
||||
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 subscriber: Vec<Mutex<Box<dyn LogSubscriber + Send + Sync>>>,
|
||||
}
|
||||
|
||||
pub trait LogSubscriber {
|
||||
@ -22,11 +28,21 @@ impl Logger {
|
||||
subscriber: Vec::new(),
|
||||
}
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
pub fn log(&self, level: LogLevel, msg: &str) {}
|
||||
|
||||
/// Calling log will sequentially acquire lock on all logging subscribers
|
||||
/// to write to them with a formatted log message.
|
||||
pub fn log(&self, level: LogLevel, msg: &str) {
|
||||
if level > self.level {
|
||||
for sub in &self.subscriber {
|
||||
let mut message = String::new();
|
||||
write!(&mut message, "{:?}: {}", level, msg).unwrap();
|
||||
sub.lock().write(&message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
pub enum LogLevel {
|
||||
DISABLED,
|
||||
CRITICAL,
|
||||
|
19
src/main.rs
19
src/main.rs
@ -1,20 +1,18 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(allocator_api)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use core::ops::Deref;
|
||||
|
||||
use gila::arch::current::display;
|
||||
use gila::arch::current::*;
|
||||
use gila::boot::*;
|
||||
use gila::log::*;
|
||||
use gila::memory;
|
||||
use gila::memory::alloc::*;
|
||||
use gila::panic;
|
||||
use gila::params;
|
||||
use gila::params::get_kernel_params;
|
||||
use gila::process;
|
||||
//use gila::arch::current::display;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn main() -> ! {
|
||||
@ -22,13 +20,22 @@ unsafe extern "C" fn main() -> ! {
|
||||
|
||||
let kernel_file_response = FILE_REQUEST.get_response().unwrap();
|
||||
|
||||
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 Some(level) = kernel_parameters.get("-loglevel") {
|
||||
if let Ok(parsed_level) = LogLevel::try_from(level.as_str()) {
|
||||
LOGGER.lock().level = parsed_level;
|
||||
}
|
||||
}
|
||||
if let Some(device) = kernel_parameters.get("-logdev") {
|
||||
let log_device_list: vec::Vec<&str> = device.split(',').collect();
|
||||
if log_device_list.contains(&"display") {
|
||||
// Append display console to log subs
|
||||
}
|
||||
if log_device_list.contains(&"serial") {
|
||||
// Append serial console to log subs
|
||||
}
|
||||
}
|
||||
|
||||
let _smp_response = SMP_REQUEST.get_response();
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use flagset::flags;
|
||||
@ -7,6 +6,8 @@ use core::alloc::{Allocator, Layout};
|
||||
use spin;
|
||||
use talc::*;
|
||||
|
||||
pub extern crate alloc;
|
||||
|
||||
static mut ARENA: [u8; 10000] = [0; 10000];
|
||||
|
||||
#[global_allocator]
|
||||
@ -17,6 +18,7 @@ static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
|
||||
})
|
||||
.lock();
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct MemoryRegion {
|
||||
start_address: usize,
|
||||
end_address: usize,
|
||||
|
@ -1,4 +1,4 @@
|
||||
extern crate alloc;
|
||||
use crate::memory::alloc;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use crate::memory::MemoryRegion;
|
||||
|
||||
extern crate alloc;
|
||||
use crate::memory::alloc;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
pub struct ProcessTable {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Process {
|
||||
/// Unique process ID.
|
||||
proc_id: u32,
|
||||
|
Loading…
Reference in New Issue
Block a user