Finish implementation of sim-memopt.
authorAndrew Cagney <cagney@redhat.com>
Thu, 4 Sep 1997 10:08:44 +0000 (10:08 +0000)
committerAndrew Cagney <cagney@redhat.com>
Thu, 4 Sep 1997 10:08:44 +0000 (10:08 +0000)
Use in d30v and tic80.
Make available a generic sim_read, sim_write implementation.

sim/common/.Sanitize
sim/common/ChangeLog
sim/common/sim-base.h
sim/common/sim-config.c
sim/common/sim-hrw.c [new file with mode: 0644]
sim/common/sim-memopt.c
sim/common/sim-utils.h
sim/tic80/ChangeLog
sim/tic80/Makefile.in
sim/tic80/sim-calls.c

index 2f802cb087295b511c7ba316aafd73c2e0397654..bd1065bde18a3cf0f2f88fe1fcdab887aeed2662 100644 (file)
@@ -66,6 +66,7 @@ sim-events.h
 sim-fpu.c
 sim-fpu.h
 sim-hload.c
+sim-hrw.c
 sim-inline.c
 sim-inline.h
 sim-io.c
index 39fce64ddf665ee8718d57e47b178bd44e444980..3dd3d982f7d598a242c0c747d80457dc877be46e 100644 (file)
@@ -1,5 +1,23 @@
 Thu Sep  4 09:27:54 1997  Andrew Cagney  <cagney@b1.cygnus.com>
 
+       * sim-config.c (sim_config): Add assert for SIM_MAGIC_NUMBER.
+
+       * sim-utils.h (NZALLOC): Define - zalloc * N.
+
+       * sim-hrw.c (sim_read, sim_write): New file.  Provide generic
+       implementation of read/write functions.
+
+       * Make-common.in (sim-hrw.o): New target.
+
+       * sim-base.h (STATE_MEMOPT_P): Delete, simulators _always_ add
+       memory.
+
+       * sim-memopt.c (memory_option_handler): Implement memory-size
+       command. Implement memory-alias command.  Let memory-delete delete
+       all memory regions.
+       (add_memopt): New function.  Add a memory region.
+       (do_memopt_delete): New function. Delete a memory region.
+
        * sim-utils.c (sim_elapsed_time_get): Never return zero.
 
        * sim-core.c (sim_core_detach): New function.
index 988eb2901e7d8994fe17a8f85e41386382a5b5bb..f2b13d6262d552a1f8e8acb52508e76e4cbe1e54 100644 (file)
@@ -202,7 +202,6 @@ typedef struct {
 
   /* memory-options for managing the core */
 #define STATE_MEMOPT(sd) ((sd)->base.memopt)
-#define STATE_MEMOPT_P(sd) (STATE_MEMOPT (sd) != NULL)
   sim_memopt *memopt;
 
   /* event handler */
index 04ad95fce6c9130dbc82005ab14769317d7c38d8..14236f372305616eccda46ddbf831fbf2550bcf7 100644 (file)
@@ -20,6 +20,7 @@
 
 
 #include "sim-main.h"
+#include "sim-assert.h"
 #include "bfd.h"
 
 
@@ -135,6 +136,7 @@ SIM_RC
 sim_config (SIM_DESC sd)
 {
   int prefered_target_byte_order;
+  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
 
   /* extract all relevant information */
   if (STATE_PROG_BFD (sd) == NULL)
diff --git a/sim/common/sim-hrw.c b/sim/common/sim-hrw.c
new file mode 100644 (file)
index 0000000..3274fb1
--- /dev/null
@@ -0,0 +1,41 @@
+/* Generic memory read/write for hardware simulator models.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   Contributed by Cygnus Support.
+
+This file is part of GDB, the GNU debugger.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#include "sim-main.h"
+#include "sim-assert.h"
+
+/* Generic implementation of sim_read that works with simulators
+   modeling real hardware */
+
+int
+sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
+{
+  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
+  return sim_core_read_buffer (sd, NULL, sim_core_write_map,
+                              buf, mem, length);
+}
+
+int
+sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
+{
+  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
+  return sim_core_write_buffer (sd, NULL, sim_core_write_map,
+                               buf, mem, length);
+}
index be98a4a710087e9135c46bf111992d45b22ab5b8..3481c218f74731a9c6459402e1dd94fef0a3fa5d 100644 (file)
@@ -48,8 +48,11 @@ static DECLARE_OPTION_HANDLER (memory_option_handler);
 
 static const OPTION memory_options[] =
 {
+  { {"memory-delete", optional_argument, NULL, OPTION_MEMORY_DELETE },
+      '\0', "ADDRESS", "Delete memory at ADDRESS (all addresses)",
+      memory_option_handler },
   { {"delete-memory", required_argument, NULL, OPTION_MEMORY_DELETE },
-      '\0', "ADDRESS", "Delete memory at ADDRESS",
+      '\0', "ADDRESS", NULL,
       memory_option_handler },
 
   { {"memory-region", required_argument, NULL, OPTION_MEMORY_REGION },
@@ -68,14 +71,71 @@ static const OPTION memory_options[] =
       '\0', NULL, "Clear all memory regions",
       memory_option_handler },
 
+  { {"memory-info", no_argument, NULL, OPTION_MEMORY_INFO },
+      '\0', NULL, "List configurable memory regions",
+      memory_option_handler },
   { {"info-memory", no_argument, NULL, OPTION_MEMORY_INFO },
-      '\0', NULL, "Add memory at address zero",
+      '\0', NULL, NULL,
       memory_option_handler },
 
   { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
 };
 
 
+static sim_memopt *
+do_memopt_add (sd, addr, nr_bytes, modulo, entry, buffer)
+     SIM_DESC sd;
+     address_word addr;
+     address_word nr_bytes;
+     unsigned modulo;
+     sim_memopt **entry;
+     void *buffer;
+{
+  sim_core_attach (sd, NULL,
+                  attach_raw_memory, access_read_write_exec, 0,
+                  addr, nr_bytes, modulo, NULL, buffer);
+  while ((*entry) != NULL)
+    entry = &(*entry)->next;
+  (*entry) = ZALLOC (sim_memopt);
+  (*entry)->addr = addr;
+  (*entry)->nr_bytes = nr_bytes;
+  (*entry)->modulo = modulo;
+  (*entry)->buffer = buffer;
+  return (*entry);
+}
+
+static SIM_RC
+do_memopt_delete (sd, addr)
+     SIM_DESC sd;
+     address_word addr;
+{
+  sim_memopt **entry = &STATE_MEMOPT (sd);
+  sim_memopt *alias;
+  while ((*entry) != NULL && (*entry)->addr != addr)
+    entry = &(*entry)->next;
+  if ((*entry) == NULL)
+    {
+      sim_io_eprintf (sd, "Memory at 0x%lx not found, not deleted\n",
+                     (long) addr);
+      return SIM_RC_FAIL;
+    }
+  /* delete any buffer */
+  if ((*entry)->buffer != NULL)
+    zfree ((*entry)->buffer);
+  /* delete it and its aliases */
+  alias = *entry;
+  *entry = alias->next;
+  while (alias != NULL)
+    {
+      sim_memopt *dead = alias;
+      alias = alias->alias;
+      sim_core_detach (sd, NULL, attach_raw_memory, 0, dead->addr);
+      zfree (dead);
+    }
+  return SIM_RC_OK;
+}
+
+
 static SIM_RC
 memory_option_handler (sd, opt, arg, is_command)
      SIM_DESC sd;
@@ -87,33 +147,17 @@ memory_option_handler (sd, opt, arg, is_command)
     {
 
     case OPTION_MEMORY_DELETE:
-      {
-       address_word addr = strtoul (arg, NULL, 0);
-       sim_memopt **entry = &STATE_MEMOPT (sd);
-       sim_memopt *alias;
-       while ((*entry) != NULL && (*entry)->addr != addr)
-         entry = &(*entry)->next;
-       if ((*entry) == NULL)
-         {
-           sim_io_eprintf (sd, "Memory at 0x%lx not found, not deleted\n",
-                           (long) addr);
-           return SIM_RC_FAIL;
-         }
-       /* delete any buffer */
-       if ((*entry)->buf != NULL)
-         zfree ((*entry)->buf);
-       /* delete it and its aliases */
-       alias = *entry;
-       *entry = alias->next;
-       while (alias != NULL)
-         {
-           sim_memopt *dead = alias;
-           alias = alias->alias;
-           sim_core_detach (sd, NULL, attach_raw_memory, 0, dead->addr);
-           zfree (dead);
-         }
-       return SIM_RC_OK;
-      }
+      if (arg == NULL)
+       {
+         while (STATE_MEMOPT (sd) != NULL)
+           do_memopt_delete (sd, STATE_MEMOPT (sd)->addr);
+         return SIM_RC_OK;
+       }
+      else
+       {
+         address_word addr = strtoul (arg, NULL, 0);
+         return do_memopt_delete (sd, addr);
+       }
     
     case OPTION_MEMORY_REGION:
       {
@@ -121,7 +165,6 @@ memory_option_handler (sd, opt, arg, is_command)
        address_word addr = 0;
        address_word nr_bytes = 0;
        unsigned modulo = 0;
-       sim_memopt **entry = &STATE_MEMOPT (sd);
        /* parse the arguments */
        addr = strtoul (chp, &chp, 0);
        if (*chp != ',')
@@ -133,31 +176,48 @@ memory_option_handler (sd, opt, arg, is_command)
        nr_bytes = strtoul (chp, &chp, 0);
        if (*chp == ',')
          modulo = strtoul (chp + 1, NULL, 0);
-       /* try to attach it */
-       sim_core_attach (sd, NULL,
-                        attach_raw_memory, access_read_write_exec, 0,
-                        addr, nr_bytes, modulo, NULL, NULL);
-       /* ok, so insert it */
-       while ((*entry) != NULL)
-         entry = &(*entry)->next;
-       (*entry) = ZALLOC (sim_memopt);
-       (*entry)->addr = addr;
-       (*entry)->nr_bytes = nr_bytes;
-       (*entry)->modulo = modulo;
+       /* try to attach/insert it */
+       do_memopt_add (sd, addr, nr_bytes, modulo, &STATE_MEMOPT (sd), NULL);
        return SIM_RC_OK;
       }
 
     case OPTION_MEMORY_ALIAS:
       {
-       sim_io_eprintf (sd, "memory-alias not supported for for this simulator\n");
-       break;
+       char *chp = arg;
+       address_word addr = 0;
+       address_word nr_bytes = 0;
+       sim_memopt *entry;
+       /* parse the arguments */
+       addr = strtoul (chp, &chp, 0);
+       if (*chp != ',')
+         {
+           sim_io_eprintf (sd, "Missing size for memory-region\n");
+           return SIM_RC_FAIL;
+         }
+       chp++;
+       nr_bytes = strtoul (chp, &chp, 0);
+       /* try to attach/insert the main record */
+       entry = do_memopt_add (sd, addr, nr_bytes, 0/*modulo*/,
+                              &STATE_MEMOPT (sd), zalloc (nr_bytes));
+       /* now attach all the aliases */
+       while (*chp == ',')
+         {
+           address_word alias;
+           chp++;
+           alias = strtoul (chp, &chp, 0);
+           do_memopt_add (sd, alias, nr_bytes, 0/*modulo*/,
+                          &entry->alias, entry->buffer);
+         }
+       return SIM_RC_OK;
       }
 
     case OPTION_MEMORY_SIZE:
       {
-       sim_io_eprintf (sd, "memory-size not supported for for this simulator\n");
-       return SIM_RC_FAIL;
-       break;
+       address_word nr_bytes = strtoul (arg, NULL, 0);
+       /* try to attach/insert it */
+       do_memopt_add (sd, 0/*addr*/, nr_bytes, 0/*modulo*/,
+                      &STATE_MEMOPT (sd), NULL);
+       return SIM_RC_OK;
       }
 
     case OPTION_MEMORY_CLEAR:
@@ -206,8 +266,10 @@ memory_option_handler (sd, opt, arg, is_command)
                sim_io_printf (sd, " alias 0x%08lx,0x%lx",
                               (long) entry->addr,
                               (long) entry->nr_bytes);
-               for (alias = entry->alias; alias != NULL; alias = alias->next)
-                 sim_io_printf (sd, ",0x%08lx", entry->addr);
+               for (alias = entry->alias;
+                    alias != NULL;
+                    alias = alias->next)
+                 sim_io_printf (sd, ",0x%08lx", alias->addr);
              }
            sim_io_printf (sd, "\n");
          }
index cd7cc59c25259c95741068dd4fc568516849019c..0bacee42bc7d28a913856154f85256ebcb22c79d 100644 (file)
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 void *zalloc (unsigned long size);
 
 #define ZALLOC(TYPE) (TYPE*)zalloc(sizeof (TYPE))
+#define NZALLOC(TYPE,N) (TYPE*)zalloc(sizeof (TYPE) * (N))
 
 void zfree(void*);
 
index 6a5102b042b15be0af0932f06e9ac79befdddb66..eed5ccbf11eb1f40b598985c217a060ef9b4d932 100644 (file)
@@ -1,3 +1,9 @@
+Thu Sep  4 17:45:14 1997  Andrew Cagney  <cagney@b1.cygnus.com>
+
+       * sim-calls.c (sim_open): Add memory before parsing arguments.
+       (sim_read): Delete, replace with sim-hrw.
+       (sim_write): Delete, replace with sim-hrw.
+
 Thu Sep  4 10:48:57 1997  Andrew Cagney  <cagney@b1.cygnus.com>
 
        * sim-calls.c (sim_open): Use sim_do_command to add memory, only
index f15b68f969b1546b4aab84a89c2e10d694dbbd05..5a0a643b5619c52966e74bdc832c73d1c23c8653 100644 (file)
@@ -16,6 +16,7 @@ SIM_OBJS = sim-endian.o sim-bits.o sim-config.o \
        sim-events.o \
        sim-core.o \
        sim-hload.o \
+       sim-hrw.o \
        sim-io.o \
        sim-utils.o \
        sim-load.o \
index 7d4c6a9f91594e014505ebddd6e9092cd531844b..55f04964da15363ddb00b8e482ea5a33b501917b 100644 (file)
@@ -50,11 +50,25 @@ sim_open (SIM_OPEN_KIND kind,
          struct _bfd *abfd,
          char **argv)
 {
+  char *buf;
   SIM_DESC sd = sim_state_alloc (kind, callback);
 
   if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
     return 0;
 
+#define TIC80_MEM_START 0x2000000
+#define TIC80_MEM_SIZE 0x100000
+
+  /* main memory */
+  asprintf (&buf, "memory region 0x%lx,0x%lx",
+           TIC80_MEM_START, TIC80_MEM_SIZE);
+  sim_do_command (sd, buf);
+  free (buf);
+  /* interrupt memory */
+  sim_do_command (sd, "memory region 0x1010000,0x1000");
+  /* some memory at zero */
+  sim_do_command (sd, "memory region 0,0x100000");
+  
   /* 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.  */
@@ -92,23 +106,6 @@ sim_open (SIM_OPEN_KIND kind,
       return 0;
     }
 
-#define TIC80_MEM_START 0x2000000
-#define TIC80_MEM_SIZE 0x100000
-
-  if (!STATE_MEMOPT_P (sd))
-    {
-      char *buf;
-      /* main memory */
-      asprintf (&buf, "memory region 0x%lx,0x%lx",
-               TIC80_MEM_START, TIC80_MEM_SIZE);
-      sim_do_command (sd, buf);
-      free (buf);
-      /* interrupt memory */
-      sim_do_command (sd, "memory region 0x1010000,0x1000");
-      /* some memory at zero */
-      sim_do_command (sd, "memory region 0,0x100000");
-    }
-
  /* FIXME: for now */
   return sd;
 }
@@ -123,22 +120,6 @@ sim_close (SIM_DESC sd, int quitting)
 }
 
 
-int
-sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
-{
-  return sim_core_read_buffer (sd, NULL, sim_core_write_map,
-                              buf, mem, length);
-}
-
-
-int
-sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
-{
-  return sim_core_write_buffer (sd, NULL, sim_core_write_map,
-                               buf, mem, length);
-}
-
-
 /* FIXME - these magic numbers need to be moved elsewhere */
 
 #define SP_REGNUM 1            /* Contains address of top of stack */
This page took 0.036383 seconds and 4 git commands to generate.