aboutsummaryrefslogtreecommitdiff
path: root/src/serial.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2008-05-07 21:29:50 -0400
committerKevin O'Connor <kevin@koconnor.net>2008-05-07 21:29:50 -0400
commit1812e20b4b4edd574e21637c6e57ca17797f155c (patch)
tree4f5844905a1a53365d493a436b4d3ac135e4e34d /src/serial.c
parentd9b0659a82cf4c34f2eaf19dbf8dad99d110d281 (diff)
downloadseabios-hppa-1812e20b4b4edd574e21637c6e57ca17797f155c.zip
seabios-hppa-1812e20b4b4edd574e21637c6e57ca17797f155c.tar.gz
seabios-hppa-1812e20b4b4edd574e21637c6e57ca17797f155c.tar.bz2
Add support for sending debug messages to a serial port.
Enable by turning on CONFIG_DEBUG_SERIAL option.
Diffstat (limited to 'src/serial.c')
-rw-r--r--src/serial.c51
1 files changed, 42 insertions, 9 deletions
diff --git a/src/serial.c b/src/serial.c
index 8ca7e36..026c399 100644
--- a/src/serial.c
+++ b/src/serial.c
@@ -54,6 +54,7 @@ getComAddr(struct bregs *regs)
return addr;
}
+// SERIAL - INITIALIZE PORT
static void
handle_1400(struct bregs *regs)
{
@@ -75,14 +76,10 @@ handle_1400(struct bregs *regs)
set_success(regs);
}
-static void
-handle_1401(struct bregs *regs)
+static int
+write_serial(u16 addr, u16 timeout, char c)
{
- u16 addr = getComAddr(regs);
- if (!addr)
- return;
u16 timer = GET_BDA(timer_counter);
- u16 timeout = GET_BDA(com_timeout[regs->dx]);
while (((inb(addr+5) & 0x60) != 0x60) && (timeout)) {
u16 val16 = GET_BDA(timer_counter);
if (val16 != timer) {
@@ -90,14 +87,29 @@ handle_1401(struct bregs *regs)
timeout--;
}
}
- if (timeout)
- outb(regs->al, addr);
- regs->ah = inb(addr+5);
if (!timeout)
+ // Ran out of time.
+ return -1;
+ outb(c, addr);
+ return 0;
+}
+
+// SERIAL - WRITE CHARACTER TO PORT
+static void
+handle_1401(struct bregs *regs)
+{
+ u16 addr = getComAddr(regs);
+ if (!addr)
+ return;
+ u16 timeout = GET_BDA(com_timeout[regs->dx]);
+ int ret = write_serial(addr, timeout, regs->al);
+ regs->ah = inb(addr+5);
+ if (ret)
regs->ah |= 0x80;
set_success(regs);
}
+// SERIAL - READ CHARACTER FROM PORT
static void
handle_1402(struct bregs *regs)
{
@@ -122,6 +134,7 @@ handle_1402(struct bregs *regs)
set_success(regs);
}
+// SERIAL - GET PORT STATUS
static void
handle_1403(struct bregs *regs)
{
@@ -159,6 +172,26 @@ handle_14(struct bregs *regs)
/****************************************************************
+ * Serial debugging
+ ****************************************************************/
+
+#define BX_DEBUG_PORT 0x03f8
+
+void
+debug_serial_setup()
+{
+ /* setup for serial logging: 8N1 */
+ outb(0x03, BX_DEBUG_PORT+3);
+}
+
+void
+debug_serial(char c)
+{
+ write_serial(BX_DEBUG_PORT, 0x0a, c);
+}
+
+
+/****************************************************************
* LPT ports
****************************************************************/