/* This file is part of the program psim.
- Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
+ Copyright (C) 1994-1996, 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
#include <signal.h> /* FIXME - should be machine dependant version */
#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
#include <ctype.h>
-#include "basics.h"
#include "psim.h"
+#include "options.h"
-#include "../../gdb/defs.h"
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
-#include "devices.h"
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
+#include "../../gdb/defs.h"
#include "../../gdb/remote-sim.h"
#include "../../gdb/callback.h"
/* Structures used by the simulator, for gdb just have static structures */
static psim *simulator;
-static char *register_names[] = REGISTER_NAMES;
-static int print_info = 0;
+static device *root_device;
+static const char *register_names[] = REGISTER_NAMES;
void
sim_open (char *args)
{
- int i;
-
+ /* Note: The simulation is not created by sim_open() because
+ complete information is not yet available */
/* trace the call */
TRACE(trace_gdb, ("sim_open(args=%s) called\n", args ? args : "(null)"));
+ if (root_device != NULL)
+ printf_filtered("Warning - re-open of simulator leaks memory\n");
+ root_device = psim_tree();
+ simulator = NULL;
+
if (args) {
char **argv = buildargv(args);
- int argp = 0;
- int argc;
- for (argc = 0; argv[argc]; argc++);
-
- while (argp < argc) {
- if (*argv[argp] != '-')
- error ("Argument is not an option '%s'", argv[argp]);
-
- else {
- /* check arguments -- note, main.c also contains argument processing
- code for the standalone emulator. */
- char *p = argv[argp] + 1;
- while (*p != '\0') {
- switch (*p) {
- default:
- printf_filtered("Usage:\n\ttarget sim [ -t <trace-option> ]\n");
- trace_usage();
- error ("");
- break;
- case 't':
- argp += 1;
- if (argv[argp] == NULL)
- error("Missing <trace> option for -t\n");
- trace_option(argv[argp]); /* better fail if NULL */
- break;
- case 'I':
- print_info = 1;
- break;
- }
- }
- }
- argp += 1;
- }
+ psim_options(root_device, argv);
+ freeargv(argv);
}
- /* do something */
- TRACE(trace_tbd, ("sim_open() - TBD - should parse the arguments\n"));
- TRACE(trace_tbd, ("sim_open() - TBD - can not create simulator here as do not have description of it\n"));
+ if (ppc_trace[trace_opts])
+ print_options ();
}
sim_close (int quitting)
{
TRACE(trace_gdb, ("sim_close(quitting=%d) called\n", quitting));
- if (print_info)
- psim_print_info (simulator, 1);
-
- /* nothing to do */
+ if (ppc_trace[trace_print_info] && simulator != NULL)
+ psim_print_info (simulator, ppc_trace[trace_print_info]);
}
/* create the simulator */
TRACE(trace_gdb, ("sim_load() - first time, create the simulator\n"));
- simulator = psim_create(argv[0]);
+ simulator = psim_create(argv[0], root_device);
/* bring in all the data section */
psim_init(simulator);
{
int result = psim_read_memory(simulator, MAX_NR_PROCESSORS,
buf, mem, length);
- TRACE(trace_gdb, ("sim_read(mem=0x%x, buf=0x%x, length=%d) = %d\n",
- mem, buf, length, result));
+ TRACE(trace_gdb, ("sim_read(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
+ (long)mem, (long)buf, length, result));
return result;
}
int result = psim_write_memory(simulator, MAX_NR_PROCESSORS,
buf, mem, length,
1/*violate_ro*/);
- TRACE(trace_gdb, ("sim_write(mem=0x%x, buf=0x%x, length=%d) = %d\n",
- mem, buf, length, result));
+ TRACE(trace_gdb, ("sim_write(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
+ (long)mem, (long)buf, length, result));
return result;
}
if (simulator == NULL) {
return;
}
- TRACE(trace_gdb, ("sim_fetch_register(regno=%d(%s), buf=0x%x)\n",
- regno, register_names[regno], buf));
+ TRACE(trace_gdb, ("sim_fetch_register(regno=%d(%s), buf=0x%lx)\n",
+ regno, register_names[regno], (long)buf));
psim_read_register(simulator, MAX_NR_PROCESSORS,
buf, register_names[regno],
raw_transfer);
{
if (simulator == NULL)
return;
- TRACE(trace_gdb, ("sim_store_register(regno=%d(%s), buf=0x%x)\n",
- regno, register_names[regno], buf));
+ TRACE(trace_gdb, ("sim_store_register(regno=%d(%s), buf=0x%lx)\n",
+ regno, register_names[regno], (long)buf));
psim_write_register(simulator, MAX_NR_PROCESSORS,
buf, register_names[regno],
raw_transfer);
}
- TRACE(trace_gdb, ("sim_stop_reason(reason=0x%x(%d), sigrc=0x%x(%d))\n",
- reason, *reason, sigrc, *sigrc));
+ TRACE(trace_gdb, ("sim_stop_reason(reason=0x%lx(%ld), sigrc=0x%lx(%ld))\n",
+ (long)reason, (long)*reason, (long)sigrc, (long)*sigrc));
}
sim_resume (int step, int siggnal)
{
void (*prev) ();
- unsigned_word program_counter;
TRACE(trace_gdb, ("sim_resume(step=%d, siggnal=%d)\n",
step, siggnal));
}
void
-sim_do_command(char *cmd)
+sim_do_command (char *cmd)
{
- TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n", cmd));
+ TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n",
+ cmd ? cmd : "(null)"));
+ if (cmd) {
+ char **argv = buildargv(cmd);
+ psim_options(root_device, argv);
+ freeargv(argv);
+ }
}
void
void *memory = (void*)xmalloc(size);
if (memory == NULL)
error("xmalloc failed\n");
- bzero(memory, size);
+ memset(memory, 0, size);
return memory;
}
{
mfree(NULL, data);
}
+
+void flush_stdoutput(void)
+{
+ gdb_flush (gdb_stdout);
+}