39 lines
963 B
C
39 lines
963 B
C
#include "../common.h"
|
|
#include "../uart.h"
|
|
#include <stdarg.h>
|
|
|
|
#define VPRINT(method, format, args) \
|
|
VPRINT_(method, format, args)
|
|
#define VPRINT_(method, format, args) \
|
|
method ## _ ## vprintf(format, args)
|
|
|
|
#define PRINT(method, str)\
|
|
PRINT_(method, str)
|
|
#define PRINT_(method, str)\
|
|
method ## _ ## puts(str)
|
|
|
|
#define DEFAULT_OUTPUT_METHOD uart
|
|
#define DEFAULT_PRINT_ARGS(format) \
|
|
va_list args = nullptr; \
|
|
va_start(args, format); \
|
|
DEFAULT_VPRINT(format, args); \
|
|
va_end(args)
|
|
#define DEFAULT_VPRINT(format, args) \
|
|
VPRINT(DEFAULT_OUTPUT_METHOD, format, args)
|
|
#define DEFAULT_PRINT(str)\
|
|
PRINT(DEFAULT_OUTPUT_METHOD, str)
|
|
|
|
void panic(const char *format, ...) {
|
|
DEFAULT_PRINT("Kernel panic!");
|
|
DEFAULT_PRINT("Reason:");
|
|
|
|
// Print the reason
|
|
DEFAULT_PRINT_ARGS(format);
|
|
|
|
// Hang
|
|
asm volatile("wfi");
|
|
}
|
|
|
|
void print(const char *format, ...) {
|
|
DEFAULT_PRINT_ARGS(format);
|
|
} |