CeDOS - Commit f4e78a67

assert: Allow different print implementations This allows us to use asserts in the bootloader and in user processes, with different fail condition handling in each.
Celina Sophie Kalus
Wed, 29 Nov 2023 14:41:31 +0100
6 files changed, 27 insertions(+), 5 deletions(-)
M boot/main.cboot/main.c

@@ -15,6 +15,12 @@ printc(*(str++));

} } +void assert_failed(const char * message) { + print_string(message); + + while (1) {} +} + int load_kernel() { // debug output uint8_t *dbuf = (uint8_t *)(0x10000);
M common/assert.hcommon/assert.h

@@ -1,10 +1,10 @@

#ifndef ASSERT_H #define ASSERT_H -#include "core.h" - #include <stdint.h> -#define assert(cond) if (!(cond)) { kpanic("Assertion failed: " #cond); } +extern void assert_failed(const char * message); + +#define assert(cond) if (!(cond)) { assert_failed("Assertion failed: " #cond); } #endif
M kernel/core.ckernel/core.c

@@ -228,4 +228,8 @@

int core_init(void) { core_con = std_con; return core_con->init(); -}+} + +void assert_failed(const char * message) { + kpanic(message); +}
M kernel/fat.ckernel/fat.c

@@ -2,6 +2,7 @@ #include "file.h"

#include "fat.h" #include "string.h" #include "assert.h" +#include "core.h" #include "mm/memory.h"
A libcedos/assert.c

@@ -0,0 +1,11 @@

+#include "cedos.h" +#include "stdio.h" + +void assert_failed(const char * message) { + printf(message); + + int pid = get_pid(); + + /* TODO: Kill this process */ + while (1) {} +}
M libcedos/cedos.clibcedos/cedos.c

@@ -94,4 +94,4 @@ uint32_t sc_mem_usage(void) {

volatile int res = 0; interrupt(0x30, res, 13, 0, 0, 0); return res; -}+}