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