helos1/runtime/panic_assert.h
Edgaru089 ec808e5e2e runtime, interrupt: print to screen on errors, print CR2 on panic
CR2 is the last accessed address set on page exceptions
2021-11-11 16:18:47 +08:00

52 lines
1.2 KiB
C

#pragma once
#ifndef HELOS
#include <assert.h>
#else
#include "../main.h"
#include "stdio.h"
#include "printf.h"
#ifdef __cplusplus
extern "C" {
#endif
#define assert(expr) \
do { \
if (!(expr)) \
Panicf("Assertion failed: (" __FILE__ ":%d[%s]), Expression: %s", __LINE__, __func__, #expr); \
} while (0)
// defined in assembly
noreturn void __Panic_HaltSystem();
// Panic() aborts the system after printing the message and some other information.
noreturn inline static void Panic(const char *message) {
asm volatile("cli");
io_Errorf("Panic: %s\n", message);
__Panic_HaltSystem();
}
// Panicf() aborts the system after printing the message using vsnprintf.
noreturn inline static void Panicf(const char *fmt, ...) {
asm volatile("cli");
va_list args;
va_start(args, fmt);
int ret = vsnprintf(Buffer, HELOS_BUFFER_SIZE, fmt, args);
va_end(args);
io_Errorf("Panic: %s\n", Buffer);
__Panic_HaltSystem();
}
#ifdef __cplusplus
}
#endif
#endif // HELOS