diff --git a/Cargo.lock b/Cargo.lock index 477aa0e..53ca6a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,7 @@ checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e" [[package]] name = "gila" -version = "0.2.1" +version = "0.2.2" dependencies = [ "flagset", "limine", diff --git a/Cargo.toml b/Cargo.toml index 80f9844..5d4a831 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gila" -version = "0.2.1" +version = "0.2.2" edition = "2024" [dependencies] diff --git a/Makefile b/Makefile index f2b6402..568414b 100644 --- a/Makefile +++ b/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. diff --git a/README.md b/README.md index d36a6c3..fb8a8f8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 998e30c..4907cb9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/log.rs b/src/log.rs index 7814b81..e8a9696 100644 --- a/src/log.rs +++ b/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 = Mutex::new(Logger::new()); pub struct EnumParseError {} pub struct Logger { pub level: LogLevel, - pub subscriber: Vec>, + pub subscriber: Vec>>, } 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, diff --git a/src/main.rs b/src/main.rs index 7069261..09792cf 100644 --- a/src/main.rs +++ b/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(); diff --git a/src/memory.rs b/src/memory.rs index 128f1a3..a621b86 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -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, ClaimOnOom> = Talc::new(unsafe { }) .lock(); +#[allow(dead_code)] pub struct MemoryRegion { start_address: usize, end_address: usize, diff --git a/src/params.rs b/src/params.rs index 350b29f..a92c276 100644 --- a/src/params.rs +++ b/src/params.rs @@ -1,4 +1,4 @@ -extern crate alloc; +use crate::memory::alloc; use alloc::string::String; use alloc::vec::Vec; diff --git a/src/process.rs b/src/process.rs index c49fcc9..353ac4a 100644 --- a/src/process.rs +++ b/src/process.rs @@ -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,