diff --git a/kernel/inc/utils/logger.h b/kernel/inc/utils/logger.h index 14725a4..d0c8701 100644 --- a/kernel/inc/utils/logger.h +++ b/kernel/inc/utils/logger.h @@ -31,6 +31,7 @@ typedef enum { } log_level_E; // logs a string to qemu's serial port -void log(log_level_E log_level, string_t string, ...); +void graphical_log_init (); +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 727a159..88c8f09 100644 --- a/kernel/src/kmain.c +++ b/kernel/src/kmain.c @@ -58,6 +58,7 @@ void kernel_init(boot_info_T* boot_info) { limine_terminal_print(boot_info, " Initializing graphics renderer..."); graphics_renderer_init(boot_info); + graphical_log_init(); limine_terminal_print(boot_info, " ok\n"); limine_terminal_print(boot_info, " Initializing scheduler..."); scheduler_init(); @@ -74,17 +75,11 @@ void kmain(boot_info_T boot_info) { limine_terminal_print(&boot_info, "Kernel initialized\n"); log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n"); - graphics_buffer_T* buffer = graphics_buffer_request(0, 0, graphics_renderer_get_width() / 2, graphics_renderer_get_height(), GRAPHICS_BUFFER_OVERLAY); -// graphics_buffer_T* buffer2 = graphics_buffer_request(0, 0, 50, 50); - -// for (int x = 0; x < 50; x++) { -// for (int y = 0; y < 50; y++) { -// graphics_buffer_set_pixel(buffer2, x, y, (color_argb_T){0x80, 0xca, 0xca, 0xca}); -// } -// } - - graphics_buffer_draw_string(buffer, 0, 0, (color_argb_T){0xFF, 0xFF, 0, 0}, "test string\n"); - graphics_renderer_update(); + log(LOG_NONE, "test none"); + log(LOG_INFO, "test info"); + log(LOG_DEBUG, "test debug"); + log(LOG_WARNING, "test warning"); + log(LOG_ERROR, "test error"); CORE_HALT_FOREVER } diff --git a/kernel/src/utils/logger.c b/kernel/src/utils/logger.c index 8d3b7df..caaccfa 100644 --- a/kernel/src/utils/logger.c +++ b/kernel/src/utils/logger.c @@ -16,6 +16,7 @@ #include "utils/logger.h" #include "utils/io.h" #include "utils/core.h" +#include "drivers/graphics/renderer.h" string_t g_log_prefixes[LOG_ENUM_END] = { "", // LOG_NONE @@ -25,14 +26,35 @@ string_t g_log_prefixes[LOG_ENUM_END] = { "[ Error ] ", }; -bool g_logger_blocked = false; +color_palette_E g_log_colors[LOG_ENUM_END] = { + COLOR_PAL_GREY_LIGHT, + COLOR_PAL_GREY_DARK, + COLOR_PAL_PINK, + COLOR_PAL_ORANGE, + COLOR_PAL_RED +}; -void log_send_string_to_port(string_t str) { +bool g_logger_blocked = false; +graphics_buffer_T* g_graphical_log_buffer = NULL; +position_T g_graphical_log_position; + +void log_string(string_t str, log_level_E log_level) { char* c = (char*)str; while (*c != '\0') { io_out_byte(LOG_PORT, *c); c++; } + + if (g_graphical_log_buffer != NULL) { + g_graphical_log_position = graphics_buffer_draw_string(g_graphical_log_buffer, g_graphical_log_position.x, g_graphical_log_position.y, g_color_palette[g_log_colors[log_level]], str); + } +} + +void graphical_log_init() { + g_graphical_log_buffer = graphics_buffer_request(0, 0, graphics_renderer_get_width() / 2, graphics_renderer_get_height(), GRAPHICS_BUFFER_OVERLAY); + g_graphical_log_position = (position_T){0, 0}; + + log(LOG_INFO, " Started graphical log"); } void log(log_level_E log_level, string_t str, ...) { @@ -50,9 +72,13 @@ void log(log_level_E log_level, string_t str, ...) { va_end(args); - log_send_string_to_port(g_log_prefixes[log_level]); - log_send_string_to_port(formatted_string); - log_send_string_to_port("\n"); + log_string(g_log_prefixes[log_level], log_level); + log_string(formatted_string, log_level); + log_string("\n", log_level); + + if (g_graphical_log_buffer != NULL) { + graphics_renderer_update(); + } g_logger_blocked = false; } \ No newline at end of file