diff --git a/kernel/src/arch/Timer.cpp b/kernel/src/arch/Timer.cpp index e9694a2c..d2ac041e 100644 --- a/kernel/src/arch/Timer.cpp +++ b/kernel/src/arch/Timer.cpp @@ -1,4 +1,5 @@ #include "arch/Timer.h" +#include "Log.h" #include "arch/Serial.h" #include "boot/bootboot.h" #include @@ -46,8 +47,7 @@ static u64 bootloader_time_to_unix(u8 boottime[8]) int second = bcd_number_to_decimal(boottime[6]); // "The last byte can store 1/100th second precision, but in lack of support on most platforms, it is 0x00". // Therefore, let's not rely on it. - Serial::printf("Current time: %.2d/%.2d/%d %.2d:%.2d:%.2d UTC\n", day, month, year, hour, minute, second) - .release_value(); + kinfoln("Current time: %.2d/%.2d/%d %.2d:%.2d:%.2d UTC", day, month, year, hour, minute, second).release_value(); return broken_down_to_unix(year - 1900, make_yday(year, month) + (day - 1), hour, minute, second); } diff --git a/kernel/src/arch/x86_64/CPU.cpp b/kernel/src/arch/x86_64/CPU.cpp index 83a65206..a4cbb6c2 100644 --- a/kernel/src/arch/x86_64/CPU.cpp +++ b/kernel/src/arch/x86_64/CPU.cpp @@ -1,4 +1,5 @@ #include "arch/x86_64/CPU.h" +#include "Log.h" #include "arch/Serial.h" #include "arch/Timer.h" #include "arch/x86_64/IO.h" @@ -275,7 +276,7 @@ static void setup_idt() // Interrupt handling #define FIXME_UNHANDLED_INTERRUPT(name) \ - Serial::println("FIXME(interrupt): " name); \ + kerrorln("FIXME(interrupt): %s", name); \ CPU::efficient_halt(); extern "C" void handle_x86_exception([[maybe_unused]] Registers* regs) @@ -315,20 +316,20 @@ extern "C" void arch_interrupt_entry(Registers* regs) } else { - Serial::println("IRQ catched! Halting."); + kwarnln("IRQ catched! Halting."); CPU::efficient_halt(); } } extern "C" [[noreturn]] void arch_double_fault() { - Serial::println("ERROR: Catched double fault"); + kerrorln("ERROR: Catched double fault"); CPU::efficient_halt(); } extern "C" [[noreturn]] void arch_machine_check() { - Serial::println("ERROR: Machine check failed"); + kerrorln("ERROR: Machine check failed"); CPU::efficient_halt(); } diff --git a/kernel/src/boot/Init.cpp b/kernel/src/boot/Init.cpp index 291cdc93..0654f8a9 100644 --- a/kernel/src/boot/Init.cpp +++ b/kernel/src/boot/Init.cpp @@ -13,7 +13,7 @@ void Init::check_magic() { if (memcmp(bootboot.magic, BOOTBOOT_MAGIC, 4)) { - Serial::println("ERROR: Invalid magic value from bootloader"); + kerrorln("ERROR: Invalid magic value from bootloader"); for (;;) ; } diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 135a0078..bf0cf636 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -11,11 +11,11 @@ Result init() { - Serial::println("Hello, world!"); + kinfoln("Hello, world!"); - Serial::printf("Current platform: %s\n", CPU::platform_string()); + kinfoln("Current platform: %s", CPU::platform_string()); - Serial::println(TRY(CPU::identify())); + kinfoln("Current processor: %s", TRY(CPU::identify())); Timer::init(); @@ -41,6 +41,6 @@ extern "C" [[noreturn]] void _start() Init::check_magic(); Init::early_init(); auto rc = init(); - rc.release_value(); + if (rc.has_error()) kerrorln("Runtime error: %s", rc.error_string()); CPU::efficient_halt(); } \ No newline at end of file diff --git a/kernel/src/memory/Heap.cpp b/kernel/src/memory/Heap.cpp index 1b18516f..54dbb9f0 100644 --- a/kernel/src/memory/Heap.cpp +++ b/kernel/src/memory/Heap.cpp @@ -1,4 +1,5 @@ #include "memory/Heap.h" +#include "Log.h" #include "arch/MMU.h" #include "arch/Serial.h" #include "memory/MemoryManager.h" @@ -240,17 +241,17 @@ Result kfree(void* ptr) { if (block->magic == BLOCK_DEAD) { - Serial::printf("ERROR: Attempt to free memory at %p, which was already freed\n", ptr); + kerrorln("ERROR: Attempt to free memory at %p, which was already freed", ptr); } else - Serial::printf("ERROR: Attempt to free memory at %p, which wasn't allocated with kmalloc\n", ptr); + kerrorln("ERROR: Attempt to free memory at %p, which wasn't allocated with kmalloc", ptr); return err(EFAULT); } if (is_block_free(block)) { - Serial::printf("ERROR: Attempt to free memory at %p, which was already freed\n", ptr); + kerrorln("ERROR: Attempt to free memory at %p, which was already freed", ptr); return err(EFAULT); } else @@ -296,10 +297,10 @@ Result krealloc(void* ptr, usize size) { if (block->magic == BLOCK_DEAD) { - Serial::printf("ERROR: Attempt to realloc memory at %p, which was already freed\n", ptr); + kerrorln("ERROR: Attempt to realloc memory at %p, which was already freed", ptr); } else - Serial::printf("ERROR: Attempt to realloc memory at %p, which wasn't allocated with kmalloc\n", ptr); + kerrorln("ERROR: Attempt to realloc memory at %p, which wasn't allocated with kmalloc", ptr); return err(EFAULT); } @@ -308,7 +309,7 @@ Result krealloc(void* ptr, usize size) if (is_block_free(block)) { - Serial::printf("ERROR: Attempt to realloc memory at %p, which was already freed\n", ptr); + kerrorln("ERROR: Attempt to realloc memory at %p, which was already freed", ptr); return err(EFAULT); } @@ -336,10 +337,10 @@ Result kcalloc(usize nmemb, usize size) void dump_heap_usage() { - Serial::println("-- Dumping usage stats for kernel heap:"); + kdbgln("-- Dumping usage stats for kernel heap:"); if (!heap_start) { - Serial::println("- Heap is not currently being used"); + kdbgln("- Heap is not currently being used"); return; } usize alloc_total = 0; @@ -349,19 +350,18 @@ void dump_heap_usage() { if (is_block_free(block)) { - Serial::printf("- Available block, of size %zu\n", block->full_size); + kdbgln("- Available block, of size %zu", block->full_size); alloc_total += block->full_size + sizeof(HeapBlock); } else { - Serial::printf("- Used block, of size %zu, of which %zu bytes are being used\n", block->full_size, - block->req_size); + kdbgln("- Used block, of size %zu, of which %zu bytes are being used", block->full_size, block->req_size); alloc_total += block->full_size + sizeof(HeapBlock); alloc_used += block->req_size; } block = block->next; } - Serial::printf("-- Total memory allocated for heap: %zu bytes\n", alloc_total); - Serial::printf("-- Heap memory in use by the kernel: %zu bytes\n", alloc_used); + kdbgln("-- Total memory allocated for heap: %zu bytes", alloc_total); + kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used); } \ No newline at end of file diff --git a/kernel/src/memory/MemoryManager.cpp b/kernel/src/memory/MemoryManager.cpp index 906efaae..65d9006d 100644 --- a/kernel/src/memory/MemoryManager.cpp +++ b/kernel/src/memory/MemoryManager.cpp @@ -1,6 +1,6 @@ #include "memory/MemoryManager.h" +#include "Log.h" #include "arch/MMU.h" -#include "arch/Serial.h" #include "boot/bootboot.h" #include #include @@ -88,7 +88,7 @@ namespace MemoryManager page_virtual_bitmap_addr = page_bitmap_addr; // we'll map this to virtual memory as soon as the MMU is ready if ((total_mem / ARCH_PAGE_SIZE / 8) >= biggest_memory_block_size) { - Serial::println("ERROR: No single memory block is enough to hold the page bitmap"); + kerrorln("ERROR: No single memory block is enough to hold the page bitmap"); for (;;) ; }