1 /* run front end support for all the simulators.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Steve Chamberlain sac@cygnus.com,
20 and others at Cygnus. */
47 #include "libiberty.h"
49 #include "gdb/callback.h"
50 #include "gdb/remote-sim.h"
55 static void usage
PARAMS ((int help
));
56 static void print_version
PARAMS ((void));
60 extern host_callback default_callback
;
66 #ifdef NEED_UI_LOOP_HOOK
67 /* Gdb foolery. This is only needed for gdb using a gui. */
68 int (*deprecated_ui_loop_hook
) PARAMS ((int signo
));
74 cntrl_c (int sig ATTRIBUTE_UNUSED
)
78 fprintf (stderr
, "Quit!\n");
88 RETSIGTYPE (*prev_sigint
) ();
93 #ifdef SIM_HAVE_ENVIRONMENT
97 static char *no_args
[4];
98 char **sim_argv
= &no_args
[0];
100 enum sim_stop reason
;
103 myname
= av
[0] + strlen (av
[0]);
104 while (myname
> av
[0] && myname
[-1] != '/')
107 /* The first element of sim_open's argv is the program name. */
109 #ifdef SIM_HAVE_BIENDIAN
111 no_args
[2] = "set-later";
114 /* FIXME: This is currently being migrated into sim_open.
115 Simulators that use functions such as sim_size() still require
117 default_callback
.init (&default_callback
);
118 sim_set_callbacks (&default_callback
);
120 #ifdef SIM_TARGET_SWITCHES
121 ac
= sim_target_parse_command_line (ac
, av
);
124 for (i
= 1; av
[i
]; ++i
)
126 if (strcmp (av
[i
], "--help") == 0)
130 else if (strcmp (av
[i
], "--version") == 0)
137 /* FIXME: This is currently being rewritten to have each simulator
138 do all argv processing. */
140 while ((i
= getopt (ac
, av
, "a:c:m:op:s:tv")) != EOF
)
144 /* FIXME: Temporary hack. */
146 int len
= strlen (av
[0]) + strlen (optarg
);
147 char *argbuf
= (char *) alloca (len
+ 2 + 50);
148 sprintf (argbuf
, "%s %s", av
[0], optarg
);
149 #ifdef SIM_HAVE_BIENDIAN
150 /* The desired endianness must be passed to sim_open.
151 The value for "set-later" is set when we know what it is.
152 -E support isn't yet part of the published interface. */
153 strcat (argbuf
, " -E set-later");
155 sim_argv
= buildargv (argbuf
);
158 #ifdef SIM_HAVE_SIMCACHE
160 sim_set_simcache_size (atoi (optarg
));
164 /* FIXME: Rename to sim_set_mem_size. */
165 sim_size (atoi (optarg
));
167 #ifdef SIM_HAVE_ENVIRONMENT
169 /* Operating enironment where any signals are delivered to the
174 #ifdef SIM_HAVE_PROFILE
176 sim_set_profile (atoi (optarg
));
179 sim_set_profile_size (atoi (optarg
));
186 /* Things that are printed with -v are the kinds of things that
187 gcc -v prints. This is not meant to include detailed tracing
188 or debugging information, just summaries. */
190 /* sim_set_verbose (1); */
192 /* FIXME: Quick hack, to be replaced by more general facility. */
207 printf ("%s %s\n", myname
, name
);
210 abfd
= bfd_openr (name
, 0);
213 fprintf (stderr
, "%s: can't open %s: %s\n",
214 myname
, name
, bfd_errmsg (bfd_get_error ()));
218 if (!bfd_check_format (abfd
, bfd_object
))
220 fprintf (stderr
, "%s: can't load %s: %s\n",
221 myname
, name
, bfd_errmsg (bfd_get_error ()));
225 #ifdef SIM_HAVE_BIENDIAN
226 /* The endianness must be passed to sim_open because one may wish to
227 examine/set registers before calling sim_load [which is the other
228 place where one can determine endianness]. We previously passed the
229 endianness via global `target_byte_order' but that's not a clean
231 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
233 if (bfd_big_endian (abfd
))
236 sim_argv
[i
] = "little";
239 /* Ensure that any run-time initialisation that needs to be
240 performed by the simulator can occur. */
241 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
245 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
248 if (sim_create_inferior (sd
, abfd
, prog_args
, NULL
) == SIM_RC_FAIL
)
251 #ifdef SIM_HAVE_ENVIRONMENT
252 /* NOTE: An old simulator supporting the operating environment MUST
253 provide sim_set_trace() and not sim_trace(). That way
254 sim_stop_reason() can be used to determine any stop reason. */
260 prev_sigint
= signal (SIGINT
, cntrl_c
);
261 sim_resume (sd
, 0, sigrc
);
262 signal (SIGINT
, prev_sigint
);
263 sim_stop_reason (sd
, &reason
, &sigrc
);
265 while (operating_p
&& reason
== sim_stopped
&& sigrc
!= SIGINT
);
270 prev_sigint
= signal (SIGINT
, cntrl_c
);
273 done
= sim_trace (sd
);
275 signal (SIGINT
, prev_sigint
);
276 sim_stop_reason (sd
, &reason
, &sigrc
);
280 prev_sigint
= signal (SIGINT
, cntrl_c
);
282 sim_resume (sd
, 0, sigrc
);
283 signal (SIGINT
, prev_sigint
);
284 sim_stop_reason (sd
, &reason
, &sigrc
);
292 /* If reason is sim_exited, then sigrc holds the exit code which we want
293 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
294 the signal that the simulator received; we want to return that to
297 /* Why did we stop? */
303 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
310 case sim_polling
: /* These indicate a serious problem. */
322 FILE *stream
= help
? stdout
: stderr
;
324 fprintf (stream
, "Usage: %s [options] program [program args]\n", myname
);
325 fprintf (stream
, "Options:\n");
326 fprintf (stream
, "-a args Pass `args' to simulator.\n");
327 #ifdef SIM_HAVE_SIMCACHE
328 fprintf (stream
, "-c size Set simulator cache size to `size'.\n");
330 fprintf (stream
, "-m size Set memory size of simulator, in bytes.\n");
331 #ifdef SIM_HAVE_ENVIRONMENT
332 fprintf (stream
, "-o Select operating (kernel) environment.\n");
334 #ifdef SIM_HAVE_PROFILE
335 fprintf (stream
, "-p freq Set profiling frequency.\n");
336 fprintf (stream
, "-s size Set profiling size.\n");
338 fprintf (stream
, "-t Perform instruction tracing.\n");
339 fprintf (stream
, " Note: Very few simulators support tracing.\n");
340 fprintf (stream
, "-v Verbose output.\n");
341 fprintf (stream
, "\n");
342 fprintf (stream
, "program args Arguments to pass to simulated program.\n");
343 fprintf (stream
, " Note: Very few simulators support this.\n");
344 #ifdef SIM_TARGET_SWITCHES
345 fprintf (stream
, "\nTarget specific options:\n");
346 sim_target_display_usage (help
);
349 if (help
&& REPORT_BUGS_TO
[0])
350 printf ("Report bugs to %s\n", REPORT_BUGS_TO
);
358 printf ("GNU simulator %s%s\n", PKGVERSION
, version
);