Parcourir la source

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.
Liav A il y a 3 ans
Parent
commit
c6c3e2a7fd
3 fichiers modifiés avec 14 ajouts et 9 suppressions
  1. 3 3
      Kernel/Graphics/GraphicsManagement.cpp
  2. 8 3
      Kernel/init.cpp
  3. 3 3
      Kernel/kprintf.cpp

+ 3 - 3
Kernel/Graphics/GraphicsManagement.cpp

@@ -23,7 +23,7 @@ namespace Kernel {
 
 static Singleton<GraphicsManagement> s_the;
 
-extern Atomic<Graphics::BootFramebufferConsole*> boot_framebuffer_console;
+extern Atomic<Graphics::Console*> 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

+ 8 - 3
Kernel/init.cpp

@@ -34,6 +34,7 @@
 #include <Kernel/Firmware/ACPI/Parser.h>
 #include <Kernel/Firmware/SysFSFirmware.h>
 #include <Kernel/Graphics/Console/BootFramebufferConsole.h>
+#include <Kernel/Graphics/Console/TextModeConsole.h>
 #include <Kernel/Graphics/GraphicsManagement.h>
 #include <Kernel/Heap/kmalloc.h>
 #include <Kernel/Interrupts/APIC.h>
@@ -136,7 +137,7 @@ READONLY_AFTER_INIT u8 multiboot_framebuffer_bpp;
 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)
 {
@@ -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<Graphics::BootFramebufferConsole>(multiboot_framebuffer_addr, multiboot_framebuffer_width, multiboot_framebuffer_height, multiboot_framebuffer_pitch).value().leak_ref();
+        g_boot_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...");
 

+ 3 - 3
Kernel/kprintf.cpp

@@ -20,7 +20,7 @@
 #include <LibC/stdarg.h>
 
 namespace Kernel {
-extern Atomic<Graphics::BootFramebufferConsole*> boot_framebuffer_console;
+extern Atomic<Graphics::Console*> 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);
     }
 }