1 /* run front end support for all the simulators.
2 Copyright (C) 1992, 1993 1994, 1995, 1996 Free Software Foundation, Inc.
4 GNU CC 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 GNU CC 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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 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 static void usage
PARAMS ((void));
55 int target_byte_order
;
57 extern host_callback default_callback
;
62 /* NOTE: sim_size() and sim_trace() are going away */
63 extern void sim_size
PARAMS ((int i
));
64 extern int sim_trace
PARAMS ((SIM_DESC sd
));
75 bfd_vma start_address
;
81 static char *no_args
[2];
82 char **sim_argv
= &no_args
[0];
88 myname
= av
[0] + strlen (av
[0]);
89 while (myname
> av
[0] && myname
[-1] != '/')
92 /* The first element of sim_open's argv is the program name. */
95 /* FIXME: This is currently being rewritten to have each simulator
96 do all argv processing. */
98 #ifdef SIM_H8300 /* FIXME: quick hack */
99 while ((i
= getopt (ac
, av
, "a:c:m:p:s:htv")) != EOF
)
101 while ((i
= getopt (ac
, av
, "a:c:m:p:s:tv")) != EOF
)
106 /* FIXME: Temporary hack. */
108 int len
= strlen (av
[0]) + strlen (optarg
);
109 char *argbuf
= (char *) alloca (len
+ 2);
110 sprintf (argbuf
, "%s %s", av
[0], optarg
);
111 sim_argv
= buildargv (argbuf
);
114 #ifdef SIM_HAVE_SIMCACHE
116 sim_set_simcache_size (atoi (optarg
));
120 /* FIXME: Rename to sim_set_mem_size. */
121 sim_size (atoi (optarg
));
123 #ifdef SIM_HAVE_PROFILE
125 sim_set_profile (atoi (optarg
));
128 sim_set_profile_size (atoi (optarg
));
133 /* FIXME: need to allow specification of what to trace. */
134 /* sim_set_trace (1); */
137 /* Things that are printed with -v are the kinds of things that
138 gcc -v prints. This is not meant to include detailed tracing
139 or debugging information, just summaries. */
141 /* sim_set_verbose (1); */
143 /* FIXME: Quick hack, to be replaced by more general facility. */
161 printf ("%s %s\n", myname
, name
);
164 exec_bfd
= abfd
= bfd_openr (name
, 0);
167 fprintf (stderr
, "%s: can't open %s: %s\n",
168 myname
, name
, bfd_errmsg (bfd_get_error ()));
172 if (!bfd_check_format (abfd
, bfd_object
))
174 fprintf (stderr
, "%s: can't load %s: %s\n",
175 myname
, name
, bfd_errmsg (bfd_get_error ()));
179 /* This must be set before sim_open is called, because gdb assumes that
180 the simulator endianness is known immediately after the sim_open call. */
181 target_byte_order
= bfd_big_endian (abfd
) ? 4321 : 1234;
183 sim_set_callbacks (NULL
, &default_callback
);
184 default_callback
.init (&default_callback
);
186 /* Ensure that any run-time initialisation that needs to be
187 performed by the simulator can occur. */
188 sd
= sim_open (sim_argv
);
190 for (s
= abfd
->sections
; s
; s
= s
->next
)
192 if (s
->flags
& SEC_LOAD
)
194 unsigned char *buffer
= (unsigned char *)malloc ((size_t)(bfd_section_size (abfd
, s
)));
197 bfd_get_section_contents (abfd
,
201 bfd_section_size (abfd
, s
));
202 sim_write (sd
, s
->vma
, buffer
, bfd_section_size (abfd
, s
));
203 /* FIXME: How come we don't free buffer? */
207 fprintf (stderr
, "%s: failed to allocate section buffer: %s\n",
208 myname
, bfd_errmsg (bfd_get_error ()));
214 start_address
= bfd_get_start_address (abfd
);
215 sim_create_inferior (sd
, start_address
, prog_args
, NULL
);
222 done
= sim_trace (sd
);
227 sim_resume (sd
, 0, 0);
232 sim_stop_reason (sd
, &reason
, &sigrc
);
236 /* If reason is sim_exited, then sigrc holds the exit code which we want
237 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
238 the signal that the simulator received; we want to return that to
241 #ifdef SIM_H8300 /* FIXME: Ugh. grep for SLEEP in compile.c */
246 /* Why did we stop? */
252 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
266 fprintf (stderr
, "Usage: %s [options] program [program args]\n", myname
);
267 fprintf (stderr
, "Options:\n");
268 fprintf (stderr
, "-a args Pass `args' to simulator.\n");
269 #ifdef SIM_HAVE_SIMCACHE
270 fprintf (stderr
, "-c size Set simulator cache size to `size'.\n");
273 fprintf (stderr
, "-h Executable is for h8/300h or h8/300s.\n");
275 fprintf (stderr
, "-m size Set memory size of simulator, in bytes.\n");
276 #ifdef SIM_HAVE_PROFILE
277 fprintf (stderr
, "-p freq Set profiling frequency.\n");
278 fprintf (stderr
, "-s size Set profiling size.\n");
280 fprintf (stderr
, "-t Perform instruction tracing.\n");
281 fprintf (stderr
, " Note: Very few simulators support tracing.\n");
282 fprintf (stderr
, "-v Verbose output.\n");
283 fprintf (stderr
, "\n");
284 fprintf (stderr
, "program args Arguments to pass to simulated program.\n");
285 fprintf (stderr
, " Note: Very few simulators support this.\n");