// ke_debug.c - debugging utilities #include #include #include #include #include #include int _fltused; // fuckass int gDebugEnabled = 0; void (*PrintChar)(char, uint32_t, uint32_t); void kernel_putchar(char c) { PrintChar(c, 0x00FF00, 0x000000); } void KeInitDebug(void (*PrintPtr)(char, uint32_t, uint32_t), int v) { gDebugEnabled = v; PrintChar = PrintPtr; printf_set_putchar(kernel_putchar); } __declspec(dllexport) void DbgPrint(const char* fmt, ...) { if (!gDebugEnabled) return; static SPINLOCK sl = {0}; uintptr_t flags = KeAcquireSpinlock(&sl); va_list va; va_start(va, fmt); vprintf(fmt, va); va_end(va); KeReleaseSpinlock(&sl, flags); } // KePanic - Forces output even if debug was compiled out, then the macro halts. __declspec(dllexport) _Noreturn void KePanic(const char *fmt, ...) { // We are done, go away _disable(); // Print a bright-red banner so the framebuffer is unmistakable. // We call PrintChar directly so we can set a red foreground. // (DbgPrint uses green; we want this visually distinct.) static const char banner[] = "\n*** KERNEL PANIC ***\n"; for (const char *p = banner; *p; p++) PrintChar(*p, 0xFF2222, 0x000000); // Now print the caller's message through the normal vprintf path. va_list va; va_start(va, fmt); vprintf(fmt, va); va_end(va); // Halt it! while (true) __halt(); }