1 /* Simulator memory option handling.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "sim-assert.h"
23 #include "sim-options.h"
36 /* "core" command line options. */
39 OPTION_MEMORY_DELETE = OPTION_START,
47 static DECLARE_OPTION_HANDLER (memory_option_handler);
49 static const OPTION memory_options[] =
51 { {"delete-memory", required_argument, NULL, OPTION_MEMORY_DELETE },
52 '\0', "ADDRESS", "Delete memory at ADDRESS",
53 memory_option_handler },
55 { {"memory-region", required_argument, NULL, OPTION_MEMORY_REGION },
56 '\0', "ADDRESS,SIZE[,MODULO]", "Add a memory region",
57 memory_option_handler },
59 { {"memory-alias", required_argument, NULL, OPTION_MEMORY_ALIAS },
60 '\0', "ADDRESS,SIZE{,ADDRESS}", "Add memory shadow",
61 memory_option_handler },
63 { {"memory-size", required_argument, NULL, OPTION_MEMORY_SIZE },
64 '\0', "SIZE", "Add memory at address zero",
65 memory_option_handler },
67 { {"memory-clear", no_argument, NULL, OPTION_MEMORY_CLEAR },
68 '\0', NULL, "Clear all memory regions",
69 memory_option_handler },
71 { {"info-memory", no_argument, NULL, OPTION_MEMORY_INFO },
72 '\0', NULL, "Add memory at address zero",
73 memory_option_handler },
75 { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
80 memory_option_handler (sd, opt, arg, is_command)
89 case OPTION_MEMORY_DELETE:
91 address_word addr = strtoul (arg, NULL, 0);
92 sim_memopt **entry = &STATE_MEMOPT (sd);
94 while ((*entry) != NULL && (*entry)->addr != addr)
95 entry = &(*entry)->next;
98 sim_io_eprintf (sd, "Memory at 0x%lx not found, not deleted\n",
102 /* delete any buffer */
103 if ((*entry)->buf != NULL)
104 zfree ((*entry)->buf);
105 /* delete it and its aliases */
107 *entry = alias->next;
108 while (alias != NULL)
110 sim_memopt *dead = alias;
111 alias = alias->alias;
112 sim_core_detach (sd, NULL, attach_raw_memory, 0, dead->addr);
118 case OPTION_MEMORY_REGION:
121 address_word addr = 0;
122 address_word nr_bytes = 0;
124 sim_memopt **entry = &STATE_MEMOPT (sd);
125 /* parse the arguments */
126 addr = strtoul (chp, &chp, 0);
129 sim_io_eprintf (sd, "Missing size for memory-region\n");
133 nr_bytes = strtoul (chp, &chp, 0);
135 modulo = strtoul (chp + 1, NULL, 0);
136 /* try to attach it */
137 sim_core_attach (sd, NULL,
138 attach_raw_memory, access_read_write_exec, 0,
139 addr, nr_bytes, modulo, NULL, NULL);
140 /* ok, so insert it */
141 while ((*entry) != NULL)
142 entry = &(*entry)->next;
143 (*entry) = ZALLOC (sim_memopt);
144 (*entry)->addr = addr;
145 (*entry)->nr_bytes = nr_bytes;
146 (*entry)->modulo = modulo;
150 case OPTION_MEMORY_ALIAS:
152 sim_io_eprintf (sd, "memory-alias not supported for for this simulator\n");
156 case OPTION_MEMORY_SIZE:
158 sim_io_eprintf (sd, "memory-size not supported for for this simulator\n");
163 case OPTION_MEMORY_CLEAR:
166 for (entry = STATE_MEMOPT (sd); entry != NULL; entry = entry->next)
169 for (alias = entry; alias != NULL; alias = alias->next)
172 address_word nr_bytes;
173 if (alias->modulo != 0)
174 nr_bytes = alias->modulo;
176 nr_bytes = alias->nr_bytes;
177 sim_core_write_buffer (sd, NULL, sim_core_write_map,
179 alias->addr + nr_bytes,
188 case OPTION_MEMORY_INFO:
191 sim_io_printf (sd, "Memory maps:\n");
192 for (entry = STATE_MEMOPT (sd); entry != NULL; entry = entry->next)
195 sim_io_printf (sd, " memory");
196 if (entry->alias == NULL)
198 sim_io_printf (sd, " region 0x%08lx,0x%lx",
200 (long) entry->nr_bytes);
201 if (entry->modulo != 0)
202 sim_io_printf (sd, ",0x%lx", (long) entry->modulo);
206 sim_io_printf (sd, " alias 0x%08lx,0x%lx",
208 (long) entry->nr_bytes);
209 for (alias = entry->alias; alias != NULL; alias = alias->next)
210 sim_io_printf (sd, ",0x%08lx", entry->addr);
212 sim_io_printf (sd, "\n");
219 sim_io_eprintf (sd, "Unknown watch option %d\n", opt);
228 /* "memory" module install handler.
230 This is called via sim_module_install to install the "memory" subsystem
231 into the simulator. */
233 static MODULE_INIT_FN sim_memory_init;
234 static MODULE_UNINSTALL_FN sim_memory_uninstall;
237 sim_memopt_install (SIM_DESC sd)
239 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
240 sim_add_option_table (sd, memory_options);
241 sim_module_add_uninstall_fn (sd, sim_memory_uninstall);
242 sim_module_add_init_fn (sd, sim_memory_init);
247 /* Uninstall the "memory" subsystem from the simulator. */
250 sim_memory_uninstall (SIM_DESC sd)
252 /* FIXME: free buffers, etc. */
257 sim_memory_init (SIM_DESC sd)
259 /* FIXME: anything needed? */