Remove i386_elf_emit_arch_note
[deliverable/binutils-gdb.git] / sim / ppc / sim_calls.c
index b9962b8d9ecd34374ccc3563626d27234c4272c8..4e61335c2d4e5b7b48cb1381a58cded60d4e4491 100644 (file)
@@ -1,10 +1,10 @@
 /*  This file is part of the program psim.
 
 /*  This file is part of the program psim.
 
-    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
+    Copyright 1994, 1995, 1996, 1998, 2003 Andrew Cagney
 
     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
 
     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
-    the Free Software Foundation; either version 2 of the License, or
+    the Free Software Foundation; either version 3 of the License, or
     (at your option) any later version.
 
     This program is distributed in the hope that it will be useful,
     (at your option) any later version.
 
     This program is distributed in the hope that it will be useful,
@@ -13,8 +13,7 @@
     GNU General Public License for more details.
  
     You should have received a copy of the GNU General Public License
     GNU General Public License for more details.
  
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+    along with this program; if not, see <http://www.gnu.org/licenses/>.
  
     */
 
  
     */
 
 #endif
 #endif
 
 #endif
 #endif
 
-#include "defs.h"
+#include "libiberty.h"
 #include "bfd.h"
 #include "bfd.h"
-#include "callback.h"
-#include "remote-sim.h"
+#include "gdb/callback.h"
+#include "gdb/remote-sim.h"
+#include "gdb/signals.h"
+
+/* Define the rate at which the simulator should poll the host
+   for a quit. */
+#ifndef POLL_QUIT_INTERVAL
+#define POLL_QUIT_INTERVAL 0x20
+#endif
 
 
+static int poll_quit_count = POLL_QUIT_INTERVAL;
 
 /* Structures used by the simulator, for gdb just have static structures */
 
 
 /* Structures used by the simulator, for gdb just have static structures */
 
-static psim *simulator;
+psim *simulator;
 static device *root_device;
 static device *root_device;
-static const char *register_names[] = REGISTER_NAMES;
-
-/* For communication between sim_load and sim_create_inferior.
-   This can be made to go away, please do.  */
-static unsigned_word entry_point;
+static host_callback *callbacks;
 
 SIM_DESC
 
 SIM_DESC
-sim_open (SIM_OPEN_KIND kind, char **argv)
+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 */
   /* Note: The simulation is not created by sim_open() because
      complete information is not yet available */
   /* trace the call */
@@ -89,44 +97,33 @@ sim_close (SIM_DESC sd, int quitting)
 
 
 SIM_RC
 
 
 SIM_RC
-sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
+sim_load (SIM_DESC sd, const char *prog, bfd *abfd, int from_tty)
 {
 {
-  char **argv;
   TRACE(trace_gdb, ("sim_load(prog=%s, from_tty=%d) called\n",
                    prog, from_tty));
   ASSERT(prog != NULL);
 
   TRACE(trace_gdb, ("sim_load(prog=%s, from_tty=%d) called\n",
                    prog, from_tty));
   ASSERT(prog != NULL);
 
-  /* parse the arguments, assume that the file is argument 0 */
-  argv = buildargv(prog);
-  ASSERT(argv != NULL && argv[0] != NULL);
-
   /* create the simulator */
   TRACE(trace_gdb, ("sim_load() - first time, create the simulator\n"));
   /* create the simulator */
   TRACE(trace_gdb, ("sim_load() - first time, create the simulator\n"));
-  simulator = psim_create(argv[0], root_device);
+  simulator = psim_create(prog, root_device);
 
   /* bring in all the data section */
   psim_init(simulator);
 
 
   /* bring in all the data section */
   psim_init(simulator);
 
-  /* release the arguments */
-  freeargv(argv);
-
   /* get the start address */
   /* get the start address */
-  if (abfd != NULL)
-    entry_point = bfd_get_start_address (abfd);
-  else
+  if (abfd == NULL)
     {
     {
-      abfd = bfd_openr (argv[0], 0);
+      abfd = bfd_openr (prog, 0);
       if (abfd == NULL)
        error ("psim: can't open \"%s\": %s\n", 
       if (abfd == NULL)
        error ("psim: can't open \"%s\": %s\n", 
-              argv[0], bfd_errmsg (bfd_get_error ()));
+              prog, 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",
       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);
+                prog, errmsg);
        }
        }
-      entry_point = bfd_get_start_address (abfd);
       bfd_close (abfd);
     }
 
       bfd_close (abfd);
     }
 
@@ -134,14 +131,6 @@ sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
 }
 
 
 }
 
 
-void
-sim_kill (SIM_DESC sd)
-{
-  TRACE(trace_gdb, ("sim_kill(void) called\n"));
-  /* do nothing, nothing to do */
-}
-
-
 int
 sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
 {
 int
 sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
 {
@@ -154,7 +143,7 @@ sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
 
 
 int
 
 
 int
-sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
+sim_write (SIM_DESC sd, SIM_ADDR mem, const unsigned char *buf, int length)
 {
   int result = psim_write_memory(simulator, MAX_NR_PROCESSORS,
                                 buf, mem, length,
 {
   int result = psim_write_memory(simulator, MAX_NR_PROCESSORS,
                                 buf, mem, length,
@@ -164,34 +153,6 @@ sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
   return result;
 }
 
   return result;
 }
 
-
-void
-sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf)
-{
-  if (simulator == NULL) {
-    return;
-  }
-  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);
-}
-
-
-void
-sim_store_register (SIM_DESC sd, int regno, unsigned char *buf)
-{
-  if (simulator == NULL)
-    return;
-  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);
-}
-
-
 void
 sim_info (SIM_DESC sd, int verbose)
 {
 void
 sim_info (SIM_DESC sd, int verbose)
 {
@@ -201,62 +162,57 @@ sim_info (SIM_DESC sd, int verbose)
 
 
 SIM_RC
 
 
 SIM_RC
-sim_create_inferior (SIM_DESC sd, char **argv, char **envp)
+sim_create_inferior (SIM_DESC sd,
+                    struct bfd *abfd,
+                    char **argv,
+                    char **envp)
 {
 {
+  unsigned_word entry_point;
   TRACE(trace_gdb, ("sim_create_inferior(start_address=0x%x, ...)\n",
                    entry_point));
 
   TRACE(trace_gdb, ("sim_create_inferior(start_address=0x%x, ...)\n",
                    entry_point));
 
+  if (simulator == NULL)
+    error ("No program loaded");
+
+  if (abfd != NULL)
+    entry_point = bfd_get_start_address (abfd);
+  else
+    entry_point = 0xfff00000; /* ??? */
+
   psim_init(simulator);
   psim_stack(simulator, argv, envp);
 
   psim_init(simulator);
   psim_stack(simulator, argv, envp);
 
-  psim_write_register(simulator, -1 /* all start at same PC */,
-                     &entry_point, "pc", cooked_transfer);
+  ASSERT (psim_write_register(simulator, -1 /* all start at same PC */,
+                             &entry_point, "pc", cooked_transfer) > 0);
   return SIM_RC_OK;
 }
 
 
   return SIM_RC_OK;
 }
 
 
-static volatile int sim_should_run;
-
 void
 sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
 {
   psim_status status = psim_get_status(simulator);
 
 void
 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;
-      *sigrc = SIGTRAP;
-      break;
-    case was_exited:
-      *reason = sim_exited;
-      *sigrc = 0;
-      break;
-    case was_signalled:
-      *reason = sim_signalled;
+  switch (status.reason) {
+  case was_continuing:
+    *reason = sim_stopped;
+    if (status.signal == 0)
+      *sigrc = GDB_SIGNAL_TRAP;
+    else
       *sigrc = status.signal;
       *sigrc = status.signal;
-      break;
-    }
     break;
     break;
-
-  case OPERATING_ENVIRONMENT:
+  case was_trap:
     *reason = sim_stopped;
     *reason = sim_stopped;
-    *sigrc = SIGTRAP;
+    *sigrc = GDB_SIGNAL_TRAP;
+    break;
+  case was_exited:
+    *reason = sim_exited;
+    *sigrc = status.signal;
+    break;
+  case was_signalled:
+    *reason = sim_signalled;
+    *sigrc = status.signal;
     break;
     break;
-
-  default:
-    error("sim_stop_reason() - unknown environment\n");
-  
   }
 
   TRACE(trace_gdb, ("sim_stop_reason(reason=0x%lx(%ld), sigrc=0x%lx(%ld))\n",
   }
 
   TRACE(trace_gdb, ("sim_stop_reason(reason=0x%lx(%ld), sigrc=0x%lx(%ld))\n",
@@ -266,10 +222,12 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
 
 
 /* Run (or resume) the program.  */
 
 
 /* Run (or resume) the program.  */
-static RETSIGTYPE
-sim_ctrl_c(int sig)
+
+int
+sim_stop (SIM_DESC sd)
 {
 {
-  sim_should_run = 0;
+  psim_stop (simulator);
+  return 1;
 }
 
 void
 }
 
 void
@@ -280,24 +238,16 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
 
   if (step)
     {
 
   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
     {
     }
   else
     {
-      RETSIGTYPE (*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
     }
 }
 
 void
-sim_do_command (SIM_DESC sd, char *cmd)
+sim_do_command (SIM_DESC sd, const char *cmd)
 {
   TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n",
                    cmd ? cmd : "(null)"));
 {
   TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n",
                    cmd ? cmd : "(null)"));
@@ -308,6 +258,26 @@ sim_do_command (SIM_DESC sd, char *cmd)
   }
 }
 
   }
 }
 
+char **
+sim_complete_command (SIM_DESC sd, const char *text, const char *word)
+{
+  return NULL;
+}
+
+/* Polling, if required */
+
+void
+sim_io_poll_quit (void)
+{
+  if (callbacks->poll_quit != NULL && poll_quit_count-- < 0)
+    {
+      poll_quit_count = POLL_QUIT_INTERVAL;
+      if (callbacks->poll_quit (callbacks))
+       psim_stop (simulator);
+    }
+}
+
+
 
 /* Map simulator IO operations onto the corresponding GDB I/O
    functions.
 
 /* Map simulator IO operations onto the corresponding GDB I/O
    functions.
@@ -316,8 +286,6 @@ sim_do_command (SIM_DESC sd, char *cmd)
    advanced operations (such as dup or write) must either be mapped to
    one of the below calls or handled internally */
 
    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)
 int
 sim_io_read_stdin(char *buf,
                  int sizeof_buf)
@@ -395,7 +363,7 @@ sim_io_flush_stdoutput(void)
 {
   switch (CURRENT_STDIO) {
   case DO_USE_STDIO:
 {
   switch (CURRENT_STDIO) {
   case DO_USE_STDIO:
-    gdb_flush (gdb_stdout);
+    callbacks->flush_stdout (callbacks);
     break;
   case DONT_USE_STDIO:
     break;
     break;
   case DONT_USE_STDIO:
     break;
@@ -406,10 +374,13 @@ sim_io_flush_stdoutput(void)
 }
 
 void
 }
 
 void
-sim_set_callbacks (SIM_DESC sd, host_callback *callback)
+sim_io_error (SIM_DESC sd, const char *fmt, ...)
 {
 {
-  callbacks = callback;
-  TRACE(trace_gdb, ("sim_set_callbacks called\n"));
+  va_list ap;
+  va_start(ap, fmt);
+  callbacks->evprintf_filtered (callbacks, fmt, ap);
+  va_end(ap);
+  callbacks->error (callbacks, "");
 }
 
 /****/
 }
 
 /****/
@@ -423,8 +394,3 @@ zalloc(long size)
   memset(memory, 0, size);
   return memory;
 }
   memset(memory, 0, size);
   return memory;
 }
-
-void zfree(void *data)
-{
-  mfree(NULL, data);
-}
This page took 0.030876 seconds and 4 git commands to generate.