From 9c143d18b951e6312b7d3d16b8e1e0128895ea58 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 13 Oct 2023 03:31:36 +0300 Subject: [PATCH] Kernel: Add temporary terminal output before controlling terminal Starting work on getting this boot on real hardware. --- kernel/kernel/Debug.cpp | 33 +++++++++++++++++++++++++++++++++ kernel/kernel/kernel.cpp | 12 +++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/kernel/kernel/Debug.cpp b/kernel/kernel/Debug.cpp index ed33892251..3fad433704 100644 --- a/kernel/kernel/Debug.cpp +++ b/kernel/kernel/Debug.cpp @@ -6,6 +6,10 @@ #include #include +#include + +extern TerminalDriver* g_terminal_driver; + namespace Debug { @@ -64,6 +68,35 @@ namespace Debug return Kernel::Serial::putchar_any(ch); if (Kernel::TTY::is_initialized()) return Kernel::TTY::putchar_current(ch); + + if (g_terminal_driver) + { + static uint32_t col = 0; + static uint32_t row = 0; + + if (ch == '\n') + { + row++; + col = 0; + } + else if (ch == '\r') + { + col = 0; + } + else + { + if (!isprint(ch)) + ch = '?'; + g_terminal_driver->putchar_at(ch, col, row, TerminalColor::BRIGHT_WHITE, TerminalColor::BLACK); + + col++; + if (col >= g_terminal_driver->width()) + { + row++; + col = 0; + } + } + } } void print_prefix(const char* file, int line) diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index f0430fe45c..3dd2a67c8d 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -82,6 +82,8 @@ static void parse_command_line() extern "C" uint8_t g_userspace_start[]; extern "C" uint8_t g_userspace_end[]; +TerminalDriver* g_terminal_driver = nullptr; + static void init2(void*); extern "C" void kernel_main() @@ -114,6 +116,10 @@ extern "C" void kernel_main() PageTable::initialize(); dprintln("PageTable initialized"); + g_terminal_driver = VesaTerminalDriver::create(); + ASSERT(g_terminal_driver); + dprintln("VESA initialized"); + Heap::initialize(); dprintln("Heap initialzed"); @@ -141,11 +147,7 @@ extern "C" void kernel_main() dprintln("Serial devices initialized"); } - TerminalDriver* terminal_driver = VesaTerminalDriver::create(); - ASSERT(terminal_driver); - dprintln("VESA initialized"); - - auto vtty = MUST(VirtualTTY::create(terminal_driver)); + auto vtty = MUST(VirtualTTY::create(g_terminal_driver)); dprintln("Virtual TTY initialized"); MUST(Scheduler::initialize());