SIM_DESC
-sim_open (SIM_OPEN_KIND kind, char **argv)
-{
- STATE_OPEN_KIND (&simulation) = kind;
-
- /* establish the simulator configuration */
- sim_config (&simulation,
- LITTLE_ENDIAN/*d30v always big endian*/);
+sim_open (SIM_OPEN_KIND kind,
+ host_callback *callback,
+ struct _bfd *abfd,
+ char **argv)
+{
+ SIM_DESC sd = &simulation;
+ STATE_OPEN_KIND (sd) = kind;
+ STATE_MAGIC (sd) = SIM_MAGIC_NUMBER;
+ STATE_CALLBACK (&simulation) = callback;
- if (sim_pre_argv_init (&simulation, argv[0]) != SIM_RC_OK)
+ if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
return 0;
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
- if (sim_parse_args (&simulation, argv) != SIM_RC_OK)
+ if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,
file descriptor leaks, etc. */
- sim_module_uninstall (&simulation);
+ sim_module_uninstall (sd);
return 0;
}
- if (sim_post_argv_init (&simulation) != SIM_RC_OK)
+ /* establish the simulator configuration */
+ if (sim_config (sd, abfd) != SIM_RC_OK)
+ {
+ sim_module_uninstall (sd);
+ return 0;
+ }
+
+ if (sim_post_argv_init (sd) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,
file descriptor leaks, etc. */
- sim_module_uninstall (&simulation);
+ sim_module_uninstall (sd);
return 0;
}
- engine_init(&simulation);
+ /* Initialize the main processor */
+ memset (&STATE_CPU (sd, 0)->reg, 0, sizeof STATE_CPU (sd, 0)->reg);
+ memset (&STATE_CPU (sd, 0)->acc, 0, sizeof STATE_CPU (sd, 0)->acc);
+ memset (&STATE_CPU (sd, 0)->cr, 0, sizeof STATE_CPU (sd, 0)->cr);
+ STATE_CPU (sd, 0)->is_user_mode = 0;
+ memset (&STATE_CPU (sd, 0)->cia, 0, sizeof STATE_CPU (sd, 0)->cia);
+ CPU_STATE (STATE_CPU (sd, 0)) = sd;
#define TIC80_MEM_START 0x2000000
#define TIC80_MEM_SIZE 0x100000
/* external memory */
- sim_core_attach(&simulation,
+ sim_core_attach(sd,
NULL,
attach_raw_memory,
access_read_write_exec,
0, TIC80_MEM_START, TIC80_MEM_SIZE, NULL, NULL);
- sim_core_attach(&simulation,
+ sim_core_attach(sd,
NULL,
attach_raw_memory,
access_read_write_exec,
0, 0, TIC80_MEM_SIZE, NULL, NULL);
/* FIXME: for now */
- return (SIM_DESC) &simulation;
-}
-
-
-/* NOTE: sim_size is going away */
-void sim_size (int i);
-void
-sim_size (int i)
-{
- sim_io_error (NULL, "unexpected call to sim_size()");
+ return sd;
}
{
/* Uninstall the modules to avoid memory leaks,
file descriptor leaks, etc. */
- sim_module_uninstall (&simulation);
+ sim_module_uninstall (sd);
}
SIM_RC
sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
{
- extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
bfd *prog_bfd;
prog_bfd = sim_load_file (sd, STATE_MY_NAME (sd),
}
-void
-sim_kill (SIM_DESC sd)
-{
-}
-
-
int
sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
{
- return sim_core_read_buffer (sd, sim_core_write_map,
+ return sim_core_read_buffer (sd, NULL, sim_core_write_map,
buf, mem, length);
}
int
sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
{
- return sim_core_write_buffer (sd, sim_core_write_map,
+ return sim_core_write_buffer (sd, NULL, sim_core_write_map,
buf, mem, length);
}
void
sim_fetch_register (SIM_DESC sd, int regnr, unsigned char *buf)
{
- if (regnr >= R0_REGNUM && regnr <= Rn_REGNUM)
- *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->reg[regnr - A0_REGNUM]);
+ if (regnr == R0_REGNUM)
+ memset (buf, 0, sizeof (unsigned32));
+ else if (regnr > R0_REGNUM && regnr <= Rn_REGNUM)
+ *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->reg[regnr - R0_REGNUM]);
else if (regnr == PC_REGNUM)
*(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.ip);
else if (regnr == NPC_REGNUM)
sim_store_register (SIM_DESC sd, int regnr, unsigned char *buf)
{
if (regnr >= R0_REGNUM && regnr <= Rn_REGNUM)
- STATE_CPU (sd, 0)->reg[regnr - A0_REGNUM] = T2H_4 (*(unsigned32*)buf);
+ STATE_CPU (sd, 0)->reg[regnr - R0_REGNUM] = T2H_4 (*(unsigned32*)buf);
else if (regnr == PC_REGNUM)
STATE_CPU (sd, 0)->cia.ip = T2H_4 (*(unsigned32*)buf);
else if (regnr == NPC_REGNUM)
STATE_CPU (sd, 0)->cia.dp = T2H_4 (*(unsigned32*)buf);
- else if (regnr == A0_REGNUM && regnr <= An_REGNUM)
- STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM] = H2T_8 (*(unsigned64*)buf);
+ else if (regnr >= A0_REGNUM && regnr <= An_REGNUM)
+ STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM] = T2H_8 (*(unsigned64*)buf);
else
- sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr);
+ sim_io_error (sd, "sim_store_register - unknown register nr %d", regnr);
return;
}
}
-volatile int keep_running = 1;
-
-void
-sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
-{
- *reason = simulation.reason;
- *sigrc = simulation.siggnal;
- keep_running = 1; /* ready for next run */
-}
-
-
-int
-sim_stop (SIM_DESC sd)
-{
- keep_running = 0;
- return 1;
-}
-
-void
-sim_resume (SIM_DESC sd, int step, int siggnal)
-{
- /* keep_running = 1 - in sim_stop_reason */
- if (step)
- keep_running = 0;
- engine_run_until_stop(sd, &keep_running);
-}
-
void
sim_do_command (SIM_DESC sd, char *cmd)
{
- sim_io_error (sd, "sim_do_command - unimplemented");
-}
-
-
-void
-sim_set_callbacks (SIM_DESC sd, host_callback *callback)
-{
- STATE_CALLBACK (&simulation) = callback;
+ if (sim_args_command (sd, cmd) != SIM_RC_OK)
+ sim_io_eprintf (sd, "Unknown command `%s'\n", cmd);
}