From c6c3e2a7fd5970984e521a420bf25a48ecc9171e Mon Sep 17 00:00:00 2001 From: Liav A Date: Wed, 9 Feb 2022 21:09:41 +0200 Subject: [PATCH] Kernel: Instantiate a TextModeConsole early on if there's no framebuffer If the bootloader that loaded us is providing a framebuffer details from the Multiboot protocol then we can instantiate a framebuffer console. Otherwise, we should use a text mode console, assuming that the BIOS and the bootloader didn't try to modeset the screen resolution so we have is a VGA 80x25 text mode being displayed on screen. Since "boot_framebuffer_console" is no longer a good representative as a global variable name, it's changed to g_boot_console to match the fact that it can be assigned with a text mode console and not framebuffer console if needed. --- Kernel/Graphics/GraphicsManagement.cpp | 6 +++--- Kernel/init.cpp | 11 ++++++++--- Kernel/kprintf.cpp | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp index aa26927094..397a463462 100644 --- a/Kernel/Graphics/GraphicsManagement.cpp +++ b/Kernel/Graphics/GraphicsManagement.cpp @@ -23,7 +23,7 @@ namespace Kernel { static Singleton s_the; -extern Atomic boot_framebuffer_console; +extern Atomic g_boot_console; GraphicsManagement& GraphicsManagement::the() { @@ -221,7 +221,7 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize() if (!m_console) { // If no graphics driver was instantiated and we had a bootloader provided // framebuffer console we can simply re-use it. - if (auto* boot_console = boot_framebuffer_console.load()) { + if (auto* boot_console = g_boot_console.load()) { m_console = *boot_console; boot_console->unref(); // Drop the leaked reference from Kernel::init() } @@ -247,7 +247,7 @@ void GraphicsManagement::set_console(Graphics::Console& console) { m_console = console; - if (auto* boot_console = boot_framebuffer_console.exchange(nullptr)) { + if (auto* boot_console = g_boot_console.exchange(nullptr)) { // Disable the initial boot framebuffer console permanently boot_console->disable(); // TODO: Even though we swapped the pointer and disabled the console diff --git a/Kernel/init.cpp b/Kernel/init.cpp index f669a15176..bdac48bfd3 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -136,7 +137,7 @@ READONLY_AFTER_INIT u8 multiboot_framebuffer_bpp; READONLY_AFTER_INIT u8 multiboot_framebuffer_type; } -Atomic boot_framebuffer_console; +Atomic g_boot_console; extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) { @@ -190,9 +191,13 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) CommandLine::initialize(); Memory::MemoryManager::initialize(0); + // NOTE: If the bootloader provided a framebuffer, then set up an initial console. + // If the bootloader didn't provide a framebuffer, then set up an initial text console. + // We do so we can see the output on the screen as soon as possible. if (!multiboot_framebuffer_addr.is_null()) { - // NOTE: If the bootloader provided a framebuffer, then set up an initial console so we can see the output on the screen as soon as possible! - boot_framebuffer_console = &try_make_ref_counted(multiboot_framebuffer_addr, multiboot_framebuffer_width, multiboot_framebuffer_height, multiboot_framebuffer_pitch).value().leak_ref(); + g_boot_console = &try_make_ref_counted(multiboot_framebuffer_addr, multiboot_framebuffer_width, multiboot_framebuffer_height, multiboot_framebuffer_pitch).value().leak_ref(); + } else { + g_boot_console = &Graphics::TextModeConsole::initialize().leak_ref(); } dmesgln("Starting SerenityOS..."); diff --git a/Kernel/kprintf.cpp b/Kernel/kprintf.cpp index ae88d36af2..3a8d343a79 100644 --- a/Kernel/kprintf.cpp +++ b/Kernel/kprintf.cpp @@ -20,7 +20,7 @@ #include namespace Kernel { -extern Atomic boot_framebuffer_console; +extern Atomic g_boot_console; } static bool serial_debug; @@ -80,7 +80,7 @@ static void critical_console_out(char ch) // especially when we want to avoid any memory allocations... if (GraphicsManagement::is_initialized() && GraphicsManagement::the().console()) { GraphicsManagement::the().console()->write(ch, true); - } else if (auto* boot_console = boot_framebuffer_console.load()) { + } else if (auto* boot_console = g_boot_console.load()) { boot_console->write(ch, true); } } @@ -99,7 +99,7 @@ static void console_out(char ch) } if (ConsoleManagement::is_initialized()) { ConsoleManagement::the().debug_tty()->emit_char(ch); - } else if (auto* boot_console = boot_framebuffer_console.load()) { + } else if (auto* boot_console = g_boot_console.load()) { boot_console->write(ch, true); } }