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 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Steve Chamberlain sac@cygnus.com,
19 and others at Cygnus. */
46 #include "libiberty.h"
48 #include "gdb/callback.h"
49 #include "gdb/remote-sim.h"
54 static void usage
PARAMS ((int help
));
55 static void print_version
PARAMS ((void));
59 extern host_callback default_callback
;
65 #ifdef NEED_UI_LOOP_HOOK
66 /* Gdb foolery. This is only needed for gdb using a gui. */
67 int (*deprecated_ui_loop_hook
) PARAMS ((int signo
));
73 cntrl_c (int sig ATTRIBUTE_UNUSED
)
77 fprintf (stderr
, "Quit!\n");
87 RETSIGTYPE (*prev_sigint
) ();
92 #ifdef SIM_HAVE_ENVIRONMENT
96 static char *no_args
[4];
97 char **sim_argv
= &no_args
[0];
102 myname
= av
[0] + strlen (av
[0]);
103 while (myname
> av
[0] && myname
[-1] != '/')
106 /* The first element of sim_open's argv is the program name. */
108 #ifdef SIM_HAVE_BIENDIAN
110 no_args
[2] = "set-later";
113 /* FIXME: This is currently being migrated into sim_open.
114 Simulators that use functions such as sim_size() still require
116 default_callback
.init (&default_callback
);
117 sim_set_callbacks (&default_callback
);
119 #ifdef SIM_TARGET_SWITCHES
120 ac
= sim_target_parse_command_line (ac
, av
);
123 for (i
= 1; av
[i
]; ++i
)
125 if (strcmp (av
[i
], "--help") == 0)
129 else if (strcmp (av
[i
], "--version") == 0)
136 /* FIXME: This is currently being rewritten to have each simulator
137 do all argv processing. */
139 while ((i
= getopt (ac
, av
, "a:c:m:op:s:tv")) != EOF
)
143 /* FIXME: Temporary hack. */
145 int len
= strlen (av
[0]) + strlen (optarg
);
146 char *argbuf
= (char *) alloca (len
+ 2 + 50);
147 sprintf (argbuf
, "%s %s", av
[0], optarg
);
148 #ifdef SIM_HAVE_BIENDIAN
149 /* The desired endianness must be passed to sim_open.
150 The value for "set-later" is set when we know what it is.
151 -E support isn't yet part of the published interface. */
152 strcat (argbuf
, " -E set-later");
154 sim_argv
= buildargv (argbuf
);
157 #ifdef SIM_HAVE_SIMCACHE
159 sim_set_simcache_size (atoi (optarg
));
163 /* FIXME: Rename to sim_set_mem_size. */
164 sim_size (atoi (optarg
));
166 #ifdef SIM_HAVE_ENVIRONMENT
168 /* Operating enironment where any signals are delivered to the
173 #ifdef SIM_HAVE_PROFILE
175 sim_set_profile (atoi (optarg
));
178 sim_set_profile_size (atoi (optarg
));
185 /* Things that are printed with -v are the kinds of things that
186 gcc -v prints. This is not meant to include detailed tracing
187 or debugging information, just summaries. */
189 /* sim_set_verbose (1); */
191 /* FIXME: Quick hack, to be replaced by more general facility. */
206 printf ("%s %s\n", myname
, name
);
209 abfd
= bfd_openr (name
, 0);
212 fprintf (stderr
, "%s: can't open %s: %s\n",
213 myname
, name
, bfd_errmsg (bfd_get_error ()));
217 if (!bfd_check_format (abfd
, bfd_object
))
219 fprintf (stderr
, "%s: can't load %s: %s\n",
220 myname
, name
, bfd_errmsg (bfd_get_error ()));
224 #ifdef SIM_HAVE_BIENDIAN
225 /* The endianness must be passed to sim_open because one may wish to
226 examine/set registers before calling sim_load [which is the other
227 place where one can determine endianness]. We previously passed the
228 endianness via global `target_byte_order' but that's not a clean
230 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
232 if (bfd_big_endian (abfd
))
235 sim_argv
[i
] = "little";
238 /* Ensure that any run-time initialisation that needs to be
239 performed by the simulator can occur. */
240 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
244 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
247 if (sim_create_inferior (sd
, abfd
, prog_args
, NULL
) == SIM_RC_FAIL
)
250 #ifdef SIM_HAVE_ENVIRONMENT
251 /* NOTE: An old simulator supporting the operating environment MUST
252 provide sim_set_trace() and not sim_trace(). That way
253 sim_stop_reason() can be used to determine any stop reason. */
259 prev_sigint
= signal (SIGINT
, cntrl_c
);
260 sim_resume (sd
, 0, sigrc
);
261 signal (SIGINT
, prev_sigint
);
262 sim_stop_reason (sd
, &reason
, &sigrc
);
264 while (operating_p
&& reason
== sim_stopped
&& sigrc
!= SIGINT
);
269 prev_sigint
= signal (SIGINT
, cntrl_c
);
272 done
= sim_trace (sd
);
274 signal (SIGINT
, prev_sigint
);
275 sim_stop_reason (sd
, &reason
, &sigrc
);
279 prev_sigint
= signal (SIGINT
, cntrl_c
);
281 sim_resume (sd
, 0, sigrc
);
282 signal (SIGINT
, prev_sigint
);
283 sim_stop_reason (sd
, &reason
, &sigrc
);
291 /* If reason is sim_exited, then sigrc holds the exit code which we want
292 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
293 the signal that the simulator received; we want to return that to
296 /* Why did we stop? */
302 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
309 case sim_polling
: /* These indicate a serious problem. */
321 FILE *stream
= help
? stdout
: stderr
;
323 fprintf (stream
, "Usage: %s [options] program [program args]\n", myname
);
324 fprintf (stream
, "Options:\n");
325 fprintf (stream
, "-a args Pass `args' to simulator.\n");
326 #ifdef SIM_HAVE_SIMCACHE
327 fprintf (stream
, "-c size Set simulator cache size to `size'.\n");
329 fprintf (stream
, "-m size Set memory size of simulator, in bytes.\n");
330 #ifdef SIM_HAVE_ENVIRONMENT
331 fprintf (stream
, "-o Select operating (kernel) environment.\n");
333 #ifdef SIM_HAVE_PROFILE
334 fprintf (stream
, "-p freq Set profiling frequency.\n");
335 fprintf (stream
, "-s size Set profiling size.\n");
337 fprintf (stream
, "-t Perform instruction tracing.\n");
338 fprintf (stream
, " Note: Very few simulators support tracing.\n");
339 fprintf (stream
, "-v Verbose output.\n");
340 fprintf (stream
, "\n");
341 fprintf (stream
, "program args Arguments to pass to simulated program.\n");
342 fprintf (stream
, " Note: Very few simulators support this.\n");
343 #ifdef SIM_TARGET_SWITCHES
344 fprintf (stream
, "\nTarget specific options:\n");
345 sim_target_display_usage (help
);
348 if (help
&& REPORT_BUGS_TO
[0])
349 printf ("Report bugs to %s\n", REPORT_BUGS_TO
);
357 printf ("GNU simulator %s%s\n", PKGVERSION
, version
);