So, today I've been messing around with remote debugging with gdb, and I've made
a patch to the serial driver that will let you remotly debug your OS with gdb
(when you've got the stubs working). To do this, you need to read the comment in
the perl file which does the interfacing between the tcp and 'serial ports' of
plex. This is provided as-is etc, as in, it works for me, not I just gotta fix
the zealos stubs.. :-)

-- 

Mark Zealey (aka JALH on irc.openprojects.net: #zealos and many more)
[EMAIL PROTECTED]

UL++++>$ G!>(GCM/GCS/GS/GM) dpu? s:-@ a16! C++++>$ P++++>+++++$ L+++>+++++$
!E---? W+++>$ N- !o? !w--- O? !M? !V? !PS !PE--@ PGP+? r++ !t---?@ !X---?
!R- b+ !tv b+ DI+ D+? G+++ e>+++++ !h++* r!-- y--

(www.geekcode.com)
--- user/plugins/bochs/iodev/serial.cc  Fri Jul 13 18:29:49 2001
+++ user/plugins/bochs/iodev/serial.cc.new      Fri Jul 13 18:05:49 2001
@@ -32,6 +32,13 @@
 // define USE_TTY_HACK to connect an xterm or similar (depends on tty.c)
 // to the serial port /AM
 
+// Define these if you want to do writing/reading via 2 fifo's. I used this to
+// debug zealos via remote gdb. This had to be done via a quick perl hack which
+// intercepted tcp and turned it into read/write for these pipes. - Mark
+#define USE_FIFO_HACK
+#define FIFO_IN "serial.in"
+#define FIFO_OUT "serial.out"
+
 #include "bochs.h"
 
 #if USE_RAW_SERIAL
@@ -62,7 +69,13 @@
 static struct termios term_orig, term_new;
 #endif
 
+#ifdef USE_FIFO_HACK
+static FILE *fifoin, *fifout;
+#endif
+
+#ifdef USE_TTY_HACK
 static int tty_id;
+#endif
 
 bx_serial_c::bx_serial_c(void)
 {
@@ -109,7 +122,21 @@
 
   BX_SER_THIS devices->register_irq(4, "Serial Port 1");
 
-#if defined (USE_TTY_HACK)
+#ifdef USE_FIFO_HACK
+  // Does anyone know why I have to use "r+" here rather than "r" and "w"? If I
+  // use "r" or "w", it causes plex to hang because it blocks, or so it seems...
+  // wierd - Mark
+  if(!(fifoin = fopen(FIFO_IN, "r+")))
+    bx_printf("Opening the fifo for reading failed\n");
+  else
+    setvbuf(fifoin, NULL, _IONBF, 0);
+
+  if(!(fifout = fopen(FIFO_OUT, "r+")))
+    bx_printf("Opening the fifo for writing failed\n");
+  else
+    setvbuf(fifout, NULL, _IONBF, 0);
+
+#elif defined (USE_TTY_HACK)
   tty_id = tty_alloc("Bx Serial Console, Your Window to the 8250");
   if (tty_id > 0)
     bx_printf("TTY Allocated fd = %d\n", tty_get_fd(tty_id));
@@ -580,7 +607,9 @@
       BX_SER_THIS s[0].rx_interrupt = 1;
     }
   } else {
-#if defined (USE_TTY_HACK)
+#ifdef USE_FIFO_HACK
+    fputc(BX_SER_THIS s[0].txbuffer, fifout);
+#elif defined (USE_TTY_HACK)
     tty(tty_id, 0, & BX_SER_THIS s[0].txbuffer);
 #elif USE_RAW_SERIAL
     if (!BX_SER_THIS raw->ready_transmit())
@@ -609,29 +638,41 @@
 void
 bx_serial_c::rx_timer(void)
 {
-  struct timeval tval;
-#if BX_HAVE_SELECT
+  int bdrate = BX_SER_THIS s[0].baudrate / 8;
+//#if BX_HAVE_SELECT
 #if BX_WITH_BEOS == 0
+  struct timeval tval;
   fd_set fds;
-#endif
-#endif
-  int bdrate = BX_SER_THIS s[0].baudrate / 8;
   unsigned char chbuf;
 
   tval.tv_sec  = 0;
   tval.tv_usec = 0;
 
-#if BX_HAVE_SELECT
-#if BX_WITH_BEOS == 0
 // MacOS: I'm not sure what to do with this, since I don't know
 // what an fd_set is or what FD_SET() or select() do. They aren't
 // declared in the CodeWarrior standard library headers. I'm just
 // leaving it commented out for the moment.
 
+  FD_ZERO(&fds);
   FD_SET(0, &fds);
 
   if (BX_SER_THIS s[0].line_status.rxdata_ready == 0) {
-#if defined (USE_TTY_HACK)
+#ifdef USE_FIFO_HACK
+    bool t = false;
+    if(fifoin) {
+      fd_set read;
+      struct timeval tv;
+      tv.tv_sec = 0;           // We don't use tval because that might change
+      tv.tv_usec = 0;          // it for later...
+      FD_ZERO(&read);
+      FD_SET(fileno(fifoin), &read);
+      if(select(fileno(fifoin) + 1, &read, NULL, NULL, &tv) == 1) {
+        chbuf = fgetc(fifoin);
+        t = true;
+      }
+    }
+    if(t) {
+#elif defined (USE_TTY_HACK)
     if (tty_prefetch_char(tty_id)) {
       tty(tty_id, 1, &chbuf);
 #elif USE_RAW_SERIAL
@@ -672,7 +713,7 @@
     bdrate *= 4; 
   }
 #endif
-#endif
+//#endif
 
   bx_pc_system.activate_timer(BX_SER_THIS s[0].rx_timer_index,
                              (int) (1000000.0 / bdrate),

plex_to_gdb_server.pl

Reply via email to