blob: 19959e7542aa28aacecb7146938144e73bd3dea3 [file] [log] [blame]
swissChili0b35bf22021-02-18 12:49:40 -08001#include "log.h"
2#include "kint.h"
3#include "vga.h"
4#include "stdarg.h"
5
6void kprintf(const char *format, ...)
7{
8 va_list args;
9 va_start(args, format);
10
11 while (*format)
12 {
13 if (*format == '%')
14 {
15 format++;
16
17 switch (*format)
18 {
19 case 'd':
20 {
21 uint x = (uint) va_arg(args, uint);
22 vga_putd(x);
23 break;
24 }
25
26 case 'x':
27 {
28 // consider hex always unsigned
29 uint x = (uint) va_arg(args, uint);
30 vga_putx(x);
31 break;
32 }
33
34 case 's':
35 {
36 char *s = va_arg(args, char *);
37 vga_write(s);
38 break;
39 }
40 }
41 format++;
42 }
43 else
44 {
45 vga_put(*format);
46 format++;
47 }
48 }
49
50 va_end(args);
51}
52
53void kassert_int(bool condition, const char *message, const char *file, const int line)
54{
55 if (!condition)
56 {
57 vga_set_color(LIGHT_RED, BLACK);
58 kprintf("ASSERTION FAILED: %s:%d\n%s\n", file, line, message);
59
60 while (1)
61 {}
62 }
63}