Skip to content

Commit

Permalink
Kernel: Add kernelearlyputstr and use it in dbgln in very-early boot
Browse files Browse the repository at this point in the history
This variant of dbgputstr does not lock the global log lock, as it is
called before the current or any other processor was initialized,
meaning that:
A) The $gs base was not setup yet, so we cannot enter into critical
   sections, and as a result we cannot use SpinLocks
B) No other processors may try to print at the same time anyway
  • Loading branch information
IdanHo committed Sep 10, 2021
1 parent 18d2a74 commit 6348b63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions AK/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,14 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams& params)

const auto string = builder.string_view();

#ifdef __serenity__
# ifdef KERNEL
if (!Kernel::Processor::is_initialized()) {
kernelearlyputstr(string.characters_without_null_termination(), string.length());
return;
}
# endif
#endif
dbgputstr(string.characters_without_null_termination(), string.length());
}

Expand Down
11 changes: 11 additions & 0 deletions Kernel/kprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,14 @@ extern "C" void kernelcriticalputstr(const char* characters, size_t length)
for (size_t i = 0; i < length; ++i)
critical_console_out(characters[i]);
}

extern "C" void kernelearlyputstr(const char* characters, size_t length)
{
if (!characters)
return;
// NOTE: We do not lock the log lock here, as this function is called before this or any other processor was initialized, meaning:
// A) The $gs base was not setup yet, so we cannot enter into critical sections, and as a result we cannot use SpinLocks
// B) No other processors may try to print at the same time anyway
for (size_t i = 0; i < length; ++i)
internal_dbgputch(characters[i]);
}
1 change: 1 addition & 0 deletions Kernel/kstdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void dbgputch(char);
void dbgputstr(const char*, size_t);
void kernelputstr(const char*, size_t);
void kernelcriticalputstr(const char*, size_t);
void kernelearlyputstr(const char*, size_t);
int snprintf(char* buf, size_t, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
void set_serial_debug(bool on_or_off);
int get_serial_debug();
Expand Down

0 comments on commit 6348b63

Please sign in to comment.