*/
-#include <signal.h> /* FIXME - should be machine dependant version */
#include <stdarg.h>
#include <ctype.h>
#define SIM_ADDR unsigned
-/* Structures used by the simulator, for gdb just have static structures */
-
-struct sim_state simulation = { 0 };
-
-
SIM_DESC
-sim_open (SIM_OPEN_KIND kind, char **argv)
+sim_open (SIM_OPEN_KIND kind,
+ host_callback *callback,
+ struct _bfd *abfd,
+ char **argv)
{
- STATE_OPEN_KIND (&simulation) = kind;
+ char *buf;
+ SIM_DESC sd = sim_state_alloc (kind, callback);
- /* establish the simulator configuration */
- sim_config (&simulation,
- LITTLE_ENDIAN/*d30v always big endian*/);
-
- if (sim_pre_argv_init (&simulation, argv[0]) != SIM_RC_OK)
+ if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
return 0;
+#define TIC80_MEM_START 0x2000000
+#define TIC80_MEM_SIZE 0x100000
+
+ /* main memory */
+ asprintf (&buf, "memory region 0x%lx,0x%lx",
+ TIC80_MEM_START, TIC80_MEM_SIZE);
+ sim_do_command (sd, buf);
+ free (buf);
+ /* interrupt memory */
+ sim_do_command (sd, "memory region 0x1010000,0x1000");
+ /* some memory at zero */
+ sim_do_command (sd, "memory region 0,0x100000");
+
/* 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)
+ /* check for/establish the a reference program image */
+ if (sim_analyze_program (sd,
+ (STATE_PROG_ARGV (sd) != NULL
+ ? *STATE_PROG_ARGV (sd)
+ : NULL),
+ abfd) != 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);
-
-#define TIC80_MEM_START 0x2000000
-#define TIC80_MEM_SIZE 0x100000
+ /* establish any remaining configuration options */
+ if (sim_config (sd) != SIM_RC_OK)
+ {
+ sim_module_uninstall (sd);
+ return 0;
+ }
- /* external memory */
- sim_core_attach(&simulation,
- NULL,
- attach_raw_memory,
- access_read_write_exec,
- 0, TIC80_MEM_START, TIC80_MEM_SIZE, NULL, NULL);
- sim_core_attach(&simulation,
- NULL,
- attach_raw_memory,
- access_read_write_exec,
- 0, 0, TIC80_MEM_SIZE, NULL, NULL);
+ if (sim_post_argv_init (sd) != SIM_RC_OK)
+ {
+ /* Uninstall the modules to avoid memory leaks,
+ file descriptor leaks, etc. */
+ sim_module_uninstall (sd);
+ return 0;
+ }
/* 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_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),
- STATE_CALLBACK (sd),
- prog,
- /* pass NULL for abfd, we always open our own */
- NULL,
- STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG);
- if (prog_bfd == NULL)
- return SIM_RC_FAIL;
- sim_analyze_program (sd, prog_bfd);
- return SIM_RC_OK;
-}
-
-
-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,
- 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,
- buf, mem, length);
+ sim_module_uninstall (sd);
}
#define Rn_REGNUM 31 /* Last General Purpose Register - for sim */
#define An_REGNUM A3_REGNUM /* Last Accumulator register - for sim */
-void
-sim_fetch_register (SIM_DESC sd, int regnr, unsigned char *buf)
+int
+sim_fetch_register (SIM_DESC sd, int regnr, unsigned char *buf, int length)
{
- 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)
*(unsigned64*)buf = H2T_8 (STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM]);
else
sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr);
- return;
+ return -1;
}
-void
-sim_store_register (SIM_DESC sd, int regnr, unsigned char *buf)
+int
+sim_store_register (SIM_DESC sd, int regnr, unsigned char *buf, int length)
{
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);
- return;
-}
-
-
-void
-sim_info (SIM_DESC sd, int verbose)
-{
+ sim_io_error (sd, "sim_store_register - unknown register nr %d", regnr);
+ return -1;
}
SIM_RC
sim_create_inferior (SIM_DESC sd,
+ struct _bfd *abfd,
char **argv,
char **envp)
{
- STATE_CPU (sd, 0)->cia.ip = STATE_START_ADDR(sd);
- STATE_CPU (sd, 0)->cia.dp = (STATE_START_ADDR(sd)
+ /* clear all registers */
+ 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));
+ /* initialize any modules */
+ sim_module_init (sd);
+ /* set the stack-pointer/program counter */
+ if (abfd != NULL)
+ STATE_CPU (sd, 0)->cia.ip = bfd_get_start_address (abfd);
+ else
+ STATE_CPU (sd, 0)->cia.ip = 0;
+ STATE_CPU (sd, 0)->cia.dp = (STATE_CPU (sd, 0)->cia.ip
+ sizeof (instruction_word));
+ STATE_CPU (sd, 0)->cr[IE_CR] |= IE_CR_IE;
STATE_CPU (sd, 0)->reg[1] = TIC80_MEM_START + TIC80_MEM_SIZE - 16;
return SIM_RC_OK;
}
-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);
}