Skip to content

Commit

Permalink
feat: display boot infomation except loongarch
Browse files Browse the repository at this point in the history
  • Loading branch information
yfblock committed Jun 3, 2024
1 parent 88420a5 commit a5743fb
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 21 deletions.
21 changes: 21 additions & 0 deletions src/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub use page_table::*;
pub use psci::system_off as shutdown;
pub use trap::{disable_irq, enable_external_irq, enable_irq, run_user_task};

use crate::debug::{display_info, println};
use crate::multicore::MultiCore;
use crate::once::LazyInit;
use crate::pagetable::PageTable;
Expand Down Expand Up @@ -55,6 +56,26 @@ pub fn rust_tmp_main(hart_id: usize, device_tree: usize) {
CPACR_EL1.write(CPACR_EL1::FPEN::TrapNothing);
aarch64_cpu::asm::barrier::isb(aarch64_cpu::asm::barrier::SY);

// Display Polyhal and Platform Information
display_info!();
println!(include_str!("../banner.txt"));
display_info!("Platform Name", "aarch64");
if let Ok(fdt) = unsafe { Fdt::from_ptr(device_tree as *const u8) } {
display_info!("Platform HART Count", "{}", fdt.cpus().count());
fdt.memory().regions().for_each(|x| {
display_info!(
"Platform Memory Region",
"{:#p} - {:#018x}",
x.starting_address,
x.starting_address as usize + x.size.unwrap()
);
});
}
display_info!("Platform Virt Mem Offset", "{:#x}", VIRT_ADDR_START);
display_info!();
display_info!("Boot HART ID", "{}", hart_id);
display_info!();

// Enter to kernel entry point(`main` function).
unsafe { crate::api::_main_for_arch(hart_id) };

Expand Down
8 changes: 8 additions & 0 deletions src/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_____ _ _ _ _
| __ \ | | | | | | /\ | |
| |__) |__ | |_ _| |__| | / \ | |
| ___/ _ \| | | | | __ | / /\ \ | |
| | | (_) | | |_| | | | |/ ____ \| |____
|_| \___/|_|\__, |_| |_/_/ \_\______|
__/ |
|___/
30 changes: 30 additions & 0 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,36 @@ use core::fmt::Write;
/// ```rust
/// DebugConsole::getchar();
/// ```

/// Print macro to print polyhal information with newline
pub(crate) macro println {
() => {
$crate::debug::print(format_args!("\n"))
},
($fmt: expr $(, $($arg: tt)+)?) => {
$crate::debug::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?))
},
}

/// Display Platform Information with specified format
/// display_info!("item name", "{}", "format");
/// The output format like below:
/// item name : format
pub(crate) macro display_info{
() => {
$crate::debug::print(format_args!("\n"))
},
($item:literal,$fmt: expr $(, $($arg: tt)+)?) => {
$crate::debug::print(format_args!(concat!("{:<26}: ", $fmt, "\n"),$item $(, $($arg)+)?))
}
}

/// Print the given arguments
#[inline]
pub(crate) fn print(args: core::fmt::Arguments) {
DebugConsole.write_fmt(args).expect("can't print arguments");
}

pub struct DebugConsole;

// Write string through DebugConsole
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![feature(naked_functions)]
#![feature(asm_const)]
#![feature(cfg_version)]
#![feature(decl_macro)]
#![cfg_attr(not(version("1.79")), feature(stdsimd))]
#![feature(const_mut_refs)]
#![feature(const_slice_from_raw_parts_mut)]
Expand Down
27 changes: 26 additions & 1 deletion src/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ pub use kcontext::{context_switch, context_switch_pt, read_current_tp, KContext}

use riscv::register::{sie, sstatus};

use crate::{api::frame_alloc, multicore::MultiCore, once::LazyInit, CPU_NUM, DTB_BIN, MEM_AREA};
use crate::{
api::frame_alloc,
debug::{display_info, println},
multicore::MultiCore,
once::LazyInit,
CPU_NUM, DTB_BIN, MEM_AREA,
};

#[percpu::def_percpu]
static CPU_ID: usize = 0;
Expand Down Expand Up @@ -63,6 +69,25 @@ pub(crate) fn rust_main(hartid: usize, device_tree: usize) {

DTB_PTR.init_by(device_tree);

display_info!();
println!(include_str!("../banner.txt"));
display_info!("Platform Name", "riscv64");
if let Ok(fdt) = unsafe { Fdt::from_ptr(device_tree as *const u8) } {
display_info!("Platform HART Count", "{}", fdt.cpus().count());
fdt.memory().regions().for_each(|x| {
display_info!(
"Platform Memory Region",
"{:#p} - {:#018x}",
x.starting_address,
x.starting_address as usize + x.size.unwrap()
);
});
}
display_info!("Platform Virt Mem Offset", "{:#x}", VIRT_ADDR_START);
display_info!();
display_info!("Boot HART ID", "{}", hartid);
display_info!();

unsafe { crate::api::_main_for_arch(hartid) };
shutdown();
}
Expand Down
65 changes: 45 additions & 20 deletions src/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ mod sigtrx;
mod time;
mod uart;

use core::cmp;

use ::multiboot::information::MemoryType;
use alloc::vec::Vec;
pub use consts::*;
Expand All @@ -34,8 +36,11 @@ use x86_64::{
};

use crate::{
currrent_arch::multiboot::use_multiboot, multicore::MultiCore, once::LazyInit, CPU_NUM,
DTB_BIN, MEM_AREA,
currrent_arch::multiboot::use_multiboot,
debug::{display_info, println},
multicore::MultiCore,
once::LazyInit,
CPU_NUM, DTB_BIN, MEM_AREA,
};

#[percpu::def_percpu]
Expand Down Expand Up @@ -84,22 +89,48 @@ fn rust_tmp_main(magic: usize, mboot_ptr: usize) {
// TODO: This is will be fixed with ACPI support
CPU_NUM.init_by(1);

info!(
"TEST CPU ID: {} ptr: {:#x}",
CPU_ID.read_current(),
unsafe { CPU_ID.current_ptr() } as usize
);
CPU_ID.write_current(345);
info!(
"TEST CPU ID: {} ptr: {:#x}",
CPU_ID.read_current(),
unsafe { CPU_ID.current_ptr() } as usize
);

info!("magic: {:#x}, mboot_ptr: {:#x}", magic, mboot_ptr);

MBOOT_PTR.init_by(mboot_ptr);

// Print PolyHAL information.
display_info!();
println!(include_str!("../banner.txt"));
display_info!("Platform Arch", "x86_64");
if let Some(features) = CpuId::new().get_feature_info() {
display_info!(
"Platform Hart Count",
"{}",
cmp::max(1, features.max_logical_processor_ids())
);
display_info!("Platform FPU Support", "{}", features.has_fpu());
}
display_info!("Platform Virt Mem Offset", "{:#x}", VIRT_ADDR_START);
if let Some(mboot) = use_multiboot(mboot_ptr as _) {
mboot
.command_line()
.inspect(|cl| display_info!("Platform Command Line", "{}", cl));
if let Some(mr) = mboot.memory_regions() {
mr.for_each(|mm| {
display_info!(
"Platform Memory Region",
"{:#018x} - {:#018x} {:?}",
mm.base_address(),
mm.base_address() + mm.length(),
mm.memory_type()
)
});
}
display_info!();
display_info!(
"Boot Image Highest Addr",
"{:#018x}",
mboot.find_highest_address()
);
}
display_info!("Boot HART ID", "{}", CPU_ID.read_current());
display_info!();

unsafe { crate::api::_main_for_arch(0) };

shutdown()
Expand All @@ -108,12 +139,6 @@ fn rust_tmp_main(magic: usize, mboot_ptr: usize) {
pub fn arch_init() {
DTB_BIN.init_by(Vec::new());
if let Some(mboot) = use_multiboot(*MBOOT_PTR as _) {
mboot
.boot_loader_name()
.inspect(|x| info!("bootloader: {}", x));
mboot
.command_line()
.inspect(|x| info!("command_line: {}", x));
let mut mem_area = Vec::new();
if mboot.has_memory_map() {
mboot
Expand Down

0 comments on commit a5743fb

Please sign in to comment.