The printk(), panic() and kernel.h update

This commit is contained in:
2026-03-26 21:07:29 +01:00
parent 2f05396651
commit 63a238d2c4
18 changed files with 366 additions and 153 deletions
+33
View File
@@ -0,0 +1,33 @@
#include <vsnprintf.h>
#include <kernel.h>
#include <stdarg.h>
#include <system.h>
static int crashing = 0;
void panic(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vpanic(fmt, ap);
va_end(ap);
}
void vpanic(const char *fmt, va_list ap) {
static char buf[PANIC_MSG_BUFSZ];
size_t len;
cli();
if (crashing) { for (;;) __asm__ volatile ("hlt"); }
crashing = true;
len = vsnprintf(buf, sizeof(buf), fmt, ap);
if (len && buf[len - 1] == '\n') buf[len - 1] = '\0';
pr_emerg("--- [ Kernel panic: %s ] ---\n", buf);
//pr_emerg("--- [ End kernel panic: %s ] ---\n", buf);
// We can add some kind of LED blink or smth later :)
for (;;) __asm__ volatile ("hlt");
}