X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/7b0dccbab69e806a63c4504c3ddb82e45241985b..96e23fa3c6eabf8a6efebac24b740c5d4a2a1050:/lunaix-os/kernel/spike.c diff --git a/lunaix-os/kernel/spike.c b/lunaix-os/kernel/spike.c index 91f597d..87726b0 100644 --- a/lunaix-os/kernel/spike.c +++ b/lunaix-os/kernel/spike.c @@ -1,19 +1,38 @@ -#include #include -#include +#include +#include static char buffer[1024]; -void __assert_fail(const char* expr, const char* file, unsigned int line) { - sprintf(buffer, "Assert %s failed (%s:%u)", expr, file, line); +void +__assert_fail(const char* expr, const char* file, unsigned int line) +{ + sprintf(buffer, "%s (%s:%u)", expr, file, line); // Here we load the buffer's address into %edi ("D" constraint) // This is a convention we made that the LUNAIX_SYS_PANIC syscall will - // print the panic message passed via %edi. (see kernel/asm/x86/interrupts.c) - asm( - "int %0" - ::"i"(LUNAIX_SYS_PANIC), "D"(buffer) - ); + // print the panic message passed via %edi. (see + // kernel/asm/x86/interrupts.c) + asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(buffer)); + + spin(); // never reach +} + +void +panick(const char* msg) +{ + asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(msg)); + spin(); +} + +void +panickf(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + __sprintf_internal(buffer, fmt, 1024, args); + va_end(args); - spin(); // never reach -} \ No newline at end of file + asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(buffer)); + spin(); +}