1 /* run front end support for all the simulators.
2 Copyright (C) 1992-2004, 2007-2012 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 static void usage
PARAMS ((int help
));
54 static void print_version
PARAMS ((void));
58 extern host_callback default_callback
;
64 #ifdef NEED_UI_LOOP_HOOK
65 /* Gdb foolery. This is only needed for gdb using a gui. */
66 int (*deprecated_ui_loop_hook
) PARAMS ((int signo
));
72 cntrl_c (int sig ATTRIBUTE_UNUSED
)
76 fprintf (stderr
, "Quit!\n");
86 RETSIGTYPE (*prev_sigint
) ();
91 #ifdef SIM_HAVE_ENVIRONMENT
95 static char *no_args
[4];
96 char **sim_argv
= &no_args
[0];
101 myname
= av
[0] + strlen (av
[0]);
102 while (myname
> av
[0] && myname
[-1] != '/')
105 /* The first element of sim_open's argv is the program name. */
107 #ifdef SIM_HAVE_BIENDIAN
109 no_args
[2] = "set-later";
112 /* FIXME: This is currently being migrated into sim_open.
113 Simulators that use functions such as sim_size() still require
115 default_callback
.init (&default_callback
);
116 sim_set_callbacks (&default_callback
);
118 #ifdef SIM_TARGET_SWITCHES
119 ac
= sim_target_parse_command_line (ac
, av
);
122 for (i
= 1; av
[i
]; ++i
)
124 if (strcmp (av
[i
], "--help") == 0)
128 else if (strcmp (av
[i
], "--version") == 0)
135 /* FIXME: This is currently being rewritten to have each simulator
136 do all argv processing. */
138 while ((i
= getopt (ac
, av
, "a:c:m:op:s:tv")) != EOF
)
142 /* FIXME: Temporary hack. */
144 int len
= strlen (av
[0]) + strlen (optarg
);
145 char *argbuf
= (char *) alloca (len
+ 2 + 50);
146 sprintf (argbuf
, "%s %s", av
[0], optarg
);
147 #ifdef SIM_HAVE_BIENDIAN
148 /* The desired endianness must be passed to sim_open.
149 The value for "set-later" is set when we know what it is.
150 -E support isn't yet part of the published interface. */
151 strcat (argbuf
, " -E set-later");
153 sim_argv
= buildargv (argbuf
);
156 #ifdef SIM_HAVE_SIMCACHE
158 sim_set_simcache_size (atoi (optarg
));
162 /* FIXME: Rename to sim_set_mem_size. */
163 sim_size (atoi (optarg
));
165 #ifdef SIM_HAVE_ENVIRONMENT
167 /* Operating enironment where any signals are delivered to the
172 #ifdef SIM_HAVE_PROFILE
174 sim_set_profile (atoi (optarg
));
177 sim_set_profile_size (atoi (optarg
));
184 /* Things that are printed with -v are the kinds of things that
185 gcc -v prints. This is not meant to include detailed tracing
186 or debugging information, just summaries. */
188 /* sim_set_verbose (1); */
190 /* FIXME: Quick hack, to be replaced by more general facility. */
205 printf ("%s %s\n", myname
, name
);
208 abfd
= bfd_openr (name
, 0);
211 fprintf (stderr
, "%s: can't open %s: %s\n",
212 myname
, name
, bfd_errmsg (bfd_get_error ()));
216 if (!bfd_check_format (abfd
, bfd_object
))
218 fprintf (stderr
, "%s: can't load %s: %s\n",
219 myname
, name
, bfd_errmsg (bfd_get_error ()));
223 #ifdef SIM_HAVE_BIENDIAN
224 /* The endianness must be passed to sim_open because one may wish to
225 examine/set registers before calling sim_load [which is the other
226 place where one can determine endianness]. We previously passed the
227 endianness via global `target_byte_order' but that's not a clean
229 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
231 if (bfd_big_endian (abfd
))
234 sim_argv
[i
] = "little";
237 /* Ensure that any run-time initialisation that needs to be
238 performed by the simulator can occur. */
239 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
243 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
246 if (sim_create_inferior (sd
, abfd
, prog_args
, NULL
) == SIM_RC_FAIL
)
249 #ifdef SIM_HAVE_ENVIRONMENT
250 /* NOTE: An old simulator supporting the operating environment MUST
251 provide sim_set_trace() and not sim_trace(). That way
252 sim_stop_reason() can be used to determine any stop reason. */
258 prev_sigint
= signal (SIGINT
, cntrl_c
);
259 sim_resume (sd
, 0, sigrc
);
260 signal (SIGINT
, prev_sigint
);
261 sim_stop_reason (sd
, &reason
, &sigrc
);
263 while (operating_p
&& reason
== sim_stopped
&& sigrc
!= SIGINT
);
268 prev_sigint
= signal (SIGINT
, cntrl_c
);
271 done
= sim_trace (sd
);
273 signal (SIGINT
, prev_sigint
);
274 sim_stop_reason (sd
, &reason
, &sigrc
);
278 prev_sigint
= signal (SIGINT
, cntrl_c
);
280 sim_resume (sd
, 0, sigrc
);
281 signal (SIGINT
, prev_sigint
);
282 sim_stop_reason (sd
, &reason
, &sigrc
);
290 /* If reason is sim_exited, then sigrc holds the exit code which we want
291 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
292 the signal that the simulator received; we want to return that to
295 /* Why did we stop? */
301 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
308 case sim_polling
: /* These indicate a serious problem. */
320 FILE *stream
= help
? stdout
: stderr
;
322 fprintf (stream
, "Usage: %s [options] program [program args]\n", myname
);
323 fprintf (stream
, "Options:\n");
324 fprintf (stream
, "-a args Pass `args' to simulator.\n");
325 #ifdef SIM_HAVE_SIMCACHE
326 fprintf (stream
, "-c size Set simulator cache size to `size'.\n");
328 fprintf (stream
, "-m size Set memory size of simulator, in bytes.\n");
329 #ifdef SIM_HAVE_ENVIRONMENT
330 fprintf (stream
, "-o Select operating (kernel) environment.\n");
332 #ifdef SIM_HAVE_PROFILE
333 fprintf (stream
, "-p freq Set profiling frequency.\n");
334 fprintf (stream
, "-s size Set profiling size.\n");
336 fprintf (stream
, "-t Perform instruction tracing.\n");
337 fprintf (stream
, " Note: Very few simulators support tracing.\n");
338 fprintf (stream
, "-v Verbose output.\n");
339 fprintf (stream
, "\n");
340 fprintf (stream
, "program args Arguments to pass to simulated program.\n");
341 fprintf (stream
, " Note: Very few simulators support this.\n");
342 #ifdef SIM_TARGET_SWITCHES
343 fprintf (stream
, "\nTarget specific options:\n");
344 sim_target_display_usage (help
);
347 if (help
&& REPORT_BUGS_TO
[0])
348 printf ("Report bugs to %s\n", REPORT_BUGS_TO
);
356 printf ("GNU simulator %s%s\n", PKGVERSION
, version
);