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
;
59 /* bfd descriptor of the executable. Same name as gdb uses. */
63 /* NOTE: sim_size() and sim_trace() are going away */
64 extern void sim_size
PARAMS ((int i
));
65 extern int sim_trace
PARAMS ((SIM_DESC sd
));
76 fprintf (stderr
, "Quit!\n");
86 RETSIGTYPE (*prev_sigint
) ();
93 static char *no_args
[4];
94 char **sim_argv
= &no_args
[0];
99 myname
= av
[0] + strlen (av
[0]);
100 while (myname
> av
[0] && myname
[-1] != '/')
103 /* The first element of sim_open's argv is the program name. */
106 no_args
[2] = "set-later";
108 /* FIXME: This is currently being rewritten to have each simulator
109 do all argv processing. */
111 #ifdef SIM_H8300 /* FIXME: quick hack */
112 while ((i
= getopt (ac
, av
, "a:c:m:p:s:htv")) != EOF
)
114 while ((i
= getopt (ac
, av
, "a:c:m:p:s:tv")) != EOF
)
119 /* FIXME: Temporary hack. */
121 int len
= strlen (av
[0]) + strlen (optarg
);
122 char *argbuf
= (char *) alloca (len
+ 2 + 50);
123 /* The desired endianness must be passed to sim_open.
124 The value for "set-later" is set when we know what it is.
125 -e support isn't yet part of the published interface. */
126 sprintf (argbuf
, "%s %s -E set-later", av
[0], optarg
);
127 sim_argv
= buildargv (argbuf
);
130 #ifdef SIM_HAVE_SIMCACHE
132 sim_set_simcache_size (atoi (optarg
));
136 /* FIXME: Rename to sim_set_mem_size. */
137 sim_size (atoi (optarg
));
139 #ifdef SIM_HAVE_PROFILE
141 sim_set_profile (atoi (optarg
));
144 sim_set_profile_size (atoi (optarg
));
149 /* FIXME: need to allow specification of what to trace. */
150 /* sim_set_trace (1); */
153 /* Things that are printed with -v are the kinds of things that
154 gcc -v prints. This is not meant to include detailed tracing
155 or debugging information, just summaries. */
157 /* sim_set_verbose (1); */
159 /* FIXME: Quick hack, to be replaced by more general facility. */
179 printf ("%s %s\n", myname
, name
);
182 sim_set_callbacks (NULL
, &default_callback
);
183 default_callback
.init (&default_callback
);
185 exec_bfd
= abfd
= bfd_openr (name
, 0);
188 fprintf (stderr
, "%s: can't open %s: %s\n",
189 myname
, name
, bfd_errmsg (bfd_get_error ()));
193 if (!bfd_check_format (abfd
, bfd_object
))
195 fprintf (stderr
, "%s: can't load %s: %s\n",
196 myname
, name
, bfd_errmsg (bfd_get_error ()));
200 /* The endianness must be passed to sim_open because one may wish to
201 examine/set registers before calling sim_load [which is the other
202 place where one can determine endianness]. We previously passed the
203 endianness via global `target_byte_order' but that's not a clean
205 for (i
= 1; sim_argv
[i
+ 1] != NULL
; ++i
)
207 if (bfd_big_endian (abfd
))
210 sim_argv
[i
] = "little";
212 /* Ensure that any run-time initialisation that needs to be
213 performed by the simulator can occur. */
214 sd
= sim_open (SIM_OPEN_STANDALONE
, sim_argv
);
218 if (sim_load (sd
, name
, abfd
, 0) == SIM_RC_FAIL
)
221 if (sim_create_inferior (sd
, prog_args
, NULL
) == SIM_RC_FAIL
)
224 prev_sigint
= signal (SIGINT
, cntrl_c
);
230 done
= sim_trace (sd
);
235 sim_resume (sd
, 0, 0);
237 signal (SIGINT
, prev_sigint
);
242 sim_stop_reason (sd
, &reason
, &sigrc
);
246 /* If reason is sim_exited, then sigrc holds the exit code which we want
247 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
248 the signal that the simulator received; we want to return that to
251 #ifdef SIM_H8300 /* FIXME: Ugh. grep for SLEEP in compile.c */
256 /* Why did we stop? */
262 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
276 fprintf (stderr
, "Usage: %s [options] program [program args]\n", myname
);
277 fprintf (stderr
, "Options:\n");
278 fprintf (stderr
, "-a args Pass `args' to simulator.\n");
279 #ifdef SIM_HAVE_SIMCACHE
280 fprintf (stderr
, "-c size Set simulator cache size to `size'.\n");
283 fprintf (stderr
, "-h Executable is for h8/300h or h8/300s.\n");
285 fprintf (stderr
, "-m size Set memory size of simulator, in bytes.\n");
286 #ifdef SIM_HAVE_PROFILE
287 fprintf (stderr
, "-p freq Set profiling frequency.\n");
288 fprintf (stderr
, "-s size Set profiling size.\n");
290 fprintf (stderr
, "-t Perform instruction tracing.\n");
291 fprintf (stderr
, " Note: Very few simulators support tracing.\n");
292 fprintf (stderr
, "-v Verbose output.\n");
293 fprintf (stderr
, "\n");
294 fprintf (stderr
, "program args Arguments to pass to simulated program.\n");
295 fprintf (stderr
, " Note: Very few simulators support this.\n");