Formatting
This commit is contained in:
parent
b3fe90ba25
commit
249c1ae92c
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
use enumflags2::{BitFlag, BitFlags};
|
use enumflags2::{BitFlag, BitFlags};
|
||||||
use intbits::Bits;
|
use intbits::Bits;
|
||||||
use x86_64::instructions::port::Port;
|
|
||||||
use num_traits::FromPrimitive;
|
|
||||||
use num_derive::FromPrimitive;
|
use num_derive::FromPrimitive;
|
||||||
|
use num_traits::FromPrimitive;
|
||||||
|
use x86_64::instructions::port::Port;
|
||||||
|
|
||||||
/// Represents an x86 port-mapped serial port.
|
/// Represents an x86 port-mapped serial port.
|
||||||
pub struct SerialPort {
|
pub struct SerialPort {
|
||||||
@ -124,7 +124,6 @@ pub enum ModemStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SerialPort {
|
impl SerialPort {
|
||||||
|
|
||||||
pub fn log_write(&mut self, msg: &str) {
|
pub fn log_write(&mut self, msg: &str) {
|
||||||
if self.crlf == Crlf::Crlf {
|
if self.crlf == Crlf::Crlf {
|
||||||
for c in msg.chars() {
|
for c in msg.chars() {
|
||||||
@ -192,7 +191,8 @@ impl SerialPort {
|
|||||||
/// Get the baud rate divisor.
|
/// Get the baud rate divisor.
|
||||||
pub fn get_divisor(&mut self) -> u16 {
|
pub fn get_divisor(&mut self) -> u16 {
|
||||||
self.set_dlab(true);
|
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);
|
self.set_dlab(false);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
@ -201,7 +201,8 @@ impl SerialPort {
|
|||||||
self.set_dlab(true);
|
self.set_dlab(true);
|
||||||
unsafe {
|
unsafe {
|
||||||
self.base_port.write((divisor & 0b11111111) as u8);
|
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);
|
self.set_dlab(false);
|
||||||
}
|
}
|
||||||
@ -338,5 +339,4 @@ impl SerialPort {
|
|||||||
pub fn get_modem_status(&mut self) -> BitFlags<ModemStatus> {
|
pub fn get_modem_status(&mut self) -> BitFlags<ModemStatus> {
|
||||||
ModemStatus::from_bits(unsafe { self.modem_status.read() }).unwrap()
|
ModemStatus::from_bits(unsafe { self.modem_status.read() }).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
// Copyright (c) 2025 shibedrill
|
// Copyright (c) 2025 shibedrill
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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::constants::LOG_DEFAULT_LEVEL;
|
||||||
|
use crate::format;
|
||||||
|
use crate::memory::alloc::boxed::Box;
|
||||||
use crate::memory::alloc::string::String;
|
use crate::memory::alloc::string::String;
|
||||||
|
use crate::memory::alloc::vec::Vec;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use crate::format;
|
|
||||||
|
|
||||||
pub type LogDevice = dyn Fn(&str) + Send + Sync;
|
pub type LogDevice = dyn Fn(&str) + Send + Sync;
|
||||||
|
|
||||||
pub struct Logger {
|
pub struct Logger {
|
||||||
pub level: LogLevel,
|
pub level: LogLevel,
|
||||||
devices: Vec<Box<LogDevice>>
|
devices: Vec<Box<LogDevice>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@ -34,7 +34,6 @@ macro_rules! log_trace {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! log_warning {
|
macro_rules! log_warning {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
@ -42,7 +41,6 @@ macro_rules! log_warning {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! log_error {
|
macro_rules! log_error {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
@ -50,7 +48,6 @@ macro_rules! log_error {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! log_critical {
|
macro_rules! log_critical {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
@ -58,14 +55,30 @@ macro_rules! log_critical {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Logger {
|
impl Logger {
|
||||||
pub fn new() -> Self {
|
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 {
|
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)
|
dev(&message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,20 +20,26 @@ mod process;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
use arch::x86_64::interrupts::IDT;
|
||||||
use boot::{BASE_REVISION, params, *};
|
use boot::{BASE_REVISION, params, *};
|
||||||
use log::*;
|
use log::*;
|
||||||
use memory::alloc::{format, vec, boxed::Box, string::{String, ToString}};
|
use memory::alloc::{
|
||||||
use arch::x86_64::interrupts::IDT;
|
boxed::Box,
|
||||||
|
format,
|
||||||
|
string::{String, ToString},
|
||||||
|
vec,
|
||||||
|
};
|
||||||
use params::*;
|
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::arch::x86_64::serial::SerialPort;
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use limine::firmware_type::FirmwareType;
|
||||||
|
use spin::mutex::Mutex;
|
||||||
|
|
||||||
lazy_static! {
|
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)]
|
#[unsafe(no_mangle)]
|
||||||
@ -59,7 +65,7 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
}
|
}
|
||||||
if log_device_list.contains(&"serial") {
|
if log_device_list.contains(&"serial") {
|
||||||
// TODO: Set up device discovery
|
// 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));
|
LOGGER.lock().add_device(Box::new(serial_logger));
|
||||||
}
|
}
|
||||||
log_trace!("Configured kernel logging devices");
|
log_trace!("Configured kernel logging devices");
|
||||||
|
Loading…
Reference in New Issue
Block a user