Formatting

This commit is contained in:
August 2025-10-02 01:05:14 -04:00
parent b3fe90ba25
commit 249c1ae92c
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
3 changed files with 57 additions and 38 deletions

View File

@ -5,9 +5,9 @@
use enumflags2::{BitFlag, BitFlags};
use intbits::Bits;
use x86_64::instructions::port::Port;
use num_traits::FromPrimitive;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use x86_64::instructions::port::Port;
/// Represents an x86 port-mapped serial port.
pub struct SerialPort {
@ -124,7 +124,6 @@ pub enum ModemStatus {
}
impl SerialPort {
pub fn log_write(&mut self, msg: &str) {
if self.crlf == Crlf::Crlf {
for c in msg.chars() {
@ -192,7 +191,8 @@ impl SerialPort {
/// Get the baud rate divisor.
pub fn get_divisor(&mut self) -> u16 {
self.set_dlab(true);
let result: u16 = unsafe { self.base_port.read() as u16 | ((self.interrupt_enable.read() as u16) << 8)};
let result: u16 =
unsafe { self.base_port.read() as u16 | ((self.interrupt_enable.read() as u16) << 8) };
self.set_dlab(false);
result
}
@ -201,7 +201,8 @@ impl SerialPort {
self.set_dlab(true);
unsafe {
self.base_port.write((divisor & 0b11111111) as u8);
self.interrupt_enable.write(((divisor & 0b1111111100000000) >> 8) as u8);
self.interrupt_enable
.write(((divisor & 0b1111111100000000) >> 8) as u8);
}
self.set_dlab(false);
}
@ -338,5 +339,4 @@ impl SerialPort {
pub fn get_modem_status(&mut self) -> BitFlags<ModemStatus> {
ModemStatus::from_bits(unsafe { self.modem_status.read() }).unwrap()
}
}

View File

@ -1,19 +1,19 @@
// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: GPL-3.0-or-later
use crate::memory::alloc::vec::Vec;
use crate::memory::alloc::boxed::Box;
use crate::constants::LOG_DEFAULT_LEVEL;
use crate::format;
use crate::memory::alloc::boxed::Box;
use crate::memory::alloc::string::String;
use crate::memory::alloc::vec::Vec;
use lazy_static::lazy_static;
use spin::Mutex;
use crate::format;
pub type LogDevice = dyn Fn(&str) + Send + Sync;
pub struct Logger {
pub level: LogLevel,
devices: Vec<Box<LogDevice>>
devices: Vec<Box<LogDevice>>,
}
lazy_static! {
@ -34,7 +34,6 @@ macro_rules! log_trace {
};
}
#[macro_export]
macro_rules! log_warning {
($($arg:tt)*) => {
@ -42,7 +41,6 @@ macro_rules! log_warning {
};
}
#[macro_export]
macro_rules! log_error {
($($arg:tt)*) => {
@ -50,7 +48,6 @@ macro_rules! log_error {
};
}
#[macro_export]
macro_rules! log_critical {
($($arg:tt)*) => {
@ -58,14 +55,30 @@ macro_rules! log_critical {
};
}
impl Logger {
pub fn new() -> Self {
Logger { level: LOG_DEFAULT_LEVEL, devices: Vec::new() }
Logger {
level: LOG_DEFAULT_LEVEL,
devices: Vec::new(),
}
pub fn log(&mut self, level: LogLevel, message: &str, file: &'static str, line: u32, column: u32) {
}
pub fn log(
&mut self,
level: LogLevel,
message: &str,
file: &'static str,
line: u32,
column: u32,
) {
for dev in &self.devices {
let message = format!("{} {}:{},{}- {}", level.normalized_string(), file, line, column, message);
let message = format!(
"{} {}:{},{}- {}",
level.normalized_string(),
file,
line,
column,
message
);
dev(&message)
}
}

View File

@ -20,20 +20,26 @@ mod process;
#[macro_use]
mod util;
use arch::x86_64::interrupts::IDT;
use boot::{BASE_REVISION, params, *};
use log::*;
use memory::alloc::{format, vec, boxed::Box, string::{String, ToString}};
use arch::x86_64::interrupts::IDT;
use memory::alloc::{
boxed::Box,
format,
string::{String, ToString},
vec,
};
use params::*;
use lazy_static::lazy_static;
use limine::firmware_type::FirmwareType;
use spin::{mutex::Mutex};
use crate::arch::x86_64::serial::SerialPort;
use crate::constants::*;
use lazy_static::lazy_static;
use limine::firmware_type::FirmwareType;
use spin::mutex::Mutex;
lazy_static! {
pub static ref SERIAL_3F8: Mutex<SerialPort> = Mutex::new(arch::x86_64::serial::SerialPort::new(0x3f8));
pub static ref SERIAL_3F8: Mutex<SerialPort> =
Mutex::new(arch::x86_64::serial::SerialPort::new(0x3f8));
}
#[unsafe(no_mangle)]
@ -59,7 +65,7 @@ unsafe extern "C" fn main() -> ! {
}
if log_device_list.contains(&"serial") {
// TODO: Set up device discovery
let serial_logger = |msg: &str| {SERIAL_3F8.lock().log_writeln(msg)};
let serial_logger = |msg: &str| SERIAL_3F8.lock().log_writeln(msg);
LOGGER.lock().add_device(Box::new(serial_logger));
}
log_trace!("Configured kernel logging devices");