diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index c50b0ed0..02d6753c 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -24,7 +24,7 @@ pub use error::Error; pub type Result = core::result::Result; /// The log level for the kernel -pub const LOG_LEVEL: log::Level = log::Level::Trace; +pub const LOG_LEVEL: log::Level = log::Level::Debug; /// The size of the stack in pages pub const STACK_SIZE_PAGES: u32 = 256; /// The size of the trap handler stack in pages diff --git a/kernel/src/start.rs b/kernel/src/start.rs index 4e0eb943..d1d88e2f 100644 --- a/kernel/src/start.rs +++ b/kernel/src/start.rs @@ -71,7 +71,7 @@ fn pre_init_hart(hartid: usize) { fn init(boot_info: &'static loader_api::BootInfo, minfo: &MachineInfo) { semihosting_logger::init(LOG_LEVEL.to_level_filter()); - log::trace!("{boot_info:?}"); + log::debug!("\n{boot_info}"); log::debug!("Setting up kernel heap..."); allocator::init(boot_info); diff --git a/loader/api/src/info.rs b/loader/api/src/info.rs index f4a6c10b..dd55e44a 100644 --- a/loader/api/src/info.rs +++ b/loader/api/src/info.rs @@ -1,3 +1,5 @@ +use core::fmt; +use core::fmt::Formatter; use core::ops::Range; use core::slice; use pmm::{PhysicalAddress, VirtualAddress}; @@ -88,6 +90,67 @@ impl BootInfo { } } +impl fmt::Display for BootInfo { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + writeln!(f, "{:<23} : {}", "BOOT HART", self.boot_hart)?; + writeln!( + f, + "{:<23} : {}", + "PHYSICAL MEMORY OFFSET", self.physical_memory_offset + )?; + writeln!( + f, + "{:<23} : {}..{}", + "KERNEL VIRT", self.kernel_virt.start, self.kernel_virt.end + )?; + writeln!( + f, + "{:<23} : {}..{}", + "KERNEL PHYS", self.kernel_elf.start, self.kernel_elf.end + )?; + if let Some(heap) = self.heap_region.as_ref() { + writeln!( + f, + "{:<23} : {}..{} ({}) bytes", + "KERNEL HEAP", + heap.start, + heap.end, + heap.end.sub_addr(heap.start) + )?; + } else { + writeln!(f, "{:<23} : None", "KERNEL HEAP")?; + } + writeln!( + f, + "{:<23} : {}..{}", + "LOADER REGION", self.loader_region.start, self.loader_region.end + )?; + if let Some(tls) = self.tls_template.as_ref() { + writeln!( + f, + "{:<23} : .tdata: {}..{}, .tbss: {}..{}", + "TLS TEMPLATE", + tls.start_addr, + tls.start_addr.add(tls.file_size), + tls.start_addr.add(tls.file_size), + tls.start_addr.add(tls.file_size + tls.mem_size) + )?; + } else { + writeln!(f, "{:<23} : None", "TLS TEMPLATE")?; + } + + for (idx, r) in self.memory_regions().iter().enumerate() { + writeln!( + f, + "MEMORY REGION {:<10}: {}..{} {:?}", + idx, r.range.start, r.range.end, r.kind + )?; + } + + Ok(()) + } +} + #[repr(C)] #[derive(Debug, Clone)] pub struct TlsTemplate { diff --git a/loader/src/arch/riscv64.rs b/loader/src/arch/riscv64.rs index 14c54236..aa6cc26a 100644 --- a/loader/src/arch/riscv64.rs +++ b/loader/src/arch/riscv64.rs @@ -3,7 +3,7 @@ use crate::kernel::parse_inlined_kernel; use crate::machine_info::MachineInfo; use crate::page_alloc::PageAllocator; use crate::vm::{init_kernel_aspace, KernelAddressSpace}; -use crate::ENABLE_KASLR; +use crate::{ENABLE_KASLR, LOG_LEVEL}; use arrayvec::ArrayVec; use core::arch::{asm, naked_asm}; use core::num::NonZeroUsize; @@ -87,11 +87,11 @@ fn start(hartid: usize, opaque: *const u8) -> ! { // but on actual hardware this might not be the case zero_bss(); - semihosting_logger::init(log::LevelFilter::Trace); + semihosting_logger::init(LOG_LEVEL); let minfo = unsafe { MachineInfo::from_dtb(opaque).expect("failed to parse machine info") }; - log::info!("{minfo:?}"); + log::debug!("\n{minfo}"); let self_regions = SelfRegions::collect(&minfo); log::trace!("{self_regions:?}"); diff --git a/loader/src/machine_info.rs b/loader/src/machine_info.rs index 95d1d288..8bd567ff 100644 --- a/loader/src/machine_info.rs +++ b/loader/src/machine_info.rs @@ -59,6 +59,39 @@ impl<'dt> fmt::Debug for MachineInfo<'dt> { } } +impl fmt::Display for MachineInfo<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + writeln!( + f, + "{:<17} : {:?}", + "DEVICE TREE BLOB", + self.fdt.as_ptr_range() + )?; + writeln!(f, "{:<17} : {}", "CPUS", self.cpus)?; + writeln!(f, "{:<17} : {}", "HART MASK", self.hart_mask)?; + if let Some(bootargs) = self.bootargs { + writeln!(f, "{:<17} : {:?}", "BOOTARGS", bootargs)?; + } else { + writeln!(f, "{:<17} : None", "BOOTARGS")?; + } + if let Some(rng_seed) = self.rng_seed { + writeln!(f, "{:<17} : {:?}", "PRNG SEED", rng_seed)?; + } else { + writeln!(f, "{:<17} : None", "PRNG SEED")?; + } + + for (idx, r) in self.memories.iter().enumerate() { + writeln!(f, "MEMORY REGION {:<4}: {}..{}", idx, r.start, r.end)?; + } + + // for (idx, r) in self.0.memory_regions().iter().enumerate() { + // writeln!(f, "MEMORY REGION {}: {:#>10x?}", idx, r.range.start.as_raw()..r.range.end.as_raw())?; + // } + + Ok(()) + } +} + #[derive(Debug)] enum MemoryReservation<'dt> { NoMap(&'dt str, ArrayVec, 16>), diff --git a/loader/src/main.rs b/loader/src/main.rs index 11cee78e..1ae76976 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -21,3 +21,4 @@ pub use error::Error; pub type Result = core::result::Result; pub const ENABLE_KASLR: bool = false; +pub const LOG_LEVEL: log::LevelFilter = log::LevelFilter::Debug; diff --git a/loader/src/vm.rs b/loader/src/vm.rs index c75d66ec..6210e0e8 100644 --- a/loader/src/vm.rs +++ b/loader/src/vm.rs @@ -122,7 +122,7 @@ pub fn init_kernel_aspace( }; let frame_usage = frame_alloc.frame_usage(); - log::info!( + log::debug!( "Mapping complete. Permanently used: {} KiB of {} MiB total ({:.3}%).", (frame_usage.used * arch::PAGE_SIZE) / KIB, (frame_usage.total * arch::PAGE_SIZE) / MIB,