2023-05-17 20:42:59 -07:00
|
|
|
#include "debug/debug.h"
|
|
|
|
|
|
|
|
#include "common/port.h"
|
2023-05-30 23:22:29 -07:00
|
|
|
#include "scheduler/scheduler.h"
|
2023-05-17 20:42:59 -07:00
|
|
|
|
|
|
|
#define COM1 0x3f8
|
|
|
|
|
2023-05-18 01:16:53 -07:00
|
|
|
namespace {
|
|
|
|
bool is_transmit_empty() { return (inb(COM1 + 5) & 0x20) != 0; }
|
|
|
|
|
|
|
|
void dbgputchar(char c) {
|
|
|
|
while (!is_transmit_empty())
|
|
|
|
;
|
|
|
|
|
|
|
|
outb(COM1, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dbgcstr(const char* str) {
|
|
|
|
for (; *str != '\0'; str++) {
|
|
|
|
dbgputchar(*str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-05 09:24:09 -08:00
|
|
|
void dbg(const glcr::StringView& str) {
|
|
|
|
for (uint64_t i = 0; i < str.size(); i++) {
|
|
|
|
dbgputchar(str[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-30 23:22:29 -07:00
|
|
|
void AddProcPrefix() {
|
|
|
|
if (gScheduler != nullptr) {
|
2023-06-12 20:56:25 -07:00
|
|
|
auto t = gScheduler->CurrentThread();
|
2023-11-05 09:24:09 -08:00
|
|
|
dbg(glcr::StrFormat("[{}.{}] ", t->pid(), t->tid()));
|
2023-05-30 23:22:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-18 01:16:53 -07:00
|
|
|
} // namespace
|
|
|
|
|
2023-11-08 08:07:57 -08:00
|
|
|
void early_dbgln(const char* str) {
|
|
|
|
dbgcstr(str);
|
|
|
|
dbgcstr("\n");
|
|
|
|
}
|
2023-11-05 08:48:41 -08:00
|
|
|
|
2023-11-05 09:24:09 -08:00
|
|
|
void dbgln(const glcr::StringView& str) {
|
|
|
|
AddProcPrefix();
|
|
|
|
dbg(str);
|
|
|
|
dbg("\n");
|
|
|
|
}
|