Wed Mar 4 16:50:18 1998 Jason Molenda (crash@bugshack.cygnus.com)
[deliverable/binutils-gdb.git] / gdb / ser-go32.c
index 70887f00b5e84b4f78992e82a4ca65633d333123..4af25f14019dc9e8225ac93872c49856165911e1 100644 (file)
@@ -20,7 +20,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "gdbcmd.h"
@@ -196,6 +196,7 @@ static struct dos_ttystate
 {
   int          base;
   int          irq;
+  int          refcnt;
   struct intrupt *intrupt;
   int          fifo;
   int          baudrate;
@@ -311,7 +312,7 @@ dos_comisr (irq)
                    port->oflo++;
                }
 
-             if (dos_putc (c & 0x7f, port) < 0)
+             if (dos_putc (c, port) < 0)
                {
                  COUNT (CNT_ORUN);
                }
@@ -474,11 +475,11 @@ dos_open (scb, name)
 
   fd = name[3] - '1';
   port = &ports[fd];
-  if (port->intrupt)
+  if (port->refcnt++ > 0)
     {
-      /* already open (EBUSY not defined!) */
-      errno = EACCES;
-      return -1;
+      /* Device already opened another user.  Just point at it. */
+      scb->fd = fd;
+      return 0;
     }
 
   /* force access to ID reg */
@@ -552,9 +553,17 @@ static void
 dos_close (scb)
      serial_t scb;
 {
-    struct dos_ttystate *port = &ports[scb->fd];
+    struct dos_ttystate *port;
     struct intrupt *intrupt;
 
+    if (!scb)
+      return;
+
+    port = &ports[scb->fd];
+
+    if (port->refcnt-- > 1)
+      return;
+
     if (!(intrupt = port->intrupt))
       return;
 
@@ -710,6 +719,7 @@ dos_setbaudrate (scb, rate)
     if (port->baudrate != rate) 
       {
        int x;
+       unsigned char cfcr;
 
        x = dos_baudconv (rate);
        if (x <= 0)
@@ -720,10 +730,12 @@ dos_setbaudrate (scb, rate)
          }
 
        disable ();
+       cfcr = inb (port, com_cfcr);
+
        outb(port, com_cfcr, CFCR_DLAB);
        outb(port, com_dlbl, x & 0xff);
        outb(port, com_dlbh, x >> 8);
-       outb(port, com_cfcr, CFCR_8BITS);
+       outb(port, com_cfcr, cfcr);
        port->baudrate = rate;
        enable ();
       }
@@ -731,6 +743,34 @@ dos_setbaudrate (scb, rate)
     return 0;
 }
 
+static int
+dos_setstopbits (scb, num)
+     serial_t scb;
+     int num;
+{
+    struct dos_ttystate *port = &ports[scb->fd];
+    unsigned char cfcr;
+
+    disable ();
+    cfcr = inb (port, com_cfcr);
+
+    switch (num)
+      {
+      case SERIAL_1_STOPBITS:
+       outb (port, com_cfcr, cfcr & ~CFCR_STOPB);
+       break;
+      case SERIAL_1_AND_A_HALF_STOPBITS:
+      case SERIAL_2_STOPBITS:
+       outb (port, com_cfcr, cfcr | CFCR_STOPB);
+       break;
+      default:
+       enable ();
+       return 1;
+      }
+    enable ();
+
+    return 0;
+}
 
 static int
 dos_write (scb, str, len)
@@ -768,6 +808,28 @@ dos_write (scb, str, len)
   return 0;
 }
 
+
+static int
+dos_sendbreak (scb)
+     serial_t scb;
+{
+  volatile struct dos_ttystate *port = &ports[scb->fd];
+  unsigned char cfcr;
+  long then;
+
+  cfcr = inb(port, com_cfcr);
+  outb(port, com_cfcr, cfcr | CFCR_SBREAK);
+
+  /* 0.25 sec delay */
+  then = rawclock () + RAWHZ / 4;
+  while ((rawclock () - then) < 0)
+    continue;
+
+  outb(port, com_cfcr, cfcr);
+  return 0;
+}
+
+
 static struct serial_ops dos_ops =
 {
   "hardwire",
@@ -778,13 +840,14 @@ static struct serial_ops dos_ops =
   dos_write,
   dos_noop,                    /* flush output */
   dos_flush_input,
-  dos_noop,                    /* send break -- currently used only for nindy */
+  dos_sendbreak,
   dos_raw,
   dos_get_tty_state,
   dos_set_tty_state,
   dos_print_tty_state,
   dos_noflush_set_tty_state,
   dos_setbaudrate,
+  dos_setstopbits,
 };
 
 
@@ -800,12 +863,12 @@ dos_info (arg, from_tty)
     {
       if (port->baudrate == 0)
        continue;
-      printf_filtered ("Port:\tCOM%d (%sactive)\n", port - ports,
+      printf_filtered ("Port:\tCOM%d (%sactive)\n", port - ports + 1,
                       port->intrupt ? "" : "not ");
       printf_filtered ("Addr:\t0x%03x (irq %d)\n", port->base, port->irq);
       printf_filtered ("16550:\t%s\n", port->fifo ? "yes" : "no");
       printf_filtered ("Speed:\t%d baud\n", port->baudrate);
-      printf_filtered ("Errs:\tframing %d parity %d overflow %d\n", 
+      printf_filtered ("Errs:\tframing %d parity %d overflow %d\n\n", 
                       port->ferr, port->perr, port->oflo);
     }
 
This page took 0.039433 seconds and 4 git commands to generate.