1
0
Fork 0
forked from AbleOS/ableos

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. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
use core::{ use {
core::{
alloc::{GlobalAlloc, Layout}, alloc::{GlobalAlloc, Layout},
mem, mem,
ptr::{self, NonNull}, ptr::{self, NonNull},
},
log::trace,
spin::Mutex,
}; };
use spin::Mutex;
struct Allocator(Mutex<Option<Heap>>); struct Allocator(Mutex<Option<Heap>>);
unsafe impl GlobalAlloc for Allocator { unsafe impl GlobalAlloc for Allocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
// log::info!("Global allocation");
let mut lock = self.0.lock(); let mut lock = self.0.lock();
let allocator = lock.as_mut().expect("heap allocator should be initialized"); 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? // FIXME: umm is `memory` VirtualAddress or PhysicalAddress? both?
pub fn init(memory: *mut u8, memory_size: usize) { 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) }); *ALLOCATOR.0.lock() = Some(unsafe { Heap::new(memory, memory_size) });
} }
@ -146,12 +146,20 @@ impl Heap {
self.allocated_chunks += chunks_needed; self.allocated_chunks += chunks_needed;
let ptr: *mut u8 = unsafe { mem::transmute(header.add(1)) }; let ptr: *mut u8 = unsafe { mem::transmute(header.add(1)) };
{
#[cfg(debug_assertions)]
trace!("Allocating {:?}", ptr);
}
// FIXME: zero or scrub memory? // FIXME: zero or scrub memory?
assert!(ptr.is_aligned_to(alignment)); assert!(ptr.is_aligned_to(alignment));
NonNull::new(ptr) NonNull::new(ptr)
} }
fn deallocate(&mut self, ptr: *mut u8) { fn deallocate(&mut self, ptr: *mut u8) {
{
#[cfg(debug_assertions)]
log::trace!("Deallocating {:?}", ptr);
}
let header = Self::allocation_header(ptr); let header = Self::allocation_header(ptr);
let start = (header as usize - self.chunks as usize) / CHUNK_SIZE; let start = (header as usize - self.chunks as usize) / CHUNK_SIZE;
assert!(self.bitmap_get(start)); assert!(self.bitmap_get(start));
@ -240,7 +248,7 @@ impl Heap {
return Some(start_of_free_chunks); return Some(start_of_free_chunks);
} }
} }
trace!("No first fit found");
None None
} }

View file

@ -17,7 +17,7 @@ pub unsafe fn init() {
tables::load_tss, tables::load_tss,
}; };
log::info!("Initialising GDT"); log::trace!("Initialising GDT");
GDT.0.load(); GDT.0.load();
CS::set_reg(GDT.1.kcode); CS::set_reg(GDT.1.kcode);
SS::set_reg(GDT.1.kdata); SS::set_reg(GDT.1.kdata);

View file

@ -1,13 +1,12 @@
use { use {
log::trace,
spin::{Lazy, Mutex}, spin::{Lazy, Mutex},
x2apic::lapic::{LocalApic, LocalApicBuilder}, x2apic::lapic::{LocalApic, LocalApicBuilder},
x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode}, x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode},
}; };
use log::info;
pub unsafe fn init() { pub unsafe fn init() {
info!("Initialising IDT"); trace!("Initialising IDT");
IDT.load(); IDT.load();
Lazy::force(&LAPIC); Lazy::force(&LAPIC);
x86_64::instructions::interrupts::enable(); x86_64::instructions::interrupts::enable();

View file

@ -1,8 +1,10 @@
use crate::memory::{MemoryManager, MAX_ORDER}; use {
use core::sync::atomic::AtomicU64; crate::memory::{MemoryManager, MAX_ORDER},
use limine::{MemmapEntry, MemoryMapEntryType, NonNullPtr}; core::sync::atomic::AtomicU64,
use spin::{Mutex, Once}; limine::{MemmapEntry, MemoryMapEntryType, NonNullPtr},
use x86_64::{structures::paging::OffsetPageTable, VirtAddr}; spin::{Mutex, Once},
x86_64::{structures::paging::OffsetPageTable, VirtAddr},
};
pub const PAGE_SIZE: usize = 4096; pub const PAGE_SIZE: usize = 4096;
@ -12,7 +14,7 @@ static PAGE_TABLE: Once<Mutex<OffsetPageTable>> = Once::new();
/// Initialise page table /// Initialise page table
pub unsafe fn init_pt(phys_base: VirtAddr) { 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); HHDM_OFFSET.store(phys_base.as_u64(), core::sync::atomic::Ordering::Relaxed);
PAGE_TABLE.call_once(|| { PAGE_TABLE.call_once(|| {
Mutex::new(OffsetPageTable::new( Mutex::new(OffsetPageTable::new(

View file

@ -3,7 +3,7 @@
use { use {
crate::{alloc::string::ToString, arch::logging::SERIAL_CONSOLE, device_tree::DeviceTree}, crate::{alloc::string::ToString, arch::logging::SERIAL_CONSOLE, device_tree::DeviceTree},
hbvm::engine::Engine, hbvm::engine::Engine,
log::{debug, info}, log::{debug, trace},
spin::{Lazy, Mutex}, spin::{Lazy, Mutex},
}; };
@ -15,24 +15,26 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
cmdline.remove(0); cmdline.remove(0);
let kcmd = clparse::Arguments::parse(cmdline.to_string()).unwrap(); let kcmd = clparse::Arguments::parse(cmdline.to_string()).unwrap();
info!("Cmdline: {kcmd:?}"); trace!("Cmdline: {kcmd:?}");
let mut kcl = xml::XMLElement::new("Kernel Command Line"); let mut kcl = xml::XMLElement::new("Kernel Command Line");
for (key, value) in kcmd.arguments { for (key, value) in kcmd.arguments {
kcl.set_attribute(key, value); kcl.set_attribute(key, value);
} }
info!("kernel command line object: {:?}", kcl); debug!("kernel command line object: {:?}", kcl);
let bootstrap = bootstrap/*.expect("no bootstrap found")*/; let bootstrap = bootstrap/*.expect("no bootstrap found")*/;
match bootstrap { match bootstrap {
Some(_bootstrap_mod) => {} Some(bootstrap_mod) => {
debug!("Bootstrap Module: {:?}", bootstrap_mod);
}
None => { None => {
info!("No bootstrap module loaded.") debug!("No bootstrap module loaded.")
} }
} }
let dt = DEVICE_TREE.lock(); let dt = DEVICE_TREE.lock();
info!("Device Tree {}", &dt); trace!("Device Tree{}", dt);
let bytes = alloc::vec![0]; let bytes = alloc::vec![0];
let mut prog = Engine::new(bytes); let mut prog = Engine::new(bytes);

View file

@ -4,7 +4,7 @@ use log::{Level, SetLoggerError};
pub fn init() -> Result<(), SetLoggerError> { pub fn init() -> Result<(), SetLoggerError> {
log::set_logger(&crate::logger::Logger)?; log::set_logger(&crate::logger::Logger)?;
log::set_max_level(log::LevelFilter::Trace); log::set_max_level(log::LevelFilter::Debug);
Ok(()) Ok(())
} }