From 90a194377c0ebf4dc100f44baeb375991c14e922 Mon Sep 17 00:00:00 2001 From: Liav A Date: Wed, 9 Feb 2022 20:53:17 +0200 Subject: [PATCH] Kernel/Graphics: Untie Text mode console from VGACompatibleAdapter class Instead, we can construct this type of object without having to instantiate a VGACompatibleAdapter object first. This can help instantiate such console very early on boot to aid debug issues on bare metal hardware. --- Kernel/Graphics/Console/TextModeConsole.cpp | 8 ++++---- Kernel/Graphics/Console/TextModeConsole.h | 4 ++-- Kernel/Graphics/Console/VGAConsole.cpp | 3 +-- Kernel/Graphics/Console/VGAConsole.h | 5 ++--- Kernel/Graphics/VGACompatibleAdapter.cpp | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Kernel/Graphics/Console/TextModeConsole.cpp b/Kernel/Graphics/Console/TextModeConsole.cpp index 23cc9792e5..759be9ba78 100644 --- a/Kernel/Graphics/Console/TextModeConsole.cpp +++ b/Kernel/Graphics/Console/TextModeConsole.cpp @@ -11,13 +11,13 @@ namespace Kernel::Graphics { -UNMAP_AFTER_INIT NonnullRefPtr TextModeConsole::initialize(const VGACompatibleAdapter& adapter) +UNMAP_AFTER_INIT NonnullRefPtr TextModeConsole::initialize() { - return adopt_ref(*new TextModeConsole(adapter)); + return adopt_ref(*new TextModeConsole()); } -UNMAP_AFTER_INIT TextModeConsole::TextModeConsole(const VGACompatibleAdapter& adapter) - : VGAConsole(adapter, VGAConsole::Mode::TextMode, 80, 25) +UNMAP_AFTER_INIT TextModeConsole::TextModeConsole() + : VGAConsole(VGAConsole::Mode::TextMode, 80, 25) , m_current_vga_window(m_vga_region->vaddr().offset(0x18000).as_ptr()) { for (size_t index = 0; index < height(); index++) { diff --git a/Kernel/Graphics/Console/TextModeConsole.h b/Kernel/Graphics/Console/TextModeConsole.h index b38a8d74b9..1db23f3552 100644 --- a/Kernel/Graphics/Console/TextModeConsole.h +++ b/Kernel/Graphics/Console/TextModeConsole.h @@ -14,7 +14,7 @@ namespace Kernel::Graphics { class TextModeConsole final : public VGAConsole { public: - static NonnullRefPtr initialize(const VGACompatibleAdapter& adapter); + static NonnullRefPtr initialize(); virtual size_t chars_per_line() const override { return width(); }; virtual bool has_hardware_cursor() const override { return true; } @@ -36,7 +36,7 @@ public: private: void clear_vga_row(u16 row); - explicit TextModeConsole(const VGACompatibleAdapter&); + TextModeConsole(); mutable Spinlock m_vga_lock; diff --git a/Kernel/Graphics/Console/VGAConsole.cpp b/Kernel/Graphics/Console/VGAConsole.cpp index 9336978189..01741ef608 100644 --- a/Kernel/Graphics/Console/VGAConsole.cpp +++ b/Kernel/Graphics/Console/VGAConsole.cpp @@ -9,10 +9,9 @@ namespace Kernel::Graphics { -UNMAP_AFTER_INIT VGAConsole::VGAConsole(const VGACompatibleAdapter& adapter, Mode mode, size_t width, size_t height) +UNMAP_AFTER_INIT VGAConsole::VGAConsole(Mode mode, size_t width, size_t height) : Console(width, height) , m_vga_region(MM.allocate_kernel_region(PhysicalAddress(0xa0000), Memory::page_round_up(0xc0000 - 0xa0000).release_value_but_fixme_should_propagate_errors(), "VGA Display", Memory::Region::Access::ReadWrite).release_value()) - , m_adapter(adapter) , m_mode(mode) { } diff --git a/Kernel/Graphics/Console/VGAConsole.h b/Kernel/Graphics/Console/VGAConsole.h index 7c2b4cb49c..f9ff5a2438 100644 --- a/Kernel/Graphics/Console/VGAConsole.h +++ b/Kernel/Graphics/Console/VGAConsole.h @@ -22,7 +22,7 @@ public: }; public: - static NonnullRefPtr initialize(const VGACompatibleAdapter&, Mode, size_t width, size_t height); + static NonnullRefPtr initialize(Mode, size_t width, size_t height); virtual bool is_hardware_paged_capable() const override { return false; } virtual bool has_hardware_cursor() const override { return false; } @@ -31,10 +31,9 @@ public: virtual ~VGAConsole() = default; protected: - VGAConsole(const VGACompatibleAdapter&, Mode, size_t width, size_t height); + VGAConsole(Mode, size_t width, size_t height); NonnullOwnPtr m_vga_region; - NonnullRefPtr m_adapter; const Mode m_mode; }; } diff --git a/Kernel/Graphics/VGACompatibleAdapter.cpp b/Kernel/Graphics/VGACompatibleAdapter.cpp index 4dd899725f..a9d42f958e 100644 --- a/Kernel/Graphics/VGACompatibleAdapter.cpp +++ b/Kernel/Graphics/VGACompatibleAdapter.cpp @@ -39,7 +39,7 @@ UNMAP_AFTER_INIT void VGACompatibleAdapter::initialize_framebuffer_devices() UNMAP_AFTER_INIT VGACompatibleAdapter::VGACompatibleAdapter(PCI::Address address) : PCI::Device(address) { - m_framebuffer_console = Graphics::TextModeConsole::initialize(*this); + m_framebuffer_console = Graphics::TextModeConsole::initialize(); GraphicsManagement::the().set_console(*m_framebuffer_console); }