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"
53 static void usage
PARAMS ((void));
57 extern host_callback default_callback
;
63 #ifdef NEED_UI_LOOP_HOOK
64 /* Gdb foolery. This is only needed for gdb using a gui. */
65 int (*deprecated_ui_loop_hook
) PARAMS ((int signo
));
71 cntrl_c (int sig ATTRIBUTE_UNUSED
)
75 fprintf (stderr
, "Quit!\n");
85 RETSIGTYPE (*prev_sigint
) ();
90 #ifdef SIM_HAVE_ENVIRONMENT
94 static char *no_args
[4];
95 char **sim_argv
= &no_args
[0];
100 myname
= av
[0] + strlen (av
[0]);
101 while (myname
> av
[0] && myname
[-1] != '/')
104 /* The first element of sim_open's argv is the program name. */
106 #ifdef SIM_HAVE_BIENDIAN
108 no_args
[2] = "set-later";
111 /* FIXME: This is currently being migrated into sim_open.
112 Simulators that use functions such as sim_size() still require
114 default_callback
.init (&default_callback
);
115 sim_set_callbacks (&default_callback
);
117 #ifdef SIM_TARGET_SWITCHES
118 ac
= sim_target_parse_command_line (ac
, av
);
121 /* FIXME: This is currently being rewritten to have each simulator
122 do all argv processing. */
124 while ((i
= getopt (ac
, av
, "a:c:m:op:s:tv")) != EOF
)
128 /* FIXME: Temporary hack. */
130 int len
= strlen (av
[0]) + strlen (optarg
);
131 char *argbuf
= (char *) alloca (len
+ 2 + 50);
132 sprintf (argbuf
, "%s %s", av
[0], optarg
);
133 #ifdef SIM_HAVE_BIENDIAN
134 /* The desired endianness must be passed to sim_open.
135 The value for "set-later" is set when we know what it is.
136 -E support isn't yet part of the published interface. */
137 strcat (argbuf
, " -E set-later");
139 sim_argv
= buildargv (argbuf
);
142 #ifdef SIM_HAVE_SIMCACHE
144 sim_set_simcache_size (atoi (optarg
));
148 /* FIXME: Rename to sim_set_mem_size. */
149 sim_size (atoi (optarg
));
151 #ifdef SIM_HAVE_ENVIRONMENT
153 /* Operating enironment where any signals are delivered to the
158 #ifdef SIM_HAVE_PROFILE
160 sim_set_profile (atoi (optarg
));
163 sim_set_profile_size (atoi (optarg
));
170 /* Things that are printed with -v are the kinds of things that
171 gcc -v prints. This is not meant to include detailed tracing
172 or debugging information, just summaries. */
174 /* sim_set_verbose (1); */
176 /* FIXME: Quick hack, to be replaced by more general facility. */
191 printf ("%s %s\n", myname
, name
);
194 abfd
= bfd_openr (name
, 0);
197 fprintf (stderr
, "%s: can't open %s: %s\n",
198 myname
, name
, bfd_errmsg (bfd_get_error ()));
202 if (!bfd_check_format (abfd
, bfd_object
))
204 fprintf (stderr
, "%s: can't load %s: %s\n",
205 myname
, name
, bfd_errmsg (bfd_get_error ()));
209 #ifdef SIM_HAVE_BIENDIAN
210 /* The endianness must be passed to sim_open because one may wish to
211 examine/set registers before calling sim_load [which is the other
212 place where one can determine endianness]. We previously passed the
213 endianness via global `target_byte_order' but that's not a clean
215 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
217 if (bfd_big_endian (abfd
))
220 sim_argv
[i
] = "little";
223 /* Ensure that any run-time initialisation that needs to be
224 performed by the simulator can occur. */
225 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
229 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
232 if (sim_create_inferior (sd
, abfd
, prog_args
, NULL
) == SIM_RC_FAIL
)
235 #ifdef SIM_HAVE_ENVIRONMENT
236 /* NOTE: An old simulator supporting the operating environment MUST
237 provide sim_set_trace() and not sim_trace(). That way
238 sim_stop_reason() can be used to determine any stop reason. */
244 prev_sigint
= signal (SIGINT
, cntrl_c
);
245 sim_resume (sd
, 0, sigrc
);
246 signal (SIGINT
, prev_sigint
);
247 sim_stop_reason (sd
, &reason
, &sigrc
);
249 while (operating_p
&& reason
== sim_stopped
&& sigrc
!= SIGINT
);
254 prev_sigint
= signal (SIGINT
, cntrl_c
);
257 done
= sim_trace (sd
);
259 signal (SIGINT
, prev_sigint
);
260 sim_stop_reason (sd
, &reason
, &sigrc
);
264 prev_sigint
= signal (SIGINT
, cntrl_c
);
266 sim_resume (sd
, 0, sigrc
);
267 signal (SIGINT
, prev_sigint
);
268 sim_stop_reason (sd
, &reason
, &sigrc
);
276 /* If reason is sim_exited, then sigrc holds the exit code which we want
277 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
278 the signal that the simulator received; we want to return that to
281 /* Why did we stop? */
287 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
294 case sim_polling
: /* These indicate a serious problem. */
306 fprintf (stderr
, "Usage: %s [options] program [program args]\n", myname
);
307 fprintf (stderr
, "Options:\n");
308 fprintf (stderr
, "-a args Pass `args' to simulator.\n");
309 #ifdef SIM_HAVE_SIMCACHE
310 fprintf (stderr
, "-c size Set simulator cache size to `size'.\n");
312 fprintf (stderr
, "-m size Set memory size of simulator, in bytes.\n");
313 #ifdef SIM_HAVE_ENVIRONMENT
314 fprintf (stderr
, "-o Select operating (kernel) environment.\n");
316 #ifdef SIM_HAVE_PROFILE
317 fprintf (stderr
, "-p freq Set profiling frequency.\n");
318 fprintf (stderr
, "-s size Set profiling size.\n");
320 fprintf (stderr
, "-t Perform instruction tracing.\n");
321 fprintf (stderr
, " Note: Very few simulators support tracing.\n");
322 fprintf (stderr
, "-v Verbose output.\n");
323 fprintf (stderr
, "\n");
324 fprintf (stderr
, "program args Arguments to pass to simulated program.\n");
325 fprintf (stderr
, " Note: Very few simulators support this.\n");
326 #ifdef SIM_TARGET_SWITCHES
327 fprintf (stderr
, "\nTarget specific options:\n");
328 sim_target_display_usage ();