Switch to logging functions everywhere

This commit is contained in:
apio 2022-11-30 17:16:36 +01:00
parent d2856d8812
commit 985d45ddfb
6 changed files with 27 additions and 26 deletions

View File

@ -1,4 +1,5 @@
#include "arch/Timer.h" #include "arch/Timer.h"
#include "Log.h"
#include "arch/Serial.h" #include "arch/Serial.h"
#include "boot/bootboot.h" #include "boot/bootboot.h"
#include <Result.h> #include <Result.h>
@ -46,8 +47,7 @@ static u64 bootloader_time_to_unix(u8 boottime[8])
int second = bcd_number_to_decimal(boottime[6]); 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". // "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. // 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) kinfoln("Current time: %.2d/%.2d/%d %.2d:%.2d:%.2d UTC", day, month, year, hour, minute, second).release_value();
.release_value();
return broken_down_to_unix(year - 1900, make_yday(year, month) + (day - 1), hour, minute, second); return broken_down_to_unix(year - 1900, make_yday(year, month) + (day - 1), hour, minute, second);
} }

View File

@ -1,4 +1,5 @@
#include "arch/x86_64/CPU.h" #include "arch/x86_64/CPU.h"
#include "Log.h"
#include "arch/Serial.h" #include "arch/Serial.h"
#include "arch/Timer.h" #include "arch/Timer.h"
#include "arch/x86_64/IO.h" #include "arch/x86_64/IO.h"
@ -275,7 +276,7 @@ static void setup_idt()
// Interrupt handling // Interrupt handling
#define FIXME_UNHANDLED_INTERRUPT(name) \ #define FIXME_UNHANDLED_INTERRUPT(name) \
Serial::println("FIXME(interrupt): " name); \ kerrorln("FIXME(interrupt): %s", name); \
CPU::efficient_halt(); CPU::efficient_halt();
extern "C" void handle_x86_exception([[maybe_unused]] Registers* regs) extern "C" void handle_x86_exception([[maybe_unused]] Registers* regs)
@ -315,20 +316,20 @@ extern "C" void arch_interrupt_entry(Registers* regs)
} }
else else
{ {
Serial::println("IRQ catched! Halting."); kwarnln("IRQ catched! Halting.");
CPU::efficient_halt(); CPU::efficient_halt();
} }
} }
extern "C" [[noreturn]] void arch_double_fault() extern "C" [[noreturn]] void arch_double_fault()
{ {
Serial::println("ERROR: Catched double fault"); kerrorln("ERROR: Catched double fault");
CPU::efficient_halt(); CPU::efficient_halt();
} }
extern "C" [[noreturn]] void arch_machine_check() extern "C" [[noreturn]] void arch_machine_check()
{ {
Serial::println("ERROR: Machine check failed"); kerrorln("ERROR: Machine check failed");
CPU::efficient_halt(); CPU::efficient_halt();
} }

View File

@ -13,7 +13,7 @@ void Init::check_magic()
{ {
if (memcmp(bootboot.magic, BOOTBOOT_MAGIC, 4)) if (memcmp(bootboot.magic, BOOTBOOT_MAGIC, 4))
{ {
Serial::println("ERROR: Invalid magic value from bootloader"); kerrorln("ERROR: Invalid magic value from bootloader");
for (;;) for (;;)
; ;
} }

View File

@ -11,11 +11,11 @@
Result<void> init() Result<void> 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(); Timer::init();
@ -41,6 +41,6 @@ extern "C" [[noreturn]] void _start()
Init::check_magic(); Init::check_magic();
Init::early_init(); Init::early_init();
auto rc = init(); auto rc = init();
rc.release_value(); if (rc.has_error()) kerrorln("Runtime error: %s", rc.error_string());
CPU::efficient_halt(); CPU::efficient_halt();
} }

View File

@ -1,4 +1,5 @@
#include "memory/Heap.h" #include "memory/Heap.h"
#include "Log.h"
#include "arch/MMU.h" #include "arch/MMU.h"
#include "arch/Serial.h" #include "arch/Serial.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
@ -240,17 +241,17 @@ Result<void> kfree(void* ptr)
{ {
if (block->magic == BLOCK_DEAD) 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 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); return err(EFAULT);
} }
if (is_block_free(block)) 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); return err(EFAULT);
} }
else else
@ -296,10 +297,10 @@ Result<void*> krealloc(void* ptr, usize size)
{ {
if (block->magic == BLOCK_DEAD) 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 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); return err(EFAULT);
} }
@ -308,7 +309,7 @@ Result<void*> krealloc(void* ptr, usize size)
if (is_block_free(block)) 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); return err(EFAULT);
} }
@ -336,10 +337,10 @@ Result<void*> kcalloc(usize nmemb, usize size)
void dump_heap_usage() void dump_heap_usage()
{ {
Serial::println("-- Dumping usage stats for kernel heap:"); kdbgln("-- Dumping usage stats for kernel heap:");
if (!heap_start) if (!heap_start)
{ {
Serial::println("- Heap is not currently being used"); kdbgln("- Heap is not currently being used");
return; return;
} }
usize alloc_total = 0; usize alloc_total = 0;
@ -349,19 +350,18 @@ void dump_heap_usage()
{ {
if (is_block_free(block)) 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); alloc_total += block->full_size + sizeof(HeapBlock);
} }
else else
{ {
Serial::printf("- Used block, of size %zu, of which %zu bytes are being used\n", block->full_size, kdbgln("- Used block, of size %zu, of which %zu bytes are being used", block->full_size, block->req_size);
block->req_size);
alloc_total += block->full_size + sizeof(HeapBlock); alloc_total += block->full_size + sizeof(HeapBlock);
alloc_used += block->req_size; alloc_used += block->req_size;
} }
block = block->next; block = block->next;
} }
Serial::printf("-- Total memory allocated for heap: %zu bytes\n", alloc_total); kdbgln("-- Total memory allocated for heap: %zu bytes", alloc_total);
Serial::printf("-- Heap memory in use by the kernel: %zu bytes\n", alloc_used); kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used);
} }

View File

@ -1,6 +1,6 @@
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "Log.h"
#include "arch/MMU.h" #include "arch/MMU.h"
#include "arch/Serial.h"
#include "boot/bootboot.h" #include "boot/bootboot.h"
#include <Alignment.h> #include <Alignment.h>
#include <String.h> #include <String.h>
@ -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 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) 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 (;;) for (;;)
; ;
} }