#endif
#endif
-#include "../../gdb/defs.h"
-
-#include "../../gdb/remote-sim.h"
-#include "../../gdb/callback.h"
+#include "defs.h"
+#include "bfd.h"
+#include "callback.h"
+#include "remote-sim.h"
/* Structures used by the simulator, for gdb just have static structures */
static psim *simulator;
static device *root_device;
static const char *register_names[] = REGISTER_NAMES;
+static host_callback *callbacks;
-void
-sim_open (char *args)
+/* For communication between sim_load and sim_create_inferior.
+ This can be made to go away, please do. */
+static unsigned_word entry_point;
+
+SIM_DESC
+sim_open (SIM_OPEN_KIND kind,
+ host_callback *callback,
+ struct _bfd *abfd,
+ char **argv)
{
+ callbacks = callback;
+
/* 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)"));
+ TRACE(trace_gdb, ("sim_open called\n"));
if (root_device != NULL)
sim_io_printf_filtered("Warning - re-open of simulator leaks memory\n");
root_device = psim_tree();
simulator = NULL;
- if (args) {
- char **argv = buildargv(args);
- psim_options(root_device, argv);
- freeargv(argv);
- }
+ psim_options(root_device, argv + 1);
if (ppc_trace[trace_opts])
print_options ();
+
+ /* fudge our descriptor for now */
+ return (SIM_DESC) 1;
}
void
-sim_close (int quitting)
+sim_close (SIM_DESC sd, int quitting)
{
TRACE(trace_gdb, ("sim_close(quitting=%d) called\n", quitting));
if (ppc_trace[trace_print_info] && simulator != NULL)
}
-int
-sim_load (char *prog, int from_tty)
+SIM_RC
+sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
{
char **argv;
TRACE(trace_gdb, ("sim_load(prog=%s, from_tty=%d) called\n",
/* bring in all the data section */
psim_init(simulator);
+ /* get the start address */
+ if (abfd != NULL)
+ entry_point = bfd_get_start_address (abfd);
+ else
+ {
+ abfd = bfd_openr (argv[0], 0);
+ if (abfd == NULL)
+ error ("psim: can't open \"%s\": %s\n",
+ argv[0], bfd_errmsg (bfd_get_error ()));
+ if (!bfd_check_format (abfd, bfd_object))
+ {
+ const char *errmsg = bfd_errmsg (bfd_get_error ());
+ bfd_close (abfd);
+ error ("psim: \"%s\" is not an object file: %s\n",
+ argv[0], errmsg);
+ }
+ entry_point = bfd_get_start_address (abfd);
+ bfd_close (abfd);
+ }
+
/* release the arguments */
freeargv(argv);
- /* `I did it my way' */
- return 0;
-}
-
-
-void
-sim_kill (void)
-{
- TRACE(trace_gdb, ("sim_kill(void) called\n"));
- /* do nothing, nothing to do */
+ return SIM_RC_OK;
}
int
-sim_read (SIM_ADDR mem, unsigned char *buf, int length)
+sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
{
int result = psim_read_memory(simulator, MAX_NR_PROCESSORS,
buf, mem, length);
int
-sim_write (SIM_ADDR mem, unsigned char *buf, int length)
+sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
{
int result = psim_write_memory(simulator, MAX_NR_PROCESSORS,
buf, mem, length,
void
-sim_fetch_register (int regno, unsigned char *buf)
+sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf)
{
if (simulator == NULL) {
return;
void
-sim_store_register (int regno, unsigned char *buf)
+sim_store_register (SIM_DESC sd, int regno, unsigned char *buf)
{
if (simulator == NULL)
return;
void
-sim_info (int verbose)
+sim_info (SIM_DESC sd, int verbose)
{
TRACE(trace_gdb, ("sim_info(verbose=%d) called\n", verbose));
psim_print_info (simulator, verbose);
}
-void
-sim_create_inferior (SIM_ADDR start_address, char **argv, char **envp)
+SIM_RC
+sim_create_inferior (SIM_DESC sd, char **argv, char **envp)
{
- unsigned_word entry_point = start_address;
-
TRACE(trace_gdb, ("sim_create_inferior(start_address=0x%x, ...)\n",
- start_address));
+ entry_point));
psim_init(simulator);
psim_stack(simulator, argv, envp);
psim_write_register(simulator, -1 /* all start at same PC */,
&entry_point, "pc", cooked_transfer);
+ return SIM_RC_OK;
}
-static volatile int sim_should_run;
-
void
-sim_stop_reason (enum sim_stop *reason, int *sigrc)
+sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
{
psim_status status = psim_get_status(simulator);
- switch (CURRENT_ENVIRONMENT) {
-
- case USER_ENVIRONMENT:
- case VIRTUAL_ENVIRONMENT:
- switch (status.reason) {
- case was_continuing:
- *reason = sim_stopped;
- *sigrc = SIGTRAP;
- if (sim_should_run) {
- error("sim_stop_reason() unknown reason for halt\n");
- }
- break;
- case was_trap:
- *reason = sim_stopped;
+ switch (status.reason) {
+ case was_continuing:
+ *reason = sim_stopped;
+ if (status.signal == 0)
*sigrc = SIGTRAP;
- break;
- case was_exited:
- *reason = sim_exited;
- *sigrc = 0;
- break;
- case was_signalled:
- *reason = sim_signalled;
+ else
*sigrc = status.signal;
- break;
- }
break;
-
- case OPERATING_ENVIRONMENT:
+ case was_trap:
*reason = sim_stopped;
*sigrc = SIGTRAP;
break;
-
- default:
- error("sim_stop_reason() - unknown environment\n");
-
+ case was_exited:
+ *reason = sim_exited;
+ *sigrc = status.signal;
+ break;
+ case was_signalled:
+ *reason = sim_signalled;
+ *sigrc = status.signal;
+ break;
}
TRACE(trace_gdb, ("sim_stop_reason(reason=0x%lx(%ld), sigrc=0x%lx(%ld))\n",
/* Run (or resume) the program. */
-static void
-sim_ctrl_c()
+
+int
+sim_stop (SIM_DESC sd)
{
- sim_should_run = 0;
+ psim_stop (simulator);
+ return 1;
}
void
-sim_resume (int step, int siggnal)
+sim_resume (SIM_DESC sd, int step, int siggnal)
{
TRACE(trace_gdb, ("sim_resume(step=%d, siggnal=%d)\n",
step, siggnal));
if (step)
{
- psim_step(simulator);
- /* sim_stop_reason has a sanity check for stopping while
- was_continuing. We don't want that here so reset sim_should_run. */
- sim_should_run = 0;
+ psim_step (simulator);
}
else
{
- void (*prev) ();
-
- prev = signal(SIGINT, sim_ctrl_c);
- sim_should_run = 1;
- psim_run_until_stop(simulator, &sim_should_run);
- signal(SIGINT, prev);
+ psim_run (simulator);
}
}
void
-sim_do_command (char *cmd)
+sim_do_command (SIM_DESC sd, char *cmd)
{
TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n",
cmd ? cmd : "(null)"));
- if (cmd) {
+ if (cmd != NULL) {
char **argv = buildargv(cmd);
- psim_options(root_device, argv);
+ psim_command(root_device, argv);
freeargv(argv);
}
}
advanced operations (such as dup or write) must either be mapped to
one of the below calls or handled internally */
-static host_callback *callbacks;
-
int
sim_io_read_stdin(char *buf,
int sizeof_buf)
error("sim_io_read_stdin: unaccounted switch\n");
break;
}
+ return 0;
}
int
error("sim_io_write_stdout: unaccounted switch\n");
break;
}
+ return 0;
}
int
error("sim_io_write_stderr: unaccounted switch\n");
break;
}
+ return 0;
}
}
}
-void
-sim_set_callbacks (host_callback *callback)
-{
- callbacks = callback;
- TRACE(trace_gdb, ("sim_set_callbacks called\n"));
-}
-
/****/
void *