1 /* New version of run front end support for simulators.
2 Copyright (C) 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. */
24 extern char **environ;
27 static void usage (void);
29 extern host_callback default_callback;
40 fprintf (stderr, "Quit!\n");
46 main (int argc, char **argv)
49 char **prog_argv = NULL;
50 struct _bfd *prog_bfd;
53 RETSIGTYPE (*prev_sigint) ();
55 myname = argv[0] + strlen (argv[0]);
56 while (myname > argv[0] && myname[-1] != '/')
59 /* Create an instance of the simulator. */
60 default_callback.init (&default_callback);
61 sd = sim_open (SIM_OPEN_STANDALONE, &default_callback, NULL, argv);
64 if (STATE_MAGIC (sd) != SIM_MAGIC_NUMBER)
66 fprintf (stderr, "Internal error - bad magic number in simulator struct\n");
70 /* Was there a program to run? */
71 prog_argv = STATE_PROG_ARGV (sd);
72 prog_bfd = STATE_PROG_BFD (sd);
73 if (prog_argv == NULL || *prog_argv == NULL)
78 /* For simulators that don't open prog during sim_open() */
81 prog_bfd = bfd_openr (name, 0);
83 fprintf (stderr, "%s: can't open \"%s\": %s\n",
84 myname, name, bfd_errmsg (bfd_get_error ()));
87 if (STATE_VERBOSE_P (sd))
88 printf ("%s %s\n", myname, name);
90 /* Load the program into the simulator. */
91 if (sim_load (sd, name, prog_bfd, 0) == SIM_RC_FAIL)
94 /* Prepare the program for execution. */
96 sim_create_inferior (sd, prog_bfd, prog_argv, environ);
98 sim_create_inferior (sd, prog_bfd, prog_argv, NULL);
101 /* Run the program. */
102 prev_sigint = signal (SIGINT, cntrl_c);
103 sim_resume (sd, 0, 0);
104 signal (SIGINT, prev_sigint);
106 /* Print any stats the simulator collected. */
109 /* Find out why the program exited. */
110 sim_stop_reason (sd, &reason, &sigrc);
112 /* Shutdown the simulator. */
115 /* If reason is sim_exited, then sigrc holds the exit code which we want
116 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
117 the signal that the simulator received; we want to return that to
120 #ifdef SIM_H8300 /* FIXME: Ugh. grep for SLEEP in compile.c */
125 /* Why did we stop? */
131 fprintf (stderr, "program stopped with signal %d.\n", sigrc);
138 fprintf (stderr, "program in undefined state (%d:%d)\n", reason, sigrc);
150 fprintf (stderr, "Usage: %s [options] program [program args]\n", myname);
151 fprintf (stderr, "Run `%s --help' for full list of options.\n", myname);