1 /* run front end support for all the simulators.
2 Copyright (C) 1992, 93-96, 1997 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"
47 #include "remote-sim.h"
50 static void usage
PARAMS ((void));
54 extern host_callback default_callback
;
60 #ifdef NEED_UI_LOOP_HOOK
61 /* Gdb foolery. This is only needed for gdb using a gui. */
62 int (*ui_loop_hook
) PARAMS ((int signo
));
68 cntrl_c (int sig ATTRIBUTE_UNUSED
)
72 fprintf (stderr
, "Quit!\n");
82 RETSIGTYPE (*prev_sigint
) ();
87 #ifdef SIM_HAVE_ENVIRONMENT
91 static char *no_args
[4];
92 char **sim_argv
= &no_args
[0];
97 myname
= av
[0] + strlen (av
[0]);
98 while (myname
> av
[0] && myname
[-1] != '/')
101 /* The first element of sim_open's argv is the program name. */
103 #ifdef SIM_HAVE_BIENDIAN
105 no_args
[2] = "set-later";
108 /* FIXME: This is currently being migrated into sim_open.
109 Simulators that use functions such as sim_size() still require
111 default_callback
.init (&default_callback
);
112 sim_set_callbacks (&default_callback
);
114 /* FIXME: This is currently being rewritten to have each simulator
115 do all argv processing. */
117 #ifdef SIM_H8300 /* FIXME: quick hack */
118 while ((i
= getopt (ac
, av
, "a:c:m:op:s:htv")) != EOF
)
120 while ((i
= getopt (ac
, av
, "a:c:m:op:s:tv")) != EOF
)
125 /* FIXME: Temporary hack. */
127 int len
= strlen (av
[0]) + strlen (optarg
);
128 char *argbuf
= (char *) alloca (len
+ 2 + 50);
129 sprintf (argbuf
, "%s %s", av
[0], optarg
);
130 #ifdef SIM_HAVE_BIENDIAN
131 /* The desired endianness must be passed to sim_open.
132 The value for "set-later" is set when we know what it is.
133 -E support isn't yet part of the published interface. */
134 strcat (argbuf
, " -E set-later");
136 sim_argv
= buildargv (argbuf
);
139 #ifdef SIM_HAVE_SIMCACHE
141 sim_set_simcache_size (atoi (optarg
));
145 /* FIXME: Rename to sim_set_mem_size. */
146 sim_size (atoi (optarg
));
148 #ifdef SIM_HAVE_ENVIRONMENT
150 /* Operating enironment where any signals are delivered to the
154 #endif SIM_HAVE_ENVIRONMENT
155 #ifdef SIM_HAVE_PROFILE
157 sim_set_profile (atoi (optarg
));
160 sim_set_profile_size (atoi (optarg
));
167 /* Things that are printed with -v are the kinds of things that
168 gcc -v prints. This is not meant to include detailed tracing
169 or debugging information, just summaries. */
171 /* sim_set_verbose (1); */
173 /* FIXME: Quick hack, to be replaced by more general facility. */
193 printf ("%s %s\n", myname
, name
);
196 abfd
= bfd_openr (name
, 0);
199 fprintf (stderr
, "%s: can't open %s: %s\n",
200 myname
, name
, bfd_errmsg (bfd_get_error ()));
204 if (!bfd_check_format (abfd
, bfd_object
))
206 fprintf (stderr
, "%s: can't load %s: %s\n",
207 myname
, name
, bfd_errmsg (bfd_get_error ()));
211 #ifdef SIM_HAVE_BIENDIAN
212 /* The endianness must be passed to sim_open because one may wish to
213 examine/set registers before calling sim_load [which is the other
214 place where one can determine endianness]. We previously passed the
215 endianness via global `target_byte_order' but that's not a clean
217 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
219 if (bfd_big_endian (abfd
))
222 sim_argv
[i
] = "little";
225 /* Ensure that any run-time initialisation that needs to be
226 performed by the simulator can occur. */
227 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
231 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
234 if (sim_create_inferior (sd
, abfd
, prog_args
, NULL
) == SIM_RC_FAIL
)
237 #ifdef SIM_HAVE_ENVIRONMENT
238 /* NOTE: An old simulator supporting the operating environment MUST
239 provide sim_set_trace() and not sim_trace(). That way
240 sim_stop_reason() can be used to determine any stop reason. */
246 prev_sigint
= signal (SIGINT
, cntrl_c
);
247 sim_resume (sd
, 0, sigrc
);
248 signal (SIGINT
, prev_sigint
);
249 sim_stop_reason (sd
, &reason
, &sigrc
);
251 while (operating_p
&& reason
== sim_stopped
&& sigrc
!= SIGINT
);
256 prev_sigint
= signal (SIGINT
, cntrl_c
);
259 done
= sim_trace (sd
);
261 signal (SIGINT
, prev_sigint
);
262 sim_stop_reason (sd
, &reason
, &sigrc
);
266 prev_sigint
= signal (SIGINT
, cntrl_c
);
268 sim_resume (sd
, 0, sigrc
);
269 signal (SIGINT
, prev_sigint
);
270 sim_stop_reason (sd
, &reason
, &sigrc
);
278 /* If reason is sim_exited, then sigrc holds the exit code which we want
279 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
280 the signal that the simulator received; we want to return that to
283 #ifdef SIM_H8300 /* FIXME: Ugh. grep for SLEEP in compile.c */
288 /* Why did we stop? */
294 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
301 case sim_polling
: /* these indicate a serious problem */
314 fprintf (stderr
, "Usage: %s [options] program [program args]\n", myname
);
315 fprintf (stderr
, "Options:\n");
316 fprintf (stderr
, "-a args Pass `args' to simulator.\n");
317 #ifdef SIM_HAVE_SIMCACHE
318 fprintf (stderr
, "-c size Set simulator cache size to `size'.\n");
321 fprintf (stderr
, "-h Executable is for H8/300H or H8/S.\n");
323 fprintf (stderr
, "-m size Set memory size of simulator, in bytes.\n");
324 #ifdef SIM_HAVE_ENVIRONMENT
325 fprintf (stderr
, "-o Select operating (kernel) environment.\n");
327 #ifdef SIM_HAVE_PROFILE
328 fprintf (stderr
, "-p freq Set profiling frequency.\n");
329 fprintf (stderr
, "-s size Set profiling size.\n");
331 fprintf (stderr
, "-t Perform instruction tracing.\n");
332 fprintf (stderr
, " Note: Very few simulators support tracing.\n");
333 fprintf (stderr
, "-v Verbose output.\n");
334 fprintf (stderr
, "\n");
335 fprintf (stderr
, "program args Arguments to pass to simulated program.\n");
336 fprintf (stderr
, " Note: Very few simulators support this.\n");