aboutsummaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authorMarvin Borner2020-05-28 17:18:03 +0200
committerMarvin Borner2020-05-28 17:18:03 +0200
commit8e1e50085e9c53ddd0b7400173ba16a140b7e967 (patch)
tree9ed70405983eb99c3b3890e7f4d8cdfe915c84b5 /src/kernel
parent94c4889e182d6c0c387241277bd365f36c624196 (diff)
Way better assertion
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/system.c8
-rw-r--r--src/kernel/system.h8
2 files changed, 10 insertions, 6 deletions
diff --git a/src/kernel/system.c b/src/kernel/system.c
index fd9a9b3..6ddae9c 100644
--- a/src/kernel/system.c
+++ b/src/kernel/system.c
@@ -71,11 +71,11 @@ void _panic(const char *f, const char *msg)
halt_loop();
}
-void _assert(const char *f, int x)
+void _assert(const char *file, int line, const char *func, const char *exp)
{
- if (x == 0) {
- _panic(f, "Assertion failed");
- }
+ cli();
+ serial_printf(RED "%s:%d: %s: Assertion '%s' failed\n" RES, file, line, func, exp);
+ halt_loop();
}
void halt_loop()
diff --git a/src/kernel/system.h b/src/kernel/system.h
index 57a55fe..785aa9b 100644
--- a/src/kernel/system.h
+++ b/src/kernel/system.h
@@ -22,6 +22,10 @@ typedef struct __attribute__((packed)) {
*/
extern void int32(u8 intnum, regs16_t *regs);
+// Filename macro
+#define __FILENAME__ \
+ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
+
/**
* Display a general log message
* @param fmt The message
@@ -61,8 +65,8 @@ void _panic(const char *f, const char *msg);
* Assert that a value is non-zero, else panic
* @param x The value
*/
-void _assert(const char *f, int x);
-#define assert(x) _assert(__func__, x)
+void _assert(const char *file, int line, const char *func, const char *exp);
+#define assert(exp) (exp) ? 0 : _assert(__FILENAME__, __LINE__, __func__, #exp)
/**
* Creates an infinite halt loop