Add GPL copyright notices to uncopyrighted files.
[deliverable/binutils-gdb.git] / gdb / remote-sim.c
index 6f3af0ca321b93bf1d93c3a81f3c38c39df235da..3377fef450f2be64148cae7a0cae3d6758fa6b36 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic remote debugging interface for simulators.
-   Copyright 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
+   Copyright 1993, 1994, 1996, 1997, 2000 Free Software Foundation, Inc.
    Contributed by Cygnus Support.
    Steve Chamberlain (sac@cygnus.com).
 
@@ -22,7 +22,7 @@
 
 #include "defs.h"
 #include "inferior.h"
-#include "wait.h"
+#include "gdb_wait.h"
 #include "value.h"
 #include "gdb_string.h"
 #include <ctype.h>
 
 /* Prototypes */
 
-extern void _initialize_remote_sim PARAMS ((void));
+extern void _initialize_remote_sim (void);
 
-extern int (*ui_loop_hook) PARAMS ((int signo));
+extern int (*ui_loop_hook) (int signo);
 
-static void dump_mem PARAMS ((char *buf, int len));
+static void dump_mem (char *buf, int len);
 
-static void init_callbacks PARAMS ((void));
+static void init_callbacks (void);
 
-static void end_callbacks PARAMS ((void));
+static void end_callbacks (void);
 
-static int gdb_os_write_stdout PARAMS ((host_callback *, const char *, int));
+static int gdb_os_write_stdout (host_callback *, const char *, int);
 
-static void gdb_os_flush_stdout PARAMS ((host_callback *));
+static void gdb_os_flush_stdout (host_callback *);
 
-static int gdb_os_write_stderr PARAMS ((host_callback *, const char *, int));
+static int gdb_os_write_stderr (host_callback *, const char *, int);
 
-static void gdb_os_flush_stderr PARAMS ((host_callback *));
+static void gdb_os_flush_stderr (host_callback *);
 
-static int gdb_os_poll_quit PARAMS ((host_callback *));
+static int gdb_os_poll_quit (host_callback *);
 
 /* printf_filtered is depreciated */
-static void gdb_os_printf_filtered PARAMS ((host_callback *, const char *,...));
+static void gdb_os_printf_filtered (host_callback *, const char *, ...);
 
-static void gdb_os_vprintf_filtered PARAMS ((host_callback *, const char *, va_list));
+static void gdb_os_vprintf_filtered (host_callback *, const char *, va_list);
 
-static void gdb_os_evprintf_filtered PARAMS ((host_callback *, const char *, va_list));
+static void gdb_os_evprintf_filtered (host_callback *, const char *, va_list);
 
-static void gdb_os_error PARAMS ((host_callback *, const char *,...));
+static void gdb_os_error (host_callback *, const char *, ...);
 
-static void gdbsim_fetch_register PARAMS ((int regno));
+static void gdbsim_fetch_register (int regno);
 
-static void gdbsim_store_register PARAMS ((int regno));
+static void gdbsim_store_register (int regno);
 
-static void gdbsim_kill PARAMS ((void));
+static void gdbsim_kill (void);
 
-static void gdbsim_load PARAMS ((char *prog, int fromtty));
+static void gdbsim_load (char *prog, int fromtty);
 
-static void gdbsim_create_inferior PARAMS ((char *exec_file, char *args, char **env));
+static void gdbsim_create_inferior (char *exec_file, char *args, char **env);
 
-static void gdbsim_open PARAMS ((char *args, int from_tty));
+static void gdbsim_open (char *args, int from_tty);
 
-static void gdbsim_close PARAMS ((int quitting));
+static void gdbsim_close (int quitting);
 
-static void gdbsim_detach PARAMS ((char *args, int from_tty));
+static void gdbsim_detach (char *args, int from_tty);
 
-static void gdbsim_resume PARAMS ((int pid, int step, enum target_signal siggnal));
+static void gdbsim_resume (int pid, int step, enum target_signal siggnal);
 
-static int gdbsim_wait PARAMS ((int pid, struct target_waitstatus * status));
+static int gdbsim_wait (int pid, struct target_waitstatus *status);
 
-static void gdbsim_prepare_to_store PARAMS ((void));
+static void gdbsim_prepare_to_store (void);
 
-static int gdbsim_xfer_inferior_memory PARAMS ((CORE_ADDR memaddr,
-                                               char *myaddr, int len,
-                                               int write,
-                                               struct target_ops * target));
+static int gdbsim_xfer_inferior_memory (CORE_ADDR memaddr,
+                                       char *myaddr, int len,
+                                       int write, struct target_ops *target);
 
-static void gdbsim_files_info PARAMS ((struct target_ops * target));
+static void gdbsim_files_info (struct target_ops *target);
 
-static void gdbsim_mourn_inferior PARAMS ((void));
+static void gdbsim_mourn_inferior (void);
 
-static void gdbsim_stop PARAMS ((void));
+static void gdbsim_stop (void);
 
-void simulator_command PARAMS ((char *args, int from_tty));
+void simulator_command (char *args, int from_tty);
 
 /* Naming convention:
 
@@ -131,7 +130,7 @@ dump_mem (buf, len)
        {
          long l[2];
          memcpy (l, buf, len);
-         printf_filtered ("\t0x%x", l[0]);
+         printf_filtered ("\t0x%lx", l[0]);
          printf_filtered (len == 8 ? " 0x%x\n" : "\n", l[1]);
        }
       else
@@ -194,12 +193,7 @@ gdb_os_write_stdout (p, buf, len)
   int i;
   char b[2];
 
-  for (i = 0; i < len; i++)
-    {
-      b[0] = buf[i];
-      b[1] = 0;
-      fputs_unfiltered (b, gdb_stdtarg);
-    }
+  ui_file_write (gdb_stdtarg, buf, len);
   return len;
 }
 
@@ -209,7 +203,7 @@ static void
 gdb_os_flush_stdout (p)
      host_callback *p;
 {
-  gdb_flush (gdb_stdout);
+  gdb_flush (gdb_stdtarg);
 }
 
 /* GDB version of os_write_stderr callback.  */
@@ -281,15 +275,15 @@ gdb_os_error (host_callback * p, const char *format,...)
     {
       va_list args;
       va_start (args, format);
-
-      error_begin ();
-      vfprintf_filtered (gdb_stderr, format, args);
-      fprintf_filtered (gdb_stderr, "\n");
+      verror (format, args);
       va_end (args);
-      return_to_top_level (RETURN_ERROR);
     }
 }
 
+#ifndef REGISTER_SIM_REGNO
+#define REGISTER_SIM_REGNO(N) (N)
+#endif
+
 static void
 gdbsim_fetch_register (regno)
      int regno;
@@ -300,19 +294,28 @@ gdbsim_fetch_register (regno)
       for (regno = 0; regno < NUM_REGS; regno++)
        gdbsim_fetch_register (regno);
     }
-  else if (REGISTER_NAME (regno) != NULL && *REGISTER_NAME (regno) != '\0')
+  else if (REGISTER_NAME (regno) != NULL
+          && *REGISTER_NAME (regno) != '\0')
     {
       char buf[MAX_REGISTER_RAW_SIZE];
-      int nr_bytes = sim_fetch_register (gdbsim_desc, regno, buf, REGISTER_RAW_SIZE (regno));
+      int nr_bytes;
+      if (REGISTER_SIM_REGNO (regno) >= 0)
+       nr_bytes = sim_fetch_register (gdbsim_desc,
+                                      REGISTER_SIM_REGNO (regno),
+                                      buf, REGISTER_RAW_SIZE (regno));
+      else
+       nr_bytes = 0;
       if (nr_bytes == 0)
        /* register not applicable, supply zero's */
        memset (buf, 0, MAX_REGISTER_RAW_SIZE);
       else if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno)
               && warn_user)
        {
-         printf_unfiltered ("Size of register %s (%d) incorrect (%d instead of %d))",
-                            REGISTER_NAME (regno), regno,
-                            nr_bytes, REGISTER_RAW_SIZE (regno));
+         fprintf_unfiltered (gdb_stderr,
+                             "Size of register %s (%d/%d) incorrect (%d instead of %d))",
+                             REGISTER_NAME (regno),
+                             regno, REGISTER_SIM_REGNO (regno),
+                             nr_bytes, REGISTER_RAW_SIZE (regno));
          warn_user = 0;
        }
       supply_register (regno, buf);
@@ -335,12 +338,16 @@ gdbsim_store_register (regno)
       for (regno = 0; regno < NUM_REGS; regno++)
        gdbsim_store_register (regno);
     }
-  else if (REGISTER_NAME (regno) != NULL && *REGISTER_NAME (regno) != '\0')
+  else if (REGISTER_NAME (regno) != NULL
+          && *REGISTER_NAME (regno) != '\0'
+          && REGISTER_SIM_REGNO (regno) >= 0)
     {
       char tmp[MAX_REGISTER_RAW_SIZE];
       int nr_bytes;
       read_register_gen (regno, tmp);
-      nr_bytes = sim_store_register (gdbsim_desc, regno, tmp, REGISTER_RAW_SIZE (regno));
+      nr_bytes = sim_store_register (gdbsim_desc,
+                                    REGISTER_SIM_REGNO (regno),
+                                    tmp, REGISTER_RAW_SIZE (regno));
       if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno))
        internal_error ("Register size different to expected");
       if (sr_get_debug ())
@@ -445,7 +452,7 @@ gdbsim_create_inferior (exec_file, args, env)
   clear_proceed_status ();
 
   /* NB: Entry point already set by sim_create_inferior. */
-  proceed ((CORE_ADDR) - 1, TARGET_SIGNAL_DEFAULT, 0);
+  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
 }
 
 /* The open routine takes the rest of the parameters from the command,
@@ -552,6 +559,7 @@ gdbsim_close (quitting)
     }
 
   end_callbacks ();
+  generic_mourn_inferior ();
 }
 
 /* Takes a program previously attached to and detaches it.
@@ -743,8 +751,11 @@ gdbsim_xfer_inferior_memory (memaddr, myaddr, len, write, target)
 
   if (sr_get_debug ())
     {
-      printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x%x, memaddr 0x%x, len %d, write %d\n",
-                      myaddr, memaddr, len, write);
+      /* FIXME: Send to something other than STDOUT? */
+      printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x");
+      gdb_print_host_address (myaddr, gdb_stdout);
+      printf_filtered (", memaddr 0x%s, len %d, write %d\n",
+                      paddr_nz (memaddr), len, write);
       if (sr_get_debug () && write)
        dump_mem (myaddr, len);
     }
This page took 0.026872 seconds and 4 git commands to generate.