swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 1 | #include "log.h" |
| 2 | #include "kint.h" |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 3 | #include "stdarg.h" |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 4 | #include "vga.h" |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 5 | |
| 6 | void 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++; |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 16 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 17 | switch (*format) |
| 18 | { |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 19 | case 'd': { |
| 20 | uint x = (uint)va_arg(args, uint); |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 21 | vga_putd(x); |
| 22 | break; |
| 23 | } |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 24 | |
| 25 | case 'x': { |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 26 | // consider hex always unsigned |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 27 | uint x = (uint)va_arg(args, uint); |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 28 | vga_putx(x); |
| 29 | break; |
| 30 | } |
| 31 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 32 | case 's': { |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 33 | char *s = va_arg(args, char *); |
| 34 | vga_write(s); |
| 35 | break; |
| 36 | } |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 37 | |
| 38 | case 'c': { |
| 39 | char s = va_arg(args, int); |
| 40 | vga_put(s); |
| 41 | break; |
| 42 | } |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 43 | } |
| 44 | format++; |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | vga_put(*format); |
| 49 | format++; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | va_end(args); |
| 54 | } |
| 55 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 56 | void kassert_int(bool condition, const char *message, const char *file, |
| 57 | const int line) |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 58 | { |
| 59 | if (!condition) |
| 60 | { |
| 61 | vga_set_color(LIGHT_RED, BLACK); |
| 62 | kprintf("ASSERTION FAILED: %s:%d\n%s\n", file, line, message); |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 63 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 64 | while (1) |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 65 | { |
| 66 | } |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 67 | } |
| 68 | } |