/* This file is part of the program psim.
- Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
+ Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <fcntl.h>
+#include <signal.h>
+
#include "psim.h"
#include "options.h"
#include "device.h" /* FIXME: psim should provide the interface */
+#include "events.h" /* FIXME: psim should provide the interface */
+
+#include "bfd.h"
+#include "gdb/callback.h"
+#include "gdb/remote-sim.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
static psim *simulation = NULL;
+void
+sim_io_poll_quit (void)
+{
+ /* nothing to do */
+}
+
void
sim_io_printf_filtered(const char *msg, ...)
{
}
void
-error (char *msg, ...)
+error (const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
return sim_io_eof;
break;
case DONT_USE_STDIO:
+#if defined(O_NDELAY) && defined(F_GETFL) && defined(F_SETFL)
{
/* check for input */
int flags;
return result;
}
break;
+#endif
default:
error("sim_io_read_stdin: invalid switch\n");
break;
}
}
+void
+sim_io_error (SIM_DESC sd, const char *msg, ...)
+{
+ va_list ap;
+ va_start(ap, msg);
+ vprintf(msg, ap);
+ printf("\n");
+ va_end(ap);
+
+ /* any final clean up */
+ if (ppc_trace[trace_print_info] && simulation != NULL)
+ psim_print_info (simulation, ppc_trace[trace_print_info]);
+
+ exit (1);
+}
+
void *
zalloc(long size)
{
void *memory = malloc(size);
if (memory == NULL)
- error("zmalloc failed\n");
+ error("zalloc failed\n");
memset(memory, 0, size);
return memory;
}
-void
-zfree(void *chunk)
+/* When a CNTRL-C occures, queue an event to shut down the simulation */
+
+static RETSIGTYPE
+cntrl_c(int sig)
{
- free(chunk);
+ psim_stop (simulation);
}
+
int
main(int argc, char **argv)
{
device *root = psim_tree();
/* parse the arguments */
- argv = psim_options(root, argv + 1);
+ argv = psim_options (root, argv + 1, SIM_OPEN_STANDALONE);
if (argv[0] == NULL) {
if (ppc_trace[trace_opts]) {
print_options ();
return 0;
} else {
- psim_usage(0);
+ psim_usage (0, 0, SIM_OPEN_STANDALONE);
}
}
name_of_file = argv[0];
psim_init(simulation);
psim_stack(simulation, argv, environ);
- psim_run(simulation);
+ {
+ RETSIGTYPE (*prev) ();
+ prev = signal(SIGINT, cntrl_c);
+ psim_run(simulation);
+ signal(SIGINT, prev);
+ }
/* any final clean up */
if (ppc_trace[trace_print_info])
status = psim_get_status(simulation);
switch (status.reason) {
case was_continuing:
- error("psim: continuing while stoped!\n");
+ error("psim: continuing while stopped!\n");
return 0;
case was_trap:
error("psim: no trap insn\n");