arc: Add nps400 machine type, and assembler flag.
[external/binutils.git] / sim / lm32 / sim-if.c
index be960c9..860c1e6 100644 (file)
@@ -1,7 +1,7 @@
 /* Main simulator entry points specific to Lattice Mico32.
    Contributed by Jon Beniston <jon@beniston.com>
    
-   Copyright (C) 2009-2013 Free Software Foundation, Inc.
+   Copyright (C) 2009-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
-
-static void free_state (SIM_DESC);
-static void print_lm32_misc_cpu (SIM_CPU * cpu, int verbose);
-static DECLARE_OPTION_HANDLER (lm32_option_handler);
-
-enum
-{
-  OPTION_ENDIAN = OPTION_START,
-};
-
-/* GDB passes -E, even though it's fixed, so we have to handle it here. common code only handles it if SIM_HAVE_BIENDIAN is defined, which it isn't for lm32.  */
-static const OPTION lm32_options[] = {
-  {{"endian", required_argument, NULL, OPTION_ENDIAN},
-   'E', "big", "Set endianness",
-   lm32_option_handler},
-  {{NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL}
-};
-
-/* Records simulator descriptor so utilities like lm32_dump_regs can be
-   called from gdb.  */
-SIM_DESC current_state;
 \f
 /* Cover function of sim_state_free to free the cpu buffers as well.  */
 
@@ -115,19 +94,6 @@ find_limit (bfd *prog_bfd)
   return 0;
 }
 
-/* Handle lm32 specific options.  */
-
-static SIM_RC
-lm32_option_handler (sd, cpu, opt, arg, is_command)
-     SIM_DESC sd;
-     sim_cpu *cpu;
-     int opt;
-     char *arg;
-     int is_command;
-{
-  return SIM_RC_OK;
-}
-
 /* Create an instance of the simulator.  */
 
 SIM_DESC
@@ -135,7 +101,7 @@ sim_open (kind, callback, abfd, argv)
      SIM_OPEN_KIND kind;
      host_callback *callback;
      struct bfd *abfd;
-     char **argv;
+     char * const *argv;
 {
   SIM_DESC sd = sim_state_alloc (kind, callback);
   char c;
@@ -154,11 +120,8 @@ sim_open (kind, callback, abfd, argv)
       free_state (sd);
       return 0;
     }
-  sim_add_option_table (sd, NULL, lm32_options);
 
-  /* 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.  */
+  /* The parser will print an error message for us, so we silently return.  */
   if (sim_parse_args (sd, argv) != SIM_RC_OK)
     {
       free_state (sd);
@@ -240,28 +203,15 @@ sim_open (kind, callback, abfd, argv)
      Must be done after lm32_cgen_cpu_open.  */
   cgen_init (sd);
 
-  /* Store in a global so things like lm32_dump_regs can be invoked
-     from the gdb command line.  */
-  current_state = sd;
-
   return sd;
 }
-
-void
-sim_close (sd, quitting)
-     SIM_DESC sd;
-     int quitting;
-{
-  lm32_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
-  sim_module_uninstall (sd);
-}
 \f
 SIM_RC
 sim_create_inferior (sd, abfd, argv, envp)
      SIM_DESC sd;
      struct bfd *abfd;
-     char **argv;
-     char **envp;
+     char * const *argv;
+     char * const *envp;
 {
   SIM_CPU *current_cpu = STATE_CPU (sd, 0);
   SIM_ADDR addr;
@@ -272,10 +222,15 @@ sim_create_inferior (sd, abfd, argv, envp)
     addr = 0;
   sim_pc_set (current_cpu, addr);
 
-#if 0
-  STATE_ARGV (sd) = sim_copy_argv (argv);
-  STATE_ENVP (sd) = sim_copy_argv (envp);
-#endif
+  /* Standalone mode (i.e. `run`) will take care of the argv for us in
+     sim_open() -> sim_parse_args().  But in debug mode (i.e. 'target sim'
+     with `gdb`), we need to handle it because the user can change the
+     argv on the fly via gdb's 'run'.  */
+  if (STATE_PROG_ARGV (sd) != argv)
+    {
+      freeargv (STATE_PROG_ARGV (sd));
+      STATE_PROG_ARGV (sd) = dupargv (argv);
+    }
 
   return SIM_RC_OK;
 }