LOGGING: Begin work on consistent logging style

This commit is contained in:
able 2023-05-26 06:30:17 -05:00
parent 40c072ad99
commit 49105e668d
6 changed files with 38 additions and 27 deletions

View file

@ -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<Option<Heap>>);
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
}

View file

@ -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);

View file

@ -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();

View file

@ -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<Mutex<OffsetPageTable>> = 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(

View file

@ -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);

View file

@ -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(())
}