aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-03-01 14:40:30 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-03-01 14:40:30 -0500
commit35d98182c5b86c25eb4e7fd18fc68f240683960b (patch)
treeeef74a8d1243e5d335b02dc99ae41ebc3077eae9
parentc7252588ebb95f97631e9470778c69afa00c35b5 (diff)
downloadkappa-35d98182c5b86c25eb4e7fd18fc68f240683960b.zip
kappa-35d98182c5b86c25eb4e7fd18fc68f240683960b.tar.gz
kappa-35d98182c5b86c25eb4e7fd18fc68f240683960b.tar.bz2
kappa-35d98182c5b86c25eb4e7fd18fc68f240683960b.tar.xz
vprintf and panic formatting
-rw-r--r--include/kernel/panic.h2
-rw-r--r--include/stdio.h5
-rw-r--r--kernel/panic.c7
-rw-r--r--libc/stdio.c37
4 files changed, 48 insertions, 3 deletions
diff --git a/include/kernel/panic.h b/include/kernel/panic.h
index db53e8e..7baeaa9 100644
--- a/include/kernel/panic.h
+++ b/include/kernel/panic.h
@@ -1 +1 @@
-void panic(const char*, ...);
+void panic(const char*, ...) __attribute__ ((format (printf, 1, 2)));
diff --git a/include/stdio.h b/include/stdio.h
index 49966cf..9bed898 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -1,4 +1,7 @@
-int printf(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));;
+#include <stdarg.h>
+
+int vprintf(const char* fmt, va_list);
+int printf(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
int puts(const char*);
int putchar(int);
diff --git a/kernel/panic.c b/kernel/panic.c
index 3a2ddf1..42b54d7 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -1,10 +1,15 @@
#include "panic.h"
+#include <stdarg.h>
#include <stdio.h>
__attribute__((noreturn)) void panic(const char *str, ...)
{
/* no printf formatting for now */
- printf("KERNEL PANIC: %s", str);
+ printf("KERNEL PANIC: ");
+ va_list ap;
+ va_start(ap, str);
+ vprintf(str, ap);
+ va_end(ap);
for(;;)
{
asm("cli");
diff --git a/libc/stdio.c b/libc/stdio.c
index 8219d11..6359c47 100644
--- a/libc/stdio.c
+++ b/libc/stdio.c
@@ -82,3 +82,40 @@ int printf(const char *fmt, ...)
va_end(ap);
return 0;
}
+
+int vprintf(const char *fmt, va_list ap)
+{
+ while(*fmt)
+ {
+ char ch = *fmt++;
+ switch(ch)
+ {
+ case '%':
+ {
+ switch(*fmt++)
+ {
+ case 'c':
+ putchar(va_arg(ap, int));
+ break;
+ case 's':
+ puts(va_arg(ap, const char*));
+ break;
+ case 'x':
+ print_hex(va_arg(ap, unsigned));
+ break;
+ case 'd':
+ puts(itoa(va_arg(ap, unsigned), 10));
+ break;
+ default:
+ puts("printf: unknown format\n");
+ break;
+ }
+ break;
+ }
+ default:
+ putchar(ch);
+ break;
+ }
+ }
+ return 0;
+}