[SeaBIOS] [PATCH v2] Add an option for debug output on the vga console

Karl Semich posted 1 patch 2 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/seabios tags/patchew/20220312122333.33147-1-0xloem@gmail.com
src/Kconfig      |  9 +++++++++
src/bootsplash.c |  9 +++++++++
src/output.c     | 33 ++++++++++++++++++++++++++-------
src/util.h       |  1 +
4 files changed, 45 insertions(+), 7 deletions(-)
[SeaBIOS] [PATCH v2] Add an option for debug output on the vga console
Posted by Karl Semich 2 years ago
Only available if threads are disabled, to prevent an undiagnosed call16 panic.

A new vga_console_active() utility function is added, and debugging output is
only forwarded to the vga console if the vga console has been enabled.

Only debugging output from 32bit flat regions is emitted, as vga console output
is only supported from within such code. This is detected with a !MODESEGMENT
check inside the debugging output code, and a new ASSERT32FLAT() check within the
vga output code.

This change has been briefly tested on a kfsn4-dre and in qemu, using serial
debugging in the latter to verify that 16bit output appears over serial that
does not appear on the vga console.

Signed-off-by: Karl Semich <0xloem@gmail.com>
---
 src/Kconfig      |  9 +++++++++
 src/bootsplash.c |  9 +++++++++
 src/output.c     | 33 ++++++++++++++++++++++++++-------
 src/util.h       |  1 +
 4 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/src/Kconfig b/src/Kconfig
index 3a8ffa1..5d2c7ab 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -571,6 +571,15 @@ menu "Debugging"
             provide the 32 bit address. E.g. 0xFEDC6000 for the AMD Kern
             (a.k.a Hudson UART).
 
+    config DEBUG_VGA_CONSOLE
+        depends on DEBUG_LEVEL != 0 && !THREADS
+        bool "VGA console debugging"
+        default y
+        help
+            Send debugging information to vga console. This is only displayed
+            after the VGA console has loaded, and only in 32 bit flat regions
+            of code. Requires that threads are disabled.
+
     config DEBUG_IO
         depends on QEMU_HARDWARE && DEBUG_LEVEL != 0
         bool "Special IO port debugging"
diff --git a/src/bootsplash.c b/src/bootsplash.c
index 538b316..2a93c8a 100644
--- a/src/bootsplash.c
+++ b/src/bootsplash.c
@@ -36,6 +36,8 @@ call16_int10(struct bregs *br)
  * VGA text / graphics console
  ****************************************************************/
 
+static int VgaConsoleActive = 0;
+
 void
 enable_vga_console(void)
 {
@@ -47,11 +49,18 @@ enable_vga_console(void)
     br.ax = 0x0003;
     call16_int10(&br);
 
+    VgaConsoleActive = 1;
+
     // Write to screen.
     printf("SeaBIOS (version %s)\n", VERSION);
     display_uuid();
 }
 
+int vga_console_active(void)
+{
+    return VgaConsoleActive;
+}
+
 static int
 find_videomode(struct vbe_info *vesa_info, struct vbe_mode_info *mode_info
                , int width, int height, int bpp_req)
diff --git a/src/output.c b/src/output.c
index 0184444..6fbf4f5 100644
--- a/src/output.c
+++ b/src/output.c
@@ -17,12 +17,15 @@
 #include "output.h" // dprintf
 #include "stacks.h" // call16_int
 #include "string.h" // memset
-#include "util.h" // ScreenAndDebug
+#include "util.h" // ScreenAndDebug vga_console_active
 
 struct putcinfo {
     void (*func)(struct putcinfo *info, char c);
 };
 
+static void __debug_putc(char c);
+static void __screen_putc(char c);
+
 
 /****************************************************************
  * Debug output
@@ -35,9 +38,8 @@ debug_banner(void)
     dprintf(1, "BUILD: %s\n", BUILDINFO);
 }
 
-// Write a character to debug port(s).
 static void
-debug_putc(struct putcinfo *action, char c)
+__debug_putc(char c)
 {
     if (! CONFIG_DEBUG_LEVEL)
         return;
@@ -47,6 +49,16 @@ debug_putc(struct putcinfo *action, char c)
     serial_debug_putc(c);
 }
 
+// Write a character to debug port(s).
+static void
+debug_putc(struct putcinfo *action, char c)
+{
+    __debug_putc(c);
+    if (CONFIG_DEBUG_LEVEL && CONFIG_DEBUG_VGA_CONSOLE && !MODESEGMENT
+        && vga_console_active())
+        __screen_putc(c);
+}
+
 // Flush any pending output to debug port(s).
 static void
 debug_flush(void)
@@ -86,17 +98,24 @@ screenc(char c)
     call16_int(0x10, &br);
 }
 
-// Handle a character from a printf request.
 static void
-screen_putc(struct putcinfo *action, char c)
+__screen_putc(char c)
 {
-    if (ScreenAndDebug)
-        debug_putc(&debuginfo, c);
+    ASSERT32FLAT();
     if (c == '\n')
         screenc('\r');
     screenc(c);
 }
 
+// Handle a character from a printf request.
+static void
+screen_putc(struct putcinfo *action, char c)
+{
+    if (ScreenAndDebug)
+        __debug_putc(c);
+    __screen_putc(c);
+}
+
 static struct putcinfo screeninfo = { screen_putc };
 
 
diff --git a/src/util.h b/src/util.h
index aff8e88..8219e0c 100644
--- a/src/util.h
+++ b/src/util.h
@@ -50,6 +50,7 @@ int boot_lchs_find_ata_device(struct pci_device *pci, int chanid, int slave,
 
 // bootsplash.c
 void enable_vga_console(void);
+int vga_console_active(void);
 void enable_bootsplash(void);
 void disable_bootsplash(void);
 
-- 
2.32.0

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org