Serial debugging code must not access BDA.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 7 Jun 2008 14:43:07 +0000 (10:43 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 7 Jun 2008 14:43:07 +0000 (10:43 -0400)
Regular serial writing code uses the system timer to timeout failed
    writes - however, serial debugging can't rely on access to the BDA
    segment or the hardware timer.
Therefore, implement a simple debug only serial writing function and
    separate it from the regular serial output code.
Also include change to dump_regs - don't call __dprintf if debugging
    not on.

src/output.c
src/post.c
src/serial.c
src/util.h

index 1c3831d9b09b9cd0b9b6057a15b5949ed238d058..054082facaddbd64b48bca4e038656ce4c602eca 100644 (file)
 #include "util.h" // printf
 #include "biosvar.h" // struct bregs
 
+#define DEBUG_PORT 0x03f8
+#define DEBUG_TIMEOUT 100000
+
+static void
+debug_serial(char c)
+{
+    int timeout = DEBUG_TIMEOUT;
+    while ((inb(DEBUG_PORT+5) & 0x60) != 0x60)
+        if (!timeout--)
+            // Ran out of time.
+            return;
+    outb(c, DEBUG_PORT);
+}
+
 static void
 screenc(u8 c)
 {
@@ -216,13 +230,13 @@ static void
 dump_regs(const char *fname, const char *type, struct bregs *regs)
 {
     if (!regs) {
-        __dprintf("%s %s: NULL\n", type, fname);
+        dprintf(1, "%s %s: NULL\n", type, fname);
         return;
     }
-    __dprintf("%s %s: a=%x b=%x c=%x d=%x si=%x di=%x\n"
+    dprintf(1, "%s %s: a=%x b=%x c=%x d=%x si=%x di=%x\n"
             , type, fname, regs->eax, regs->ebx, regs->ecx, regs->edx
             , regs->esi, regs->edi);
-    __dprintf("  ds=%x es=%x ip=%x cs=%x f=%x r=%p\n"
+    dprintf(1, "  ds=%x es=%x ip=%x cs=%x f=%x r=%p\n"
             , regs->ds, regs->es, regs->ip, regs->cs, regs->flags, regs);
 }
 
index f8b12a5cd6757ed00efd615374d65e767ae45ad4..4b56551dc89d402b4b2aef06bd0bed991b41a4e8 100644 (file)
@@ -214,9 +214,6 @@ rom_scan(u32 start, u32 end)
 static void
 post()
 {
-    if (CONFIG_DEBUG_SERIAL)
-        debug_serial_setup();
-
     dprintf(1, "Start bios\n");
 
     dprintf(3, "init bda\n");
index 026c399dc930843b7633cb2755bccb3aa35bc3a7..f9988a3e0d65f6b6b8a4e87a557692767b435ba5 100644 (file)
@@ -76,10 +76,15 @@ handle_1400(struct bregs *regs)
     set_success(regs);
 }
 
-static int
-write_serial(u16 addr, u16 timeout, char c)
+// SERIAL - WRITE CHARACTER TO PORT
+static void
+handle_1401(struct bregs *regs)
 {
+    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) {
@@ -87,24 +92,10 @@ write_serial(u16 addr, u16 timeout, char c)
             timeout--;
         }
     }
-    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);
+    if (timeout)
+        outb(regs->al, addr);
     regs->ah = inb(addr+5);
-    if (ret)
+    if (!timeout)
         regs->ah |= 0x80;
     set_success(regs);
 }
@@ -171,26 +162,6 @@ 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
  ****************************************************************/
index 11ca26972f48056c70c69a972e2d380af9c1cb57..ec6faed3c23854105c30b68e1f9d9d45d92be558 100644 (file)
@@ -149,8 +149,6 @@ void handle_15c2(struct bregs *regs);
 
 // serial.c
 void serial_setup();
-void debug_serial_setup();
-void debug_serial(char c);
 void lpt_setup();
 
 // clock.c