3 Copyright 1996-2018 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 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/>. */
25 #include "sim-options.h"
26 #include "sim-assert.h"
32 #ifdef HAVE_DV_SOCKSER
33 /* TODO: Shouldn't have device models here. */
34 #include "dv-sockser.h"
37 #include "libiberty.h"
39 /* List of all modules. */
40 static MODULE_INSTALL_FN
* const modules
[] = {
53 sim_watchpoint_install
,
60 #ifdef HAVE_DV_SOCKSER
61 /* TODO: Shouldn't have device models here. */
67 /* Functions called from sim_open. */
69 /* Initialize common parts before argument processing. */
72 sim_pre_argv_init (SIM_DESC sd
, const char *myname
)
74 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
75 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
77 STATE_MY_NAME (sd
) = lbasename (myname
);
79 /* Set the cpu names to default values. */
82 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
85 if (asprintf (&name
, "cpu%d", i
) < 0)
87 CPU_NAME (STATE_CPU (sd
, i
)) = name
;
91 sim_config_default (sd
);
93 /* Install all configured in modules. */
94 if (sim_module_install (sd
) != SIM_RC_OK
)
100 /* Initialize common parts after argument processing. */
103 sim_post_argv_init (SIM_DESC sd
)
106 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
107 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
109 /* Set the cpu->state backlinks for each cpu. */
110 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
112 CPU_STATE (STATE_CPU (sd
, i
)) = sd
;
113 CPU_INDEX (STATE_CPU (sd
, i
)) = i
;
116 if (sim_module_init (sd
) != SIM_RC_OK
)
122 /* Install all modules.
123 If this fails, no modules are left installed. */
126 sim_module_install (SIM_DESC sd
)
128 MODULE_INSTALL_FN
* const *modp
;
130 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
131 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
133 STATE_MODULES (sd
) = ZALLOC (struct module_list
);
134 for (modp
= modules
; *modp
!= NULL
; ++modp
)
136 if ((*modp
) (sd
) != SIM_RC_OK
)
138 sim_module_uninstall (sd
);
139 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
146 /* Called after all modules have been installed and after argv
147 has been processed. */
150 sim_module_init (SIM_DESC sd
)
152 struct module_list
*modules
= STATE_MODULES (sd
);
153 MODULE_INIT_LIST
*modp
;
155 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
156 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
158 for (modp
= modules
->init_list
; modp
!= NULL
; modp
= modp
->next
)
160 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
166 /* Called when ever the simulator is resumed */
169 sim_module_resume (SIM_DESC sd
)
171 struct module_list
*modules
= STATE_MODULES (sd
);
172 MODULE_RESUME_LIST
*modp
;
174 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
175 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
177 for (modp
= modules
->resume_list
; modp
!= NULL
; modp
= modp
->next
)
179 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
185 /* Called when ever the simulator is suspended */
188 sim_module_suspend (SIM_DESC sd
)
190 struct module_list
*modules
= STATE_MODULES (sd
);
191 MODULE_SUSPEND_LIST
*modp
;
193 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
194 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
196 for (modp
= modules
->suspend_list
; modp
!= NULL
; modp
= modp
->next
)
198 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
204 /* Uninstall installed modules, called by sim_close. */
207 sim_module_uninstall (SIM_DESC sd
)
209 struct module_list
*modules
= STATE_MODULES (sd
);
210 MODULE_UNINSTALL_LIST
*modp
;
212 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
213 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
215 /* Uninstall the modules. */
216 for (modp
= modules
->uninstall_list
; modp
!= NULL
; modp
= modp
->next
)
219 /* clean-up init list */
221 MODULE_INIT_LIST
*n
, *d
;
222 for (d
= modules
->init_list
; d
!= NULL
; d
= n
)
229 /* clean-up resume list */
231 MODULE_RESUME_LIST
*n
, *d
;
232 for (d
= modules
->resume_list
; d
!= NULL
; d
= n
)
239 /* clean-up suspend list */
241 MODULE_SUSPEND_LIST
*n
, *d
;
242 for (d
= modules
->suspend_list
; d
!= NULL
; d
= n
)
249 /* clean-up uninstall list */
251 MODULE_UNINSTALL_LIST
*n
, *d
;
252 for (d
= modules
->uninstall_list
; d
!= NULL
; d
= n
)
259 /* clean-up info list */
261 MODULE_INFO_LIST
*n
, *d
;
262 for (d
= modules
->info_list
; d
!= NULL
; d
= n
)
270 STATE_MODULES (sd
) = NULL
;
273 /* Called when ever simulator info is needed */
276 sim_module_info (SIM_DESC sd
, int verbose
)
278 struct module_list
*modules
= STATE_MODULES (sd
);
279 MODULE_INFO_LIST
*modp
;
281 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
282 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
284 for (modp
= modules
->info_list
; modp
!= NULL
; modp
= modp
->next
)
286 (*modp
->fn
) (sd
, verbose
);
290 /* Add FN to the init handler list.
291 init in the same order as the install. */
294 sim_module_add_init_fn (SIM_DESC sd
, MODULE_INIT_FN fn
)
296 struct module_list
*modules
= STATE_MODULES (sd
);
297 MODULE_INIT_LIST
*l
= ZALLOC (MODULE_INIT_LIST
);
298 MODULE_INIT_LIST
**last
;
300 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
301 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
303 last
= &modules
->init_list
;
304 while (*last
!= NULL
)
305 last
= &((*last
)->next
);
312 /* Add FN to the resume handler list.
313 resume in the same order as the install. */
316 sim_module_add_resume_fn (SIM_DESC sd
, MODULE_RESUME_FN fn
)
318 struct module_list
*modules
= STATE_MODULES (sd
);
319 MODULE_RESUME_LIST
*l
= ZALLOC (MODULE_RESUME_LIST
);
320 MODULE_RESUME_LIST
**last
;
322 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
323 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
325 last
= &modules
->resume_list
;
326 while (*last
!= NULL
)
327 last
= &((*last
)->next
);
334 /* Add FN to the init handler list.
335 suspend in the reverse order to install. */
338 sim_module_add_suspend_fn (SIM_DESC sd
, MODULE_SUSPEND_FN fn
)
340 struct module_list
*modules
= STATE_MODULES (sd
);
341 MODULE_SUSPEND_LIST
*l
= ZALLOC (MODULE_SUSPEND_LIST
);
342 MODULE_SUSPEND_LIST
**last
;
344 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
345 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
347 last
= &modules
->suspend_list
;
348 while (*last
!= NULL
)
349 last
= &((*last
)->next
);
352 l
->next
= modules
->suspend_list
;
353 modules
->suspend_list
= l
;
356 /* Add FN to the uninstall handler list.
357 Uninstall in reverse order to install. */
360 sim_module_add_uninstall_fn (SIM_DESC sd
, MODULE_UNINSTALL_FN fn
)
362 struct module_list
*modules
= STATE_MODULES (sd
);
363 MODULE_UNINSTALL_LIST
*l
= ZALLOC (MODULE_UNINSTALL_LIST
);
365 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
366 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
369 l
->next
= modules
->uninstall_list
;
370 modules
->uninstall_list
= l
;
373 /* Add FN to the info handler list.
374 Report info in the same order as the install. */
377 sim_module_add_info_fn (SIM_DESC sd
, MODULE_INFO_FN fn
)
379 struct module_list
*modules
= STATE_MODULES (sd
);
380 MODULE_INFO_LIST
*l
= ZALLOC (MODULE_INFO_LIST
);
381 MODULE_INFO_LIST
**last
;
383 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
384 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
386 last
= &modules
->info_list
;
387 while (*last
!= NULL
)
388 last
= &((*last
)->next
);