Kernel: Move debug printing to its own file

It didn't make sense that dprint was defined in Serial.h.
We also now dump dprint to tty if there is no serial and tty is initialized
This commit is contained in:
Bananymous
2023-01-25 21:39:03 +02:00
parent b315fdc27f
commit c0bc002ac6
16 changed files with 73 additions and 55 deletions

View File

@@ -0,0 +1,32 @@
#pragma once
#include <BAN/Formatter.h>
#include <kernel/PIT.h>
#define dprintln(...) \
do { \
BAN::Formatter::print(Debug::putchar, "[{5}.{3}] {}:{}: ", PIT::ms_since_boot() / 1000, PIT::ms_since_boot() % 1000, __FILE__, __LINE__); \
BAN::Formatter::print(Debug::putchar, __VA_ARGS__); \
BAN::Formatter::print(Debug::putchar, "\r\n"); \
} while(false)
#define dwarnln(...) \
do { \
BAN::Formatter::print(Debug::putchar, "\e[33m"); \
dprintln(__VA_ARGS__); \
BAN::Formatter::print(Debug::putchar, "\e[m"); \
} while(false)
#define derrorln(...) \
do { \
BAN::Formatter::print(Debug::putchar, "\e[31m"); \
dprintln(__VA_ARGS__); \
BAN::Formatter::print(Debug::putchar, "\e[m"); \
} while(false)
#define BOCHS_BREAK() asm volatile("xchgw %bx, %bx")
namespace Debug
{
void putchar(char);
}

View File

@@ -1,8 +1,7 @@
#pragma once
#include <kernel/Debug.h>
#include <kernel/kprint.h>
#include <kernel/Serial.h>
#include <kernel/TTY.h>
#define Panic(...) PanicImpl(__FILE__, __LINE__, __VA_ARGS__)
@@ -15,15 +14,9 @@ namespace Kernel
__attribute__((__noreturn__))
static void PanicImpl(const char* file, int line, const char* message, Args... args)
{
derrorln("Kernel panic at {}:{}", file, line);
kprintln("\e[31mKernel panic at {}:{}\e[m", file, line);
derrorln(message, args...);
dump_stacktrace();
if (TTY::IsInitialized())
{
kprint("\e[31mKernel panic at {}:{}\n", file, line);
kprint(message, args...);
kprint("\e[m\n");
}
asm volatile("cli");
for (;;)
asm volatile("hlt");

View File

@@ -1,36 +1,11 @@
#pragma once
#include <BAN/Formatter.h>
#include <kernel/PIT.h>
#define dprintln(...) \
do { \
BAN::Formatter::print(Serial::serial_putc, "[{5}.{3}] {}:{}: ", PIT::ms_since_boot() / 1000, PIT::ms_since_boot() % 1000, __FILE__, __LINE__); \
BAN::Formatter::print(Serial::serial_putc, __VA_ARGS__); \
BAN::Formatter::print(Serial::serial_putc, "\r\n"); \
} while(false)
#define dwarnln(...) \
do { \
BAN::Formatter::print(Serial::serial_putc, "\e[33m"); \
dprintln(__VA_ARGS__); \
BAN::Formatter::print(Serial::serial_putc, "\e[m"); \
} while(false)
#define derrorln(...) \
do { \
BAN::Formatter::print(Serial::serial_putc, "\e[31m"); \
dprintln(__VA_ARGS__); \
BAN::Formatter::print(Serial::serial_putc, "\e[m"); \
} while(false)
#define BOCHS_BREAK() asm volatile("xchgw %bx, %bx")
namespace Serial
{
void initialize();
void Initialize();
bool IsInitialized();
void serial_putc(char);
void putchar(char);
}

View File

@@ -1,7 +1,6 @@
#pragma once
#include <kernel/TerminalDriver.h>
#include <kernel/Serial.h>
class TTY
{