Better panic, with PANIC macro

This commit is contained in:
Imbus 2025-09-02 00:17:44 +02:00
parent a6ae43f583
commit 6c21ac7669
2 changed files with 18 additions and 6 deletions

View file

@ -1,8 +1,18 @@
#include "stdbool.h"
#include <mini-printf.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <uart.h>
volatile int panicked;
void panic(char *s) {
panicked = 1;
uart_puts(s);
while (1);
volatile int panicked = false;
__attribute__((visibility("hidden")))
void __panic(const char *restrict fmt, ...) {
va_list ap;
va_start(ap, fmt);
(void)mini_vpprintf(stdout_puts, NULL, fmt, ap);
va_end(ap);
panicked = true;
while (true) asm volatile("wfi");
}

View file

@ -1,6 +1,8 @@
#ifndef KERNEL_PANIC_H
#define KERNEL_PANIC_H
void panic(char *s);
#define PANIC(fmt, ...) __panic("[%s:%d %s] \n" fmt, __FILE__, __LINE__, __func__)
void __panic(const char *restrict fmt, ...);
#endif