diff --git a/kernel/inc/utils/logger.h b/kernel/inc/utils/logger.h index f118f9f..f780485 100644 --- a/kernel/inc/utils/logger.h +++ b/kernel/inc/utils/logger.h @@ -30,6 +30,6 @@ typedef enum { } log_level_E; // logs a string to qemu's serial port -void log(log_level_E log_level, string_t string); +void log(log_level_E log_level, string_t string, ...); #endif //NOX_LOGGER_H diff --git a/kernel/src/kmain.c b/kernel/src/kmain.c index 57b5b5a..9c1d326 100644 --- a/kernel/src/kmain.c +++ b/kernel/src/kmain.c @@ -41,17 +41,5 @@ void kmain(boot_info_T boot_info) { kernel_init(&boot_info); - uint64_t size = format_size("Test: %d", 1312); - - char string[size]; - format(string, "Test: %d", 1312); - - char buf[16]; - format(buf, "size: %d", size); - - log(LOG_DEBUG, string); - log(LOG_DEBUG, buf); - - CORE_HALT_FOREVER } diff --git a/kernel/src/mm/memory_map.c b/kernel/src/mm/memory_map.c index 2c99d8d..a0bf747 100644 --- a/kernel/src/mm/memory_map.c +++ b/kernel/src/mm/memory_map.c @@ -19,7 +19,7 @@ uint64_t memory_map_get_total_memory_size(boot_info_T* boot_info) { static uint64_t size = 0; if (size > 0) { - log(LOG_INFO, "Memory size is already calculated, returning known value"); + log(LOG_INFO, "Memory size is already calculated: %d", size); return size; }; diff --git a/kernel/src/mm/page_frame.c b/kernel/src/mm/page_frame.c index 37d9f8f..b4a7ab5 100644 --- a/kernel/src/mm/page_frame.c +++ b/kernel/src/mm/page_frame.c @@ -160,7 +160,7 @@ void pframe_manager_init(boot_info_T* boot_info) { } uint64_t total_memory = memory_map_get_total_memory_size(boot_info); - log(LOG_INFO, " * Total Memory size: 'size'"); // TODO: replace with format string + log(LOG_INFO, " * Total Memory size: %d B", total_memory); // TODO: replace with format string g_page_frame_manager.page_bitmap = bitmap_init_from_buffer((void*)largest_usable_entry->base, total_memory / PFRAME_SIZE / 8 + 1); g_page_frame_manager.page_bitmap_index = 0; diff --git a/kernel/src/platform/interrupts.c b/kernel/src/platform/interrupts.c index e1560e6..5198a3a 100644 --- a/kernel/src/platform/interrupts.c +++ b/kernel/src/platform/interrupts.c @@ -124,7 +124,7 @@ cpu_state_T* interrupts_handle(cpu_state_T* state) { return exception_handle(state); } - log(LOG_WARNING, "Non exception interrupt detected"); + log(LOG_WARNING, "Non exception interrupt detected ID: 0x%xb", state->interrupt_id); return state; } diff --git a/kernel/src/utils/logger.c b/kernel/src/utils/logger.c index fadf915..dc30f29 100644 --- a/kernel/src/utils/logger.c +++ b/kernel/src/utils/logger.c @@ -31,8 +31,19 @@ void log_send_string_to_port(string_t str) { } } -void log(log_level_E log_level, string_t str) { +void log(log_level_E log_level, string_t str, ...) { + va_list args; + va_start(args, str); + + uint64_t size = variadic_format_size(str, args); + char formatted_string[size]; + + va_start(args, str); + variadic_format(formatted_string, str, args); + + va_end(args); + log_send_string_to_port(log_prefixes[log_level]); - log_send_string_to_port(str); + log_send_string_to_port(formatted_string); log_send_string_to_port("\n"); } \ No newline at end of file diff --git a/kernel/src/utils/panic.c b/kernel/src/utils/panic.c index 51fba39..8a826a7 100644 --- a/kernel/src/utils/panic.c +++ b/kernel/src/utils/panic.c @@ -19,7 +19,7 @@ void panic(cpu_state_T* state, string_t message) { log(LOG_ERROR, "!=====[ KERNEL PANIC ]=====!"); - log(LOG_ERROR, message); + log(LOG_ERROR, "Error Message:", message); CORE_HALT_FOREVER } \ No newline at end of file