Kernel/Graphics: Always ensure a console is set when initialization ends

We use a ScopeGuard to ensure we always set a console of some sort if we
exit early from the initialization sequence in the GraphicsManagement
code. We do so to ensure we can boot into text mode console in an ISA-PC
machine type, because earlier we failed with an assertion due to not
setting any console for VirtualConsole to use.
This commit is contained in:
Liav A 2022-09-16 13:10:06 +03:00 committed by Linus Groh
parent 48730ff8ec
commit 02a980ee54
Notes: sideshowbarker 2024-07-17 06:46:57 +09:00

View file

@ -189,15 +189,20 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize()
* a variant that is suitable for ISA VGA handling, and not PCI adapters.
*/
ScopeGuard assign_console_on_initialization_exit([this] {
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 = g_boot_console.load()) {
m_console = *boot_console;
boot_console->unref(); // Drop the leaked reference from Kernel::init()
}
}
});
auto graphics_subsystem_mode = kernel_command_line().graphics_subsystem_mode();
if (graphics_subsystem_mode == CommandLine::GraphicsSubsystemMode::Disabled) {
VERIFY(!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 = g_boot_console.load()) {
m_console = *boot_console;
boot_console->unref(); // Drop the leaked reference from Kernel::init()
}
return true;
}
@ -232,15 +237,6 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize()
return true;
}
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 = g_boot_console.load()) {
m_console = *boot_console;
boot_console->unref(); // Drop the leaked reference from Kernel::init()
}
}
if (m_graphics_devices.is_empty()) {
dbgln("No graphics adapter was initialized.");
return false;