Add support for sending debug messages to a serial port.
authorKevin O'Connor <kevin@koconnor.net>
Thu, 8 May 2008 01:29:50 +0000 (21:29 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 8 May 2008 01:29:50 +0000 (21:29 -0400)
Enable by turning on CONFIG_DEBUG_SERIAL option.

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

index 0b3e42e22de0f84089f1d6e368c14c575c714593..88b54d8280cf2cb92156e6636283b246aab9da25 100644 (file)
@@ -13,6 +13,8 @@
 #define CONFIG_APPNAME "Bochs"
 #endif
 
+#define CONFIG_DEBUG_SERIAL 0
+
 #define CONFIG_FLOPPY_SUPPORT 1
 #define CONFIG_PS2_MOUSE 1
 #define CONFIG_ATA 1
index fc77c214899c91e7e39f0c58ab2515ceb9591a31..b2f28e9f439f91df2bdfaa4c4c9ae6a411177750 100644 (file)
@@ -24,8 +24,15 @@ screenc(u8 c)
 static void
 putc(u16 action, char c)
 {
-    outb(c, PORT_BIOS_DEBUG);
+    if (CONFIG_DEBUG_SERIAL)
+        // Send character to serial port.
+        debug_serial(c);
+    else
+        // Send character to debug port.
+        outb(c, PORT_BIOS_DEBUG);
+
     if (action) {
+        // Send character to video screen.
         if (c == '\n')
             screenc('\r');
         screenc(c);
index 64f42bb213228561ef53288395bf7112ab329712..36fc2e9d50ee8bede8fe0cb148ece5dd7b3271d0 100644 (file)
@@ -176,6 +176,9 @@ rom_scan(u32 start, u32 end)
 static void
 post()
 {
+    if (CONFIG_DEBUG_SERIAL)
+        debug_serial_setup();
+
     BX_INFO("Start bios\n");
 
     init_bda();
index 8ca7e36781e7737b238b5103029c3a78dfb74656..026c399dc930843b7633cb2755bccb3aa35bc3a7 100644 (file)
@@ -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)
 {
@@ -158,6 +171,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
  ****************************************************************/
index 10d18350e49ece9da089178512ab30b9d6b9c393..acd981aeef471ee52ad9f39dad245574dfe93c19 100644 (file)
@@ -145,6 +145,8 @@ 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