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 | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 43 | case 'b': { |
| 44 | uint v = va_arg(args, uint); |
| 45 | if (v) |
| 46 | vga_write("true"); |
| 47 | else |
| 48 | vga_write("false"); |
| 49 | } |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 50 | } |
| 51 | format++; |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | vga_put(*format); |
| 56 | format++; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | va_end(args); |
| 61 | } |
| 62 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 63 | void kassert_int(bool condition, const char *message, const char *file, |
| 64 | const int line) |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 65 | { |
| 66 | if (!condition) |
| 67 | { |
| 68 | vga_set_color(LIGHT_RED, BLACK); |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 69 | kprintf(ERROR "ASSERTION FAILED: %s:%d\n%s\n", file, line, message); |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 70 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 71 | while (1) |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 72 | { |
| 73 | } |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 74 | } |
| 75 | } |