1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 20:15:08 +00:00

Kernel: Changed serial debug functions and variables for readability

Change the name of set_serial_debug(bool on_or_off) to
set_serial_debug_enabled(bool desired_state). This is to make the names
more expressive and less unclear as to what the function does, as it
only sets the enabled state.
Likewise, change the name of get_serial_debug() to
is_serial_debug_enabled() in order to make clear from the name that
this is simply the state of s_serial_debug_enabled.
Change the name of serial_debug to s_serial_debug_enabled since this is
a static bool describing this state.
Finally, change the signature of set_serial_debug_enabled to return a
bool, as this is more logical and understandable.
This commit is contained in:
Skye Sprung 2022-08-24 23:49:23 +02:00 committed by Sam Atkins
parent cd763de280
commit eca85f2050
3 changed files with 12 additions and 12 deletions

View file

@ -319,7 +319,7 @@ void init_stage2(void*)
VirtualFileSystem::initialize(); VirtualFileSystem::initialize();
if (!get_serial_debug()) if (!is_serial_debug_enabled())
(void)SerialDevice::must_create(0).leak_ref(); (void)SerialDevice::must_create(0).leak_ref();
(void)SerialDevice::must_create(1).leak_ref(); (void)SerialDevice::must_create(1).leak_ref();
(void)SerialDevice::must_create(2).leak_ref(); (void)SerialDevice::must_create(2).leak_ref();
@ -409,7 +409,7 @@ UNMAP_AFTER_INIT void setup_serial_debug()
// 8-N-1 57600 baud. this is particularly useful for debugging the boot // 8-N-1 57600 baud. this is particularly useful for debugging the boot
// process on live hardware. // process on live hardware.
if (StringView { kernel_cmdline, strlen(kernel_cmdline) }.contains("serial_debug"sv)) { if (StringView { kernel_cmdline, strlen(kernel_cmdline) }.contains("serial_debug"sv)) {
set_serial_debug(true); set_serial_debug_enabled(true);
} }
} }

View file

@ -23,19 +23,19 @@ namespace Kernel {
extern Atomic<Graphics::Console*> g_boot_console; extern Atomic<Graphics::Console*> g_boot_console;
} }
static bool serial_debug; static bool s_serial_debug_enabled;
// A recursive spinlock allows us to keep writing in the case where a // A recursive spinlock allows us to keep writing in the case where a
// page fault happens in the middle of a dbgln(), etc // page fault happens in the middle of a dbgln(), etc
static RecursiveSpinlock s_log_lock { LockRank::None }; static RecursiveSpinlock s_log_lock { LockRank::None };
void set_serial_debug(bool on_or_off) void set_serial_debug_enabled(bool desired_state)
{ {
serial_debug = on_or_off; s_serial_debug_enabled = desired_state;
} }
int get_serial_debug() bool is_serial_debug_enabled()
{ {
return serial_debug; return s_serial_debug_enabled;
} }
static void serial_putch(char ch) static void serial_putch(char ch)
@ -71,7 +71,7 @@ static void serial_putch(char ch)
static void critical_console_out(char ch) static void critical_console_out(char ch)
{ {
if (serial_debug) if (s_serial_debug_enabled)
serial_putch(ch); serial_putch(ch);
// No need to output things to the real ConsoleDevice as no one is likely // No need to output things to the real ConsoleDevice as no one is likely
// to read it (because we are in a fatal situation, so only print things and halt) // to read it (because we are in a fatal situation, so only print things and halt)
@ -87,7 +87,7 @@ static void critical_console_out(char ch)
static void console_out(char ch) static void console_out(char ch)
{ {
if (serial_debug) if (s_serial_debug_enabled)
serial_putch(ch); serial_putch(ch);
// It would be bad to reach the assert in ConsoleDevice()::the() and do a stack overflow // It would be bad to reach the assert in ConsoleDevice()::the() and do a stack overflow
@ -151,7 +151,7 @@ int snprintf(char* buffer, size_t size, char const* fmt, ...)
static inline void internal_dbgputch(char ch) static inline void internal_dbgputch(char ch)
{ {
if (serial_debug) if (s_serial_debug_enabled)
serial_putch(ch); serial_putch(ch);
IO::out8(IO::BOCHS_DEBUG_PORT, ch); IO::out8(IO::BOCHS_DEBUG_PORT, ch);
} }

View file

@ -15,8 +15,8 @@ void kernelputstr(char const*, size_t);
void kernelcriticalputstr(char const*, size_t); void kernelcriticalputstr(char const*, size_t);
void kernelearlyputstr(char const*, size_t); void kernelearlyputstr(char const*, size_t);
int snprintf(char* buf, size_t, char const* fmt, ...) __attribute__((format(printf, 3, 4))); int snprintf(char* buf, size_t, char const* fmt, ...) __attribute__((format(printf, 3, 4)));
void set_serial_debug(bool on_or_off); void set_serial_debug_enabled(bool desired_state);
int get_serial_debug(); bool is_serial_debug_enabled();
} }
void dbgputstr(StringView view); void dbgputstr(StringView view);