blob: 9f0807f09c0bd32b6bd2ba5c1956e7c84e9d754e [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
swissChili36ed5d72021-07-23 14:56:36 -070025 case 'p':
26 vga_put('0');
27 vga_put('x');
28
swissChili825d46b2021-02-21 10:14:16 -080029 case 'x': {
swissChili0b35bf22021-02-18 12:49:40 -080030 // consider hex always unsigned
swissChili825d46b2021-02-21 10:14:16 -080031 uint x = (uint)va_arg(args, uint);
swissChili36ed5d72021-07-23 14:56:36 -070032 if (x)
33 vga_putx(x);
34 else
35 vga_put('0');
swissChili0b35bf22021-02-18 12:49:40 -080036 break;
37 }
38
swissChili825d46b2021-02-21 10:14:16 -080039 case 's': {
swissChili0b35bf22021-02-18 12:49:40 -080040 char *s = va_arg(args, char *);
41 vga_write(s);
42 break;
43 }
swissChili19ef4182021-02-21 17:45:51 -080044
45 case 'c': {
46 char s = va_arg(args, int);
47 vga_put(s);
48 break;
49 }
swissChilief829f32021-06-13 20:00:54 -070050 case 'b': {
51 uint v = va_arg(args, uint);
52 if (v)
53 vga_write("true");
54 else
55 vga_write("false");
56 }
swissChili0b35bf22021-02-18 12:49:40 -080057 }
58 format++;
59 }
60 else
61 {
62 vga_put(*format);
63 format++;
64 }
65 }
66
67 va_end(args);
68}
69
swissChili825d46b2021-02-21 10:14:16 -080070void kassert_int(bool condition, const char *message, const char *file,
71 const int line)
swissChili0b35bf22021-02-18 12:49:40 -080072{
73 if (!condition)
74 {
swissChili9bd74de2021-06-15 20:30:48 -070075 kprintf(ERROR "ASSERTION FAILED: %s:%d\n%s\n", file, line, message);
swissChili825d46b2021-02-21 10:14:16 -080076
swissChili0b35bf22021-02-18 12:49:40 -080077 while (1)
swissChili825d46b2021-02-21 10:14:16 -080078 {
79 }
swissChili0b35bf22021-02-18 12:49:40 -080080 }
81}