Kernel: d{print,warn,error}ln(...) now has a spinlock

This commit is contained in:
Bananymous 2023-04-22 17:58:51 +03:00
parent 3f1c0ec91b
commit 8a5608df91
2 changed files with 36 additions and 6 deletions

View File

@ -5,23 +5,29 @@
#define dprintln(...) \ #define dprintln(...) \
do { \ do { \
Debug::DebugLock::lock(); \
BAN::Formatter::print(Debug::putchar, "[{5}.{3}] {}:{}: ", PIT::ms_since_boot() / 1000, PIT::ms_since_boot() % 1000, __FILE__, __LINE__); \ 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, __VA_ARGS__); \
BAN::Formatter::print(Debug::putchar, "\r\n"); \ BAN::Formatter::print(Debug::putchar, "\r\n"); \
Debug::DebugLock::unlock(); \
} while(false) } while(false)
#define dwarnln(...) \ #define dwarnln(...) \
do { \ do { \
Debug::DebugLock::lock(); \
BAN::Formatter::print(Debug::putchar, "\e[33m"); \ BAN::Formatter::print(Debug::putchar, "\e[33m"); \
dprintln(__VA_ARGS__); \ dprintln(__VA_ARGS__); \
BAN::Formatter::print(Debug::putchar, "\e[m"); \ BAN::Formatter::print(Debug::putchar, "\e[m"); \
Debug::DebugLock::unlock(); \
} while(false) } while(false)
#define derrorln(...) \ #define derrorln(...) \
do { \ do { \
Debug::DebugLock::lock(); \
BAN::Formatter::print(Debug::putchar, "\e[31m"); \ BAN::Formatter::print(Debug::putchar, "\e[31m"); \
dprintln(__VA_ARGS__); \ dprintln(__VA_ARGS__); \
BAN::Formatter::print(Debug::putchar, "\e[m"); \ BAN::Formatter::print(Debug::putchar, "\e[m"); \
Debug::DebugLock::unlock(); \
} while(false) } while(false)
#define BOCHS_BREAK() asm volatile("xchgw %bx, %bx") #define BOCHS_BREAK() asm volatile("xchgw %bx, %bx")
@ -30,4 +36,11 @@ namespace Debug
{ {
void dump_stack_trace(); void dump_stack_trace();
void putchar(char); void putchar(char);
class DebugLock
{
public:
static void lock();
static void unlock();
};
} }

View File

@ -1,5 +1,7 @@
#include <kernel/Debug.h> #include <kernel/Debug.h>
#include <kernel/InterruptController.h>
#include <kernel/Serial.h> #include <kernel/Serial.h>
#include <kernel/SpinLock.h>
#include <kernel/Terminal/TTY.h> #include <kernel/Terminal/TTY.h>
namespace Debug namespace Debug
@ -53,4 +55,19 @@ namespace Debug
return Kernel::TTY::putchar_current(ch); return Kernel::TTY::putchar_current(ch);
} }
static Kernel::RecursiveSpinLock s_debug_lock;
void DebugLock::lock()
{
if (interrupts_enabled())
s_debug_lock.lock();
}
void DebugLock::unlock()
{
if (interrupts_enabled())
s_debug_lock.unlock();
}
} }