1999-04-16 09:35:26 +08:00
|
|
|
/* run front end support for all the simulators.
|
2007-01-10 01:59:20 +08:00
|
|
|
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
|
2011-01-01 23:34:07 +08:00
|
|
|
2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
|
|
|
|
Free Software Foundation, Inc.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
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
|
2007-08-24 22:30:15 +08:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2007-08-24 22:30:15 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* Steve Chamberlain sac@cygnus.com,
|
|
|
|
and others at Cygnus. */
|
|
|
|
|
2004-05-11 00:18:03 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "cconfig.h"
|
1999-04-16 09:35:26 +08:00
|
|
|
#include "tconfig.h"
|
2004-05-11 00:18:03 +08:00
|
|
|
#endif
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef __STDC__
|
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
|
|
|
#include <varargs.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "libiberty.h"
|
|
|
|
#include "bfd.h"
|
2002-06-09 23:45:54 +08:00
|
|
|
#include "gdb/callback.h"
|
|
|
|
#include "gdb/remote-sim.h"
|
2000-02-09 04:54:27 +08:00
|
|
|
#include "ansidecl.h"
|
2002-05-20 22:32:50 +08:00
|
|
|
#include "run-sim.h"
|
2008-06-07 09:31:27 +08:00
|
|
|
#include "version.h"
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2008-06-07 09:31:27 +08:00
|
|
|
static void usage PARAMS ((int help));
|
|
|
|
static void print_version PARAMS ((void));
|
1999-04-16 09:35:26 +08:00
|
|
|
extern int optind;
|
|
|
|
extern char *optarg;
|
|
|
|
|
|
|
|
extern host_callback default_callback;
|
|
|
|
|
|
|
|
static char *myname;
|
|
|
|
|
|
|
|
extern int getopt ();
|
|
|
|
|
1999-04-27 02:34:20 +08:00
|
|
|
#ifdef NEED_UI_LOOP_HOOK
|
2002-05-31 10:17:26 +08:00
|
|
|
/* Gdb foolery. This is only needed for gdb using a gui. */
|
2004-06-29 08:54:00 +08:00
|
|
|
int (*deprecated_ui_loop_hook) PARAMS ((int signo));
|
1999-04-27 02:34:20 +08:00
|
|
|
#endif
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
static SIM_DESC sd;
|
|
|
|
|
|
|
|
static RETSIGTYPE
|
2000-02-09 04:54:27 +08:00
|
|
|
cntrl_c (int sig ATTRIBUTE_UNUSED)
|
1999-04-16 09:35:26 +08:00
|
|
|
{
|
|
|
|
if (! sim_stop (sd))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Quit!\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (ac, av)
|
|
|
|
int ac;
|
|
|
|
char **av;
|
|
|
|
{
|
|
|
|
RETSIGTYPE (*prev_sigint) ();
|
|
|
|
bfd *abfd;
|
|
|
|
int i;
|
|
|
|
int verbose = 0;
|
|
|
|
int trace = 0;
|
2000-02-22 16:52:21 +08:00
|
|
|
#ifdef SIM_HAVE_ENVIRONMENT
|
|
|
|
int operating_p = 0;
|
|
|
|
#endif
|
1999-04-16 09:35:26 +08:00
|
|
|
char *name;
|
|
|
|
static char *no_args[4];
|
|
|
|
char **sim_argv = &no_args[0];
|
|
|
|
char **prog_args;
|
|
|
|
enum sim_stop reason;
|
|
|
|
int sigrc;
|
|
|
|
|
|
|
|
myname = av[0] + strlen (av[0]);
|
|
|
|
while (myname > av[0] && myname[-1] != '/')
|
|
|
|
--myname;
|
|
|
|
|
|
|
|
/* The first element of sim_open's argv is the program name. */
|
|
|
|
no_args[0] = av[0];
|
|
|
|
#ifdef SIM_HAVE_BIENDIAN
|
|
|
|
no_args[1] = "-E";
|
|
|
|
no_args[2] = "set-later";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* FIXME: This is currently being migrated into sim_open.
|
|
|
|
Simulators that use functions such as sim_size() still require
|
2002-05-31 10:17:26 +08:00
|
|
|
this. */
|
1999-04-16 09:35:26 +08:00
|
|
|
default_callback.init (&default_callback);
|
|
|
|
sim_set_callbacks (&default_callback);
|
|
|
|
|
2002-05-20 22:32:50 +08:00
|
|
|
#ifdef SIM_TARGET_SWITCHES
|
|
|
|
ac = sim_target_parse_command_line (ac, av);
|
|
|
|
#endif
|
|
|
|
|
2008-06-07 09:31:27 +08:00
|
|
|
for (i = 1; av[i]; ++i)
|
|
|
|
{
|
|
|
|
if (strcmp (av[i], "--help") == 0)
|
|
|
|
{
|
|
|
|
usage (1);
|
|
|
|
}
|
|
|
|
else if (strcmp (av[i], "--version") == 0)
|
|
|
|
{
|
|
|
|
print_version ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
/* FIXME: This is currently being rewritten to have each simulator
|
|
|
|
do all argv processing. */
|
|
|
|
|
2002-05-31 10:17:26 +08:00
|
|
|
while ((i = getopt (ac, av, "a:c:m:op:s:tv")) != EOF)
|
1999-04-16 09:35:26 +08:00
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 'a':
|
|
|
|
/* FIXME: Temporary hack. */
|
|
|
|
{
|
|
|
|
int len = strlen (av[0]) + strlen (optarg);
|
|
|
|
char *argbuf = (char *) alloca (len + 2 + 50);
|
|
|
|
sprintf (argbuf, "%s %s", av[0], optarg);
|
|
|
|
#ifdef SIM_HAVE_BIENDIAN
|
|
|
|
/* The desired endianness must be passed to sim_open.
|
|
|
|
The value for "set-later" is set when we know what it is.
|
|
|
|
-E support isn't yet part of the published interface. */
|
|
|
|
strcat (argbuf, " -E set-later");
|
|
|
|
#endif
|
|
|
|
sim_argv = buildargv (argbuf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifdef SIM_HAVE_SIMCACHE
|
|
|
|
case 'c':
|
|
|
|
sim_set_simcache_size (atoi (optarg));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 'm':
|
|
|
|
/* FIXME: Rename to sim_set_mem_size. */
|
|
|
|
sim_size (atoi (optarg));
|
|
|
|
break;
|
2000-02-22 16:52:21 +08:00
|
|
|
#ifdef SIM_HAVE_ENVIRONMENT
|
|
|
|
case 'o':
|
|
|
|
/* Operating enironment where any signals are delivered to the
|
2002-05-31 10:17:26 +08:00
|
|
|
target. */
|
2000-02-22 16:52:21 +08:00
|
|
|
operating_p = 1;
|
|
|
|
break;
|
2002-11-14 10:54:14 +08:00
|
|
|
#endif
|
1999-04-16 09:35:26 +08:00
|
|
|
#ifdef SIM_HAVE_PROFILE
|
|
|
|
case 'p':
|
|
|
|
sim_set_profile (atoi (optarg));
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sim_set_profile_size (atoi (optarg));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 't':
|
|
|
|
trace = 1;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
/* Things that are printed with -v are the kinds of things that
|
|
|
|
gcc -v prints. This is not meant to include detailed tracing
|
|
|
|
or debugging information, just summaries. */
|
|
|
|
verbose = 1;
|
|
|
|
/* sim_set_verbose (1); */
|
|
|
|
break;
|
|
|
|
/* FIXME: Quick hack, to be replaced by more general facility. */
|
|
|
|
default:
|
2008-06-07 09:31:27 +08:00
|
|
|
usage (0);
|
1999-04-16 09:35:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ac -= optind;
|
|
|
|
av += optind;
|
|
|
|
if (ac <= 0)
|
2008-06-07 09:31:27 +08:00
|
|
|
usage (0);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
name = *av;
|
|
|
|
prog_args = av;
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
printf ("%s %s\n", myname, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
abfd = bfd_openr (name, 0);
|
2002-05-31 10:17:26 +08:00
|
|
|
if (!abfd)
|
1999-04-16 09:35:26 +08:00
|
|
|
{
|
2002-05-31 10:17:26 +08:00
|
|
|
fprintf (stderr, "%s: can't open %s: %s\n",
|
1999-04-16 09:35:26 +08:00
|
|
|
myname, name, bfd_errmsg (bfd_get_error ()));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bfd_check_format (abfd, bfd_object))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: can't load %s: %s\n",
|
|
|
|
myname, name, bfd_errmsg (bfd_get_error ()));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SIM_HAVE_BIENDIAN
|
|
|
|
/* The endianness must be passed to sim_open because one may wish to
|
|
|
|
examine/set registers before calling sim_load [which is the other
|
|
|
|
place where one can determine endianness]. We previously passed the
|
|
|
|
endianness via global `target_byte_order' but that's not a clean
|
|
|
|
interface. */
|
|
|
|
for (i = 1; sim_argv[i + 1] != NULL; ++i)
|
|
|
|
continue;
|
|
|
|
if (bfd_big_endian (abfd))
|
|
|
|
sim_argv[i] = "big";
|
|
|
|
else
|
|
|
|
sim_argv[i] = "little";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Ensure that any run-time initialisation that needs to be
|
2002-05-31 10:17:26 +08:00
|
|
|
performed by the simulator can occur. */
|
1999-04-16 09:35:26 +08:00
|
|
|
sd = sim_open (SIM_OPEN_STANDALONE, &default_callback, abfd, sim_argv);
|
|
|
|
if (sd == 0)
|
|
|
|
exit (1);
|
|
|
|
|
|
|
|
if (sim_load (sd, name, abfd, 0) == SIM_RC_FAIL)
|
|
|
|
exit (1);
|
|
|
|
|
|
|
|
if (sim_create_inferior (sd, abfd, prog_args, NULL) == SIM_RC_FAIL)
|
|
|
|
exit (1);
|
|
|
|
|
2000-02-22 16:52:21 +08:00
|
|
|
#ifdef SIM_HAVE_ENVIRONMENT
|
|
|
|
/* NOTE: An old simulator supporting the operating environment MUST
|
|
|
|
provide sim_set_trace() and not sim_trace(). That way
|
2002-05-31 10:17:26 +08:00
|
|
|
sim_stop_reason() can be used to determine any stop reason. */
|
2000-02-22 16:52:21 +08:00
|
|
|
if (trace)
|
|
|
|
sim_set_trace ();
|
2000-05-23 19:34:27 +08:00
|
|
|
sigrc = 0;
|
2000-02-22 16:52:21 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
prev_sigint = signal (SIGINT, cntrl_c);
|
|
|
|
sim_resume (sd, 0, sigrc);
|
|
|
|
signal (SIGINT, prev_sigint);
|
|
|
|
sim_stop_reason (sd, &reason, &sigrc);
|
|
|
|
}
|
|
|
|
while (operating_p && reason == sim_stopped && sigrc != SIGINT);
|
|
|
|
#else
|
1999-04-16 09:35:26 +08:00
|
|
|
if (trace)
|
|
|
|
{
|
|
|
|
int done = 0;
|
2000-02-09 13:08:42 +08:00
|
|
|
prev_sigint = signal (SIGINT, cntrl_c);
|
1999-04-16 09:35:26 +08:00
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
done = sim_trace (sd);
|
|
|
|
}
|
2000-02-09 13:08:42 +08:00
|
|
|
signal (SIGINT, prev_sigint);
|
2000-02-22 16:52:21 +08:00
|
|
|
sim_stop_reason (sd, &reason, &sigrc);
|
1999-04-16 09:35:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-02-22 16:52:21 +08:00
|
|
|
prev_sigint = signal (SIGINT, cntrl_c);
|
2000-05-23 19:34:27 +08:00
|
|
|
sigrc = 0;
|
2000-02-22 16:52:21 +08:00
|
|
|
sim_resume (sd, 0, sigrc);
|
|
|
|
signal (SIGINT, prev_sigint);
|
|
|
|
sim_stop_reason (sd, &reason, &sigrc);
|
1999-04-16 09:35:26 +08:00
|
|
|
}
|
2000-02-22 16:52:21 +08:00
|
|
|
#endif
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
sim_info (sd, 0);
|
|
|
|
sim_close (sd, 0);
|
|
|
|
|
|
|
|
/* If reason is sim_exited, then sigrc holds the exit code which we want
|
|
|
|
to return. If reason is sim_stopped or sim_signalled, then sigrc holds
|
|
|
|
the signal that the simulator received; we want to return that to
|
|
|
|
indicate failure. */
|
|
|
|
|
|
|
|
/* Why did we stop? */
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case sim_signalled:
|
|
|
|
case sim_stopped:
|
|
|
|
if (sigrc != 0)
|
2002-05-31 10:17:26 +08:00
|
|
|
fprintf (stderr, "program stopped with signal %d.\n", sigrc);
|
1999-04-16 09:35:26 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sim_exited:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sim_running:
|
2002-05-31 10:17:26 +08:00
|
|
|
case sim_polling: /* These indicate a serious problem. */
|
1999-04-16 09:35:26 +08:00
|
|
|
abort ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return sigrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-07 09:31:27 +08:00
|
|
|
usage (int help)
|
1999-04-16 09:35:26 +08:00
|
|
|
{
|
2008-06-07 09:31:27 +08:00
|
|
|
FILE *stream = help ? stdout : stderr;
|
|
|
|
|
|
|
|
fprintf (stream, "Usage: %s [options] program [program args]\n", myname);
|
|
|
|
fprintf (stream, "Options:\n");
|
|
|
|
fprintf (stream, "-a args Pass `args' to simulator.\n");
|
1999-04-16 09:35:26 +08:00
|
|
|
#ifdef SIM_HAVE_SIMCACHE
|
2008-06-07 09:31:27 +08:00
|
|
|
fprintf (stream, "-c size Set simulator cache size to `size'.\n");
|
1999-04-16 09:35:26 +08:00
|
|
|
#endif
|
2008-06-07 09:31:27 +08:00
|
|
|
fprintf (stream, "-m size Set memory size of simulator, in bytes.\n");
|
2000-02-22 16:52:21 +08:00
|
|
|
#ifdef SIM_HAVE_ENVIRONMENT
|
2008-06-07 09:31:27 +08:00
|
|
|
fprintf (stream, "-o Select operating (kernel) environment.\n");
|
2000-02-22 16:52:21 +08:00
|
|
|
#endif
|
1999-04-16 09:35:26 +08:00
|
|
|
#ifdef SIM_HAVE_PROFILE
|
2008-06-07 09:31:27 +08:00
|
|
|
fprintf (stream, "-p freq Set profiling frequency.\n");
|
|
|
|
fprintf (stream, "-s size Set profiling size.\n");
|
1999-04-16 09:35:26 +08:00
|
|
|
#endif
|
2008-06-07 09:31:27 +08:00
|
|
|
fprintf (stream, "-t Perform instruction tracing.\n");
|
|
|
|
fprintf (stream, " Note: Very few simulators support tracing.\n");
|
|
|
|
fprintf (stream, "-v Verbose output.\n");
|
|
|
|
fprintf (stream, "\n");
|
|
|
|
fprintf (stream, "program args Arguments to pass to simulated program.\n");
|
|
|
|
fprintf (stream, " Note: Very few simulators support this.\n");
|
2002-05-20 22:32:50 +08:00
|
|
|
#ifdef SIM_TARGET_SWITCHES
|
2008-06-07 09:31:27 +08:00
|
|
|
fprintf (stream, "\nTarget specific options:\n");
|
|
|
|
sim_target_display_usage (help);
|
2002-05-20 22:32:50 +08:00
|
|
|
#endif
|
2008-06-07 09:31:27 +08:00
|
|
|
|
|
|
|
if (help && REPORT_BUGS_TO[0])
|
|
|
|
printf ("Report bugs to %s\n", REPORT_BUGS_TO);
|
|
|
|
|
|
|
|
exit (help ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_version ()
|
|
|
|
{
|
|
|
|
printf ("GNU simulator %s%s\n", PKGVERSION, version);
|
1999-04-16 09:35:26 +08:00
|
|
|
}
|