1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 18:47:41 +00:00

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.
This commit is contained in:
Liav A 2022-02-09 21:09:41 +02:00 committed by Linus Groh
parent 278b0aa629
commit c6c3e2a7fd
3 changed files with 14 additions and 9 deletions

View file

@ -23,7 +23,7 @@ namespace Kernel {
static Singleton<GraphicsManagement> s_the; static Singleton<GraphicsManagement> s_the;
extern Atomic<Graphics::BootFramebufferConsole*> boot_framebuffer_console; extern Atomic<Graphics::Console*> g_boot_console;
GraphicsManagement& GraphicsManagement::the() GraphicsManagement& GraphicsManagement::the()
{ {
@ -221,7 +221,7 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize()
if (!m_console) { if (!m_console) {
// If no graphics driver was instantiated and we had a bootloader provided // If no graphics driver was instantiated and we had a bootloader provided
// framebuffer console we can simply re-use it. // 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; m_console = *boot_console;
boot_console->unref(); // Drop the leaked reference from Kernel::init() boot_console->unref(); // Drop the leaked reference from Kernel::init()
} }
@ -247,7 +247,7 @@ void GraphicsManagement::set_console(Graphics::Console& console)
{ {
m_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 // Disable the initial boot framebuffer console permanently
boot_console->disable(); boot_console->disable();
// TODO: Even though we swapped the pointer and disabled the console // TODO: Even though we swapped the pointer and disabled the console

View file

@ -34,6 +34,7 @@
#include <Kernel/Firmware/ACPI/Parser.h> #include <Kernel/Firmware/ACPI/Parser.h>
#include <Kernel/Firmware/SysFSFirmware.h> #include <Kernel/Firmware/SysFSFirmware.h>
#include <Kernel/Graphics/Console/BootFramebufferConsole.h> #include <Kernel/Graphics/Console/BootFramebufferConsole.h>
#include <Kernel/Graphics/Console/TextModeConsole.h>
#include <Kernel/Graphics/GraphicsManagement.h> #include <Kernel/Graphics/GraphicsManagement.h>
#include <Kernel/Heap/kmalloc.h> #include <Kernel/Heap/kmalloc.h>
#include <Kernel/Interrupts/APIC.h> #include <Kernel/Interrupts/APIC.h>
@ -136,7 +137,7 @@ READONLY_AFTER_INIT u8 multiboot_framebuffer_bpp;
READONLY_AFTER_INIT u8 multiboot_framebuffer_type; READONLY_AFTER_INIT u8 multiboot_framebuffer_type;
} }
Atomic<Graphics::BootFramebufferConsole*> boot_framebuffer_console; Atomic<Graphics::Console*> g_boot_console;
extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) 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(); CommandLine::initialize();
Memory::MemoryManager::initialize(0); 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()) { 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! g_boot_console = &try_make_ref_counted<Graphics::BootFramebufferConsole>(multiboot_framebuffer_addr, multiboot_framebuffer_width, multiboot_framebuffer_height, multiboot_framebuffer_pitch).value().leak_ref();
boot_framebuffer_console = &try_make_ref_counted<Graphics::BootFramebufferConsole>(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..."); dmesgln("Starting SerenityOS...");

View file

@ -20,7 +20,7 @@
#include <LibC/stdarg.h> #include <LibC/stdarg.h>
namespace Kernel { namespace Kernel {
extern Atomic<Graphics::BootFramebufferConsole*> boot_framebuffer_console; extern Atomic<Graphics::Console*> g_boot_console;
} }
static bool serial_debug; static bool serial_debug;
@ -80,7 +80,7 @@ static void critical_console_out(char ch)
// especially when we want to avoid any memory allocations... // especially when we want to avoid any memory allocations...
if (GraphicsManagement::is_initialized() && GraphicsManagement::the().console()) { if (GraphicsManagement::is_initialized() && GraphicsManagement::the().console()) {
GraphicsManagement::the().console()->write(ch, true); 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); boot_console->write(ch, true);
} }
} }
@ -99,7 +99,7 @@ static void console_out(char ch)
} }
if (ConsoleManagement::is_initialized()) { if (ConsoleManagement::is_initialized()) {
ConsoleManagement::the().debug_tty()->emit_char(ch); 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); boot_console->write(ch, true);
} }
} }