feat: (devfs) a new filesystem for device exposure.
[lunaix-os.git] / lunaix-os / kernel / spike.c
1 #include <arch/x86/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     sprintf(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     asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(buffer));
17
18     spin(); // never reach
19 }
20
21 void
22 panick(const char* msg)
23 {
24     asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(msg));
25     spin();
26 }
27
28 void
29 panickf(const char* fmt, ...)
30 {
31     va_list args;
32     va_start(args, fmt);
33     __sprintf_internal(buffer, fmt, 1024, args);
34     va_end(args);
35
36     asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(buffer));
37     spin();
38 }