aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1997-09-04 10:08:44 +0000
committerAndrew Cagney <cagney@redhat.com>1997-09-04 10:08:44 +0000
commit6dbaff8f6067e91995adc90e5c8939de41c56e9a (patch)
treef71cef520e051d5d508c23d7b8f7540626c2e97d
parenta34abff813f4fdd5f289ea45de9e874e31e7edf3 (diff)
downloadgdb-6dbaff8f6067e91995adc90e5c8939de41c56e9a.zip
gdb-6dbaff8f6067e91995adc90e5c8939de41c56e9a.tar.gz
gdb-6dbaff8f6067e91995adc90e5c8939de41c56e9a.tar.bz2
Finish implementation of sim-memopt.
Use in d30v and tic80. Make available a generic sim_read, sim_write implementation.
-rw-r--r--sim/common/.Sanitize1
-rw-r--r--sim/common/ChangeLog18
-rw-r--r--sim/common/sim-base.h1
-rw-r--r--sim/common/sim-config.c2
-rw-r--r--sim/common/sim-hrw.c41
-rw-r--r--sim/common/sim-memopt.c158
-rw-r--r--sim/common/sim-utils.h1
-rw-r--r--sim/tic80/ChangeLog6
-rw-r--r--sim/tic80/Makefile.in1
-rw-r--r--sim/tic80/sim-calls.c47
10 files changed, 194 insertions, 82 deletions
diff --git a/sim/common/.Sanitize b/sim/common/.Sanitize
index 2f802cb..bd1065b 100644
--- a/sim/common/.Sanitize
+++ b/sim/common/.Sanitize
@@ -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
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index 39fce64..3dd3d98 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -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.
diff --git a/sim/common/sim-base.h b/sim/common/sim-base.h
index 988eb29..f2b13d6 100644
--- a/sim/common/sim-base.h
+++ b/sim/common/sim-base.h
@@ -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 */
diff --git a/sim/common/sim-config.c b/sim/common/sim-config.c
index 04ad95f..14236f3 100644
--- a/sim/common/sim-config.c
+++ b/sim/common/sim-config.c
@@ -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
index 0000000..3274fb1
--- /dev/null
+++ b/sim/common/sim-hrw.c
@@ -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);
+}
diff --git a/sim/common/sim-memopt.c b/sim/common/sim-memopt.c
index be98a4a..3481c21 100644
--- a/sim/common/sim-memopt.c
+++ b/sim/common/sim-memopt.c
@@ -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");
}
diff --git a/sim/common/sim-utils.h b/sim/common/sim-utils.h
index cd7cc59c..0bacee4 100644
--- a/sim/common/sim-utils.h
+++ b/sim/common/sim-utils.h
@@ -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*);
diff --git a/sim/tic80/ChangeLog b/sim/tic80/ChangeLog
index 6a5102b..eed5ccb 100644
--- a/sim/tic80/ChangeLog
+++ b/sim/tic80/ChangeLog
@@ -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
diff --git a/sim/tic80/Makefile.in b/sim/tic80/Makefile.in
index f15b68f..5a0a643 100644
--- a/sim/tic80/Makefile.in
+++ b/sim/tic80/Makefile.in
@@ -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 \
diff --git a/sim/tic80/sim-calls.c b/sim/tic80/sim-calls.c
index 7d4c6a9..55f0496 100644
--- a/sim/tic80/sim-calls.c
+++ b/sim/tic80/sim-calls.c
@@ -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 */