增加内核日志功能 #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
RUSTLIB_PATH = ../rustlib/${ARCH}/lib
RUST_LIBS = "${RUSTLIB_PATH}/libaddr2line.rlib" "${RUSTLIB_PATH}/libadler.rlib" \
"${RUSTLIB_PATH}/liballoc.rlib" "${RUSTLIB_PATH}/libcfg_if.rlib" "${RUSTLIB_PATH}/libcompiler_builtins.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"
RUST_LIBS = "${RUSTLIB_PATH}/liballoc.rlib" "${RUSTLIB_PATH}/libcompiler_builtins.rlib" \
"${RUSTLIB_PATH}/libcore.rlib" "${RUSTLIB_PATH}/librustc_std_workspace_core.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" {
fn system_time_get() -> usize;
@ -14,8 +16,8 @@ pub struct SystemTime {
ns_time: usize,
}
impl Debug for SystemTime {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl ToString for SystemTime {
fn to_string(&self) -> alloc::string::String {
let second_dur = 1000usize;
let minute_dur = second_dur * 60;
let hour_dur = minute_dur * 60;
@ -93,8 +95,7 @@ impl Debug for SystemTime {
minute /= minute_dur;
let milisec = second % second_dur;
second /= second_dur;
write!(
f,
format!(
"[{:02}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}]",
year, month, day, hour, minute, second, milisec
)
@ -118,7 +119,7 @@ impl Ord 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) {
Some(Ordering::Equal) => self.ns_time.partial_cmp(&other.ns_time),
ord => ord,

View File

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

View File

@ -1,7 +1,6 @@
use std::{
ops::{Deref, DerefMut},
ptr::null_mut,
};
use core::{ops::{Deref, DerefMut}, ptr::null_mut};
use alloc::{vec, vec::Vec};
/// ## RwLock<T>
/// 读写锁

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" {
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 {
fn to_string(&self) -> String {
format!("Color({: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)
format!("{:02x}{:02x}{:02x}", self.0, self.1, self.2)
}
}
@ -165,11 +166,13 @@ impl ColorPair {
}
}
impl Debug for ColorPair {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl ToString for ColorPair {
fn to_string(&self) -> String {
match self {
ColorPair::Reset => write!(f, "\x1b{{}}"),
ColorPair::Color { fore, back } => write!(f, "\x1b{{{:?}{:?}}}", fore, back),
ColorPair::Reset => format!("\x1b{{}}"),
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 libk;