Handle panic through kvprintf instead

This commit is contained in:
Imbus 2025-09-02 02:37:00 +02:00
parent e30cc4c3d0
commit 5596841482
3 changed files with 13 additions and 6 deletions

View file

@ -7,12 +7,11 @@
volatile int panicked = false; volatile int panicked = false;
__attribute__((visibility("hidden"))) __attribute__((visibility("hidden"))) void __panic(const char *restrict fmt, ...) {
void __panic(const char *restrict fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
(void)mini_vpprintf(stdout_puts, NULL, fmt, ap); kvprintf(fmt, ap);
va_end(ap); va_end(ap);
panicked = true; panicked = true;
while (true) asm volatile("wfi"); for (;;) asm volatile("wfi");
} }

View file

@ -1,5 +1,6 @@
#include <mini-printf.h> #include <mini-printf.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
#include <uart.h> #include <uart.h>
/** Helper routine to put characters into our uart device */ /** Helper routine to put characters into our uart device */
@ -21,7 +22,12 @@ static int stdout_puts(char *s, int len, void *unused) {
int kprintf(const char *restrict fmt, ...) { int kprintf(const char *restrict fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
int ret = mini_vpprintf(stdout_puts, NULL, fmt, ap); int ret = kvprintf(fmt, &ap);
va_end(ap); va_end(ap);
return ret; return ret;
} }
int kvprintf(const char *fmt, va_list ap) {
int ret = mini_vpprintf(stdout_puts, NULL, fmt, ap);
return ret;
}

View file

@ -1,8 +1,10 @@
#ifndef STDIO_H #ifndef STDIO_H
#define STDIO_H #define STDIO_H
int stdout_puts(char *s, int len, void *unused); #include <stdarg.h>
int kprintf(const char *restrict format, ...); int kprintf(const char *restrict format, ...);
int kvprintf(const char *fmt, va_list ap);
// int fprintf(FILE *restrict stream, const char *restrict format, ...); // int fprintf(FILE *restrict stream, const char *restrict format, ...);
// int dprintf(int fd, const char *restrict format, ...); // int dprintf(int fd, const char *restrict format, ...);