1 /* run front end support for all the simulators.
2 Copyright (C) 1992, 93-96, 1997, 2002 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 2, or (at your option)
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 along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Steve Chamberlain sac@cygnus.com,
19 and others at Cygnus. */
44 #include "libiberty.h"
46 #include "gdb/callback.h"
47 #include "gdb/remote-sim.h"
51 static void usage
PARAMS ((void));
55 extern host_callback default_callback
;
61 #ifdef NEED_UI_LOOP_HOOK
62 /* Gdb foolery. This is only needed for gdb using a gui. */
63 int (*ui_loop_hook
) PARAMS ((int signo
));
69 cntrl_c (int sig ATTRIBUTE_UNUSED
)
73 fprintf (stderr
, "Quit!\n");
83 RETSIGTYPE (*prev_sigint
) ();
88 #ifdef SIM_HAVE_ENVIRONMENT
92 static char *no_args
[4];
93 char **sim_argv
= &no_args
[0];
98 myname
= av
[0] + strlen (av
[0]);
99 while (myname
> av
[0] && myname
[-1] != '/')
102 /* The first element of sim_open's argv is the program name. */
104 #ifdef SIM_HAVE_BIENDIAN
106 no_args
[2] = "set-later";
109 /* FIXME: This is currently being migrated into sim_open.
110 Simulators that use functions such as sim_size() still require
112 default_callback
.init (&default_callback
);
113 sim_set_callbacks (&default_callback
);
115 #ifdef SIM_TARGET_SWITCHES
116 ac
= sim_target_parse_command_line (ac
, av
);
119 /* FIXME: This is currently being rewritten to have each simulator
120 do all argv processing. */
122 #ifdef SIM_H8300 /* FIXME: quick hack */
123 while ((i
= getopt (ac
, av
, "a:c:m:op:s:hStv")) != EOF
)
125 while ((i
= getopt (ac
, av
, "a:c:m:op:s:tv")) != EOF
)
130 /* FIXME: Temporary hack. */
132 int len
= strlen (av
[0]) + strlen (optarg
);
133 char *argbuf
= (char *) alloca (len
+ 2 + 50);
134 sprintf (argbuf
, "%s %s", av
[0], optarg
);
135 #ifdef SIM_HAVE_BIENDIAN
136 /* The desired endianness must be passed to sim_open.
137 The value for "set-later" is set when we know what it is.
138 -E support isn't yet part of the published interface. */
139 strcat (argbuf
, " -E set-later");
141 sim_argv
= buildargv (argbuf
);
144 #ifdef SIM_HAVE_SIMCACHE
146 sim_set_simcache_size (atoi (optarg
));
150 /* FIXME: Rename to sim_set_mem_size. */
151 sim_size (atoi (optarg
));
153 #ifdef SIM_HAVE_ENVIRONMENT
155 /* Operating enironment where any signals are delivered to the
159 #endif SIM_HAVE_ENVIRONMENT
160 #ifdef SIM_HAVE_PROFILE
162 sim_set_profile (atoi (optarg
));
165 sim_set_profile_size (atoi (optarg
));
172 /* Things that are printed with -v are the kinds of things that
173 gcc -v prints. This is not meant to include detailed tracing
174 or debugging information, just summaries. */
176 /* sim_set_verbose (1); */
178 /* FIXME: Quick hack, to be replaced by more general facility. */
201 printf ("%s %s\n", myname
, name
);
204 abfd
= bfd_openr (name
, 0);
207 fprintf (stderr
, "%s: can't open %s: %s\n",
208 myname
, name
, bfd_errmsg (bfd_get_error ()));
212 if (!bfd_check_format (abfd
, bfd_object
))
214 fprintf (stderr
, "%s: can't load %s: %s\n",
215 myname
, name
, bfd_errmsg (bfd_get_error ()));
219 #ifdef SIM_HAVE_BIENDIAN
220 /* The endianness must be passed to sim_open because one may wish to
221 examine/set registers before calling sim_load [which is the other
222 place where one can determine endianness]. We previously passed the
223 endianness via global `target_byte_order' but that's not a clean
225 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
227 if (bfd_big_endian (abfd
))
230 sim_argv
[i
] = "little";
233 /* Ensure that any run-time initialisation that needs to be
234 performed by the simulator can occur. */
235 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
239 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
242 if (sim_create_inferior (sd
, abfd
, prog_args
, NULL
) == SIM_RC_FAIL
)
245 #ifdef SIM_HAVE_ENVIRONMENT
246 /* NOTE: An old simulator supporting the operating environment MUST
247 provide sim_set_trace() and not sim_trace(). That way
248 sim_stop_reason() can be used to determine any stop reason. */
254 prev_sigint
= signal (SIGINT
, cntrl_c
);
255 sim_resume (sd
, 0, sigrc
);
256 signal (SIGINT
, prev_sigint
);
257 sim_stop_reason (sd
, &reason
, &sigrc
);
259 while (operating_p
&& reason
== sim_stopped
&& sigrc
!= SIGINT
);
264 prev_sigint
= signal (SIGINT
, cntrl_c
);
267 done
= sim_trace (sd
);
269 signal (SIGINT
, prev_sigint
);
270 sim_stop_reason (sd
, &reason
, &sigrc
);
274 prev_sigint
= signal (SIGINT
, cntrl_c
);
276 sim_resume (sd
, 0, sigrc
);
277 signal (SIGINT
, prev_sigint
);
278 sim_stop_reason (sd
, &reason
, &sigrc
);
286 /* If reason is sim_exited, then sigrc holds the exit code which we want
287 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
288 the signal that the simulator received; we want to return that to
291 #ifdef SIM_H8300 /* FIXME: Ugh. grep for SLEEP in compile.c */
296 /* Why did we stop? */
302 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
309 case sim_polling
: /* These indicate a serious problem. */
322 fprintf (stderr
, "Usage: %s [options] program [program args]\n", myname
);
323 fprintf (stderr
, "Options:\n");
324 fprintf (stderr
, "-a args Pass `args' to simulator.\n");
325 #ifdef SIM_HAVE_SIMCACHE
326 fprintf (stderr
, "-c size Set simulator cache size to `size'.\n");
329 fprintf (stderr
, "-h Executable is for h8/300h.\n");
330 fprintf (stderr
, "-S Executable is for h8/300s.\n");
332 fprintf (stderr
, "-m size Set memory size of simulator, in bytes.\n");
333 #ifdef SIM_HAVE_ENVIRONMENT
334 fprintf (stderr
, "-o Select operating (kernel) environment.\n");
336 #ifdef SIM_HAVE_PROFILE
337 fprintf (stderr
, "-p freq Set profiling frequency.\n");
338 fprintf (stderr
, "-s size Set profiling size.\n");
340 fprintf (stderr
, "-t Perform instruction tracing.\n");
341 fprintf (stderr
, " Note: Very few simulators support tracing.\n");
342 fprintf (stderr
, "-v Verbose output.\n");
343 fprintf (stderr
, "\n");
344 fprintf (stderr
, "program args Arguments to pass to simulated program.\n");
345 fprintf (stderr
, " Note: Very few simulators support this.\n");
346 #ifdef SIM_TARGET_SWITCHES
347 fprintf (stderr
, "\nTarget specific options:\n");
348 sim_target_display_usage ();