sim: overhaul & unify endian settings management
[deliverable/binutils-gdb.git] / sim / mn10300 / interp.c
index 4940acc6e7cbc52a47ca7d524bef2c7b9f6a8a01..b793d3c019feecec143e52a83a563ec5dc3b23d4 100644 (file)
@@ -1,4 +1,6 @@
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 
 #include "sim-main.h"
@@ -8,18 +10,8 @@
 #include "bfd.h"
 #include "sim-assert.h"
 
-
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 
 #include "bfd.h"
 
@@ -86,21 +78,27 @@ mn10300_pc_set (sim_cpu *cpu, sim_cia pc)
   PC = pc;
 }
 
+static int mn10300_reg_fetch (SIM_CPU *, int, unsigned char *, int);
+static int mn10300_reg_store (SIM_CPU *, int, unsigned char *, int);
+
 /* These default values correspond to expected usage for the chip.  */
 
 SIM_DESC
 sim_open (SIM_OPEN_KIND kind,
          host_callback *cb,
          struct bfd *abfd,
-         char **argv)
+         char * const *argv)
 {
   int i;
   SIM_DESC sd = sim_state_alloc (kind, cb);
 
   SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
 
+  /* 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, /*cgen_cpu_max_extra_bytes ()*/0) != SIM_RC_OK)
+  if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK)
     return 0;
 
   /* for compatibility */
@@ -109,8 +107,6 @@ sim_open (SIM_OPEN_KIND kind,
   /* FIXME: should be better way of setting up interrupts.  For
      moment, only support watchpoints causing a breakpoint (gdb
      halt). */
-  STATE_WATCHPOINTS (sd)->pc = &(PC);
-  STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PC);
   STATE_WATCHPOINTS (sd)->interrupt_handler = NULL;
   STATE_WATCHPOINTS (sd)->interrupt_names = NULL;
 
@@ -122,9 +118,7 @@ sim_open (SIM_OPEN_KIND kind,
   sim_do_command (sd, "memory region 0,0x100000");
   sim_do_command (sd, "memory region 0x40000000,0x200000");
 
-  /* 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)
     {
       /* Uninstall the modules to avoid memory leaks,
@@ -308,6 +302,8 @@ sim_open (SIM_OPEN_KIND kind,
     {
       SIM_CPU *cpu = STATE_CPU (sd, i);
 
+      CPU_REG_FETCH (cpu) = mn10300_reg_fetch;
+      CPU_REG_STORE (cpu) = mn10300_reg_store;
       CPU_PC_FETCH (cpu) = mn10300_pc_get;
       CPU_PC_STORE (cpu) = mn10300_pc_set;
     }
@@ -318,8 +314,8 @@ sim_open (SIM_OPEN_KIND kind,
 SIM_RC
 sim_create_inferior (SIM_DESC sd,
                     struct bfd *prog_bfd,
-                    char **argv,
-                    char **env)
+                    char * const *argv,
+                    char * const *env)
 {
   memset (&State, 0, sizeof (State));
   if (prog_bfd != NULL) {
@@ -338,11 +334,8 @@ sim_create_inferior (SIM_DESC sd,
 /* FIXME These would more efficient to use than load_mem/store_mem,
    but need to be changed to use the memory map.  */
 
-int
-sim_fetch_register (SIM_DESC sd,
-                   int rn,
-                   unsigned char *memory,
-                   int length)
+static int
+mn10300_reg_fetch (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
 {
   reg_t reg = State.regs[rn];
   uint8 *a = memory;
@@ -353,11 +346,8 @@ sim_fetch_register (SIM_DESC sd,
   return length;
 }
  
-int
-sim_store_register (SIM_DESC sd,
-                   int rn,
-                   unsigned char *memory,
-                   int length)
+static int
+mn10300_reg_store (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
 {
   uint8 *a = memory;
   State.regs[rn] = (a[3] << 24) + (a[2] << 16) + (a[1] << 8) + a[0];
@@ -477,6 +467,9 @@ mn10300_cpu_exception_resume(SIM_DESC sd, sim_cpu* cpu, int exception)
 
   if(exception == 0 && State.exc_suspended > 0)
     {
+#ifndef SIGTRAP
+# define SIGTRAP 5
+#endif
       if(State.exc_suspended != SIGTRAP) /* warn not for breakpoints */
          sim_io_eprintf(sd, "Warning, resuming but ignoring pending exception signal (%d)\n",
                       State.exc_suspended); 
This page took 0.024617 seconds and 4 git commands to generate.