From 5576151e6864bc0b3122c660d3234f30c83fc6bc Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 2 Sep 2022 15:59:21 +0300 Subject: [PATCH] Kernel: Don't blindly compile Bochs debug output code in ConsoleDevice Only use the Bochs debug output if we compile a x86 build since bochs debug output relies on x86 specific instructions. We also remove the CONSOLE_OUT_TO_BOCHS_DEBUG_PORT flag as we always compile bochs debug output for x86 builds and we always want to include the bochs debug output capability as it is very handy and doesn't hurt bare metal hardware or do any other problem besides taking a small amount of CPU cycles. --- Kernel/Devices/ConsoleDevice.cpp | 12 +++++------- Kernel/kprintf.cpp | 5 +++++ Kernel/kstdio.h | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Kernel/Devices/ConsoleDevice.cpp b/Kernel/Devices/ConsoleDevice.cpp index 5e59705a45..4c3644a6eb 100644 --- a/Kernel/Devices/ConsoleDevice.cpp +++ b/Kernel/Devices/ConsoleDevice.cpp @@ -4,16 +4,16 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include +#if ARCH(I386) || ARCH(X86_64) +# include +#endif #include #include #include #include #include -// Output bytes to kernel debug port 0xE9 (Bochs console). It's very handy. -#define CONSOLE_OUT_TO_BOCHS_DEBUG_PORT - static Kernel::Spinlock g_console_lock { LockRank::None }; UNMAP_AFTER_INIT NonnullLockRefPtr ConsoleDevice::must_create() @@ -57,8 +57,6 @@ ErrorOr ConsoleDevice::write(OpenFileDescription&, u64, Kernel::UserOrKe void ConsoleDevice::put_char(char ch) { Kernel::SpinlockLocker lock(g_console_lock); -#ifdef CONSOLE_OUT_TO_BOCHS_DEBUG_PORT - IO::out8(IO::BOCHS_DEBUG_PORT, ch); -#endif + dbgputchar(ch); m_logbuffer.enqueue(ch); } diff --git a/Kernel/kprintf.cpp b/Kernel/kprintf.cpp index e244a2d80f..ecaa7bb1b7 100644 --- a/Kernel/kprintf.cpp +++ b/Kernel/kprintf.cpp @@ -144,6 +144,11 @@ static inline void internal_dbgputch(char ch) #endif } +extern "C" void dbgputchar(char ch) +{ + internal_dbgputch(ch); +} + extern "C" void dbgputstr(char const* characters, size_t length) { if (!characters) diff --git a/Kernel/kstdio.h b/Kernel/kstdio.h index 1006e607b8..be755c1698 100644 --- a/Kernel/kstdio.h +++ b/Kernel/kstdio.h @@ -13,6 +13,7 @@ extern "C" { void dbgputstr(char const*, size_t); void kernelputstr(char const*, size_t); void kernelcriticalputstr(char const*, size_t); +void dbgputchar(char); void kernelearlyputstr(char const*, size_t); int snprintf(char* buf, size_t, char const* fmt, ...) __attribute__((format(printf, 3, 4))); void set_serial_debug_enabled(bool desired_state);