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"
49 #include "../libiberty/alloca-conf.h"
51 static void usage
PARAMS ((void));
55 extern host_callback default_callback
;
60 /* NOTE: sim_size() and sim_trace() are going away */
61 extern int sim_trace
PARAMS ((SIM_DESC sd
));
72 fprintf (stderr
, "Quit!\n");
82 RETSIGTYPE (*prev_sigint
) ();
89 static char *no_args
[4];
90 char **sim_argv
= &no_args
[0];
95 myname
= av
[0] + strlen (av
[0]);
96 while (myname
> av
[0] && myname
[-1] != '/')
99 /* The first element of sim_open's argv is the program name. */
101 #ifdef SIM_HAVE_BIENDIAN
103 no_args
[2] = "set-later";
106 /* FIXME: This is currently being migrated into sim_open.
107 Simulators that use functions such as sim_size() still require
109 default_callback
.init (&default_callback
);
110 sim_set_callbacks (&default_callback
);
112 /* FIXME: This is currently being rewritten to have each simulator
113 do all argv processing. */
115 #ifdef SIM_H8300 /* FIXME: quick hack */
116 while ((i
= getopt (ac
, av
, "a:c:m:p:s:htv")) != EOF
)
118 while ((i
= getopt (ac
, av
, "a:c:m:p:s:tv")) != EOF
)
123 /* FIXME: Temporary hack. */
125 int len
= strlen (av
[0]) + strlen (optarg
);
126 char *argbuf
= (char *) alloca (len
+ 2 + 50);
127 sprintf (argbuf
, "%s %s", av
[0], optarg
);
128 #ifdef SIM_HAVE_BIENDIAN
129 /* The desired endianness must be passed to sim_open.
130 The value for "set-later" is set when we know what it is.
131 -E support isn't yet part of the published interface. */
132 strcat (argbuf
, " -E set-later");
134 sim_argv
= buildargv (argbuf
);
137 #ifdef SIM_HAVE_SIMCACHE
139 sim_set_simcache_size (atoi (optarg
));
143 /* FIXME: Rename to sim_set_mem_size. */
144 sim_size (atoi (optarg
));
146 #ifdef SIM_HAVE_PROFILE
148 sim_set_profile (atoi (optarg
));
151 sim_set_profile_size (atoi (optarg
));
156 /* FIXME: need to allow specification of what to trace. */
157 /* sim_set_trace (1); */
160 /* Things that are printed with -v are the kinds of things that
161 gcc -v prints. This is not meant to include detailed tracing
162 or debugging information, just summaries. */
164 /* sim_set_verbose (1); */
166 /* FIXME: Quick hack, to be replaced by more general facility. */
186 printf ("%s %s\n", myname
, name
);
189 abfd
= bfd_openr (name
, 0);
192 fprintf (stderr
, "%s: can't open %s: %s\n",
193 myname
, name
, bfd_errmsg (bfd_get_error ()));
197 if (!bfd_check_format (abfd
, bfd_object
))
199 fprintf (stderr
, "%s: can't load %s: %s\n",
200 myname
, name
, bfd_errmsg (bfd_get_error ()));
204 #ifdef SIM_HAVE_BIENDIAN
205 /* The endianness must be passed to sim_open because one may wish to
206 examine/set registers before calling sim_load [which is the other
207 place where one can determine endianness]. We previously passed the
208 endianness via global `target_byte_order' but that's not a clean
210 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
212 if (bfd_big_endian (abfd
))
215 sim_argv
[i
] = "little";
218 /* Ensure that any run-time initialisation that needs to be
219 performed by the simulator can occur. */
220 sd
= sim_open (SIM_OPEN_STANDALONE
, &default_callback
, abfd
, sim_argv
);
224 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
227 if (sim_create_inferior (sd
, prog_args
, NULL
) == SIM_RC_FAIL
)
230 prev_sigint
= signal (SIGINT
, cntrl_c
);
236 done
= sim_trace (sd
);
241 sim_resume (sd
, 0, 0);
243 signal (SIGINT
, prev_sigint
);
248 sim_stop_reason (sd
, &reason
, &sigrc
);
252 /* If reason is sim_exited, then sigrc holds the exit code which we want
253 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
254 the signal that the simulator received; we want to return that to
257 #ifdef SIM_H8300 /* FIXME: Ugh. grep for SLEEP in compile.c */
262 /* Why did we stop? */
268 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
282 fprintf (stderr
, "Usage: %s [options] program [program args]\n", myname
);
283 fprintf (stderr
, "Options:\n");
284 fprintf (stderr
, "-a args Pass `args' to simulator.\n");
285 #ifdef SIM_HAVE_SIMCACHE
286 fprintf (stderr
, "-c size Set simulator cache size to `size'.\n");
289 fprintf (stderr
, "-h Executable is for h8/300h or h8/300s.\n");
291 fprintf (stderr
, "-m size Set memory size of simulator, in bytes.\n");
292 #ifdef SIM_HAVE_PROFILE
293 fprintf (stderr
, "-p freq Set profiling frequency.\n");
294 fprintf (stderr
, "-s size Set profiling size.\n");
296 fprintf (stderr
, "-t Perform instruction tracing.\n");
297 fprintf (stderr
, " Note: Very few simulators support tracing.\n");
298 fprintf (stderr
, "-v Verbose output.\n");
299 fprintf (stderr
, "\n");
300 fprintf (stderr
, "program args Arguments to pass to simulated program.\n");
301 fprintf (stderr
, " Note: Very few simulators support this.\n");