--- /dev/null
+/* 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);
+}
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 },
'\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;
{
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:
{
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 != ',')
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:
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");
}
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. */
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;
}
}
-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 */