feature (kernel): Implemented graphical log overlay

This commit is contained in:
antifallobst 2023-02-22 23:42:44 +01:00
parent cce1400b74
commit c32988aa72
3 changed files with 39 additions and 17 deletions

View File

@ -31,6 +31,7 @@ typedef enum {
} log_level_E; } log_level_E;
// logs a string to qemu's serial port // logs a string to qemu's serial port
void graphical_log_init ();
void log (log_level_E log_level, string_t string, ...); void log (log_level_E log_level, string_t string, ...);
#endif //NOX_LOGGER_H #endif //NOX_LOGGER_H

View File

@ -58,6 +58,7 @@ void kernel_init(boot_info_T* boot_info) {
limine_terminal_print(boot_info, " Initializing graphics renderer..."); limine_terminal_print(boot_info, " Initializing graphics renderer...");
graphics_renderer_init(boot_info); graphics_renderer_init(boot_info);
graphical_log_init();
limine_terminal_print(boot_info, " ok\n"); limine_terminal_print(boot_info, " ok\n");
limine_terminal_print(boot_info, " Initializing scheduler..."); limine_terminal_print(boot_info, " Initializing scheduler...");
scheduler_init(); scheduler_init();
@ -74,17 +75,11 @@ void kmain(boot_info_T boot_info) {
limine_terminal_print(&boot_info, "Kernel initialized\n"); limine_terminal_print(&boot_info, "Kernel initialized\n");
log(LOG_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); log(LOG_NONE, "test none");
// graphics_buffer_T* buffer2 = graphics_buffer_request(0, 0, 50, 50); log(LOG_INFO, "test info");
log(LOG_DEBUG, "test debug");
// for (int x = 0; x < 50; x++) { log(LOG_WARNING, "test warning");
// for (int y = 0; y < 50; y++) { log(LOG_ERROR, "test error");
// 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();
CORE_HALT_FOREVER CORE_HALT_FOREVER
} }

View File

@ -16,6 +16,7 @@
#include "utils/logger.h" #include "utils/logger.h"
#include "utils/io.h" #include "utils/io.h"
#include "utils/core.h" #include "utils/core.h"
#include "drivers/graphics/renderer.h"
string_t g_log_prefixes[LOG_ENUM_END] = { string_t g_log_prefixes[LOG_ENUM_END] = {
"", // LOG_NONE "", // LOG_NONE
@ -25,14 +26,35 @@ string_t g_log_prefixes[LOG_ENUM_END] = {
"[ Error ] ", "[ 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; char* c = (char*)str;
while (*c != '\0') { while (*c != '\0') {
io_out_byte(LOG_PORT, *c); io_out_byte(LOG_PORT, *c);
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, "<Logger> Started graphical log");
} }
void log(log_level_E log_level, string_t str, ...) { 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); va_end(args);
log_send_string_to_port(g_log_prefixes[log_level]); log_string(g_log_prefixes[log_level], log_level);
log_send_string_to_port(formatted_string); log_string(formatted_string, log_level);
log_send_string_to_port("\n"); log_string("\n", log_level);
if (g_graphical_log_buffer != NULL) {
graphics_renderer_update();
}
g_logger_blocked = false; g_logger_blocked = false;
} }