Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / sim / common / hw-instances.c
CommitLineData
b85e4829
AC
1/* The common simulator framework for GDB, the GNU Debugger.
2
b811d2c2 3 Copyright 2002-2020 Free Software Foundation, Inc.
b85e4829
AC
4
5 Contributed by Andrew Cagney and Red Hat.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
4744ac1b 11 the Free Software Foundation; either version 3 of the License, or
b85e4829
AC
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
4744ac1b 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22
23#include "hw-main.h"
24#include "hw-base.h"
25
c2c6d25f 26#include "sim-io.h"
c906108c
SS
27#include "sim-assert.h"
28
12c4cbd5
MF
29struct hw_instance_data
30{
c906108c
SS
31 hw_finish_instance_method *to_finish;
32 struct hw_instance *instances;
33};
34
35static hw_finish_instance_method abort_hw_finish_instance;
36
37void
38create_hw_instance_data (struct hw *me)
39{
40 me->instances_of_hw = HW_ZALLOC (me, struct hw_instance_data);
41 set_hw_finish_instance (me, abort_hw_finish_instance);
42}
43
44void
45delete_hw_instance_data (struct hw *me)
46{
47 /* NOP */
48}
49
50
51static void
52abort_hw_finish_instance (struct hw *hw,
53 struct hw_instance *instance)
54{
55 hw_abort (hw, "no instance finish method");
56}
57
58void
59set_hw_finish_instance (struct hw *me,
60 hw_finish_instance_method *finish)
61{
62 me->instances_of_hw->to_finish = finish;
63}
64
65
66#if 0
67void
68clean_hw_instances (struct hw *me)
69{
70 struct hw_instance **instance = &me->instances;
71 while (*instance != NULL)
72 {
73 struct hw_instance *old_instance = *instance;
74 hw_instance_delete (old_instance);
75 instance = &me->instances;
76 }
77}
78#endif
79
80
81void
82hw_instance_delete (struct hw_instance *instance)
83{
84#if 1
85 hw_abort (hw_instance_hw (instance), "not implemented");
86#else
87 struct hw *me = hw_instance_hw (instance);
88 if (instance->to_instance_delete == NULL)
89 hw_abort (me, "no delete method");
34b47c38 90 instance->method->delete (instance);
c906108c 91 if (instance->args != NULL)
d79fe0d6 92 free (instance->args);
c906108c 93 if (instance->path != NULL)
d79fe0d6 94 free (instance->path);
c906108c
SS
95 if (instance->child == NULL)
96 {
97 /* only remove leaf nodes */
98 struct hw_instance **curr = &me->instances;
99 while (*curr != instance)
100 {
101 ASSERT (*curr != NULL);
102 curr = &(*curr)->next;
103 }
104 *curr = instance->next;
105 }
106 else
107 {
108 /* check it isn't in the instance list */
109 struct hw_instance *curr = me->instances;
110 while (curr != NULL)
111 {
34b47c38 112 ASSERT (curr != instance);
c906108c
SS
113 curr = curr->next;
114 }
115 /* unlink the child */
116 ASSERT (instance->child->parent == instance);
117 instance->child->parent = NULL;
118 }
119 cap_remove (me->ihandles, instance);
d79fe0d6 120 free (instance);
c906108c
SS
121#endif
122}
123
124
125static int
126panic_hw_instance_read (struct hw_instance *instance,
127 void *addr,
128 unsigned_word len)
129{
130 hw_abort (hw_instance_hw (instance), "no read method");
131 return -1;
132}
133
134
135
136static int
137panic_hw_instance_write (struct hw_instance *instance,
138 const void *addr,
139 unsigned_word len)
140{
141 hw_abort (hw_instance_hw (instance), "no write method");
142 return -1;
143}
144
145
146static int
147panic_hw_instance_seek (struct hw_instance *instance,
148 unsigned_word pos_hi,
149 unsigned_word pos_lo)
150{
151 hw_abort (hw_instance_hw (instance), "no seek method");
152 return -1;
153}
154
155
156int
157hw_instance_call_method (struct hw_instance *instance,
158 const char *method_name,
159 int n_stack_args,
028f6515 160 unsigned_cell stack_args[/*n_stack_args*/],
c906108c
SS
161 int n_stack_returns,
162 unsigned_cell stack_returns[/*n_stack_args*/])
163{
164#if 1
165 hw_abort (hw_instance_hw (instance), "not implemented");
166 return -1;
167#else
168 struct hw *me = instance->owner;
169 const hw_instance_methods *method = instance->method->methods;
170 if (method == NULL)
171 {
172 hw_abort (me, "no methods (want %s)", method_name);
173 }
174 while (method->name != NULL)
175 {
34b47c38 176 if (strcmp (method->name, method_name) == 0)
c906108c
SS
177 {
178 return method->method (instance,
179 n_stack_args, stack_args,
180 n_stack_returns, stack_returns);
181 }
182 method++;
183 }
184 hw_abort (me, "no %s method", method_name);
185 return 0;
186#endif
187}
188
189
190#define set_hw_instance_read(instance, method)\
191((instance)->to_instance_read = (method))
192
193#define set_hw_instance_write(instance, method)\
194((instance)->to_instance_write = (method))
195
196#define set_hw_instance_seek(instance, method)\
197((instance)->to_instance_seek = (method))
198
199
200#if 0
201static void
202set_hw_instance_finish (struct hw *me,
203 hw_instance_finish_method *method)
204{
205 if (me->instances_of_hw == NULL)
206 me->instances_of_hw = HW_ZALLOC (me, struct hw_instance_data);
207 me->instances_of_hw->to_finish = method;
208}
209#endif
210
211
212struct hw_instance *
213hw_instance_create (struct hw *me,
214 struct hw_instance *parent,
215 const char *path,
216 const char *args)
217{
218 struct hw_instance *instance = ZALLOC (struct hw_instance);
219 /*instance->unit*/
220 /* link this instance into the devices list */
221 instance->hw_of_instance = me;
222 instance->parent_of_instance = NULL;
223 /* link this instance into the front of the devices instance list */
224 instance->sibling_of_instance = me->instances_of_hw->instances;
225 me->instances_of_hw->instances = instance;
226 if (parent != NULL)
227 {
228 ASSERT (parent->child_of_instance == NULL);
229 parent->child_of_instance = instance;
230 instance->parent_of_instance = parent;
231 }
232 instance->args_of_instance = hw_strdup (me, args);
233 instance->path_of_instance = hw_strdup (me, path);
234 set_hw_instance_read (instance, panic_hw_instance_read);
235 set_hw_instance_write (instance, panic_hw_instance_write);
236 set_hw_instance_seek (instance, panic_hw_instance_seek);
237 hw_handle_add_ihandle (me, instance);
238 me->instances_of_hw->to_finish (me, instance);
239 return instance;
240}
241
242
243struct hw_instance *
244hw_instance_interceed (struct hw_instance *parent,
245 const char *path,
246 const char *args)
247{
248#if 1
249 return NULL;
250#else
251 struct hw_instance *instance = ZALLOC (struct hw_instance);
252 /*instance->unit*/
253 /* link this instance into the devices list */
254 if (me != NULL)
255 {
256 ASSERT (parent == NULL);
257 instance->hw_of_instance = me;
258 instance->parent_of_instance = NULL;
259 /* link this instance into the front of the devices instance list */
260 instance->sibling_of_instance = me->instances_of_hw->instances;
261 me->instances_of_hw->instances = instance;
262 }
263 if (parent != NULL)
264 {
265 struct hw_instance **previous;
266 ASSERT (parent->child_of_instance == NULL);
267 parent->child_of_instance = instance;
268 instance->owner = parent->owner;
269 instance->parent_of_instance = parent;
270 /* in the devices instance list replace the parent instance with
271 this one */
272 instance->next = parent->next;
273 /* replace parent with this new node */
274 previous = &instance->owner->instances;
275 while (*previous != parent)
276 {
277 ASSERT (*previous != NULL);
278 previous = &(*previous)->next;
279 }
280 *previous = instance;
281 }
282 instance->data = data;
34b47c38
MF
283 instance->args = (args == NULL ? NULL : (char *) strdup (args));
284 instance->path = (path == NULL ? NULL : (char *) strdup (path));
c906108c
SS
285 cap_add (instance->owner->ihandles, instance);
286 return instance;
287#endif
288}
This page took 0.974189 seconds and 4 git commands to generate.