3 Copyright 1996, 1997, 1998, 2003 Free Software Foundation, Inc.
5 Contributed by Cygnus Support.
7 This file is part of GDB, the GNU debugger.
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 2, or (at your option)
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 along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "sim-options.h"
26 #include "sim-assert.h"
32 #include "libiberty.h"
34 /* List of all modules. */
35 static MODULE_INSTALL_FN
* const modules
[] = {
51 #ifndef SIM_HAVE_FLATMEM
52 /* FIXME: should handle flatmem as well FLATMEM */
56 sim_watchpoint_install
,
64 /* Configured in [simulator specific] additional modules. */
71 /* Functions called from sim_open. */
73 /* Initialize common parts before argument processing. */
76 sim_pre_argv_init (SIM_DESC sd
, const char *myname
)
78 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
79 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
81 STATE_MY_NAME (sd
) = myname
+ strlen (myname
);
82 while (STATE_MY_NAME (sd
) > myname
&& STATE_MY_NAME (sd
)[-1] != '/')
85 /* Set the cpu names to default values. */
88 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
91 asprintf (&name
, "cpu%d", i
);
92 CPU_NAME (STATE_CPU (sd
, i
)) = name
;
96 sim_config_default (sd
);
98 /* Install all configured in modules. */
99 if (sim_module_install (sd
) != SIM_RC_OK
)
105 /* Initialize common parts after argument processing. */
108 sim_post_argv_init (SIM_DESC sd
)
111 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
112 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
114 /* Set the cpu->state backlinks for each cpu. */
115 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
117 CPU_STATE (STATE_CPU (sd
, i
)) = sd
;
118 CPU_INDEX (STATE_CPU (sd
, i
)) = i
;
121 if (sim_module_init (sd
) != SIM_RC_OK
)
127 /* Install all modules.
128 If this fails, no modules are left installed. */
131 sim_module_install (SIM_DESC sd
)
133 MODULE_INSTALL_FN
* const *modp
;
135 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
136 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
138 STATE_MODULES (sd
) = ZALLOC (struct module_list
);
139 for (modp
= modules
; *modp
!= NULL
; ++modp
)
141 if ((*modp
) (sd
) != SIM_RC_OK
)
143 sim_module_uninstall (sd
);
144 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
151 /* Called after all modules have been installed and after argv
152 has been processed. */
155 sim_module_init (SIM_DESC sd
)
157 struct module_list
*modules
= STATE_MODULES (sd
);
158 MODULE_INIT_LIST
*modp
;
160 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
161 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
163 for (modp
= modules
->init_list
; modp
!= NULL
; modp
= modp
->next
)
165 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
171 /* Called when ever the simulator is resumed */
174 sim_module_resume (SIM_DESC sd
)
176 struct module_list
*modules
= STATE_MODULES (sd
);
177 MODULE_RESUME_LIST
*modp
;
179 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
180 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
182 for (modp
= modules
->resume_list
; modp
!= NULL
; modp
= modp
->next
)
184 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
190 /* Called when ever the simulator is suspended */
193 sim_module_suspend (SIM_DESC sd
)
195 struct module_list
*modules
= STATE_MODULES (sd
);
196 MODULE_SUSPEND_LIST
*modp
;
198 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
199 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
201 for (modp
= modules
->suspend_list
; modp
!= NULL
; modp
= modp
->next
)
203 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
209 /* Uninstall installed modules, called by sim_close. */
212 sim_module_uninstall (SIM_DESC sd
)
214 struct module_list
*modules
= STATE_MODULES (sd
);
215 MODULE_UNINSTALL_LIST
*modp
;
217 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
218 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
220 /* Uninstall the modules. */
221 for (modp
= modules
->uninstall_list
; modp
!= NULL
; modp
= modp
->next
)
224 /* clean-up init list */
226 MODULE_INIT_LIST
*n
, *d
;
227 for (d
= modules
->init_list
; d
!= NULL
; d
= n
)
234 /* clean-up resume list */
236 MODULE_RESUME_LIST
*n
, *d
;
237 for (d
= modules
->resume_list
; d
!= NULL
; d
= n
)
244 /* clean-up suspend list */
246 MODULE_SUSPEND_LIST
*n
, *d
;
247 for (d
= modules
->suspend_list
; d
!= NULL
; d
= n
)
254 /* clean-up uninstall list */
256 MODULE_UNINSTALL_LIST
*n
, *d
;
257 for (d
= modules
->uninstall_list
; d
!= NULL
; d
= n
)
264 /* clean-up info list */
266 MODULE_INFO_LIST
*n
, *d
;
267 for (d
= modules
->info_list
; d
!= NULL
; d
= n
)
275 STATE_MODULES (sd
) = NULL
;
278 /* Called when ever simulator info is needed */
281 sim_module_info (SIM_DESC sd
, int verbose
)
283 struct module_list
*modules
= STATE_MODULES (sd
);
284 MODULE_INFO_LIST
*modp
;
286 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
287 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
289 for (modp
= modules
->info_list
; modp
!= NULL
; modp
= modp
->next
)
291 (*modp
->fn
) (sd
, verbose
);
295 /* Add FN to the init handler list.
296 init in the same order as the install. */
299 sim_module_add_init_fn (SIM_DESC sd
, MODULE_INIT_FN fn
)
301 struct module_list
*modules
= STATE_MODULES (sd
);
302 MODULE_INIT_LIST
*l
= ZALLOC (MODULE_INIT_LIST
);
303 MODULE_INIT_LIST
**last
;
305 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
306 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
308 last
= &modules
->init_list
;
309 while (*last
!= NULL
)
310 last
= &((*last
)->next
);
317 /* Add FN to the resume handler list.
318 resume in the same order as the install. */
321 sim_module_add_resume_fn (SIM_DESC sd
, MODULE_RESUME_FN fn
)
323 struct module_list
*modules
= STATE_MODULES (sd
);
324 MODULE_RESUME_LIST
*l
= ZALLOC (MODULE_RESUME_LIST
);
325 MODULE_RESUME_LIST
**last
;
327 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
328 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
330 last
= &modules
->resume_list
;
331 while (*last
!= NULL
)
332 last
= &((*last
)->next
);
339 /* Add FN to the init handler list.
340 suspend in the reverse order to install. */
343 sim_module_add_suspend_fn (SIM_DESC sd
, MODULE_SUSPEND_FN fn
)
345 struct module_list
*modules
= STATE_MODULES (sd
);
346 MODULE_SUSPEND_LIST
*l
= ZALLOC (MODULE_SUSPEND_LIST
);
347 MODULE_SUSPEND_LIST
**last
;
349 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
350 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
352 last
= &modules
->suspend_list
;
353 while (*last
!= NULL
)
354 last
= &((*last
)->next
);
357 l
->next
= modules
->suspend_list
;
358 modules
->suspend_list
= l
;
361 /* Add FN to the uninstall handler list.
362 Uninstall in reverse order to install. */
365 sim_module_add_uninstall_fn (SIM_DESC sd
, MODULE_UNINSTALL_FN fn
)
367 struct module_list
*modules
= STATE_MODULES (sd
);
368 MODULE_UNINSTALL_LIST
*l
= ZALLOC (MODULE_UNINSTALL_LIST
);
370 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
371 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
374 l
->next
= modules
->uninstall_list
;
375 modules
->uninstall_list
= l
;
378 /* Add FN to the info handler list.
379 Report info in the same order as the install. */
382 sim_module_add_info_fn (SIM_DESC sd
, MODULE_INFO_FN fn
)
384 struct module_list
*modules
= STATE_MODULES (sd
);
385 MODULE_INFO_LIST
*l
= ZALLOC (MODULE_INFO_LIST
);
386 MODULE_INFO_LIST
**last
;
388 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
389 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
391 last
= &modules
->info_list
;
392 while (*last
!= NULL
)
393 last
= &((*last
)->next
);