Flush defunct sim_kill.
[deliverable/binutils-gdb.git] / sim / tic80 / sim-calls.c
index cf8e2e9be3000fc6e1dc080b5b8a5cb033a58185..b6f66206a07e92282b598b07d632292f055f26d8 100644 (file)
@@ -50,64 +50,70 @@ struct sim_state simulation = { 0 };
 
 
 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;
 }
 
 
@@ -116,14 +122,13 @@ sim_close (SIM_DESC sd, int quitting)
 {
   /* 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),
@@ -139,16 +144,10 @@ sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
 }
 
 
-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);
 }
 
@@ -156,7 +155,7 @@ sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int 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);
 }
 
@@ -177,8 +176,10 @@ sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int 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)
@@ -195,15 +196,15 @@ void
 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;
 }
 
@@ -228,42 +229,9 @@ sim_create_inferior (SIM_DESC sd,
 }
 
 
-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);
 }
This page took 0.027775 seconds and 4 git commands to generate.