blob: ff22727968c6b3b3061d76bb6407c60afb778675 [file] [log] [blame]
swissChili0b35bf22021-02-18 12:49:40 -08001#include "log.h"
2#include "kint.h"
swissChili0b35bf22021-02-18 12:49:40 -08003#include "stdarg.h"
swissChili825d46b2021-02-21 10:14:16 -08004#include "vga.h"
swissChili0b35bf22021-02-18 12:49:40 -08005
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++;
swissChili825d46b2021-02-21 10:14:16 -080016
swissChili0b35bf22021-02-18 12:49:40 -080017 switch (*format)
18 {
swissChili825d46b2021-02-21 10:14:16 -080019 case 'd': {
20 uint x = (uint)va_arg(args, uint);
swissChili0b35bf22021-02-18 12:49:40 -080021 vga_putd(x);
22 break;
23 }
swissChili825d46b2021-02-21 10:14:16 -080024
25 case 'x': {
swissChili0b35bf22021-02-18 12:49:40 -080026 // consider hex always unsigned
swissChili825d46b2021-02-21 10:14:16 -080027 uint x = (uint)va_arg(args, uint);
swissChili0b35bf22021-02-18 12:49:40 -080028 vga_putx(x);
29 break;
30 }
31
swissChili825d46b2021-02-21 10:14:16 -080032 case 's': {
swissChili0b35bf22021-02-18 12:49:40 -080033 char *s = va_arg(args, char *);
34 vga_write(s);
35 break;
36 }
swissChili19ef4182021-02-21 17:45:51 -080037
38 case 'c': {
39 char s = va_arg(args, int);
40 vga_put(s);
41 break;
42 }
swissChilief829f32021-06-13 20:00:54 -070043 case 'b': {
44 uint v = va_arg(args, uint);
45 if (v)
46 vga_write("true");
47 else
48 vga_write("false");
49 }
swissChili0b35bf22021-02-18 12:49:40 -080050 }
51 format++;
52 }
53 else
54 {
55 vga_put(*format);
56 format++;
57 }
58 }
59
60 va_end(args);
61}
62
swissChili825d46b2021-02-21 10:14:16 -080063void kassert_int(bool condition, const char *message, const char *file,
64 const int line)
swissChili0b35bf22021-02-18 12:49:40 -080065{
66 if (!condition)
67 {
68 vga_set_color(LIGHT_RED, BLACK);
swissChili9bd74de2021-06-15 20:30:48 -070069 kprintf(ERROR "ASSERTION FAILED: %s:%d\n%s\n", file, line, message);
swissChili825d46b2021-02-21 10:14:16 -080070
swissChili0b35bf22021-02-18 12:49:40 -080071 while (1)
swissChili825d46b2021-02-21 10:14:16 -080072 {
73 }
swissChili0b35bf22021-02-18 12:49:40 -080074 }
75}