Commit | Line | Data |
---|---|---|
c967f187 | 1 | /* Module support. |
b0df95bb | 2 | Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. |
c967f187 DE |
3 | Contributed by Cygnus Support. |
4 | ||
5 | This file is part of GDB, the GNU debugger. | |
6 | ||
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) | |
10 | any later version. | |
11 | ||
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. | |
16 | ||
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. */ | |
20 | ||
21 | #include "sim-main.h" | |
22 | #include "sim-io.h" | |
23 | #include "sim-options.h" | |
fdd64f95 AC |
24 | #include "sim-assert.h" |
25 | ||
643878d0 AC |
26 | /* start-sanitize-am30 */ |
27 | #if WITH_HW | |
28 | #include "sim-hw.h" | |
29 | #endif | |
30 | /* end-sanitize-am30 */ | |
31 | ||
fdd64f95 | 32 | #include "libiberty.h" |
c967f187 DE |
33 | |
34 | /* List of all modules. */ | |
35 | static MODULE_INSTALL_FN * const modules[] = { | |
36 | standard_install, | |
c2481130 | 37 | sim_events_install, |
fdd64f95 AC |
38 | #if WITH_ENGINE |
39 | sim_engine_install, | |
40 | #endif | |
41 | #if WITH_TRACE | |
c967f187 | 42 | trace_install, |
fdd64f95 AC |
43 | #endif |
44 | #if WITH_PROFILE | |
c967f187 | 45 | profile_install, |
fdd64f95 | 46 | #endif |
c967f187 | 47 | sim_core_install, |
a34abff8 AC |
48 | #ifndef SIM_HAVE_FLATMEM |
49 | /* FIXME: should handle flatmem as well FLATMEM */ | |
50 | sim_memopt_install, | |
51 | #endif | |
fdd64f95 AC |
52 | #if WITH_WATCHPOINTS |
53 | sim_watchpoint_install, | |
54 | #endif | |
c967f187 DE |
55 | #if WITH_SCACHE |
56 | scache_install, | |
57 | #endif | |
c2481130 | 58 | #ifdef SIM_HAVE_MODEL |
643878d0 | 59 | sim_model_install, |
c2481130 DE |
60 | #endif |
61 | #ifdef SIM_HAVE_BREAKPOINTS | |
62 | sim_break_install, | |
c967f187 | 63 | #endif |
643878d0 AC |
64 | /* start-sanitize-am30 */ |
65 | #if WITH_HW | |
66 | sim_hw_install, | |
67 | #endif | |
68 | /* end-sanitize-am30 */ | |
c967f187 DE |
69 | /* Configured in [simulator specific] additional modules. */ |
70 | #ifdef MODULE_LIST | |
71 | MODULE_LIST | |
72 | #endif | |
73 | 0 | |
74 | }; | |
75 | \f | |
76 | /* Functions called from sim_open. */ | |
77 | ||
78 | /* Initialize common parts before argument processing. */ | |
79 | ||
80 | SIM_RC | |
81 | sim_pre_argv_init (SIM_DESC sd, const char *myname) | |
82 | { | |
fdd64f95 | 83 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
0e701ac3 AC |
84 | SIM_ASSERT (STATE_MODULES (sd) == NULL); |
85 | ||
c967f187 DE |
86 | STATE_MY_NAME (sd) = myname + strlen (myname); |
87 | while (STATE_MY_NAME (sd) > myname && STATE_MY_NAME (sd)[-1] != '/') | |
88 | --STATE_MY_NAME (sd); | |
89 | ||
966df580 DE |
90 | /* Set the cpu names to default values. */ |
91 | { | |
92 | int i; | |
93 | for (i = 0; i < MAX_NR_PROCESSORS; ++i) | |
94 | { | |
baf8377d | 95 | char *name; |
966df580 DE |
96 | asprintf (&name, "cpu%d", i); |
97 | CPU_NAME (STATE_CPU (sd, i)) = name; | |
98 | } | |
99 | } | |
100 | ||
82ea14fd AC |
101 | sim_config_default (sd); |
102 | ||
c967f187 DE |
103 | /* Install all configured in modules. */ |
104 | if (sim_module_install (sd) != SIM_RC_OK) | |
105 | return SIM_RC_FAIL; | |
106 | ||
107 | return SIM_RC_OK; | |
108 | } | |
109 | ||
110 | /* Initialize common parts after argument processing. */ | |
111 | ||
112 | SIM_RC | |
113 | sim_post_argv_init (SIM_DESC sd) | |
114 | { | |
115 | int i; | |
fdd64f95 | 116 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
0e701ac3 | 117 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
c967f187 DE |
118 | |
119 | if (sim_module_init (sd) != SIM_RC_OK) | |
120 | return SIM_RC_FAIL; | |
121 | ||
122 | /* Set the cpu->state backlinks for each cpu. */ | |
123 | for (i = 0; i < MAX_NR_PROCESSORS; ++i) | |
82ea14fd AC |
124 | { |
125 | CPU_STATE (STATE_CPU (sd, i)) = sd; | |
126 | CPU_INDEX (STATE_CPU (sd, i)) = i; | |
127 | } | |
c967f187 DE |
128 | |
129 | return SIM_RC_OK; | |
130 | } | |
131 | \f | |
c2481130 DE |
132 | /* Install all modules. |
133 | If this fails, no modules are left installed. */ | |
c967f187 DE |
134 | |
135 | SIM_RC | |
136 | sim_module_install (SIM_DESC sd) | |
137 | { | |
138 | MODULE_INSTALL_FN * const *modp; | |
0e701ac3 | 139 | |
fdd64f95 | 140 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
0e701ac3 | 141 | SIM_ASSERT (STATE_MODULES (sd) == NULL); |
c967f187 | 142 | |
0e701ac3 | 143 | STATE_MODULES (sd) = ZALLOC (struct module_list); |
c967f187 DE |
144 | for (modp = modules; *modp != NULL; ++modp) |
145 | { | |
146 | if ((*modp) (sd) != SIM_RC_OK) | |
c2481130 DE |
147 | { |
148 | sim_module_uninstall (sd); | |
0e701ac3 | 149 | SIM_ASSERT (STATE_MODULES (sd) == NULL); |
c2481130 DE |
150 | return SIM_RC_FAIL; |
151 | } | |
c967f187 DE |
152 | } |
153 | return SIM_RC_OK; | |
154 | } | |
155 | ||
156 | /* Called after all modules have been installed and after argv | |
157 | has been processed. */ | |
158 | ||
159 | SIM_RC | |
160 | sim_module_init (SIM_DESC sd) | |
161 | { | |
0e701ac3 | 162 | struct module_list *modules = STATE_MODULES (sd); |
c967f187 | 163 | MODULE_INIT_LIST *modp; |
0e701ac3 | 164 | |
fdd64f95 | 165 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
b0df95bb | 166 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
c967f187 | 167 | |
0e701ac3 | 168 | for (modp = modules->init_list; modp != NULL; modp = modp->next) |
c967f187 DE |
169 | { |
170 | if ((*modp->fn) (sd) != SIM_RC_OK) | |
171 | return SIM_RC_FAIL; | |
172 | } | |
173 | return SIM_RC_OK; | |
174 | } | |
175 | ||
fdd64f95 AC |
176 | /* Called when ever the simulator is resumed */ |
177 | ||
178 | SIM_RC | |
179 | sim_module_resume (SIM_DESC sd) | |
180 | { | |
0e701ac3 | 181 | struct module_list *modules = STATE_MODULES (sd); |
fdd64f95 | 182 | MODULE_RESUME_LIST *modp; |
0e701ac3 | 183 | |
fdd64f95 | 184 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
b0df95bb | 185 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
fdd64f95 | 186 | |
0e701ac3 | 187 | for (modp = modules->resume_list; modp != NULL; modp = modp->next) |
fdd64f95 AC |
188 | { |
189 | if ((*modp->fn) (sd) != SIM_RC_OK) | |
190 | return SIM_RC_FAIL; | |
191 | } | |
192 | return SIM_RC_OK; | |
193 | } | |
194 | ||
195 | /* Called when ever the simulator is suspended */ | |
196 | ||
197 | SIM_RC | |
198 | sim_module_suspend (SIM_DESC sd) | |
199 | { | |
0e701ac3 | 200 | struct module_list *modules = STATE_MODULES (sd); |
fdd64f95 | 201 | MODULE_SUSPEND_LIST *modp; |
0e701ac3 | 202 | |
fdd64f95 | 203 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
b0df95bb | 204 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
fdd64f95 | 205 | |
0e701ac3 | 206 | for (modp = modules->suspend_list; modp != NULL; modp = modp->next) |
fdd64f95 AC |
207 | { |
208 | if ((*modp->fn) (sd) != SIM_RC_OK) | |
209 | return SIM_RC_FAIL; | |
210 | } | |
211 | return SIM_RC_OK; | |
212 | } | |
213 | ||
c967f187 DE |
214 | /* Uninstall installed modules, called by sim_close. */ |
215 | ||
216 | void | |
217 | sim_module_uninstall (SIM_DESC sd) | |
218 | { | |
0e701ac3 | 219 | struct module_list *modules = STATE_MODULES (sd); |
c967f187 | 220 | MODULE_UNINSTALL_LIST *modp; |
0e701ac3 | 221 | |
fdd64f95 | 222 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
b0df95bb | 223 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
c967f187 DE |
224 | |
225 | /* Uninstall the modules. */ | |
0e701ac3 | 226 | for (modp = modules->uninstall_list; modp != NULL; modp = modp->next) |
c967f187 | 227 | (*modp->fn) (sd); |
0e701ac3 AC |
228 | |
229 | /* clean-up init list */ | |
230 | { | |
231 | MODULE_INIT_LIST *n, *d; | |
232 | for (d = modules->init_list; d != NULL; d = n) | |
233 | { | |
234 | n = d->next; | |
235 | zfree (d); | |
236 | } | |
237 | } | |
238 | ||
239 | /* clean-up resume list */ | |
240 | { | |
241 | MODULE_RESUME_LIST *n, *d; | |
242 | for (d = modules->resume_list; d != NULL; d = n) | |
243 | { | |
244 | n = d->next; | |
245 | zfree (d); | |
246 | } | |
247 | } | |
248 | ||
249 | /* clean-up suspend list */ | |
250 | { | |
251 | MODULE_SUSPEND_LIST *n, *d; | |
252 | for (d = modules->suspend_list; d != NULL; d = n) | |
253 | { | |
254 | n = d->next; | |
255 | zfree (d); | |
256 | } | |
257 | } | |
258 | ||
259 | /* clean-up uninstall list */ | |
260 | { | |
261 | MODULE_UNINSTALL_LIST *n, *d; | |
262 | for (d = modules->uninstall_list; d != NULL; d = n) | |
263 | { | |
264 | n = d->next; | |
265 | zfree (d); | |
266 | } | |
267 | } | |
268 | ||
269 | /* clean-up info list */ | |
270 | { | |
271 | MODULE_INFO_LIST *n, *d; | |
272 | for (d = modules->info_list; d != NULL; d = n) | |
273 | { | |
274 | n = d->next; | |
275 | zfree (d); | |
276 | } | |
277 | } | |
278 | ||
279 | zfree (modules); | |
280 | STATE_MODULES (sd) = NULL; | |
281 | } | |
282 | ||
283 | /* Called when ever simulator info is needed */ | |
284 | ||
285 | void | |
286 | sim_module_info (SIM_DESC sd, int verbose) | |
287 | { | |
288 | struct module_list *modules = STATE_MODULES (sd); | |
289 | MODULE_INFO_LIST *modp; | |
290 | ||
291 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); | |
b0df95bb | 292 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
0e701ac3 AC |
293 | |
294 | for (modp = modules->info_list; modp != NULL; modp = modp->next) | |
295 | { | |
296 | (*modp->fn) (sd, verbose); | |
297 | } | |
c967f187 DE |
298 | } |
299 | \f | |
fdd64f95 AC |
300 | /* Add FN to the init handler list. |
301 | init in the same order as the install. */ | |
c967f187 DE |
302 | |
303 | void | |
304 | sim_module_add_init_fn (SIM_DESC sd, MODULE_INIT_FN fn) | |
305 | { | |
0e701ac3 AC |
306 | struct module_list *modules = STATE_MODULES (sd); |
307 | MODULE_INIT_LIST *l = ZALLOC (MODULE_INIT_LIST); | |
308 | MODULE_INIT_LIST **last; | |
309 | ||
fdd64f95 | 310 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
b0df95bb | 311 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
fdd64f95 | 312 | |
0e701ac3 | 313 | last = &modules->init_list; |
fdd64f95 AC |
314 | while (*last != NULL) |
315 | last = &((*last)->next); | |
316 | ||
317 | l->fn = fn; | |
318 | l->next = NULL; | |
319 | *last = l; | |
320 | } | |
321 | ||
322 | /* Add FN to the resume handler list. | |
323 | resume in the same order as the install. */ | |
324 | ||
325 | void | |
326 | sim_module_add_resume_fn (SIM_DESC sd, MODULE_RESUME_FN fn) | |
327 | { | |
0e701ac3 | 328 | struct module_list *modules = STATE_MODULES (sd); |
fdd64f95 AC |
329 | MODULE_RESUME_LIST *l = ZALLOC (MODULE_RESUME_LIST); |
330 | MODULE_RESUME_LIST **last; | |
0e701ac3 | 331 | |
fdd64f95 | 332 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
b0df95bb | 333 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
fdd64f95 | 334 | |
0e701ac3 | 335 | last = &modules->resume_list; |
fdd64f95 AC |
336 | while (*last != NULL) |
337 | last = &((*last)->next); | |
338 | ||
339 | l->fn = fn; | |
340 | l->next = NULL; | |
341 | *last = l; | |
342 | } | |
343 | ||
344 | /* Add FN to the init handler list. | |
345 | suspend in the reverse order to install. */ | |
346 | ||
347 | void | |
348 | sim_module_add_suspend_fn (SIM_DESC sd, MODULE_SUSPEND_FN fn) | |
349 | { | |
0e701ac3 | 350 | struct module_list *modules = STATE_MODULES (sd); |
fdd64f95 AC |
351 | MODULE_SUSPEND_LIST *l = ZALLOC (MODULE_SUSPEND_LIST); |
352 | MODULE_SUSPEND_LIST **last; | |
0e701ac3 | 353 | |
fdd64f95 | 354 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
b0df95bb | 355 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
fdd64f95 | 356 | |
0e701ac3 | 357 | last = &modules->suspend_list; |
fdd64f95 AC |
358 | while (*last != NULL) |
359 | last = &((*last)->next); | |
c967f187 DE |
360 | |
361 | l->fn = fn; | |
0e701ac3 AC |
362 | l->next = modules->suspend_list; |
363 | modules->suspend_list = l; | |
c967f187 DE |
364 | } |
365 | ||
fdd64f95 AC |
366 | /* Add FN to the uninstall handler list. |
367 | Uninstall in reverse order to install. */ | |
c967f187 DE |
368 | |
369 | void | |
370 | sim_module_add_uninstall_fn (SIM_DESC sd, MODULE_UNINSTALL_FN fn) | |
371 | { | |
0e701ac3 AC |
372 | struct module_list *modules = STATE_MODULES (sd); |
373 | MODULE_UNINSTALL_LIST *l = ZALLOC (MODULE_UNINSTALL_LIST); | |
374 | ||
375 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); | |
b0df95bb | 376 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
0e701ac3 AC |
377 | |
378 | l->fn = fn; | |
379 | l->next = modules->uninstall_list; | |
380 | modules->uninstall_list = l; | |
381 | } | |
382 | ||
383 | /* Add FN to the info handler list. | |
384 | Report info in the same order as the install. */ | |
385 | ||
386 | void | |
387 | sim_module_add_info_fn (SIM_DESC sd, MODULE_INFO_FN fn) | |
388 | { | |
389 | struct module_list *modules = STATE_MODULES (sd); | |
390 | MODULE_INFO_LIST *l = ZALLOC (MODULE_INFO_LIST); | |
391 | MODULE_INFO_LIST **last; | |
392 | ||
393 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); | |
b0df95bb | 394 | SIM_ASSERT (STATE_MODULES (sd) != NULL); |
0e701ac3 AC |
395 | |
396 | last = &modules->info_list; | |
397 | while (*last != NULL) | |
398 | last = &((*last)->next); | |
c967f187 DE |
399 | |
400 | l->fn = fn; | |
0e701ac3 AC |
401 | l->next = NULL; |
402 | *last = l; | |
c967f187 | 403 | } |