refactor: organize all arch related files together.
[lunaix-os.git] / lunaix-os / kernel / spike.c
1 #include <arch/i386/interrupts.h>
2 #include <klibc/stdio.h>
3 #include <lunaix/spike.h>
4
5 static char buffer[1024];
6
7 void
8 __assert_fail(const char* expr, const char* file, unsigned int line)
9 {
10     ksprintf(buffer, "%s (%s:%u)", expr, file, line);
11
12     // Here we load the buffer's address into %edi ("D" constraint)
13     //  This is a convention we made that the LUNAIX_SYS_PANIC syscall will
14     //  print the panic message passed via %edi. (see
15     //  kernel/asm/x86/interrupts.c)
16     cpu_trap_panic(buffer);
17
18     DO_SPIN // never reach
19 }
20
21 void
22 panick(const char* msg)
23 {       
24     cpu_trap_panic(msg);
25     DO_SPIN
26 }
27
28 void
29 panickf(const char* fmt, ...)
30 {
31     va_list args;
32     va_start(args, fmt);
33     __ksprintf_internal(buffer, fmt, 1024, args);
34     va_end(args);
35
36     asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(buffer));
37     DO_SPIN
38 }