* remote-mips.c, remote-monitor.c, remote-st2000.c: Convert to
authorStu Grossman <grossman@cygnus>
Fri, 9 Apr 1993 22:55:00 +0000 (22:55 +0000)
committerStu Grossman <grossman@cygnus>
Fri, 9 Apr 1993 22:55:00 +0000 (22:55 +0000)
new serial interface.

gdb/ChangeLog
gdb/remote-mips.c
gdb/remote-monitor.c
gdb/remote-st2000.c

index 4d557189130816c7f468ddab5c04ffe521247f71..279235fa37e464d2857c0b9763a208f226a18e34 100644 (file)
@@ -1,3 +1,8 @@
+Fri Apr  9 15:53:19 1993  Stu Grossman  (grossman@cygnus.com)
+
+       * remote-mips.c, remote-monitor.c, remote-st2000.c:  Convert to
+       new serial interface.
+
 Fri Apr  9 15:01:12 1993  Stu Grossman  (grossman@cygnus.com)
 
        * remote.c (remote_open):  Use SERIAL_OPEN instead of serial_open.
index 73a653c25464048567ff588d6e51a7aadade3028..1c7573cd2da0617e12913298176418aaf77ee444 100644 (file)
@@ -278,6 +278,9 @@ static int mips_need_reply = 0;
 /* This can be set to get debugging with ``set remotedebug''.  */
 static int mips_debug = 0;
 
+/* Handle used to access serial I/O stream.  */
+static serial_t mips_desc;
+
 /* Read a character from the remote, aborting on error.  Returns -2 on
    timeout (since that's what serial_readchar returns).  FIXME: If we
    see the string "<IDT>" from the board, then we are debugging on the
@@ -299,14 +302,14 @@ mips_readchar (timeout)
   static int state = 0;
   static char nextstate[5] = { '<', 'I', 'D', 'T', '>' };
 
-  ch = serial_readchar (timeout);
-  if (ch == EOF)
+  ch = SERIAL_READCHAR (mips_desc, timeout);
+  if (ch == SERIAL_EOF)
     error ("End of file from remote");
-  if (ch == -3)
+  if (ch == SERIAL_ERROR)
     error ("Error reading from remote: %s", safe_strerror (errno));
   if (mips_debug > 1)
     {
-      if (ch != -2)
+      if (ch != SERIAL_TIMEOUT)
        printf_filtered ("Read '%c' %d 0x%x\n", ch, ch, ch);
       else
        printf_filtered ("Timed out in read\n");
@@ -317,13 +320,13 @@ mips_readchar (timeout)
      described above.  The first character in a packet after the SYN
      (which is not echoed) is always an @ unless the packet is more
      than 64 characters long, which ours never are.  */
-  if ((ch == -2 || ch == '@')
+  if ((ch == SERIAL_TIMEOUT || ch == '@')
       && state == 5
       && ! mips_initializing)
     {
       if (mips_debug > 0)
        printf_filtered ("Reinitializing MIPS debugging mode\n");
-      serial_write ("\rdb tty0\r", sizeof "\rdb tty0\r" - 1);
+      SERIAL_WRITE (mips_desc, "\rdb tty0\r", sizeof "\rdb tty0\r" - 1);
       sleep (1);
 
       mips_need_reply = 0;
@@ -514,7 +517,7 @@ mips_send_packet (s, get_ack)
          printf_filtered ("Writing \"%s\"\n", packet + 1);
        }
 
-      if (serial_write (packet, HDR_LENGTH + len + TRLR_LENGTH) == 0)
+      if (SERIAL_WRITE (mips_desc, packet, HDR_LENGTH + len + TRLR_LENGTH))
        error ("write to target failed: %s", safe_strerror (errno));
 
       garbage = 0;
@@ -701,7 +704,7 @@ mips_receive_packet (buff)
                           ack + 1);
        }
 
-      if (serial_write (ack, HDR_LENGTH + TRLR_LENGTH) == 0)
+      if (SERIAL_WRITE (mips_desc, ack, HDR_LENGTH + TRLR_LENGTH))
        error ("write to target failed: %s", safe_strerror (errno));
     }
 
@@ -732,7 +735,7 @@ mips_receive_packet (buff)
                       ack + 1);
     }
 
-  if (serial_write (ack, HDR_LENGTH + TRLR_LENGTH) == 0)
+  if (SERIAL_WRITE (mips_desc, ack, HDR_LENGTH + TRLR_LENGTH))
     error ("write to target failed: %s", safe_strerror (errno));
 
   return len;
@@ -844,7 +847,7 @@ mips_initialize ()
      it means.  The packet seems to be triggered by a carriage return
      character, although perhaps any character would do.  */
   cr = '\r';
-  serial_write (&cr, 1);
+  SERIAL_WRITE (mip_desc, &cr, 1);
 
   hold_wait = mips_receive_wait;
   mips_receive_wait = 3;
@@ -862,12 +865,12 @@ mips_initialize ()
         board and trying again.  */
       printf_filtered ("Failed to initialize; trying to reset board\n");
       cc = '\003';
-      serial_write (&cc, 1);
+      SERIAL_WRITE (mips_desc, &cc, 1);
       sleep (2);
-      serial_write ("\rdb tty0\r", sizeof "\rdb tty0\r" - 1);
+      SERIAL_WRITE (mips_desc, "\rdb tty0\r", sizeof "\rdb tty0\r" - 1);
       sleep (1);
       cr = '\r';
-      serial_write (&cr, 1);
+      SERIAL_WRITE (mips_desc, &cr, 1);
     }
 
   mips_receive_wait = hold_wait;
@@ -895,9 +898,13 @@ device is attached to the target board (e.g., /dev/ttya).");
   if (mips_is_open)
     unpush_target (&mips_ops);
 
-  if (serial_open (name) == 0)
+  mips_desc = SERIAL_OPEN (name);
+
+  if (!mips_desc)
     perror_with_name (name);
 
+  SERIAL_RAW (mips_desc);
+
   mips_is_open = 1;
 
   mips_initialize ();
@@ -924,7 +931,7 @@ mips_close (quitting)
       /* Get the board out of remote debugging mode.  */
       mips_request ('x', (unsigned int) 0, (unsigned int) 0, &err);
 
-      serial_close ();
+      SERIAL_CLOSE (mips_desc);
     }
 }
 
@@ -1217,7 +1224,7 @@ mips_kill ()
 
       /* Send a ^C.  */
       cc = '\003';
-      serial_write (&cc, 1);
+      SERIAL_WRITE (mips_desc, &cc, 1);
       sleep (1);
       target_mourn_inferior ();
     }
index 7736fe8a464cf2c70e595d505dfabff868c72f2d..d45af5e611a3e69ee2938e81a22af51ddffc67b7 100644 (file)
@@ -83,7 +83,7 @@ static int timeout = 24;
 /* Descriptor for I/O to remote machine.  Initialize it to -1 so that
    monitor_open knows that we don't have a file open when the program
    starts.  */
-int monitor_desc = -1;
+static serial_t monitor_desc;
 
 /* Send data to monitor.  Works just like printf. */
 
@@ -102,8 +102,8 @@ printf_monitor(va_alist)
 
   vsprintf(buf, pattern, args);
 
-  if (!serial_write(buf, strlen(buf)))
-    fprintf(stderr, "serial_write failed: %s\n", safe_strerror(errno));
+  if (SERIAL_WRITE(monitor_desc, buf, strlen(buf)))
+    fprintf(stderr, "SERIAL_WRITE failed: %s\n", safe_strerror(errno));
 }
 
 /* Read a character from the remote system, doing all the fancy
@@ -114,7 +114,7 @@ readchar(timeout)
 {
   int c;
 
-  c = serial_readchar(timeout);
+  c = SERIAL_READCHAR(monitor_desc, timeout);
 
   if (kiodebug)
     putchar(c & 0x7f);
@@ -127,7 +127,7 @@ readchar(timeout)
   if (c >= 0)
     return c & 0x7f;
 
-  if (c == -2)
+  if (c == SERIAL_TIMEOUT)
     {
       if (timeout == 0)
        return c;               /* Polls shouldn't generate timeout errors */
@@ -318,34 +318,32 @@ static int baudrate = 9600;
 static char dev_name[100];
 
 static void
-rom68k_open(args, from_tty)
+general_open(args, name, from_tty)
      char *args;
+     char *name;
      int from_tty;
 {
   int n;
   char junk[100];
-  TERMINAL sg;
 
   target_preopen(from_tty);
   
   n = sscanf(args, " %s %d %s", dev_name, &baudrate, junk);
 
   if (n != 2)
-    error("Bad arguments.  Usage: target rom68k <device> <speed>\n\
-or target monitor <host> <port>\n");
+    error("Bad arguments.  Usage: target %s <device> <speed>\n\
+or target monitor <host> <port>\n", name);
 
   monitor_close(0);
 
-  monitor_desc = serial_open(dev_name);
+  monitor_desc = SERIAL_OPEN(dev_name);
 
-  serial_setbaudrate(baudrate);
+  if (!monitor_desc)
+    perror_with_name(dev_name);
 
-  ioctl (monitor_desc, TIOCGETP, &sg);
-  sg.sg_flags = O_CRDELAY | O_NLDELAY | ~(RAW);
-  ioctl (monitor_desc, TIOCSETN, &sg);
+  SERIAL_SETBAUDRATE(monitor_desc, baudrate);
 
-  push_target(&rom68k_ops);
-  push_monitor (&rom68k_cmds);
+  SERIAL_RAW(monitor_desc);
 
 #if defined (LOG_FILE)
   log_file = fopen (LOG_FILE, "w");
@@ -354,7 +352,7 @@ or target monitor <host> <port>\n");
 #endif
 
   /* Hello?  Are you there?  */
-  printf_monitor("\n");        /* CR wakes up monitor */
+  printf_monitor("\r");        /* CR wakes up monitor */
   
   expect_prompt(1);
 
@@ -364,44 +362,25 @@ or target monitor <host> <port>\n");
 }
 
 static void
-mon68_open(args, from_tty)
+rom68k_open(args, from_tty)
      char *args;
      int from_tty;
 {
-  int n;
-  char junk[100];
-
-  target_preopen(from_tty);
-  
-  n = sscanf(args, " %s %d %s", dev_name, &baudrate, junk);
-
-  if (n != 2)
-    error("Bad arguments.  Usage: target mon68 <device> <speed>\n\
-or target monitor <host> <port>\n");
-
-  monitor_close(0);
-
-  monitor_desc = serial_open(dev_name);
+  push_target(&rom68k_ops);
+  push_monitor (&rom68k_cmds);
 
-  serial_setbaudrate(baudrate);
+  general_open (args, "rom68k", from_tty);
+}
 
+static void
+mon68_open(args, from_tty)
+     char *args;
+     int from_tty;
+{
   push_target(&mon68_ops);
   push_monitor (&mon68_cmds);
 
-#if defined (LOG_FILE)
-  log_file = fopen (LOG_FILE, "w");
-  if (log_file == NULL)
-    perror_with_name (LOG_FILE);
-#endif
-
-  /* Hello?  Are you there?  */
-  printf_monitor("\n");        /* CR wakes up dbug */
-  
-  expect_prompt(1);
-
-  if (from_tty)
-    printf("Remote %s connected to %s\n", target_shortname,
-          dev_name);
+  general_open (args, "mon68", from_tty);
 }
 
 static void
@@ -409,50 +388,21 @@ bug_open(args, from_tty)
      char *args;
      int from_tty;
 {
-  int n;
-  char junk[100];
-
-  target_preopen(from_tty);
-  
-  n = sscanf(args, " %s %d %s", dev_name, &baudrate, junk);
-
-  if (n != 2)
-    error("Bad arguments.  Usage: target bug <device> <speed>\n\
-or target monitor <host> <port>\n");
-
-  monitor_close(0);
-
-  monitor_desc = serial_open(dev_name);
-
-  serial_setbaudrate(baudrate);
-
   push_target(&bug_ops);
   push_monitor (&bug_cmds);
 
-#if defined (LOG_FILE)
-  log_file = fopen (LOG_FILE, "w");
-  if (log_file == NULL)
-    perror_with_name (LOG_FILE);
-#endif
-
-  /* Hello?  Are you there?  */
-  printf_monitor("\r");        /* CR wakes up dbug */
-  
-  expect_prompt(1);
-
-  if (from_tty)
-    printf("Remote %s connected to %s\n", target_shortname,
-          dev_name);
+  general_open (args, "bug", from_tty);
 }
 
 /*
  * _close -- Close out all files and local state before this target loses control.
  */
+
 static void
 monitor_close (quitting)
      int quitting;
 {
-  serial_close();
+  SERIAL_CLOSE(monitor_desc);
 
 #if defined (LOG_FILE)
   if (log_file) {
@@ -896,8 +846,8 @@ monitor_load (arg)
          fflush (stdout);
        }
 
-      if (!serial_write(buf, bytes_read)) {
-       fprintf(stderr, "serial_write failed: (while downloading) %s\n", safe_strerror(errno));
+      if (SERIAL_WRITE(monitor_desc, buf, bytes_read)) {
+       fprintf(stderr, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror(errno));
        break;
       }
       i = 0;
@@ -940,6 +890,8 @@ monitor_command (args, fromtty)
   expect_prompt(0);
 }
 
+#if 0
+
 /* Connect the user directly to MONITOR.  This command acts just like the
    'cu' or 'tip' command.  Use <CR>~. or <CR>~^D to break out.  */
 
@@ -948,7 +900,7 @@ static struct ttystate ttystate;
 static void
 cleanup_tty()
 {  printf("\r\n[Exiting connect mode]\r\n");
-  serial_restore(0, &ttystate);
+  /*SERIAL_RESTORE(0, &ttystate);*/
 }
 
 static void
@@ -1030,6 +982,7 @@ connect_command (args, fromtty)
        }
     }
 }
+#endif
 
 /*
  * Define the monitor command strings. Since these are passed directly
index 67ed256778ee37e77bc4e2da753c3b97d2d589b2..fc75504555e5a4f1b3794ef4b394f3c5882752f1 100644 (file)
@@ -60,7 +60,8 @@ static int timeout = 24;
 /* Descriptor for I/O to remote machine.  Initialize it to -1 so that
    st2000_open knows that we don't have a file open when the program
    starts.  */
-int st2000_desc = -1;
+
+static serial_t st2000_desc;
 
 /* Send data to stdebug.  Works just like printf. */
 
@@ -77,19 +78,20 @@ printf_stdebug(va_alist)
   pattern = va_arg(args, char *);
 
   vsprintf(buf, pattern, args);
-  if (!serial_write(buf, strlen(buf)))
-    fprintf(stderr, "serial_write failed: %s\n", safe_strerror(errno));
+  if (SERIAL_WRITE(st2000_desc, buf, strlen(buf)))
+    fprintf(stderr, "SERIAL_WRITE failed: %s\n", safe_strerror(errno));
 }
 
-/* Read a character from the remote system, doing all the fancy
-   timeout stuff.  */
+/* Read a character from the remote system, doing all the fancy timeout
+   stuff.  */
+
 static int
 readchar(timeout)
      int timeout;
 {
   int c;
 
-  c = serial_readchar(timeout);
+  c = SERIAL_READCHAR(st2000_desc, timeout);
 
 #ifdef LOG_FILE
   putc(c & 0x7f, log_file);
@@ -98,7 +100,7 @@ readchar(timeout)
   if (c >= 0)
     return c & 0x7f;
 
-  if (c == -2)
+  if (c == SERIAL_TIMEOUT)
     {
       if (timeout == 0)
        return c;               /* Polls shouldn't generate timeout errors */
@@ -296,9 +298,14 @@ or target st2000 <host> <port>\n");
 
   st2000_close(0);
 
-  st2000_desc = serial_open(dev_name);
+  st2000_desc = SERIAL_OPEN(dev_name);
+
+  if (!st2000_desc)
+    perror_with_name(dev_name);
 
-  serial_setbaudrate(baudrate);
+  SERIAL_SETBAUDRATE(st2000_desc, baudrate);
+
+  SERIAL_RAW(st2000_desc);
 
   push_target(&st2000_ops);
 
@@ -324,7 +331,7 @@ static void
 st2000_close (quitting)
      int quitting;
 {
-  serial_close();
+  SERIAL_CLOSE(st2000_desc);
 
 #if defined (LOG_FILE)
   if (log_file) {
@@ -661,7 +668,7 @@ st2000_command (args, fromtty)
      char      *args;
      int       fromtty;
 {
-  if (st2000_desc < 0)
+  if (!st2000_desc)
     error("st2000 target not open.");
   
   if (!args)
@@ -674,15 +681,18 @@ st2000_command (args, fromtty)
 /* Connect the user directly to STDBUG.  This command acts just like the
    'cu' or 'tip' command.  Use <CR>~. or <CR>~^D to break out.  */
 
-static struct ttystate ttystate;
+/*static struct ttystate ttystate;*/
 
 static void
 cleanup_tty()
 {
   printf("\r\n[Exiting connect mode]\r\n");
-  serial_restore(0, &ttystate);
+/*  SERIAL_RESTORE(0, &ttystate);*/
 }
 
+#if 0
+/* This all should now be in serial.c */
+
 static void
 connect_command (args, fromtty)
      char      *args;
@@ -762,6 +772,7 @@ connect_command (args, fromtty)
        }
     }
 }
+#endif /* 0 */
 
 /* Define the target subroutine names */
 
This page took 0.035535 seconds and 4 git commands to generate.