1 /* run front end support for all the simulators.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004 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 2, or (at your option)
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 along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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"
54 static void usage
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 /* FIXME: This is currently being rewritten to have each simulator
123 do all argv processing. */
125 while ((i
= getopt (ac
, av
, "a:c:m:op:s:tv")) != EOF
)
129 /* FIXME: Temporary hack. */
131 int len
= strlen (av
[0]) + strlen (optarg
);
132 char *argbuf
= (char *) alloca (len
+ 2 + 50);
133 sprintf (argbuf
, "%s %s", av
[0], optarg
);
134 #ifdef SIM_HAVE_BIENDIAN
135 /* The desired endianness must be passed to sim_open.
136 The value for "set-later" is set when we know what it is.
137 -E support isn't yet part of the published interface. */
138 strcat (argbuf
, " -E set-later");
140 sim_argv
= buildargv (argbuf
);
143 #ifdef SIM_HAVE_SIMCACHE
145 sim_set_simcache_size (atoi (optarg
));
149 /* FIXME: Rename to sim_set_mem_size. */
150 sim_size (atoi (optarg
));
152 #ifdef SIM_HAVE_ENVIRONMENT
154 /* Operating enironment where any signals are delivered to the
159 #ifdef SIM_HAVE_PROFILE
161 sim_set_profile (atoi (optarg
));
164 sim_set_profile_size (atoi (optarg
));
171 /* Things that are printed with -v are the kinds of things that
172 gcc -v prints. This is not meant to include detailed tracing
173 or debugging information, just summaries. */
175 /* sim_set_verbose (1); */
177 /* FIXME: Quick hack, to be replaced by more general facility. */
192 printf ("%s %s\n", myname
, name
);
195 abfd
= bfd_openr (name
, 0);
198 fprintf (stderr
, "%s: can't open %s: %s\n",
199 myname
, name
, bfd_errmsg (bfd_get_error ()));
203 if (!bfd_check_format (abfd
, bfd_object
))
205 fprintf (stderr
, "%s: can't load %s: %s\n",
206 myname
, name
, bfd_errmsg (bfd_get_error ()));
210 #ifdef SIM_HAVE_BIENDIAN
211 /* The endianness must be passed to sim_open because one may wish to
212 examine/set registers before calling sim_load [which is the other
213 place where one can determine endianness]. We previously passed the
214 endianness via global `target_byte_order' but that's not a clean
216 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
218 if (bfd_big_endian (abfd
))
221 sim_argv
[i
] = "little";
224 /* Ensure that any run-time initialisation that needs to be
225 performed by the simulator can occur. */
226 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
230 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
233 if (sim_create_inferior (sd
, abfd
, prog_args
, NULL
) == SIM_RC_FAIL
)
236 #ifdef SIM_HAVE_ENVIRONMENT
237 /* NOTE: An old simulator supporting the operating environment MUST
238 provide sim_set_trace() and not sim_trace(). That way
239 sim_stop_reason() can be used to determine any stop reason. */
245 prev_sigint
= signal (SIGINT
, cntrl_c
);
246 sim_resume (sd
, 0, sigrc
);
247 signal (SIGINT
, prev_sigint
);
248 sim_stop_reason (sd
, &reason
, &sigrc
);
250 while (operating_p
&& reason
== sim_stopped
&& sigrc
!= SIGINT
);
255 prev_sigint
= signal (SIGINT
, cntrl_c
);
258 done
= sim_trace (sd
);
260 signal (SIGINT
, prev_sigint
);
261 sim_stop_reason (sd
, &reason
, &sigrc
);
265 prev_sigint
= signal (SIGINT
, cntrl_c
);
267 sim_resume (sd
, 0, sigrc
);
268 signal (SIGINT
, prev_sigint
);
269 sim_stop_reason (sd
, &reason
, &sigrc
);
277 /* If reason is sim_exited, then sigrc holds the exit code which we want
278 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
279 the signal that the simulator received; we want to return that to
282 /* Why did we stop? */
288 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
295 case sim_polling
: /* These indicate a serious problem. */
307 fprintf (stderr
, "Usage: %s [options] program [program args]\n", myname
);
308 fprintf (stderr
, "Options:\n");
309 fprintf (stderr
, "-a args Pass `args' to simulator.\n");
310 #ifdef SIM_HAVE_SIMCACHE
311 fprintf (stderr
, "-c size Set simulator cache size to `size'.\n");
313 fprintf (stderr
, "-m size Set memory size of simulator, in bytes.\n");
314 #ifdef SIM_HAVE_ENVIRONMENT
315 fprintf (stderr
, "-o Select operating (kernel) environment.\n");
317 #ifdef SIM_HAVE_PROFILE
318 fprintf (stderr
, "-p freq Set profiling frequency.\n");
319 fprintf (stderr
, "-s size Set profiling size.\n");
321 fprintf (stderr
, "-t Perform instruction tracing.\n");
322 fprintf (stderr
, " Note: Very few simulators support tracing.\n");
323 fprintf (stderr
, "-v Verbose output.\n");
324 fprintf (stderr
, "\n");
325 fprintf (stderr
, "program args Arguments to pass to simulated program.\n");
326 fprintf (stderr
, " Note: Very few simulators support this.\n");
327 #ifdef SIM_TARGET_SWITCHES
328 fprintf (stderr
, "\nTarget specific options:\n");
329 sim_target_display_usage ();