Better panic, with PANIC macro
This commit is contained in:
parent
a6ae43f583
commit
6c21ac7669
2 changed files with 18 additions and 6 deletions
|
@ -1,8 +1,18 @@
|
||||||
|
#include "stdbool.h"
|
||||||
|
#include <mini-printf.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <uart.h>
|
#include <uart.h>
|
||||||
volatile int panicked;
|
|
||||||
|
|
||||||
void panic(char *s) {
|
volatile int panicked = false;
|
||||||
panicked = 1;
|
|
||||||
uart_puts(s);
|
__attribute__((visibility("hidden")))
|
||||||
while (1);
|
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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef KERNEL_PANIC_H
|
#ifndef KERNEL_PANIC_H
|
||||||
#define 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
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue