2001-10-04 Frank Ch. Eigler <fche@redhat.com>
[binutils-gdb.git] / gdb / ser-go32.c
index 93e43ca422ed526f46515a1e8c35f1c93fdfd926..0642b5aa4bdaef2d3bf54c5b65996ab585e34e1a 100644 (file)
@@ -1,12 +1,12 @@
 /* Remote serial interface for local (hardwired) serial ports for GO32.
 /* Remote serial interface for local (hardwired) serial ports for GO32.
-   Copyright 1992, 1993, 2000 Free Software Foundation, Inc.
+   Copyright 1992, 1993, 2000, 2001 Free Software Foundation, Inc.
 
    Contributed by Nigel Stephens, Algorithmics Ltd. (nigel@algor.co.uk).
 
 
    Contributed by Nigel Stephens, Algorithmics Ltd. (nigel@algor.co.uk).
 
-   This version uses DPMI interrupts to handle buffered i/o 
+   This version uses DPMI interrupts to handle buffered i/o
    without the separate "asynctsr" program.
 
    without the separate "asynctsr" program.
 
-   This file is part of GDB.  
+   This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 #include "defs.h"
 #include "gdbcmd.h"
 #include "serial.h"
 #include "defs.h"
 #include "gdbcmd.h"
 #include "serial.h"
+#include "gdb_string.h"
 
 
 /*
 
 
 /*
 #define        MSR_DDSR        0x02
 #define        MSR_DCTS        0x01
 
 #define        MSR_DDSR        0x02
 #define        MSR_DCTS        0x01
 
-#include <string.h>
+#include <time.h>
 #include <dos.h>
 #include <go32.h>
 #include <dpmi.h>
 #include <dos.h>
 #include <go32.h>
 #include <dpmi.h>
@@ -139,9 +140,6 @@ typedef unsigned long u_long;
 /* input buffer size */
 #define CBSIZE 4096
 
 /* input buffer size */
 #define CBSIZE 4096
 
-/* return raw 18Hz clock count */
-extern long rawclock (void);
-
 #define RAWHZ  18
 
 #ifdef DOS_STATS
 #define RAWHZ  18
 
 #ifdef DOS_STATS
@@ -230,15 +228,15 @@ ports[4] =
   }
 };
 
   }
 };
 
-static int dos_open PARAMS ((serial_t scb, const char *name));
-static void dos_raw PARAMS ((serial_t scb));
-static int dos_readchar PARAMS ((serial_t scb, int timeout));
-static int dos_setbaudrate PARAMS ((serial_t scb, int rate));
-static int dos_write PARAMS ((serial_t scb, const char *str, int len));
-static void dos_close PARAMS ((serial_t scb));
-static serial_ttystate dos_get_tty_state PARAMS ((serial_t scb));
-static int dos_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
-static int dos_baudconv PARAMS ((int rate));
+static int dos_open (struct serial *scb, const char *name);
+static void dos_raw (struct serial *scb);
+static int dos_readchar (struct serial *scb, int timeout);
+static int dos_setbaudrate (struct serial *scb, int rate);
+static int dos_write (struct serial *scb, const char *str, int len);
+static void dos_close (struct serial *scb);
+static serial_ttystate dos_get_tty_state (struct serial *scb);
+static int dos_set_tty_state (struct serial *scb, serial_ttystate state);
+static int dos_baudconv (int rate);
 
 #define inb(p,a)       inportb((p)->base + (a))
 #define outb(p,a,v)    outportb((p)->base + (a), (v))
 
 #define inb(p,a)       inportb((p)->base + (a))
 #define outb(p,a,v)    outportb((p)->base + (a), (v))
@@ -247,8 +245,7 @@ static int dos_baudconv PARAMS ((int rate));
 
 
 static int
 
 
 static int
-dos_getc (port)
-     volatile struct dos_ttystate *port;
+dos_getc (volatile struct dos_ttystate *port)
 {
   int c;
 
 {
   int c;
 
@@ -265,9 +262,7 @@ dos_getc (port)
 
 
 static int
 
 
 static int
-dos_putc (c, port)
-     int c;
-     struct dos_ttystate *port;
+dos_putc (int c, struct dos_ttystate *port)
 {
   if (port->count >= CBSIZE - 1)
     return -1;
 {
   if (port->count >= CBSIZE - 1)
     return -1;
@@ -279,8 +274,7 @@ dos_putc (c, port)
 
 
 static void
 
 
 static void
-dos_comisr (irq)
-     int irq;
+dos_comisr (int irq)
 {
   struct dos_ttystate *port;
   unsigned char iir, lsr, c;
 {
   struct dos_ttystate *port;
   unsigned char iir, lsr, c;
@@ -359,29 +353,24 @@ dos_comisr (irq)
     }
 }
 
     }
 }
 
-#ifdef __STDC__
 #define ISRNAME(x) dos_comisr##x
 #define ISRNAME(x) dos_comisr##x
-#else
-#define ISRNAME(x) dos_comisr/**/x
-#endif
-#define ISR(x) static void ISRNAME(x)() {dos_comisr(x);}
+#define ISR(x) static void ISRNAME(x)(void) {dos_comisr(x);}
 
 ISR (0) ISR (1) ISR (2) ISR (3)
 ISR (4) ISR (5) ISR (6) ISR (7)
 
 
 ISR (0) ISR (1) ISR (2) ISR (3)
 ISR (4) ISR (5) ISR (6) ISR (7)
 
-     typedef void (*isr_t) ();
+typedef void (*isr_t) (void);
 
 
-     static isr_t isrs[NINTR] =
-     {
+static isr_t isrs[NINTR] =
+  {
        ISRNAME (0), ISRNAME (1), ISRNAME (2), ISRNAME (3),
        ISRNAME (4), ISRNAME (5), ISRNAME (6), ISRNAME (7)
        ISRNAME (0), ISRNAME (1), ISRNAME (2), ISRNAME (3),
        ISRNAME (4), ISRNAME (5), ISRNAME (6), ISRNAME (7)
-};
+  };
 \f
 
 
 \f
 
 
-     static struct intrupt *
-       dos_hookirq (irq)
-     unsigned int irq;
+static struct intrupt *
+dos_hookirq (unsigned int irq)
 {
   struct intrupt *intr;
   unsigned int vec;
 {
   struct intrupt *intr;
   unsigned int vec;
@@ -420,7 +409,8 @@ ISR (4) ISR (5) ISR (6) ISR (7)
   intr->new_pmhandler.pm_offset = (u_long) isr;
   _go32_dpmi_allocate_iret_wrapper (&intr->new_pmhandler);
 
   intr->new_pmhandler.pm_offset = (u_long) isr;
   _go32_dpmi_allocate_iret_wrapper (&intr->new_pmhandler);
 
-  if (_go32_dpmi_set_protected_mode_interrupt_vector (vec, &intr->new_pmhandler))
+  if (_go32_dpmi_set_protected_mode_interrupt_vector (vec,
+                                                     &intr->new_pmhandler))
     {
       return 0;
     }
     {
       return 0;
     }
@@ -436,8 +426,7 @@ ISR (4) ISR (5) ISR (6) ISR (7)
 
 
 static void
 
 
 static void
-dos_unhookirq (intr)
-     struct intrupt *intr;
+dos_unhookirq (struct intrupt *intr)
 {
   unsigned int irq, vec;
   unsigned char mask;
 {
   unsigned int irq, vec;
   unsigned char mask;
@@ -464,9 +453,7 @@ dos_unhookirq (intr)
 
 
 static int
 
 
 static int
-dos_open (scb, name)
-     serial_t scb;
-     const char *name;
+dos_open (struct serial *scb, const char *name)
 {
   struct dos_ttystate *port;
   int fd, i;
 {
   struct dos_ttystate *port;
   int fd, i;
@@ -518,7 +505,8 @@ ok:
   outb (port, com_ier, 0);
 
   /* tentatively enable 16550 fifo, and see if it responds */
   outb (port, com_ier, 0);
 
   /* tentatively enable 16550 fifo, and see if it responds */
-  outb (port, com_fifo, FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER);
+  outb (port, com_fifo,
+       FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER);
   sleep (1);
   port->fifo = ((inb (port, com_iir) & IIR_FIFO_MASK) == IIR_FIFO_MASK);
 
   sleep (1);
   port->fifo = ((inb (port, com_iir) & IIR_FIFO_MASK) == IIR_FIFO_MASK);
 
@@ -570,8 +558,7 @@ ok:
 
 
 static void
 
 
 static void
-dos_close (scb)
-     serial_t scb;
+dos_close (struct serial *scb)
 {
   struct dos_ttystate *port;
   struct intrupt *intrupt;
 {
   struct dos_ttystate *port;
   struct intrupt *intrupt;
@@ -613,21 +600,19 @@ dos_close (scb)
 
 
 static int
 
 
 static int
-dos_noop (serial_t scb ATTRIBUTE_UNUSED)
+dos_noop (struct serial *scb)
 {
   return 0;
 }
 
 static void
 {
   return 0;
 }
 
 static void
-dos_raw (serial_t scb ATTRIBUTE_UNUSED)
+dos_raw (struct serial *scb)
 {
   /* Always in raw mode */
 }
 
 static int
 {
   /* Always in raw mode */
 }
 
 static int
-dos_readchar (scb, timeout)
-     serial_t scb;
-     int timeout;
+dos_readchar (struct serial *scb, int timeout)
 {
   struct dos_ttystate *port = &ports[scb->fd];
   long then;
 {
   struct dos_ttystate *port = &ports[scb->fd];
   long then;
@@ -638,7 +623,6 @@ dos_readchar (scb, timeout)
     {
       if (timeout >= 0 && (rawclock () - then) >= 0)
        return SERIAL_TIMEOUT;
     {
       if (timeout >= 0 && (rawclock () - then) >= 0)
        return SERIAL_TIMEOUT;
-      notice_quit ();
     }
 
   return c;
     }
 
   return c;
@@ -646,8 +630,7 @@ dos_readchar (scb, timeout)
 
 
 static serial_ttystate
 
 
 static serial_ttystate
-dos_get_tty_state (scb)
-     serial_t scb;
+dos_get_tty_state (struct serial *scb)
 {
   struct dos_ttystate *port = &ports[scb->fd];
   struct dos_ttystate *state;
 {
   struct dos_ttystate *port = &ports[scb->fd];
   struct dos_ttystate *state;
@@ -671,9 +654,7 @@ dos_get_tty_state (scb)
 }
 
 static int
 }
 
 static int
-dos_set_tty_state (scb, ttystate)
-     serial_t scb;
-     serial_ttystate ttystate;
+dos_set_tty_state (struct serial *scb, serial_ttystate ttystate)
 {
   struct dos_ttystate *state;
 
 {
   struct dos_ttystate *state;
 
@@ -683,8 +664,8 @@ dos_set_tty_state (scb, ttystate)
 }
 
 static int
 }
 
 static int
-dos_noflush_set_tty_state (serial_t scb, serial_ttystate new_ttystate,
-                          serial_ttystate old_ttystate ATTRIBUTE_UNUSED)
+dos_noflush_set_tty_state (struct serial *scb, serial_ttystate new_ttystate,
+                          serial_ttystate old_ttystate)
 {
   struct dos_ttystate *state;
 
 {
   struct dos_ttystate *state;
 
@@ -694,8 +675,7 @@ dos_noflush_set_tty_state (serial_t scb, serial_ttystate new_ttystate,
 }
 
 static int
 }
 
 static int
-dos_flush_input (scb)
-     serial_t scb;
+dos_flush_input (struct serial *scb)
 {
   struct dos_ttystate *port = &ports[scb->fd];
   disable ();
 {
   struct dos_ttystate *port = &ports[scb->fd];
   disable ();
@@ -707,24 +687,22 @@ dos_flush_input (scb)
 }
 
 static void
 }
 
 static void
-dos_print_tty_state (serial_t scb ATTRIBUTE_UNUSED,
-                    serial_ttystate ttystate ATTRIBUTE_UNUSED,
-                    struct ui_file *stream ATTRIBUTE_UNUSED)
+dos_print_tty_state (struct serial *scb, serial_ttystate ttystate,
+                    struct ui_file *stream)
 {
   /* Nothing to print */
   return;
 }
 
 static int
 {
   /* Nothing to print */
   return;
 }
 
 static int
-dos_baudconv (rate)
-     int rate;
+dos_baudconv (int rate)
 {
   long x, err;
 
   if (rate <= 0)
     return -1;
 
 {
   long x, err;
 
   if (rate <= 0)
     return -1;
 
-#define divrnd(n, q)   (((n) * 2 / (q) + 1) / 2)       /* divide and round off */
+#define divrnd(n, q)   (((n) * 2 / (q) + 1) / 2) /* divide and round off */
   x = divrnd (COMTICK, rate);
   if (x <= 0)
     return -1;
   x = divrnd (COMTICK, rate);
   if (x <= 0)
     return -1;
@@ -740,9 +718,7 @@ dos_baudconv (rate)
 
 
 static int
 
 
 static int
-dos_setbaudrate (scb, rate)
-     serial_t scb;
-     int rate;
+dos_setbaudrate (struct serial *scb, int rate)
 {
   struct dos_ttystate *port = &ports[scb->fd];
 
 {
   struct dos_ttystate *port = &ports[scb->fd];
 
@@ -774,9 +750,7 @@ dos_setbaudrate (scb, rate)
 }
 
 static int
 }
 
 static int
-dos_setstopbits (scb, num)
-     serial_t scb;
-     int num;
+dos_setstopbits (struct serial *scb, int num)
 {
   struct dos_ttystate *port = &ports[scb->fd];
   unsigned char cfcr;
 {
   struct dos_ttystate *port = &ports[scb->fd];
   unsigned char cfcr;
@@ -803,10 +777,7 @@ dos_setstopbits (scb, num)
 }
 
 static int
 }
 
 static int
-dos_write (scb, str, len)
-     serial_t scb;
-     const char *str;
-     int len;
+dos_write (struct serial *scb, const char *str, int len)
 {
   volatile struct dos_ttystate *port = &ports[scb->fd];
   int fifosize = port->fifo ? 16 : 1;
 {
   volatile struct dos_ttystate *port = &ports[scb->fd];
   int fifosize = port->fifo ? 16 : 1;
@@ -818,9 +789,16 @@ dos_write (scb, str, len)
       /* send the data, fifosize bytes at a time */
       cnt = fifosize > len ? len : fifosize;
       port->txbusy = 1;
       /* send the data, fifosize bytes at a time */
       cnt = fifosize > len ? len : fifosize;
       port->txbusy = 1;
+      /* Francisco Pastor <fpastor.etra-id@etra.es> says OUTSB messes
+        up the communications with UARTs with FIFOs.  */
+#ifdef UART_FIFO_WORKS
       outportsb (port->base + com_data, str, cnt);
       str += cnt;
       len -= cnt;
       outportsb (port->base + com_data, str, cnt);
       str += cnt;
       len -= cnt;
+#else
+      for ( ; cnt > 0; cnt--, len--)
+       outportb (port->base + com_data, *str++);
+#endif
 #ifdef DOS_STATS
       cnts[CNT_TX] += cnt;
 #endif
 #ifdef DOS_STATS
       cnts[CNT_TX] += cnt;
 #endif
@@ -840,8 +818,7 @@ dos_write (scb, str, len)
 
 
 static int
 
 
 static int
-dos_sendbreak (scb)
-     serial_t scb;
+dos_sendbreak (struct serial *scb)
 {
   volatile struct dos_ttystate *port = &ports[scb->fd];
   unsigned char cfcr;
 {
   volatile struct dos_ttystate *port = &ports[scb->fd];
   unsigned char cfcr;
@@ -879,12 +856,12 @@ static struct serial_ops dos_ops =
   dos_setbaudrate,
   dos_setstopbits,
   dos_noop,                    /* wait for output to drain */
   dos_setbaudrate,
   dos_setstopbits,
   dos_noop,                    /* wait for output to drain */
-  (void (*)(serial_t, int))NULL        /* change into async mode */
+  (void (*)(struct serial *, int))NULL /* change into async mode */
 };
 
 
 static void
 };
 
 
 static void
-dos_info (char *arg ATTRIBUTE_UNUSED, int from_tty ATTRIBUTE_UNUSED)
+dos_info (char *arg, int from_tty)
 {
   struct dos_ttystate *port;
 #ifdef DOS_STATS
 {
   struct dos_ttystate *port;
 #ifdef DOS_STATS
@@ -914,7 +891,7 @@ dos_info (char *arg ATTRIBUTE_UNUSED, int from_tty ATTRIBUTE_UNUSED)
 
 
 void
 
 
 void
-_initialize_ser_dos ()
+_initialize_ser_dos (void)
 {
   serial_add_interface (&dos_ops);
 
 {
   serial_add_interface (&dos_ops);