Be sure to add "void" to all function prototypes that take no args.
[seabios.git] / src / output.c
index e860b0b2c6247d6b6ecaf54e2ca644931ac53433..3de565a18a7d7e0da87e69be3924e0fb175d2eda 100644 (file)
@@ -25,7 +25,7 @@ struct putcinfo {
 #define DEBUG_TIMEOUT 100000
 
 void
-debug_serial_setup()
+debug_serial_setup(void)
 {
     if (!CONFIG_DEBUG_SERIAL)
         return;
@@ -59,7 +59,7 @@ debug_serial(char c)
 
 // Make sure all serial port writes have been completely sent.
 static void
-debug_serial_flush()
+debug_serial_flush(void)
 {
     if (!CONFIG_DEBUG_SERIAL)
         return;
@@ -84,11 +84,13 @@ putc_debug(struct putcinfo *action, char c)
     debug_serial(c);
 }
 
-// In 16bit mode just need a dummy variable (putc_debug is always used
-// anyway), and in 32bit mode need a pointer to the 32bit instance of
-// putc_debug().
+// In segmented mode just need a dummy variable (putc_debug is always
+// used anyway), and in 32bit flat mode need a pointer to the 32bit
+// instance of putc_debug().
 #if MODE16
 static struct putcinfo debuginfo VAR16;
+#elif MODESEGMENT
+static struct putcinfo debuginfo VAR32SEG;
 #else
 static struct putcinfo debuginfo = { putc_debug };
 #endif
@@ -115,7 +117,7 @@ static void
 putc_screen(struct putcinfo *action, char c)
 {
     if (CONFIG_SCREEN_AND_DEBUG)
-        putc_debug(action, c);
+        putc_debug(&debuginfo, c);
     if (c == '\n')
         screenc('\r');
     screenc(c);
@@ -132,8 +134,8 @@ static struct putcinfo screeninfo = { putc_screen };
 static void
 putc(struct putcinfo *action, char c)
 {
-    if (MODE16) {
-        // Only debugging output supported in 16bit mode.
+    if (MODESEGMENT) {
+        // Only debugging output supported in segmented mode.
         putc_debug(action, c);
         return;
     }
@@ -325,6 +327,18 @@ panic(const char *fmt, ...)
 void
 __dprintf(const char *fmt, ...)
 {
+    if (!MODESEGMENT && CONFIG_THREADS && CONFIG_DEBUG_LEVEL >= DEBUG_thread
+        && *fmt != '\\' && *fmt != '/') {
+        struct thread_info *cur = getCurThread();
+        if (cur != &MainThread) {
+            // Show "thread id" for this debug message.
+            putc_debug(&debuginfo, '|');
+            puthex(&debuginfo, (u32)cur, 8);
+            putc_debug(&debuginfo, '|');
+            putc_debug(&debuginfo, ' ');
+        }
+    }
+
     va_list args;
     va_start(args, fmt);
     bvprintf(&debuginfo, fmt, args);
@@ -335,7 +349,7 @@ __dprintf(const char *fmt, ...)
 void
 printf(const char *fmt, ...)
 {
-    ASSERT32();
+    ASSERT32FLAT();
     va_list args;
     va_start(args, fmt);
     bvprintf(&screeninfo, fmt, args);
@@ -364,12 +378,15 @@ putc_str(struct putcinfo *info, char c)
     sinfo->str++;
 }
 
-void
+// Build a formatted string.  Note, this function returns the actual
+// number of bytes used (not including null) even in the overflow
+// case.
+int
 snprintf(char *str, size_t size, const char *fmt, ...)
 {
-    ASSERT32();
+    ASSERT32FLAT();
     if (!size)
-        return;
+        return 0;
     struct snprintfinfo sinfo = { { putc_str }, str, str + size };
     va_list args;
     va_start(args, fmt);
@@ -377,8 +394,9 @@ snprintf(char *str, size_t size, const char *fmt, ...)
     va_end(args);
     char *end = sinfo.str;
     if (end >= sinfo.end)
-        end--;
+        end = sinfo.end - 1;
     *end = '\0';
+    return end - str;
 }
 
 
@@ -447,25 +465,61 @@ __debug_stub(struct bregs *regs, int lineno, const char *fname)
     dump_regs(regs);
 }
 
-// Report on a handler returning a failure notification to the caller.
+// Report on an invalid parameter.
 void
-__set_fail(struct bregs *regs, int lineno, const char *fname)
+__warn_invalid(struct bregs *regs, int lineno, const char *fname)
 {
-    dprintf(1, "fail %s:%d:\n", fname, lineno);
-    dump_regs(regs);
-    set_fail_silent(regs);
+    if (CONFIG_DEBUG_LEVEL >= DEBUG_invalid) {
+        dprintf(1, "invalid %s:%d:\n", fname, lineno);
+        dump_regs(regs);
+    }
+}
+
+// Report on an unimplemented feature.
+void
+__warn_unimplemented(struct bregs *regs, int lineno, const char *fname)
+{
+    if (CONFIG_DEBUG_LEVEL >= DEBUG_unimplemented) {
+        dprintf(1, "unimplemented %s:%d:\n", fname, lineno);
+        dump_regs(regs);
+    }
+}
+
+// Report a handler reporting an invalid parameter to the caller.
+void
+__set_invalid(struct bregs *regs, int lineno, const char *fname)
+{
+    __warn_invalid(regs, lineno, fname);
+    set_invalid_silent(regs);
+}
+
+// Report a call of an unimplemented function.
+void
+__set_unimplemented(struct bregs *regs, int lineno, const char *fname)
+{
+    __warn_unimplemented(regs, lineno, fname);
+    set_invalid_silent(regs);
 }
 
-// Report on a handler returning a failure code to the caller.  Note,
-// the lineno and return code are encoded in the same parameter as gcc
-// does a better job of scheduling function calls when there are 3 or
-// less parameters.
+// Report a handler reporting an invalid parameter code to the
+// caller.  Note, the lineno and return code are encoded in the same
+// parameter as gcc does a better job of scheduling function calls
+// when there are 3 or less parameters.
 void
-__set_code_fail(struct bregs *regs, u32 linecode, const char *fname)
+__set_code_invalid(struct bregs *regs, u32 linecode, const char *fname)
 {
     u8 code = linecode;
     u32 lineno = linecode >> 8;
-    dprintf(1, "fail %s:%d(%x):\n", fname, lineno, code);
-    dump_regs(regs);
-    set_code_fail_silent(regs, code);
+    __warn_invalid(regs, lineno, fname);
+    set_code_invalid_silent(regs, code);
+}
+
+// Report a call of an unimplemented function.
+void
+__set_code_unimplemented(struct bregs *regs, u32 linecode, const char *fname)
+{
+    u8 code = linecode;
+    u32 lineno = linecode >> 8;
+    __warn_unimplemented(regs, lineno, fname);
+    set_code_invalid_silent(regs, code);
 }