[IO] rework dprintf to take a debug level, defined in DEBUGLEVEL

printf at the moment just calls dprintf, but soon will become
a seperate I/O queue.
diff --git a/include/assert.h b/include/assert.h
index db58611..332dfdb 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -24,14 +24,14 @@
 #define __ASSERT_H
 
 #include <compiler.h>
-#include <platform/debug.h>
+#include <debug.h>
 
 #define ASSERT(x) \
-	do { if (unlikely(!(x))) { dprintf("ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); debug_halt(); } } while (0)
+	do { if (unlikely(!(x))) { panic("ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
 
-#if DEBUG
+#if DEBUGLEVEL > 1
 #define DEBUG_ASSERT(x) \
-	do { if (unlikely(!(x))) { dprintf("DEBUG ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); debug_halt(); } } while (0)
+	do { if (unlikely(!(x))) { panic("DEBUG ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
 #else
 #define DEBUG_ASSERT(x) \
 	do { } while(0)
diff --git a/include/debug.h b/include/debug.h
index 1013e87..e5ebc19 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -24,6 +24,8 @@
 #define __DEBUG_H
 
 #include <assert.h>
+#include <stdarg.h>
+#include <compiler.h>
 #include <platform/debug.h>
 #include <printf.h>
 
@@ -37,6 +39,26 @@
 #define DEBUGLEVEL 2
 #endif
 
+/* debug levels */
+#define CRITICAL 0
+#define ALWAYS 0
+#define INFO 1
+#define SPEW 2
+
+/* output */
+void _dputc(char c); // XXX for now, platform implements
+int _dputs(const char *str);
+int _dprintf(const char *fmt, ...) __PRINTFLIKE(1, 2);
+int _dvprintf(const char *fmt, va_list ap);
+
+#define dputc(level, str) do { if ((level) <= DEBUGLEVEL) { _dputc(str); } } while (0)
+#define dputs(level, str) do { if ((level) <= DEBUGLEVEL) { _dputs(str); } } while (0)
+#define dprintf(level, x...) do { if ((level) <= DEBUGLEVEL) { _dprintf(x); } } while (0)
+#define dvprintf(level, x...) do { if ((level) <= DEBUGLEVEL) { _dvprintf(x); } } while (0)
+
+/* input */
+int dgetc(char *c);
+
 /* systemwide halts */
 void halt(void) __NO_RETURN;
 
diff --git a/include/platform/debug.h b/include/platform/debug.h
index 2a48006..4ab460a 100644
--- a/include/platform/debug.h
+++ b/include/platform/debug.h
@@ -31,11 +31,6 @@
 extern "C" {
 #endif
 
-void dputc(char c);
-int dgetc(char *c);
-int dputs(const char *str);
-int dprintf(const char *fmt, ...) __PRINTFLIKE(1, 2);
-int dvprintf(const char *fmt, va_list ap);
 void debug_dump_regs(void);
 uint32_t debug_cycle_count(void);
 
@@ -45,7 +40,7 @@
 
 void debug_set_trace_level(int trace_type, int level);
 
-void debug_halt(void) __NO_RETURN;
+void platform_halt(void) __NO_RETURN;
 
 #if defined(__cplusplus)
 }
diff --git a/include/stdio.h b/include/stdio.h
new file mode 100644
index 0000000..ebabfca
--- /dev/null
+++ b/include/stdio.h
@@ -0,0 +1,12 @@
+#ifndef __STDIO_H
+#define __STDIO_H
+
+#include <debug.h>
+#include <printf.h>
+
+void putc(char c);
+int puts(const char *str);
+int getc(char *c); // XXX not really getc
+
+#endif
+