diff --git a/kernel/src/allocator.rs b/kernel/src/allocator.rs index 4df7f733..8dcd3ed6 100644 --- a/kernel/src/allocator.rs +++ b/kernel/src/allocator.rs @@ -27,20 +27,20 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -use core::{ - alloc::{GlobalAlloc, Layout}, - mem, - ptr::{self, NonNull}, +use { + core::{ + alloc::{GlobalAlloc, Layout}, + mem, + ptr::{self, NonNull}, + }, + log::trace, + spin::Mutex, }; -use spin::Mutex; - struct Allocator(Mutex>); unsafe impl GlobalAlloc for Allocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - // log::info!("Global allocation"); - let mut lock = self.0.lock(); let allocator = lock.as_mut().expect("heap allocator should be initialized"); @@ -62,7 +62,7 @@ static ALLOCATOR: Allocator = Allocator(Mutex::new(None)); // FIXME: umm is `memory` VirtualAddress or PhysicalAddress? both? pub fn init(memory: *mut u8, memory_size: usize) { - log::info!("Initialising kernel heap allocator"); + trace!("Initialising kernel heap allocator"); *ALLOCATOR.0.lock() = Some(unsafe { Heap::new(memory, memory_size) }); } @@ -146,12 +146,20 @@ impl Heap { self.allocated_chunks += chunks_needed; let ptr: *mut u8 = unsafe { mem::transmute(header.add(1)) }; + { + #[cfg(debug_assertions)] + trace!("Allocating {:?}", ptr); + } // FIXME: zero or scrub memory? assert!(ptr.is_aligned_to(alignment)); NonNull::new(ptr) } fn deallocate(&mut self, ptr: *mut u8) { + { + #[cfg(debug_assertions)] + log::trace!("Deallocating {:?}", ptr); + } let header = Self::allocation_header(ptr); let start = (header as usize - self.chunks as usize) / CHUNK_SIZE; assert!(self.bitmap_get(start)); @@ -240,7 +248,7 @@ impl Heap { return Some(start_of_free_chunks); } } - + trace!("No first fit found"); None } diff --git a/kernel/src/arch/x86_64/gdt.rs b/kernel/src/arch/x86_64/gdt.rs index 4a86072e..4bc32b21 100644 --- a/kernel/src/arch/x86_64/gdt.rs +++ b/kernel/src/arch/x86_64/gdt.rs @@ -17,7 +17,7 @@ pub unsafe fn init() { tables::load_tss, }; - log::info!("Initialising GDT"); + log::trace!("Initialising GDT"); GDT.0.load(); CS::set_reg(GDT.1.kcode); SS::set_reg(GDT.1.kdata); diff --git a/kernel/src/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs index 7c08d592..63042d94 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -1,13 +1,12 @@ use { + log::trace, spin::{Lazy, Mutex}, x2apic::lapic::{LocalApic, LocalApicBuilder}, x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode}, }; -use log::info; - pub unsafe fn init() { - info!("Initialising IDT"); + trace!("Initialising IDT"); IDT.load(); Lazy::force(&LAPIC); x86_64::instructions::interrupts::enable(); diff --git a/kernel/src/arch/x86_64/memory.rs b/kernel/src/arch/x86_64/memory.rs index 3d1f9e4e..bd6d17b9 100644 --- a/kernel/src/arch/x86_64/memory.rs +++ b/kernel/src/arch/x86_64/memory.rs @@ -1,8 +1,10 @@ -use crate::memory::{MemoryManager, MAX_ORDER}; -use core::sync::atomic::AtomicU64; -use limine::{MemmapEntry, MemoryMapEntryType, NonNullPtr}; -use spin::{Mutex, Once}; -use x86_64::{structures::paging::OffsetPageTable, VirtAddr}; +use { + crate::memory::{MemoryManager, MAX_ORDER}, + core::sync::atomic::AtomicU64, + limine::{MemmapEntry, MemoryMapEntryType, NonNullPtr}, + spin::{Mutex, Once}, + x86_64::{structures::paging::OffsetPageTable, VirtAddr}, +}; pub const PAGE_SIZE: usize = 4096; @@ -12,7 +14,7 @@ static PAGE_TABLE: Once> = Once::new(); /// Initialise page table pub unsafe fn init_pt(phys_base: VirtAddr) { - log::info!("Retrieving page table"); + log::debug!("Retrieving page table"); HHDM_OFFSET.store(phys_base.as_u64(), core::sync::atomic::Ordering::Relaxed); PAGE_TABLE.call_once(|| { Mutex::new(OffsetPageTable::new( diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index de97f2fe..dde63b64 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -3,7 +3,7 @@ use { crate::{alloc::string::ToString, arch::logging::SERIAL_CONSOLE, device_tree::DeviceTree}, hbvm::engine::Engine, - log::{debug, info}, + log::{debug, trace}, spin::{Lazy, Mutex}, }; @@ -15,24 +15,26 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! { cmdline.remove(0); let kcmd = clparse::Arguments::parse(cmdline.to_string()).unwrap(); - info!("Cmdline: {kcmd:?}"); + trace!("Cmdline: {kcmd:?}"); let mut kcl = xml::XMLElement::new("Kernel Command Line"); for (key, value) in kcmd.arguments { kcl.set_attribute(key, value); } - info!("kernel command line object: {:?}", kcl); + debug!("kernel command line object: {:?}", kcl); let bootstrap = bootstrap/*.expect("no bootstrap found")*/; match bootstrap { - Some(_bootstrap_mod) => {} + Some(bootstrap_mod) => { + debug!("Bootstrap Module: {:?}", bootstrap_mod); + } None => { - info!("No bootstrap module loaded.") + debug!("No bootstrap module loaded.") } } let dt = DEVICE_TREE.lock(); - info!("Device Tree {}", &dt); + trace!("Device Tree{}", dt); let bytes = alloc::vec![0]; let mut prog = Engine::new(bytes); diff --git a/kernel/src/logger.rs b/kernel/src/logger.rs index 3b8cd3f0..2fe17a4a 100644 --- a/kernel/src/logger.rs +++ b/kernel/src/logger.rs @@ -4,7 +4,7 @@ use log::{Level, SetLoggerError}; pub fn init() -> Result<(), SetLoggerError> { log::set_logger(&crate::logger::Logger)?; - log::set_max_level(log::LevelFilter::Trace); + log::set_max_level(log::LevelFilter::Debug); Ok(()) }