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