增加内核日志功能 #3

Merged
pointer-to-bios merged 17 commits from pointer-to-bios/metaverse-dev:main into main 2024-02-05 22:10:26 +08:00
7 changed files with 41 additions and 40 deletions
Showing only changes of commit 6d24ee84f4 - Show all commits

@ -1 +1 @@
Subproject commit 0d9cd0822c355e784c6f4ff5ac2fd88f6d917ea7 Subproject commit a7d79f8d3d865c93dad38796530e6a4dc53a0377

View File

@ -37,16 +37,8 @@ ifeq (${ARCH},x86_64)
endif endif
RUSTLIB_PATH = ../rustlib/${ARCH}/lib RUSTLIB_PATH = ../rustlib/${ARCH}/lib
RUST_LIBS = "${RUSTLIB_PATH}/libaddr2line.rlib" "${RUSTLIB_PATH}/libadler.rlib" \ RUST_LIBS = "${RUSTLIB_PATH}/liballoc.rlib" "${RUSTLIB_PATH}/libcompiler_builtins.rlib" \
"${RUSTLIB_PATH}/liballoc.rlib" "${RUSTLIB_PATH}/libcfg_if.rlib" "${RUSTLIB_PATH}/libcompiler_builtins.rlib" \ "${RUSTLIB_PATH}/libcore.rlib" "${RUSTLIB_PATH}/librustc_std_workspace_core.rlib"
"${RUSTLIB_PATH}/libcore.rlib" "${RUSTLIB_PATH}/libgetopts.rlib" "${RUSTLIB_PATH}/libgimli.rlib" \
"${RUSTLIB_PATH}/libhashbrown.rlib" "${RUSTLIB_PATH}/libmemchr.rlib" "${RUSTLIB_PATH}/libminiz_oxide.rlib" \
"${RUSTLIB_PATH}/libobject.rlib" "${RUSTLIB_PATH}/libpanic_abort.rlib" "${RUSTLIB_PATH}/libpanic_unwind.rlib" \
"${RUSTLIB_PATH}/libproc_macro.rlib" "${RUSTLIB_PATH}/libprofiler_builtins.rlib" \
"${RUSTLIB_PATH}/librustc_demangle.rlib" "${RUSTLIB_PATH}/librustc_std_workspace_alloc.rlib" \
"${RUSTLIB_PATH}/librustc_std_workspace_core.rlib" "${RUSTLIB_PATH}/librustc_std_workspace_std.rlib" \
"${RUSTLIB_PATH}/libstd_detect.rlib" "${RUSTLIB_PATH}/libstd.rlib" "${RUSTLIB_PATH}/libsysroot.rlib" \
"${RUSTLIB_PATH}/libtest.rlib" "${RUSTLIB_PATH}/libunicode_width.rlib" "${RUSTLIB_PATH}/libunwind.rlib"
################################ ################################

View File

@ -1,4 +1,6 @@
use std::{cmp::Ordering, fmt::Debug, ops::Sub, time::Duration}; use core::{cmp::Ordering, ops::Sub, time::Duration};
use alloc::{format, string::ToString};
extern "C" { extern "C" {
fn system_time_get() -> usize; fn system_time_get() -> usize;
@ -14,8 +16,8 @@ pub struct SystemTime {
ns_time: usize, ns_time: usize,
} }
impl Debug for SystemTime { impl ToString for SystemTime {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn to_string(&self) -> alloc::string::String {
let second_dur = 1000usize; let second_dur = 1000usize;
let minute_dur = second_dur * 60; let minute_dur = second_dur * 60;
let hour_dur = minute_dur * 60; let hour_dur = minute_dur * 60;
@ -93,8 +95,7 @@ impl Debug for SystemTime {
minute /= minute_dur; minute /= minute_dur;
let milisec = second % second_dur; let milisec = second % second_dur;
second /= second_dur; second /= second_dur;
write!( format!(
f,
"[{:02}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}]", "[{:02}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}]",
year, month, day, hour, minute, second, milisec year, month, day, hour, minute, second, milisec
) )
@ -118,7 +119,7 @@ impl Ord for SystemTime {
} }
impl PartialOrd for SystemTime { impl PartialOrd for SystemTime {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match self.unix_time.partial_cmp(&other.unix_time) { match self.unix_time.partial_cmp(&other.unix_time) {
Some(Ordering::Equal) => self.ns_time.partial_cmp(&other.ns_time), Some(Ordering::Equal) => self.ns_time.partial_cmp(&other.ns_time),
ord => ord, ord => ord,

View File

@ -1,3 +1,7 @@
use alloc::string::ToString;
use alloc::{format, vec::Vec};
use alloc::vec;
use super::{ use super::{
clock::time::SystemTime, clock::time::SystemTime,
tty::tty::{Color, Message, MessageBuilder}, tty::tty::{Color, Message, MessageBuilder},
@ -149,7 +153,7 @@ impl Iterator for LogIterator {
if let Some((time, msg)) = self.logs.first() { if let Some((time, msg)) = self.logs.first() {
Some( Some(
MessageBuilder::new() MessageBuilder::new()
.message(format!("{:?}", time)) .message(format!("{}", time.to_string()))
.append(MessageBuilder::from_message(msg)) .append(MessageBuilder::from_message(msg))
.build(), .build(),
) )

View File

@ -1,19 +1,18 @@
use std::{ use core::{ops::{Deref, DerefMut}, ptr::null_mut};
ops::{Deref, DerefMut},
ptr::null_mut, use alloc::{vec, vec::Vec};
};
/// ## RwLock<T> /// ## RwLock<T>
/// 读写锁 /// 读写锁
/// ///
/// * 对于写入操作: /// * 对于写入操作:
/// ///
/// 锁没有占用时,获取锁,并执行闭包。 /// 锁没有占用时,获取锁,并执行闭包。
/// ///
/// 当锁已经被占用,将闭包悬挂。 /// 当锁已经被占用,将闭包悬挂。
/// ///
/// 释放锁时,将所有悬挂的闭包都执行。 /// 释放锁时,将所有悬挂的闭包都执行。
/// ///
/// 正在释放锁时,`write`方法返回`Err(())` /// 正在释放锁时,`write`方法返回`Err(())`
/// ///
/// ``` /// ```

View File

@ -1,4 +1,11 @@
use std::{fmt::Debug, ptr::null_mut}; use core::ptr::null_mut;
use alloc::{
format,
string::{String, ToString},
vec,
vec::Vec,
};
extern "C" { extern "C" {
fn tty_new(tty_type: u8, mode: u8) -> *mut u8; fn tty_new(tty_type: u8, mode: u8) -> *mut u8;
@ -140,13 +147,7 @@ pub struct Color(pub u8, pub u8, pub u8);
impl ToString for Color { impl ToString for Color {
fn to_string(&self) -> String { fn to_string(&self) -> String {
format!("Color({:02x}, {:02x}, {:02x})", self.0, self.1, self.2) format!("{:02x}{:02x}{:02x}", self.0, self.1, self.2)
}
}
impl Debug for Color {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:02x}{:02x}{:02x}", self.0, self.1, self.2)
} }
} }
@ -165,11 +166,13 @@ impl ColorPair {
} }
} }
impl Debug for ColorPair { impl ToString for ColorPair {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn to_string(&self) -> String {
match self { match self {
ColorPair::Reset => write!(f, "\x1b{{}}"), ColorPair::Reset => format!("\x1b{{}}"),
ColorPair::Color { fore, back } => write!(f, "\x1b{{{:?}{:?}}}", fore, back), ColorPair::Color { fore, back } => {
format!("\x1b{{{}{}}}", fore.to_string(), back.to_string())
}
} }
} }
} }

View File

@ -1,4 +1,6 @@
extern crate core; #![no_std]
extern crate alloc;
pub mod kernel; pub mod kernel;
pub mod libk; pub mod libk;