blob: ac49971d09ce1fde55dd2c6da42830501b6ee962 [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 }
swissChili0b35bf22021-02-18 12:49:40 -080043 }
44 format++;
45 }
46 else
47 {
48 vga_put(*format);
49 format++;
50 }
51 }
52
53 va_end(args);
54}
55
swissChili825d46b2021-02-21 10:14:16 -080056void kassert_int(bool condition, const char *message, const char *file,
57 const int line)
swissChili0b35bf22021-02-18 12:49:40 -080058{
59 if (!condition)
60 {
61 vga_set_color(LIGHT_RED, BLACK);
62 kprintf("ASSERTION FAILED: %s:%d\n%s\n", file, line, message);
swissChili825d46b2021-02-21 10:14:16 -080063
swissChili0b35bf22021-02-18 12:49:40 -080064 while (1)
swissChili825d46b2021-02-21 10:14:16 -080065 {
66 }
swissChili0b35bf22021-02-18 12:49:40 -080067 }
68}