sim: remove use of PTR
[binutils-gdb.git] / sim / m32r / sim-if.c
index 33ae7c106e391b42016202982f39f0ea4d1fad85..878a0d5f576412578c6feabf83601f50b3579d9b 100644 (file)
@@ -1,5 +1,5 @@
 /* Main simulator entry points specific to the M32R.
-   Copyright (C) 1996-2021 Free Software Foundation, Inc.
+   Copyright (C) 1996-2022 Free Software Foundation, Inc.
    Contributed by Cygnus Support.
 
    This file is part of GDB, the GNU debugger.
 /* This must come before any other includes.  */
 #include "defs.h"
 
+#include <string.h>
+#include <stdlib.h>
+
+#include "sim/callback.h"
 #include "sim-main.h"
 #include "sim-options.h"
 #include "libiberty.h"
 #include "bfd.h"
 
-#include <string.h>
-#include <stdlib.h>
-
 #include "dv-m32r_uart.h"
 
+#define M32R_DEFAULT_MEM_SIZE 0x2000000 /* 32M */
+
 static void free_state (SIM_DESC);
 static void print_m32r_misc_cpu (SIM_CPU *cpu, int verbose);
 \f
@@ -58,6 +61,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = m32r_sim_machs;
+  STATE_MODEL_NAME (sd) = "m32r/d";
   current_alignment = STRICT_ALIGNMENT;
   current_target_byte_order = BFD_ENDIAN_BIG;
 
@@ -95,11 +99,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
     sim_do_commandf (sd, "memory region 0,0x%x", M32R_DEFAULT_MEM_SIZE);
 
   /* check for/establish the reference program image */
-  if (sim_analyze_program (sd,
-                          (STATE_PROG_ARGV (sd) != NULL
-                           ? *STATE_PROG_ARGV (sd)
-                           : NULL),
-                          abfd) != SIM_RC_OK)
+  if (sim_analyze_program (sd, STATE_PROG_FILE (sd), abfd) != SIM_RC_OK)
     {
       free_state (sd);
       return 0;
@@ -146,9 +146,10 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 \f
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
-                    char * const *envp)
+                    char * const *env)
 {
   SIM_CPU *current_cpu = STATE_CPU (sd, 0);
+  host_callback *cb = STATE_CALLBACK (sd);
   SIM_ADDR addr;
 
   if (abfd != NULL)
@@ -157,12 +158,13 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
     addr = 0;
   sim_pc_set (current_cpu, addr);
 
-#ifdef M32R_LINUX
-  m32rbf_h_cr_set (current_cpu,
-                    m32r_decode_gdb_ctrl_regnum(SPI_REGNUM), 0x1f00000);
-  m32rbf_h_cr_set (current_cpu,
-                    m32r_decode_gdb_ctrl_regnum(SPU_REGNUM), 0x1f00000);
-#endif
+  if (STATE_ENVIRONMENT (sd) == USER_ENVIRONMENT)
+    {
+      m32rbf_h_cr_set (current_cpu,
+                      m32r_decode_gdb_ctrl_regnum(SPI_REGNUM), 0x1f00000);
+      m32rbf_h_cr_set (current_cpu,
+                      m32r_decode_gdb_ctrl_regnum(SPU_REGNUM), 0x1f00000);
+    }
 
   /* 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'
@@ -174,6 +176,15 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
       STATE_PROG_ARGV (sd) = dupargv (argv);
     }
 
+  if (STATE_PROG_ENVP (sd) != env)
+    {
+      freeargv (STATE_PROG_ENVP (sd));
+      STATE_PROG_ENVP (sd) = dupargv (env);
+    }
+
+  cb->argv = STATE_PROG_ARGV (sd);
+  cb->envp = STATE_PROG_ENVP (sd);
+
   return SIM_RC_OK;
 }