From 4a34caba5c402aeb8e90f67fedb0ffc0e6ea0048 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 15 Dec 2021 04:53:05 +0500 Subject: [PATCH] Use libkernaux asserts --- kernel/main.c | 2 ++ kernel/panic.c | 10 ++++++++++ kernel/panic.h | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/kernel/main.c b/kernel/main.c index 6f61611..4f58843 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -28,6 +28,8 @@ void main( const unsigned long multiboot2_magic, const struct KernAux_Multiboot2 *const multiboot2_info ) { + kernaux_assert_cb = kernaux_assert_fn; + if (multiboot2_magic != KERNAUX_MULTIBOOT2_MAGIC) { panic("Multiboot 2 magic number is invalid."); } diff --git a/kernel/panic.c b/kernel/panic.c index e9a8162..27500b1 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -13,3 +13,13 @@ void halt() { panic("Kernel main function returned."); } + +void kernaux_assert_fn( + const char *const file, + const int line, + const char *const str +) { + kernaux_console_printf("[FAIL] assertion failed: %s:%u: %s\n", + file, line, str); + kernaux_arch_i386_hang(); +} diff --git a/kernel/panic.h b/kernel/panic.h index 1653be4..2118cf0 100644 --- a/kernel/panic.h +++ b/kernel/panic.h @@ -1,8 +1,11 @@ #ifndef KERNEL_INCLUDED_PANIC #define KERNEL_INCLUDED_PANIC 1 -void panic(const char *s); +#include #define assert(cond, s) { if (!(cond)) { panic(s); } } +void panic(const char *s); +void kernaux_assert_fn(const char *file, int line, const char *str); + #endif