3 Copyright 1996-2020 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"
41 /* List of all modules. */
42 static MODULE_INSTALL_FN
* const modules
[] = {
55 sim_watchpoint_install
,
62 #ifdef HAVE_DV_SOCKSER
63 /* TODO: Shouldn't have device models here. */
69 /* Functions called from sim_open. */
71 /* Initialize common parts before argument processing. */
74 sim_pre_argv_init (SIM_DESC sd
, const char *myname
)
76 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
77 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
79 STATE_MY_NAME (sd
) = lbasename (myname
);
81 /* Set the cpu names to default values. */
84 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
87 if (asprintf (&name
, "cpu%d", i
) < 0)
89 CPU_NAME (STATE_CPU (sd
, i
)) = name
;
93 sim_config_default (sd
);
95 /* Install all configured in modules. */
96 if (sim_module_install (sd
) != SIM_RC_OK
)
102 /* Initialize common parts after argument processing. */
105 sim_post_argv_init (SIM_DESC sd
)
108 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
109 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
111 /* Set the cpu->state backlinks for each cpu. */
112 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
114 CPU_STATE (STATE_CPU (sd
, i
)) = sd
;
115 CPU_INDEX (STATE_CPU (sd
, i
)) = i
;
118 if (sim_module_init (sd
) != SIM_RC_OK
)
124 /* Install all modules.
125 If this fails, no modules are left installed. */
128 sim_module_install (SIM_DESC sd
)
130 MODULE_INSTALL_FN
* const *modp
;
132 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
133 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
135 STATE_MODULES (sd
) = ZALLOC (struct module_list
);
136 for (modp
= modules
; *modp
!= NULL
; ++modp
)
138 if ((*modp
) (sd
) != SIM_RC_OK
)
140 sim_module_uninstall (sd
);
141 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
148 /* Called after all modules have been installed and after argv
149 has been processed. */
152 sim_module_init (SIM_DESC sd
)
154 struct module_list
*modules
= STATE_MODULES (sd
);
155 MODULE_INIT_LIST
*modp
;
157 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
158 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
160 for (modp
= modules
->init_list
; modp
!= NULL
; modp
= modp
->next
)
162 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
168 /* Called when ever the simulator is resumed */
171 sim_module_resume (SIM_DESC sd
)
173 struct module_list
*modules
= STATE_MODULES (sd
);
174 MODULE_RESUME_LIST
*modp
;
176 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
177 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
179 for (modp
= modules
->resume_list
; modp
!= NULL
; modp
= modp
->next
)
181 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
187 /* Called when ever the simulator is suspended */
190 sim_module_suspend (SIM_DESC sd
)
192 struct module_list
*modules
= STATE_MODULES (sd
);
193 MODULE_SUSPEND_LIST
*modp
;
195 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
196 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
198 for (modp
= modules
->suspend_list
; modp
!= NULL
; modp
= modp
->next
)
200 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
206 /* Uninstall installed modules, called by sim_close. */
209 sim_module_uninstall (SIM_DESC sd
)
211 struct module_list
*modules
= STATE_MODULES (sd
);
212 MODULE_UNINSTALL_LIST
*modp
;
214 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
215 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
217 /* Uninstall the modules. */
218 for (modp
= modules
->uninstall_list
; modp
!= NULL
; modp
= modp
->next
)
221 /* clean-up init list */
223 MODULE_INIT_LIST
*n
, *d
;
224 for (d
= modules
->init_list
; d
!= NULL
; d
= n
)
231 /* clean-up resume list */
233 MODULE_RESUME_LIST
*n
, *d
;
234 for (d
= modules
->resume_list
; d
!= NULL
; d
= n
)
241 /* clean-up suspend list */
243 MODULE_SUSPEND_LIST
*n
, *d
;
244 for (d
= modules
->suspend_list
; d
!= NULL
; d
= n
)
251 /* clean-up uninstall list */
253 MODULE_UNINSTALL_LIST
*n
, *d
;
254 for (d
= modules
->uninstall_list
; d
!= NULL
; d
= n
)
261 /* clean-up info list */
263 MODULE_INFO_LIST
*n
, *d
;
264 for (d
= modules
->info_list
; d
!= NULL
; d
= n
)
272 STATE_MODULES (sd
) = NULL
;
275 /* Called when ever simulator info is needed */
278 sim_module_info (SIM_DESC sd
, int verbose
)
280 struct module_list
*modules
= STATE_MODULES (sd
);
281 MODULE_INFO_LIST
*modp
;
283 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
284 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
286 for (modp
= modules
->info_list
; modp
!= NULL
; modp
= modp
->next
)
288 (*modp
->fn
) (sd
, verbose
);
292 /* Add FN to the init handler list.
293 init in the same order as the install. */
296 sim_module_add_init_fn (SIM_DESC sd
, MODULE_INIT_FN fn
)
298 struct module_list
*modules
= STATE_MODULES (sd
);
299 MODULE_INIT_LIST
*l
= ZALLOC (MODULE_INIT_LIST
);
300 MODULE_INIT_LIST
**last
;
302 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
303 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
305 last
= &modules
->init_list
;
306 while (*last
!= NULL
)
307 last
= &((*last
)->next
);
314 /* Add FN to the resume handler list.
315 resume in the same order as the install. */
318 sim_module_add_resume_fn (SIM_DESC sd
, MODULE_RESUME_FN fn
)
320 struct module_list
*modules
= STATE_MODULES (sd
);
321 MODULE_RESUME_LIST
*l
= ZALLOC (MODULE_RESUME_LIST
);
322 MODULE_RESUME_LIST
**last
;
324 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
325 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
327 last
= &modules
->resume_list
;
328 while (*last
!= NULL
)
329 last
= &((*last
)->next
);
336 /* Add FN to the init handler list.
337 suspend in the reverse order to install. */
340 sim_module_add_suspend_fn (SIM_DESC sd
, MODULE_SUSPEND_FN fn
)
342 struct module_list
*modules
= STATE_MODULES (sd
);
343 MODULE_SUSPEND_LIST
*l
= ZALLOC (MODULE_SUSPEND_LIST
);
344 MODULE_SUSPEND_LIST
**last
;
346 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
347 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
349 last
= &modules
->suspend_list
;
350 while (*last
!= NULL
)
351 last
= &((*last
)->next
);
354 l
->next
= modules
->suspend_list
;
355 modules
->suspend_list
= l
;
358 /* Add FN to the uninstall handler list.
359 Uninstall in reverse order to install. */
362 sim_module_add_uninstall_fn (SIM_DESC sd
, MODULE_UNINSTALL_FN fn
)
364 struct module_list
*modules
= STATE_MODULES (sd
);
365 MODULE_UNINSTALL_LIST
*l
= ZALLOC (MODULE_UNINSTALL_LIST
);
367 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
368 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
371 l
->next
= modules
->uninstall_list
;
372 modules
->uninstall_list
= l
;
375 /* Add FN to the info handler list.
376 Report info in the same order as the install. */
379 sim_module_add_info_fn (SIM_DESC sd
, MODULE_INFO_FN fn
)
381 struct module_list
*modules
= STATE_MODULES (sd
);
382 MODULE_INFO_LIST
*l
= ZALLOC (MODULE_INFO_LIST
);
383 MODULE_INFO_LIST
**last
;
385 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
386 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
388 last
= &modules
->info_list
;
389 while (*last
!= NULL
)
390 last
= &((*last
)->next
);