aboutsummaryrefslogtreecommitdiffstats
path: root/com32
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-11-19 11:10:00 -0800
committerH. Peter Anvin <hpa@zytor.com>2009-11-19 11:10:00 -0800
commit709cdd1bfa7aace9c76016a15f55b3005b843cc8 (patch)
tree831bf12d78da1570976f8a01c6dc105fac1515b0 /com32
parenteea0f4d527b1a66fc78b0310a4dbb54ea08a4e96 (diff)
downloadsyslinux-709cdd1bfa7aace9c76016a15f55b3005b843cc8.tar.gz
syslinux-709cdd1bfa7aace9c76016a15f55b3005b843cc8.tar.xz
syslinux-709cdd1bfa7aace9c76016a15f55b3005b843cc8.zip
dprintf: a generic debug-to-serial infrastructure
Actually provide real infrastructure for debug-to-serial. Very useful when debugging fullscreen applications, especially under an emulator like Qemu. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32')
-rw-r--r--com32/include/dprintf.h22
-rw-r--r--com32/lib/Makefile2
-rw-r--r--com32/lib/dprintf.c17
-rw-r--r--com32/lib/vdprintf.c43
4 files changed, 84 insertions, 0 deletions
diff --git a/com32/include/dprintf.h b/com32/include/dprintf.h
new file mode 100644
index 00000000..4c9682c0
--- /dev/null
+++ b/com32/include/dprintf.h
@@ -0,0 +1,22 @@
+/*
+ * dprintf.h
+ */
+
+#ifndef _DPRINTF_H
+#define _DPRINTF_H
+
+#ifdef DEBUG
+
+#include <stdio.h>
+
+int dprintf(const char *, ...);
+int vdprintf(const char *, va_list);
+
+#else
+
+#define dprintf(fmt, ...) ((void)(0))
+#define vdprintf(fmt, ap) ((void)(0))
+
+#endif /* DEBUG */
+
+#endif /* _DPRINTF_H */
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 3a9eafd6..f1e2680f 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -27,6 +27,8 @@ LIBOBJS = \
asprintf.o vasprintf.o strlcpy.o strlcat.o \
vsscanf.o zalloc.o \
\
+ dprintf.o vdprintf.o \
+ \
opendir.o readdir.o closedir.o getcwd.o chdir.o fdopendir.o \
\
libgcc/__ashldi3.o libgcc/__udivdi3.o \
diff --git a/com32/lib/dprintf.c b/com32/lib/dprintf.c
new file mode 100644
index 00000000..96170237
--- /dev/null
+++ b/com32/lib/dprintf.c
@@ -0,0 +1,17 @@
+/*
+ * dprintf.c
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int dprintf(const char *format, ...)
+{
+ va_list ap;
+ int rv;
+
+ va_start(ap, format);
+ rv = vdprintf(stdout, format, ap);
+ va_end(ap);
+ return rv;
+}
diff --git a/com32/lib/vdprintf.c b/com32/lib/vdprintf.c
new file mode 100644
index 00000000..46a4b00d
--- /dev/null
+++ b/com32/lib/vdprintf.c
@@ -0,0 +1,43 @@
+/*
+ * vdprintf.c
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <sys/io.h>
+
+#define BUFFER_SIZE 32768
+
+struct file_info;
+extern ssize_t __serial_write(struct file_info *, const void *, size_t);
+
+static const uint16_t debug_base = 0x03f8; /* I/O base address */
+
+int 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 rv;
+
+ if (rv > BUFFER_SIZE - 1)
+ rv = BUFFER_SIZE - 1;
+
+ /*
+ * This unconditionally outputs to a serial port at 0x3f8 regardless of
+ * if one is enabled or not (this means we don't have to enable the real
+ * serial console and therefore get conflicting output.)
+ */
+ while (rv--) {
+ while ((inb(debug_base+5) & 0x20) == 0)
+ ;
+ outb(*p++, debug_base);
+ }
+}