1 /* run front end support for all the simulators.
2 Copyright (C) 1992-2015 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Steve Chamberlain sac@cygnus.com,
18 and others at Cygnus. */
45 #include "libiberty.h"
47 #include "gdb/callback.h"
48 #include "gdb/remote-sim.h"
53 #ifdef SIM_USE_DEPRECATED_RUN_FRONTEND
54 # warning "This sim is using the deprecated run.c; please migrate to nrun.c."
56 # error "Please do not create new sim ports using run.c; use nrun.c instead." \
57 "New submissions using run.c will not be accepted."
60 static void usage (int help
);
61 static void print_version (void);
65 extern host_callback default_callback
;
71 #ifdef NEED_UI_LOOP_HOOK
72 /* Gdb foolery. This is only needed for gdb using a gui. */
73 int (*deprecated_ui_loop_hook
) (int signo
);
79 cntrl_c (int sig ATTRIBUTE_UNUSED
)
83 fprintf (stderr
, "Quit!\n");
93 RETSIGTYPE (*prev_sigint
) ();
98 #ifdef SIM_HAVE_ENVIRONMENT
102 static char *no_args
[4];
103 char **sim_argv
= &no_args
[0];
105 enum sim_stop reason
;
108 myname
= av
[0] + strlen (av
[0]);
109 while (myname
> av
[0] && myname
[-1] != '/')
112 /* The first element of sim_open's argv is the program name. */
114 #ifdef SIM_HAVE_BIENDIAN
116 no_args
[2] = "set-later";
119 /* FIXME: This is currently being migrated into sim_open.
120 Simulators that use functions such as sim_size() still require
122 default_callback
.init (&default_callback
);
123 sim_set_callbacks (&default_callback
);
125 #ifdef SIM_TARGET_SWITCHES
126 ac
= sim_target_parse_command_line (ac
, av
);
129 for (i
= 1; av
[i
]; ++i
)
131 if (strcmp (av
[i
], "--help") == 0)
135 else if (strcmp (av
[i
], "--version") == 0)
142 /* FIXME: This is currently being rewritten to have each simulator
143 do all argv processing. */
145 while ((i
= getopt (ac
, av
, "a:c:m:op:s:tv")) != EOF
)
149 /* FIXME: Temporary hack. */
151 int len
= strlen (av
[0]) + strlen (optarg
);
152 char *argbuf
= (char *) alloca (len
+ 2 + 50);
153 sprintf (argbuf
, "%s %s", av
[0], optarg
);
154 #ifdef SIM_HAVE_BIENDIAN
155 /* The desired endianness must be passed to sim_open.
156 The value for "set-later" is set when we know what it is.
157 -E support isn't yet part of the published interface. */
158 strcat (argbuf
, " -E set-later");
160 sim_argv
= buildargv (argbuf
);
163 #ifdef SIM_HAVE_SIMCACHE
165 sim_set_simcache_size (atoi (optarg
));
169 /* FIXME: Rename to sim_set_mem_size. */
170 sim_size (atoi (optarg
));
172 #ifdef SIM_HAVE_ENVIRONMENT
174 /* Operating enironment where any signals are delivered to the
179 #ifdef SIM_HAVE_PROFILE
181 sim_set_profile (atoi (optarg
));
184 sim_set_profile_size (atoi (optarg
));
191 /* Things that are printed with -v are the kinds of things that
192 gcc -v prints. This is not meant to include detailed tracing
193 or debugging information, just summaries. */
195 /* sim_set_verbose (1); */
197 /* FIXME: Quick hack, to be replaced by more general facility. */
212 printf ("%s %s\n", myname
, name
);
215 abfd
= bfd_openr (name
, 0);
218 fprintf (stderr
, "%s: can't open %s: %s\n",
219 myname
, name
, bfd_errmsg (bfd_get_error ()));
223 if (!bfd_check_format (abfd
, bfd_object
))
225 fprintf (stderr
, "%s: can't load %s: %s\n",
226 myname
, name
, bfd_errmsg (bfd_get_error ()));
230 #ifdef SIM_HAVE_BIENDIAN
231 /* The endianness must be passed to sim_open because one may wish to
232 examine/set registers before calling sim_load [which is the other
233 place where one can determine endianness]. We previously passed the
234 endianness via global `target_byte_order' but that's not a clean
236 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
238 if (bfd_big_endian (abfd
))
241 sim_argv
[i
] = "little";
244 /* Ensure that any run-time initialisation that needs to be
245 performed by the simulator can occur. */
246 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
250 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
253 if (sim_create_inferior (sd
, abfd
, prog_args
, NULL
) == SIM_RC_FAIL
)
256 #ifdef SIM_HAVE_ENVIRONMENT
257 /* NOTE: An old simulator supporting the operating environment MUST
258 provide sim_set_trace() and not sim_trace(). That way
259 sim_stop_reason() can be used to determine any stop reason. */
265 prev_sigint
= signal (SIGINT
, cntrl_c
);
266 sim_resume (sd
, 0, sigrc
);
267 signal (SIGINT
, prev_sigint
);
268 sim_stop_reason (sd
, &reason
, &sigrc
);
270 while (operating_p
&& reason
== sim_stopped
&& sigrc
!= SIGINT
);
275 prev_sigint
= signal (SIGINT
, cntrl_c
);
278 done
= sim_trace (sd
);
280 signal (SIGINT
, prev_sigint
);
281 sim_stop_reason (sd
, &reason
, &sigrc
);
285 prev_sigint
= signal (SIGINT
, cntrl_c
);
287 sim_resume (sd
, 0, sigrc
);
288 signal (SIGINT
, prev_sigint
);
289 sim_stop_reason (sd
, &reason
, &sigrc
);
297 /* If reason is sim_exited, then sigrc holds the exit code which we want
298 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
299 the signal that the simulator received; we want to return that to
302 /* Why did we stop? */
308 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
315 case sim_polling
: /* These indicate a serious problem. */
327 FILE *stream
= help
? stdout
: stderr
;
329 fprintf (stream
, "Usage: %s [options] program [program args]\n", myname
);
330 fprintf (stream
, "Options:\n");
331 fprintf (stream
, "-a args Pass `args' to simulator.\n");
332 #ifdef SIM_HAVE_SIMCACHE
333 fprintf (stream
, "-c size Set simulator cache size to `size'.\n");
335 fprintf (stream
, "-m size Set memory size of simulator, in bytes.\n");
336 #ifdef SIM_HAVE_ENVIRONMENT
337 fprintf (stream
, "-o Select operating (kernel) environment.\n");
339 #ifdef SIM_HAVE_PROFILE
340 fprintf (stream
, "-p freq Set profiling frequency.\n");
341 fprintf (stream
, "-s size Set profiling size.\n");
343 fprintf (stream
, "-t Perform instruction tracing.\n");
344 fprintf (stream
, " Note: Very few simulators support tracing.\n");
345 fprintf (stream
, "-v Verbose output.\n");
346 fprintf (stream
, "\n");
347 fprintf (stream
, "program args Arguments to pass to simulated program.\n");
348 fprintf (stream
, " Note: Very few simulators support this.\n");
349 #ifdef SIM_TARGET_SWITCHES
350 fprintf (stream
, "\nTarget specific options:\n");
351 sim_target_display_usage (help
);
354 if (help
&& REPORT_BUGS_TO
[0])
355 printf ("Report bugs to %s\n", REPORT_BUGS_TO
);
363 printf ("GNU simulator %s%s\n", PKGVERSION
, version
);