breakpoints/19546: Fix crash after updating breakpoints
[deliverable/binutils-gdb.git] / sim / m32c / main.c
index 96c0ac45f2bf03e902cf4f07ac969dc62b682c6b..d7d1d931d3fff30f67c997e8ec906343f2f00607 100644 (file)
@@ -1,26 +1,25 @@
 /* main.c --- main function for stand-alone M32C simulator.
 
-Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+Copyright (C) 2005-2016 Free Software Foundation, Inc.
 Contributed by Red Hat, Inc.
 
 This file is part of the GNU simulators.
 
-The GNU simulators are free software; you can redistribute them and/or
-modify them under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+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
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
 
-The GNU simulators are distributed in the hope that they will be
-useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with the GNU simulators; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA  */
+along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -28,6 +27,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 #include <assert.h>
 #include <setjmp.h>
 #include <signal.h>
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_SOCKET_H
+#ifdef HAVE_NETINET_IN_H
+#ifdef HAVE_NETINET_TCP_H
+#define HAVE_networking
+#endif
+#endif
+#endif
+
+#ifdef HAVE_networking
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#endif
+
 
 #include "bfd.h"
 
@@ -36,8 +51,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 #include "misc.h"
 #include "load.h"
 #include "trace.h"
+#ifdef TIMER_A
+#include "int.h"
+#include "timer_a.h"
+#endif
+
+#ifdef HAVE_networking
+extern int m32c_console_ofd;
+extern int m32c_console_ifd;
+#endif
 
-static int disassemble = 0;
+int m32c_disassemble = 0;
 static unsigned int cycles = 0;
 
 static void
@@ -52,24 +76,94 @@ done (int exit_code)
   exit (exit_code);
 }
 
+#ifdef HAVE_networking
+static void
+setup_tcp_console (char *portname)
+{
+  int port = atoi (portname);
+  struct sockaddr_in address;
+  int isocket;
+  socklen_t as;
+  unsigned char *a;
+
+  if (port < 1024)
+    {
+      printf ("invalid port number %d\n", port);
+      exit (1);
+    }
+  printf ("waiting for tcp console on port %d\n", port);
+
+  memset (&address, 0, sizeof (address));
+  address.sin_family = AF_INET;
+  address.sin_port = htons (port);
+
+  isocket = socket (AF_INET, SOCK_STREAM, 0);
+  if (isocket == -1)
+    {
+      perror ("socket");
+      exit (1);
+    }
+
+  if (bind (isocket, (struct sockaddr *) &address, sizeof (address)))
+    {
+      perror ("bind");
+      exit (1);
+    }
+  listen (isocket, 2);
+
+  printf ("waiting for connection...\n");
+  as = sizeof (address);
+  m32c_console_ifd = accept (isocket, (struct sockaddr *) &address, &as);
+  if (m32c_console_ifd == -1)
+    {
+      perror ("accept");
+      exit (1);
+    }
+  a = (unsigned char *) (&address.sin_addr.s_addr);
+  printf ("connection from %d.%d.%d.%d\n", a[0], a[1], a[2], a[3]);
+  m32c_console_ofd = m32c_console_ifd;
+}
+#endif
+
 int
 main (int argc, char **argv)
 {
   int o;
   int save_trace;
   bfd *prog;
+#ifdef HAVE_networking
+  char *console_port_s = 0;
+#endif
+
+  setbuf (stdout, 0);
 
-  while ((o = getopt (argc, argv, "tvdm:")) != -1)
+  in_gdb = 0;
+
+  while ((o = getopt (argc, argv, "tc:vdm:C")) != -1)
     switch (o)
       {
       case 't':
        trace++;
        break;
+      case 'c':
+#ifdef HAVE_networking
+       console_port_s = optarg;
+#else
+       fprintf (stderr, "Nework console not available in this build.\n");
+#endif
+       break;
+      case 'C':
+#ifdef HAVE_TERMIOS_H
+       m32c_use_raw_console = 1;
+#else
+       fprintf (stderr, "Raw console not available in this build.\n");
+#endif
+       break;
       case 'v':
        verbose++;
        break;
       case 'd':
-       disassemble++;
+       m32c_disassemble++;
        break;
       case 'm':
        if (strcmp (optarg, "r8c") == 0 || strcmp (optarg, "m16c") == 0)
@@ -85,8 +179,8 @@ main (int argc, char **argv)
        break;
       case '?':
        fprintf (stderr,
-                 "usage: run [-v] [-t] [-d] [-m r8c|m16c|m32cm|m32c]"
-                 " program\n");
+                "usage: run [-v] [-C] [-c port] [-t] [-d] [-m r8c|m16c|m32cm|m32c]"
+                " program\n");
        exit (1);
       }
 
@@ -108,8 +202,12 @@ main (int argc, char **argv)
   m32c_load (prog);
   trace = save_trace;
 
-  if (disassemble)
-    sim_disasm_init (prog);
+#ifdef HAVE_networking
+  if (console_port_s)
+    setup_tcp_console (console_port_s);
+#endif
+
+  sim_disasm_init (prog);
 
   while (1)
     {
@@ -118,7 +216,7 @@ main (int argc, char **argv)
       if (trace)
        printf ("\n");
 
-      if (disassemble)
+      if (m32c_disassemble)
        sim_disasm_one ();
 
       enable_counting = verbose;
@@ -134,5 +232,9 @@ main (int argc, char **argv)
        assert (M32C_STEPPED (rc));
 
       trace_register_changes ();
+
+#ifdef TIMER_A
+      update_timer_a ();
+#endif
     }
 }
This page took 0.053131 seconds and 4 git commands to generate.