[binutils, ARM, 5/16] BF insns infrastructure with new global reloc R_ARM_THM_BF16
[binutils-gdb.git] / sim / common / hw-instances.c
blobb11fd5acd7a52c7bd7864507f87c824ce6a40afa
1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002-2019 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "hw-main.h"
24 #include "hw-base.h"
26 #include "sim-io.h"
27 #include "sim-assert.h"
29 struct hw_instance_data
31 hw_finish_instance_method *to_finish;
32 struct hw_instance *instances;
35 static hw_finish_instance_method abort_hw_finish_instance;
37 void
38 create_hw_instance_data (struct hw *me)
40 me->instances_of_hw = HW_ZALLOC (me, struct hw_instance_data);
41 set_hw_finish_instance (me, abort_hw_finish_instance);
44 void
45 delete_hw_instance_data (struct hw *me)
47 /* NOP */
51 static void
52 abort_hw_finish_instance (struct hw *hw,
53 struct hw_instance *instance)
55 hw_abort (hw, "no instance finish method");
58 void
59 set_hw_finish_instance (struct hw *me,
60 hw_finish_instance_method *finish)
62 me->instances_of_hw->to_finish = finish;
66 #if 0
67 void
68 clean_hw_instances (struct hw *me)
70 struct hw_instance **instance = &me->instances;
71 while (*instance != NULL)
73 struct hw_instance *old_instance = *instance;
74 hw_instance_delete (old_instance);
75 instance = &me->instances;
78 #endif
81 void
82 hw_instance_delete (struct hw_instance *instance)
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");
90 instance->method->delete (instance);
91 if (instance->args != NULL)
92 free (instance->args);
93 if (instance->path != NULL)
94 free (instance->path);
95 if (instance->child == NULL)
97 /* only remove leaf nodes */
98 struct hw_instance **curr = &me->instances;
99 while (*curr != instance)
101 ASSERT (*curr != NULL);
102 curr = &(*curr)->next;
104 *curr = instance->next;
106 else
108 /* check it isn't in the instance list */
109 struct hw_instance *curr = me->instances;
110 while (curr != NULL)
112 ASSERT (curr != instance);
113 curr = curr->next;
115 /* unlink the child */
116 ASSERT (instance->child->parent == instance);
117 instance->child->parent = NULL;
119 cap_remove (me->ihandles, instance);
120 free (instance);
121 #endif
125 static int
126 panic_hw_instance_read (struct hw_instance *instance,
127 void *addr,
128 unsigned_word len)
130 hw_abort (hw_instance_hw (instance), "no read method");
131 return -1;
136 static int
137 panic_hw_instance_write (struct hw_instance *instance,
138 const void *addr,
139 unsigned_word len)
141 hw_abort (hw_instance_hw (instance), "no write method");
142 return -1;
146 static int
147 panic_hw_instance_seek (struct hw_instance *instance,
148 unsigned_word pos_hi,
149 unsigned_word pos_lo)
151 hw_abort (hw_instance_hw (instance), "no seek method");
152 return -1;
157 hw_instance_call_method (struct hw_instance *instance,
158 const char *method_name,
159 int n_stack_args,
160 unsigned_cell stack_args[/*n_stack_args*/],
161 int n_stack_returns,
162 unsigned_cell stack_returns[/*n_stack_args*/])
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)
172 hw_abort (me, "no methods (want %s)", method_name);
174 while (method->name != NULL)
176 if (strcmp (method->name, method_name) == 0)
178 return method->method (instance,
179 n_stack_args, stack_args,
180 n_stack_returns, stack_returns);
182 method++;
184 hw_abort (me, "no %s method", method_name);
185 return 0;
186 #endif
190 #define set_hw_instance_read(instance, method)\
191 ((instance)->to_instance_read = (method))
193 #define set_hw_instance_write(instance, method)\
194 ((instance)->to_instance_write = (method))
196 #define set_hw_instance_seek(instance, method)\
197 ((instance)->to_instance_seek = (method))
200 #if 0
201 static void
202 set_hw_instance_finish (struct hw *me,
203 hw_instance_finish_method *method)
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;
209 #endif
212 struct hw_instance *
213 hw_instance_create (struct hw *me,
214 struct hw_instance *parent,
215 const char *path,
216 const char *args)
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)
228 ASSERT (parent->child_of_instance == NULL);
229 parent->child_of_instance = instance;
230 instance->parent_of_instance = parent;
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;
243 struct hw_instance *
244 hw_instance_interceed (struct hw_instance *parent,
245 const char *path,
246 const char *args)
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)
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;
263 if (parent != NULL)
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)
277 ASSERT (*previous != NULL);
278 previous = &(*previous)->next;
280 *previous = instance;
282 instance->data = data;
283 instance->args = (args == NULL ? NULL : (char *) strdup (args));
284 instance->path = (path == NULL ? NULL : (char *) strdup (path));
285 cap_add (instance->owner->ihandles, instance);
286 return instance;
287 #endif