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 | |
swissChili | 36ed5d7 | 2021-07-23 14:56:36 -0700 | [diff] [blame] | 25 | case 'p': |
| 26 | vga_put('0'); |
| 27 | vga_put('x'); |
| 28 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 29 | case 'x': { |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 30 | // consider hex always unsigned |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 31 | uint x = (uint)va_arg(args, uint); |
swissChili | 36ed5d7 | 2021-07-23 14:56:36 -0700 | [diff] [blame] | 32 | if (x) |
| 33 | vga_putx(x); |
| 34 | else |
| 35 | vga_put('0'); |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 36 | break; |
| 37 | } |
| 38 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 39 | case 's': { |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 40 | char *s = va_arg(args, char *); |
| 41 | vga_write(s); |
| 42 | break; |
| 43 | } |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 44 | |
| 45 | case 'c': { |
| 46 | char s = va_arg(args, int); |
| 47 | vga_put(s); |
| 48 | break; |
| 49 | } |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 50 | case 'b': { |
| 51 | uint v = va_arg(args, uint); |
| 52 | if (v) |
| 53 | vga_write("true"); |
| 54 | else |
| 55 | vga_write("false"); |
| 56 | } |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 57 | } |
| 58 | format++; |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | vga_put(*format); |
| 63 | format++; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | va_end(args); |
| 68 | } |
| 69 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 70 | void kassert_int(bool condition, const char *message, const char *file, |
| 71 | const int line) |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 72 | { |
| 73 | if (!condition) |
| 74 | { |
| 75 | vga_set_color(LIGHT_RED, BLACK); |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 76 | kprintf(ERROR "ASSERTION FAILED: %s:%d\n%s\n", file, line, message); |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 77 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 78 | while (1) |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 79 | { |
| 80 | } |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 81 | } |
| 82 | } |