2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
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)
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.
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. */
23 #include "sim-options.h"
24 #include "sim-assert.h"
30 #include "libiberty.h"
32 /* List of all modules. */
33 static MODULE_INSTALL_FN
* const modules
[] = {
49 #ifndef SIM_HAVE_FLATMEM
50 /* FIXME: should handle flatmem as well FLATMEM */
54 sim_watchpoint_install
,
59 #ifdef SIM_HAVE_BREAKPOINTS
65 /* Configured in [simulator specific] additional modules. */
72 /* Functions called from sim_open. */
74 /* Initialize common parts before argument processing. */
77 sim_pre_argv_init (SIM_DESC sd
, const char *myname
)
79 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
80 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
82 STATE_MY_NAME (sd
) = myname
+ strlen (myname
);
83 while (STATE_MY_NAME (sd
) > myname
&& STATE_MY_NAME (sd
)[-1] != '/')
86 /* Set the cpu names to default values. */
89 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
92 asprintf (&name
, "cpu%d", i
);
93 CPU_NAME (STATE_CPU (sd
, i
)) = name
;
97 sim_config_default (sd
);
99 /* Install all configured in modules. */
100 if (sim_module_install (sd
) != SIM_RC_OK
)
106 /* Initialize common parts after argument processing. */
109 sim_post_argv_init (SIM_DESC sd
)
112 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
113 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
115 /* Set the cpu->state backlinks for each cpu. */
116 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
118 CPU_STATE (STATE_CPU (sd
, i
)) = sd
;
119 CPU_INDEX (STATE_CPU (sd
, i
)) = i
;
122 if (sim_module_init (sd
) != SIM_RC_OK
)
128 /* Install all modules.
129 If this fails, no modules are left installed. */
132 sim_module_install (SIM_DESC sd
)
134 MODULE_INSTALL_FN
* const *modp
;
136 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
137 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
139 STATE_MODULES (sd
) = ZALLOC (struct module_list
);
140 for (modp
= modules
; *modp
!= NULL
; ++modp
)
142 if ((*modp
) (sd
) != SIM_RC_OK
)
144 sim_module_uninstall (sd
);
145 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
152 /* Called after all modules have been installed and after argv
153 has been processed. */
156 sim_module_init (SIM_DESC sd
)
158 struct module_list
*modules
= STATE_MODULES (sd
);
159 MODULE_INIT_LIST
*modp
;
161 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
162 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
164 for (modp
= modules
->init_list
; modp
!= NULL
; modp
= modp
->next
)
166 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
172 /* Called when ever the simulator is resumed */
175 sim_module_resume (SIM_DESC sd
)
177 struct module_list
*modules
= STATE_MODULES (sd
);
178 MODULE_RESUME_LIST
*modp
;
180 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
181 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
183 for (modp
= modules
->resume_list
; modp
!= NULL
; modp
= modp
->next
)
185 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
191 /* Called when ever the simulator is suspended */
194 sim_module_suspend (SIM_DESC sd
)
196 struct module_list
*modules
= STATE_MODULES (sd
);
197 MODULE_SUSPEND_LIST
*modp
;
199 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
200 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
202 for (modp
= modules
->suspend_list
; modp
!= NULL
; modp
= modp
->next
)
204 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
210 /* Uninstall installed modules, called by sim_close. */
213 sim_module_uninstall (SIM_DESC sd
)
215 struct module_list
*modules
= STATE_MODULES (sd
);
216 MODULE_UNINSTALL_LIST
*modp
;
218 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
219 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
221 /* Uninstall the modules. */
222 for (modp
= modules
->uninstall_list
; modp
!= NULL
; modp
= modp
->next
)
225 /* clean-up init list */
227 MODULE_INIT_LIST
*n
, *d
;
228 for (d
= modules
->init_list
; d
!= NULL
; d
= n
)
235 /* clean-up resume list */
237 MODULE_RESUME_LIST
*n
, *d
;
238 for (d
= modules
->resume_list
; d
!= NULL
; d
= n
)
245 /* clean-up suspend list */
247 MODULE_SUSPEND_LIST
*n
, *d
;
248 for (d
= modules
->suspend_list
; d
!= NULL
; d
= n
)
255 /* clean-up uninstall list */
257 MODULE_UNINSTALL_LIST
*n
, *d
;
258 for (d
= modules
->uninstall_list
; d
!= NULL
; d
= n
)
265 /* clean-up info list */
267 MODULE_INFO_LIST
*n
, *d
;
268 for (d
= modules
->info_list
; d
!= NULL
; d
= n
)
276 STATE_MODULES (sd
) = NULL
;
279 /* Called when ever simulator info is needed */
282 sim_module_info (SIM_DESC sd
, int verbose
)
284 struct module_list
*modules
= STATE_MODULES (sd
);
285 MODULE_INFO_LIST
*modp
;
287 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
288 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
290 for (modp
= modules
->info_list
; modp
!= NULL
; modp
= modp
->next
)
292 (*modp
->fn
) (sd
, verbose
);
296 /* Add FN to the init handler list.
297 init in the same order as the install. */
300 sim_module_add_init_fn (SIM_DESC sd
, MODULE_INIT_FN fn
)
302 struct module_list
*modules
= STATE_MODULES (sd
);
303 MODULE_INIT_LIST
*l
= ZALLOC (MODULE_INIT_LIST
);
304 MODULE_INIT_LIST
**last
;
306 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
307 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
309 last
= &modules
->init_list
;
310 while (*last
!= NULL
)
311 last
= &((*last
)->next
);
318 /* Add FN to the resume handler list.
319 resume in the same order as the install. */
322 sim_module_add_resume_fn (SIM_DESC sd
, MODULE_RESUME_FN fn
)
324 struct module_list
*modules
= STATE_MODULES (sd
);
325 MODULE_RESUME_LIST
*l
= ZALLOC (MODULE_RESUME_LIST
);
326 MODULE_RESUME_LIST
**last
;
328 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
329 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
331 last
= &modules
->resume_list
;
332 while (*last
!= NULL
)
333 last
= &((*last
)->next
);
340 /* Add FN to the init handler list.
341 suspend in the reverse order to install. */
344 sim_module_add_suspend_fn (SIM_DESC sd
, MODULE_SUSPEND_FN fn
)
346 struct module_list
*modules
= STATE_MODULES (sd
);
347 MODULE_SUSPEND_LIST
*l
= ZALLOC (MODULE_SUSPEND_LIST
);
348 MODULE_SUSPEND_LIST
**last
;
350 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
351 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
353 last
= &modules
->suspend_list
;
354 while (*last
!= NULL
)
355 last
= &((*last
)->next
);
358 l
->next
= modules
->suspend_list
;
359 modules
->suspend_list
= l
;
362 /* Add FN to the uninstall handler list.
363 Uninstall in reverse order to install. */
366 sim_module_add_uninstall_fn (SIM_DESC sd
, MODULE_UNINSTALL_FN fn
)
368 struct module_list
*modules
= STATE_MODULES (sd
);
369 MODULE_UNINSTALL_LIST
*l
= ZALLOC (MODULE_UNINSTALL_LIST
);
371 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
372 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
375 l
->next
= modules
->uninstall_list
;
376 modules
->uninstall_list
= l
;
379 /* Add FN to the info handler list.
380 Report info in the same order as the install. */
383 sim_module_add_info_fn (SIM_DESC sd
, MODULE_INFO_FN fn
)
385 struct module_list
*modules
= STATE_MODULES (sd
);
386 MODULE_INFO_LIST
*l
= ZALLOC (MODULE_INFO_LIST
);
387 MODULE_INFO_LIST
**last
;
389 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
390 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
392 last
= &modules
->info_list
;
393 while (*last
!= NULL
)
394 last
= &((*last
)->next
);