Jonathan Boeing
2015-Feb-08 16:13 UTC
[syslinux] [PATCH 0/1] dprintf: add debug console support
This patch adds support for printing messages through a debug console. QEMU, for example, supports this through the debugcon facility. The benefit is that it's *much* faster than printing over a serial port. To print to I/O port 0x402 (the default used by SeaBIOS and OVMF), add "-DDEBUG_IO_PORT=0x402 -DCORE_DEBUG=1" to the build CFLAGS. To enable a debug console in QEMU that listens to I/O port 0x402 and prints to stdio, add "-debugcon stdio -global isa-debugcon.iobase=0x402" to the QEMU command line. Jonathan Boeing (1): dprintf: add debug console support com32/include/dprintf.h | 2 +- com32/lib/dprintf.c | 4 ++-- com32/lib/vdprintf.c | 21 ++++++++++++++++++++- core/lwip/src/netif/undiif.c | 2 +- mk/devel.mk | 1 + 5 files changed, 25 insertions(+), 5 deletions(-) -- 2.3.0
Jonathan Boeing
2015-Feb-08 16:13 UTC
[syslinux] [PATCH 1/1] dprintf: add debug console support
Add a vdprintf implementation that prints to a QEMU/Bochs style debug console. A debug console is an I/O port; writes to it are trapped by the host and printed to a target. Signed-off-by: Jonathan Boeing <jonathan.n.boeing at gmail.com> --- com32/include/dprintf.h | 2 +- com32/lib/dprintf.c | 4 ++-- com32/lib/vdprintf.c | 21 ++++++++++++++++++++- core/lwip/src/netif/undiif.c | 2 +- mk/devel.mk | 1 + 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/com32/include/dprintf.h b/com32/include/dprintf.h index b3f1b46..24cab7b 100644 --- a/com32/include/dprintf.h +++ b/com32/include/dprintf.h @@ -7,7 +7,7 @@ #include <syslinux/debug.h> -#if !defined(DEBUG_PORT) && !defined(DEBUG_STDIO) +#if !defined(DEBUG_PORT) && !defined(DEBUG_STDIO) && !defined(DEBUG_IO_PORT) # undef CORE_DEBUG #endif diff --git a/com32/lib/dprintf.c b/com32/lib/dprintf.c index dea77b3..e9dacb3 100644 --- a/com32/lib/dprintf.c +++ b/com32/lib/dprintf.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdarg.h> -#ifdef DEBUG_PORT +#if defined(DEBUG_PORT) || defined(DEBUG_IO_PORT) void vdprintf(const char *, va_list); @@ -18,4 +18,4 @@ void dprintf(const char *format, ...) va_end(ap); } -#endif /* DEBUG_PORT */ +#endif /* DEBUG_PORT || DEBUG_IO_PORT */ diff --git a/com32/lib/vdprintf.c b/com32/lib/vdprintf.c index bcf55bb..95c10e9 100644 --- a/com32/lib/vdprintf.c +++ b/com32/lib/vdprintf.c @@ -10,7 +10,26 @@ #include <sys/io.h> #include <sys/cpu.h> -#ifdef DEBUG_PORT +#ifdef DEBUG_IO_PORT + +#define BUFFER_SIZE 0x100 + +void vdprintf(const char *format, va_list ap) +{ + int rv; + char buffer[BUFFER_SIZE]; + char *p; + + rv = vsnprintf(buffer, BUFFER_SIZE, format, ap); + if (rv < 0) + return; + + p = buffer; + while(*p) + outb(*p++, DEBUG_IO_PORT); +} + +#elif defined DEBUG_PORT #define BUFFER_SIZE 4096 diff --git a/core/lwip/src/netif/undiif.c b/core/lwip/src/netif/undiif.c index e62a984..05606e6 100644 --- a/core/lwip/src/netif/undiif.c +++ b/core/lwip/src/netif/undiif.c @@ -52,7 +52,7 @@ # ifndef DEBUG # define DEBUG 1 # endif -# ifndef DEBUG_PORT +# if !defined(DEBUG_PORT) && !defined(DEBUG_IO_PORT) # define DEBUG_PORT 0x3f8 # endif #endif /* UNDIIF_ID_FULL_DEBUG */ diff --git a/mk/devel.mk b/mk/devel.mk index b1fca87..1e57dcf 100644 --- a/mk/devel.mk +++ b/mk/devel.mk @@ -2,6 +2,7 @@ GCCWARN += -Wno-clobbered #GCCWARN += -DDEBUG_MALLOC # GCCWARN += -DDEBUG_PORT=0x3f8 -DCORE_DEBUG=1 +# GCCWARN += -DDEBUG_IO_PORT=0x402 -DCORE_DEBUG=1 GCCWARN += -DDYNAMIC_DEBUG ## The following will enable printing ethernet/arp/ip/icmp/tcp/udp headers -- 2.3.0
Geert Stappers
2015-Feb-08 16:41 UTC
[syslinux] [PATCH 0/1] dprintf: add debug console support
On Sun, Feb 08, 2015 at 09:13:02AM -0700, Jonathan Boeing via Syslinux wrote:> This patch adds support for printing messages through a debug console. QEMU, > for example, supports this through the debugcon facility. The benefit is that > it's *much* faster than printing over a serial port. > > To print to I/O port 0x402 (the default used by SeaBIOS and OVMF), > add "-DDEBUG_IO_PORT=0x402 -DCORE_DEBUG=1" to the build CFLAGS. > > To enable a debug console in QEMU that listens to I/O port 0x402 and prints to > stdio, add "-debugcon stdio -global isa-debugcon.iobase=0x402" to the QEMU > command line.When enabled, what will the effect on real hardware without the diagnostic hardware ? When enabled, what will the effect on real hardware ? What (real) diagnostic hardware is adviced? Oops, I should have start with: Thank you for providing these development tools. Cheers Geert Stappers
Jonathan Boeing
2015-Feb-08 17:39 UTC
[syslinux] [PATCH 0/1] dprintf: add debug console support
On Sun, 8 Feb 2015 17:41:58 +0100 Geert Stappers via Syslinux <syslinux at zytor.com> wrote:> On Sun, Feb 08, 2015 at 09:13:02AM -0700, Jonathan Boeing via > Syslinux wrote: > > This patch adds support for printing messages through a debug > > console. QEMU, for example, supports this through the debugcon > > facility. The benefit is that it's *much* faster than printing > > over a serial port. > > > > To print to I/O port 0x402 (the default used by SeaBIOS and OVMF), > > add "-DDEBUG_IO_PORT=0x402 -DCORE_DEBUG=1" to the build CFLAGS. > > > > To enable a debug console in QEMU that listens to I/O port 0x402 > > and prints to stdio, add "-debugcon stdio -global > > isa-debugcon.iobase=0x402" to the QEMU command line. > > > When enabled, what will the effect on real hardware without the > diagnostic hardware ? > > When enabled, what will the effect on real hardware ? > > What (real) diagnostic hardware is adviced? >This doesn't support real hardware[1]; it's a VM-only thing. If run on real hardware, it shouldn't have any effect[2] as long as it's writing to an unused I/O port. Port 0x402 seems to be unused (based on some google searching) outside of debug consoles. Bochs has a list at http://bochs.sourceforge.net/techspec/PORTS.LST that shows it's in the EISA range, but not specifically used. So, it should be safe on real hardware, but I'd recommend it only for testing and development on a VM. Also, syslinux works correctly if it's enabled and run on a VM without a debug console. The writes are just silently discarded. [1] Specialized (read expensive) CPU debugging hardware could capture these writes. I'm not sure if Intel System Studio can capture them, but it's still $2399 for the JTAG-equipped version. [2] It's CPU implementation specific, but it shouldn't have any visible effect. Regards, Jonathan Boeing