fix stabs.texinfo xref bugs
[deliverable/binutils-gdb.git] / gdb / ser-go32.c
index 2a493bc53d80a8a3b84836df9e8138179e7c20da..1d930a884804d3cc190844b5f6b4ab4cf2e37ffc 100644 (file)
@@ -1,7 +1,5 @@
-/* Remote serial interface for GO32 
-
-   Copyright 1992
-   Free Software Foundation, Inc.
+/* Remote serial interface for local (hardwired) serial ports for GO32.
+   Copyright 1992, 1993 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -19,25 +17,15 @@ 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.  */
 
-#include <stdio.h>
-#include <sys/dos.h>
-
 #include "defs.h"
 #include "serial.h"
-
+#include <sys/dos.h>
 
 #define SIGNATURE 0x4154
 #define VERSION 1
 #define OFFSET 0x104
 
-/*#define MONO 1*/
-
-#define dprintf if(0)printf
-
-#ifdef __GNUC__
-#define far
 #define peek(a,b) (*(unsigned short *)(0xe0000000 + (a)*16 + (b)))
-#endif
 
 typedef struct {
   short jmp_op;
@@ -50,7 +38,7 @@ typedef struct {
   short iov;
 } ASYNC_STRUCT;
 
-static ASYNC_STRUCT far *async;
+static ASYNC_STRUCT *async;
 static int iov;
 #define com_rb iov
 #define com_tb iov
@@ -61,270 +49,261 @@ static int iov;
 #define com_lsr        iov+5
 #define com_msr        iov+6
 
-#if MONO
-#include <sys/pc.h>
-static int mono_pos=0;
-#define mono_rx 0x07
-#define mono_tx 0x70
-
-void mono_put(char byte, char attr)
+static int
+strncasecmp(str1, str2, len)
+     char *str1, *str2;
+     register int len;
 {
-  ScreenSecondary[320+mono_pos+80] = 0x0720;
-  ScreenSecondary[320+mono_pos] = (attr<<8) | (byte&0xff);
-  mono_pos = (mono_pos+1) % 1200;
-}
+  unsigned char c1, c2;
 
-#endif
+  for (; len != 0; --len)
+    {
+      c1 = *str1++;
+      c2 = *str2++;
+
+      if (toupper(c1) != toupper(c2))
+       return toupper(c1) - toupper(c2);
+
+      if (c1 == '\0')
+       return 0;
+    }
+  return 0;
+}
 
-static char far *aptr(short p)
+static char *
+aptr(p)
+     short p;
 {
-#ifdef __GNUC__
   return (char *)((unsigned)async - OFFSET + p);
-#else
-  return (char far *)MK_FP(FP_SEG(async), p);
-#endif
 }
 
-static ASYNC_STRUCT far *getivec(int which)
+static ASYNC_STRUCT *
+getivec(int which)
 {
-  ASYNC_STRUCT far *a;
+  ASYNC_STRUCT *a;
 
   if (peek(0, which*4) != OFFSET)
     return 0;
-#ifdef __GNUC__
+
   a = (ASYNC_STRUCT *)(0xe0000000 + peek(0, which*4+2)*16 + peek(0, which*4));
 
-#else
-  a = (ASYNC_STRUCT far *)MK_FP(peek(0,which*4+2),peek(0,which*4));
-#endif
   if (a->signature != SIGNATURE)
     return 0;
+
   if (a->version != VERSION)
     return 0;
+
   return a;
 }
 
-int dos_async_init()
+static int
+dos_async_init(port)
+     int port;
 {
   int i;
-  ASYNC_STRUCT far *a1;
-  ASYNC_STRUCT far *a2;
-  a1 = getivec(12);
-  a2 = getivec(11);
-  async = 0;
-  if (a1)
-    async = a1;
-  if (a2)
-    async = a2;
-  if (a1 && a2)
-  {
-    if (a1 < a2)
-      async = a1;
-    else
-      async = a2;
-  }
-  if (async == 0)
-  {
-    error("GDB can not connect to asynctsr program, check that it is installed\n\
+
+  switch (port)
+    {
+    case 1:
+      async = getivec (12);
+      break;
+    case 2:
+      async = getivec (11);
+      break;
+    default:
+      return 0;
+    }
+
+  if (!async)
+    {
+      error("GDB can not connect to asynctsr program, check that it is installed\n\
 and that serial I/O is not being redirected (perhaps by NFS)\n\n\
 example configuration:\n\
 C> mode com2:9600,n,8,1,p\n\
 C> asynctsr 2\n\
 C> gdb \n");
 
-  }
+    }
+
   iov = async->iov;
   outportb(com_ier, 0x0f);
   outportb(com_bfr, 0x03);
   outportb(com_mcr, 0x0b);
   async->getp = async->putp = async->buffer_start;
   
-#if MONO
-  for (i=0; i<1200; i++)
-    ScreenSecondary[320+i] = 0x0720;
-#endif
-  if (iov > 0x300)
-    return 1;
-  else
-    return 2;
+  return 1;
 }
 
-dos_async_tx(char c)
+static void
+dos_async_tx(c)
+     const char c;
 {
-  dprintf("dos_async_tx: enter %x - with IOV %x", c, com_lsr);
-  fflush(stdout);
   while (~inportb(com_lsr) & 0x20);
+
   outportb(com_tb, c);
-#if MONO
-  mono_put(c, mono_tx);
-#endif
-  dprintf("exit\n");
 }
 
-int dos_async_ready()
+static int
+dos_async_ready()
 {
   return (async->getp != async->putp);
 }
 
-int dos_async_rx()
+static int
+dos_async_rx()
 {
   char rv;
-  dprintf("dos_async_rx: enter - ");
-  fflush(stdout);
+
   while (!dos_async_ready())
-   if (kbhit())
-   {
-     printf("abort!\n");
-     return 0;
-   }
-  dprintf("async=%x getp=%x\n", async, async->getp);
-  fflush(stdout);
+    if (kbhit())
+      {
+       printf("abort!\n");
+       return 0;
+      }
+
   rv = *aptr(async->getp++);
-#if MONO
-  mono_put(rv, mono_rx);
-#endif
   if (async->getp >= async->buffer_end)
-   async->getp = async->buffer_start;
-  dprintf("exit %x\n", rv);
-  return rv;
-}
-
-int dos_kb_ready()
-{
-  return (peek(0x40,0x1a) != peek(0x40,0x1c));
-}
+    async->getp = async->buffer_start;
 
-int dos_kb_rx()
-{
-#ifdef __GNUC__
-  return getkey();
-#else
-  return getch();
-#endif
+  return rv;
 }
 
-int dosasync_read(int fd, char *buffer, int length, int timeout)
+static int
+dosasync_read (fd, buf, len, timeout)
+     int fd;
+     char *buf;
+     int len;
+     int timeout;
 {
   long now, then;
-  int l = length;
+  int l = len;
+
   time (&now);
-  then = now+timeout;
-  dprintf("dosasync_read: enter(%d,%d)\n", length, timeout);
+  then = now + timeout;
+
   while (l--)
-  {
-    if (timeout)
     {
-      while (!dos_async_ready())
-      {
-        time (&now);
-        if (now == then)
-        {
-          dprintf("dosasync_read: timeout(%d)\n", length-l-1);
-          return length-l-1;
-        }
-      }
+      if (timeout)
+       {
+         while (!dos_async_ready())
+           {
+             time (&now);
+             if (now >= then)
+               return len - l - 1;
+           }
+       }
+      *buf++ = dos_async_rx();
     }
-    *buffer++ = dos_async_rx();
-  }
-  dprintf("dosasync_read: exit %d\n", length);
-  return length;
-}
 
-int dosasync_write(int fd, CONST char *buffer, int length)
-{
-  int l = length;
-  while (l--)
-   dos_async_tx(*buffer++);
-  return length;
+  return len;
 }
 
-
-
-char *strlwr(char *s)
+static int
+dosasync_write(fd, buf, len)
+     int fd;
+     const char *buf;
+     int len;
 {
-  char *p = s;
-  while (*s)
-  {
-    if ((*s >= 'A') && (*s <= 'Z'))
-      *s += 'a'-'A';
-    s++;
-  }
-  return p;
-}
+  int l = len;
+
+  while (l--)
+    dos_async_tx (*buf++);
 
-sigsetmask() {
+  return len;
 }
 
+static int
+go32_open (scb, name)
+     serial_t scb;
+     const char *name;
+{
+  int port;
 
+  if (strncasecmp (name, "com", 3) != 0)
+    {
+      errno = ENOENT;
+      return -1;
+    }
 
-static int fd;
+  port = name[3] - '0';
 
-CONST char *
-DEFUN_VOID(serial_default_name)
-{
-  return "com1";
-}
+  if ((port != 1) && (port != 2))
+    {
+      errno = ENOENT;
+      return -11;
+    }
 
+  scb->fd = dos_async_init(port);
+  if (!scb->fd)
+    return -1;
 
-void
-DEFUN_VOID(serial_raw)
-{
-/* Always in raw mode */
+  return 0;
 }
 
-
-int
-DEFUN(serial_open,(name),
-      CONST char *name)
+static void
+go32_raw (scb)
+     serial_t scb;
 {
-  fd = dos_async_init();
-  if (fd) return 1;
-  return 0;
+  /* Always in raw mode */
 }
 
-int
-DEFUN(serial_timedreadchar,(to, ok),
-      int to AND
-      int *ok)
+static int
+go32_readchar (scb, timeout)
+     serial_t scb;
+     int timeout;
 {
   char buf;
-  if ( dosasync_read(fd, &buf, 1, to))  
-  {
-    *ok = 1;
-  }
+
+  if (dosasync_read(scb->fd, &buf, 1, timeout))  
+    return buf;
   else
-  {
-    *ok = 0;
-  }
-  return buf;
+    return SERIAL_TIMEOUT;
 }
 
-int
-DEFUN(serial_setbaudrate,(rate),
-      int rate)
+static int
+go32_setbaudrate (scb, rate)
+     serial_t scb;
+     int rate;
 {
   return 0;
 }
 
-int
-DEFUN(serial_nextbaudrate,(rate),
-      int rate)
+static int
+go32_write (scb, str, len)
+     serial_t scb;
+     const char *str;
+     int len;
 {
+  dosasync_write(scb->fd, str, len);
+
   return 0;
 }
 
-int
-DEFUN(serial_write,(str, len),
-      CONST char *str AND
-      int len)
+static void
+go32_close ()
 {
-  dosasync_write(fd, str, len);
 }
 
-int
-DEFUN_VOID(serial_close)
+static void
+go32_restore (scb)
+     serial_t scb;
 {
-
-
 }
 
+static struct serial_ops go32_ops =
+{
+  "hardwire",
+  0,
+  go32_open,
+  go32_close,
+  go32_readchar,
+  go32_write,
+  go32_raw,
+  go32_restore,
+  go32_setbaudrate
+};
+
+_initialize_ser_go32 ()
+{
+  serial_add_interface (&go32_ops);
+}
This page took 0.027589 seconds and 4 git commands to generate.