sim: overhaul & unify endian settings management
[deliverable/binutils-gdb.git] / sim / cris / sim-if.c
index edd7885caf703bed88b57d32badb9989cb4bc371..c183856fa4c8ae929a24ecc3075cc656c2c70d7a 100644 (file)
@@ -20,7 +20,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Based on the fr30 file, mixing in bits from the i960 and pruning of
    dead code.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "libiberty.h"
 #include "bfd.h"
 #include "elf-bfd.h"
@@ -28,18 +30,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "sim-main.h"
 #include <stdlib.h>
 #include <errno.h>
+#include <unistd.h>
 #include "sim-options.h"
 #include "dis-asm.h"
-
-/* Apparently the autoconf bits are missing (though HAVE_ENVIRON is used
-   in other dirs; also lacking there).  Patch around it for major systems.  */
-#if defined (HAVE_ENVIRON) || defined (__GLIBC__)
-extern char **environ;
-#define GET_ENVIRON() environ
-#else
-char *missing_environ[] = { "SHELL=/bin/sh", "PATH=/bin:/usr/bin", NULL };
-#define GET_ENVIRON() missing_environ
-#endif
+#include "environ.h"
 
 /* Used with get_progbounds to find out how much memory is needed for the
    program.  We don't want to allocate more, since that could mask
@@ -660,6 +654,9 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
      standard ;-) that the rest of the elements won't be initialized.  */
   bfd_byte sp_init[4] = {0, 0, 0, 0};
 
+  /* Set default options before parsing user options.  */
+  current_target_byte_order = BFD_ENDIAN_LITTLE;
+
   /* The cpu data is kept in a separately allocated chunk of memory.  */
   if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK)
     {
@@ -747,7 +744,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
   if (abfd != NULL && !cris_bare_iron)
     {
       const char *name = bfd_get_filename (abfd);
-      char **my_environ = GET_ENVIRON ();
       /* We use these maps to give the same behavior as the old xsim
         simulator.  */
       USI envtop = 0x40000000;
@@ -764,8 +760,8 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
       bfd_byte buf[4];
 
       /* Count in the environment as well. */
-      for (envc = 0; my_environ[envc] != NULL; envc++)
-       len += strlen (my_environ[envc]) + 1;
+      for (envc = 0; environ[envc] != NULL; envc++)
+       len += strlen (environ[envc]) + 1;
 
       for (i = 0; prog_argv[i] != NULL; my_argc++, i++)
        len += strlen (prog_argv[i]) + 1;
@@ -849,10 +845,9 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
       for (i = 0; i < envc; i++, csp += 4)
        {
-         unsigned int strln = strlen (my_environ[i]) + 1;
+         unsigned int strln = strlen (environ[i]) + 1;
 
-         if (sim_core_write_buffer (sd, NULL, NULL_CIA, my_environ[i], epp,
-                                    strln)
+         if (sim_core_write_buffer (sd, NULL, NULL_CIA, environ[i], epp, strln)
              != strln)
            goto abandon_chip;
 
@@ -887,7 +882,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   /* Allocate core managed memory if none specified by user.  */
   if (sim_core_read_buffer (sd, NULL, read_map, &c, startmem, 1) == 0)
-    sim_do_commandf (sd, "memory region 0x%" PRIx32 "x,0x%" PRIu32 "x",
+    sim_do_commandf (sd, "memory region 0x%" PRIx32 ",0x%" PRIu32,
                     startmem, endmem - startmem);
 
   /* Allocate simulator I/O managed memory if none specified by user.  */
@@ -948,10 +943,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 #endif
   }
 
-  /* Initialize various cgen things not done by common framework.
-     Must be done after cris_cgen_cpu_open.  */
-  cgen_init (sd);
-
   cris_set_callbacks (callback);
 
   return sd;
This page took 0.023491 seconds and 4 git commands to generate.