diff options
author | Marvin Borner | 2019-12-21 22:22:03 +0100 |
---|---|---|
committer | Marvin Borner | 2019-12-21 22:22:03 +0100 |
commit | 499784a824c541001c2fd52ae95eba88dcfc952b (patch) | |
tree | c3c26d7c8a3b9291d909f4655b7d27a5ae2369bc /src/kernel/lib/stdio | |
parent | 38610cd06dc0b5a3a4ee46f5fe7c341191aa2bc1 (diff) |
Many debugging/serial improvements
Sorry for the little information, but I did many things :)
Diffstat (limited to 'src/kernel/lib/stdio')
-rw-r--r-- | src/kernel/lib/stdio/debug.c | 59 | ||||
-rw-r--r-- | src/kernel/lib/stdio/vprintf.c | 8 |
2 files changed, 63 insertions, 4 deletions
diff --git a/src/kernel/lib/stdio/debug.c b/src/kernel/lib/stdio/debug.c new file mode 100644 index 0000000..d66ee59 --- /dev/null +++ b/src/kernel/lib/stdio/debug.c @@ -0,0 +1,59 @@ +#include <stdarg.h> +#include <stdint.h> +#include <kernel/lib/string.h> +#include <kernel/lib/stdlib.h> +#include <kernel/io/io.h> + +void _write_serial(const char *data) +{ + for (size_t i = 0; i < strlen(data); i++) serial_put(data[i]); +} + +void serial_printf(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + + uint8_t readyToFormat = 0; + + char buff = 0; + + for (; *fmt; fmt++) { + if (readyToFormat) { + if (*fmt == '%') { + serial_put('%'); + readyToFormat = 0; + continue; + } + + buff = *fmt; + if (buff == 's') { + const char *str = va_arg(args, const char*); + _write_serial(str); + readyToFormat = 0; + } else if (buff == 'x') { + char *p = htoa((uint32_t) va_arg(args, int)); + _write_serial(p); + kfree(p); + readyToFormat = 0; + } else if (buff == 'd') { + char *p = itoa(va_arg(args, int)); + _write_serial(p); + kfree(p); + readyToFormat = 0; + } else if (buff == 'c') { + serial_put((char) va_arg(args, int)); + readyToFormat = 0; + } + } else { + if (*fmt == '%') + readyToFormat = 1; + else + serial_put(*fmt); + } + } + + serial_put('\n'); + + va_end(args); +}
\ No newline at end of file diff --git a/src/kernel/lib/stdio/vprintf.c b/src/kernel/lib/stdio/vprintf.c index 885f584..81b7be0 100644 --- a/src/kernel/lib/stdio/vprintf.c +++ b/src/kernel/lib/stdio/vprintf.c @@ -4,7 +4,7 @@ #include <kernel/lib/string.h> #include <kernel/lib/stdlib.h> -void __writes(const char *data) +void _writes(const char *data) { for (size_t i = 0; i < strlen(data); i++) writec(data[i]); } @@ -26,16 +26,16 @@ void vprintf(const char *fmt, va_list args) buff = *fmt; if (buff == 's') { const char *str = va_arg(args, const char*); - __writes(str); + _writes(str); readyToFormat = 0; } else if (buff == 'x') { char *p = htoa((uint32_t) va_arg(args, int)); - __writes(p); + _writes(p); kfree(p); readyToFormat = 0; } else if (buff == 'd') { char *p = itoa(va_arg(args, int)); - __writes(p); + _writes(p); kfree(p); readyToFormat = 0; } else if (buff == 'c') { |