Skip to content

Commit

Permalink
build: Add logger
Browse files Browse the repository at this point in the history
Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Jul 5, 2024
1 parent f3cd7ad commit 93acb48
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2024 Akira Moroo

pub struct Logger;

impl log::Log for Logger {
fn enabled(&self, metadata: &log::Metadata) -> bool {
metadata.level() <= log::Level::Info
}

fn log(&self, record: &log::Record) {
if self.enabled(record.metadata()) {
log!("[{}] {}", record.level(), record.args());
}
}

fn flush(&self) {}
}

pub fn init() {
log::set_logger(&Logger).expect("Failed to set logger");
log::set_max_level(log::LevelFilter::Info);
}
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mod fdt;
mod integration;
mod layout;
mod loader;
mod logger;
mod mem;
mod part;
mod pci;
Expand Down Expand Up @@ -183,6 +184,7 @@ fn boot_from_device(
#[no_mangle]
pub extern "C" fn rust64_start(#[cfg(not(feature = "coreboot"))] pvh_info: &pvh::StartInfo) -> ! {
serial::PORT.borrow_mut().init();
logger::init();

arch::x86_64::sse::enable_sse();
arch::x86_64::paging::setup();
Expand All @@ -204,6 +206,7 @@ pub extern "C" fn rust64_start(x0: *const u8) -> ! {

// Use atomic operation before MMU enabled may cause exception, see https://www.ipshop.xyz/5909.html
serial::PORT.borrow_mut().init();
logger::init();

let info = fdt::StartInfo::new(
x0,
Expand All @@ -226,6 +229,7 @@ pub extern "C" fn rust64_start(a0: u64, a1: *const u8) -> ! {
use crate::bootinfo::{EntryType, Info, MemoryEntry};

serial::PORT.borrow_mut().init();
logger::init();

log!("Starting on RV64 0x{:x} 0x{:x}", a0, a1 as u64,);

Expand Down

0 comments on commit 93acb48

Please sign in to comment.