3 Copyright 1996-2015 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
[] = {
57 sim_watchpoint_install
,
64 #ifdef HAVE_DV_SOCKSER
65 /* TODO: Shouldn't have device models here. */
68 /* Configured in [simulator specific] additional modules. */
75 /* Functions called from sim_open. */
77 /* Initialize common parts before argument processing. */
80 sim_pre_argv_init (SIM_DESC sd
, const char *myname
)
82 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
83 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
85 STATE_MY_NAME (sd
) = myname
+ strlen (myname
);
86 while (STATE_MY_NAME (sd
) > myname
&& STATE_MY_NAME (sd
)[-1] != '/')
89 /* Set the cpu names to default values. */
92 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
95 if (asprintf (&name
, "cpu%d", i
) < 0)
97 CPU_NAME (STATE_CPU (sd
, i
)) = name
;
101 sim_config_default (sd
);
103 /* Install all configured in modules. */
104 if (sim_module_install (sd
) != SIM_RC_OK
)
110 /* Initialize common parts after argument processing. */
113 sim_post_argv_init (SIM_DESC sd
)
116 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
117 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
119 /* Set the cpu->state backlinks for each cpu. */
120 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
122 CPU_STATE (STATE_CPU (sd
, i
)) = sd
;
123 CPU_INDEX (STATE_CPU (sd
, i
)) = i
;
126 if (sim_module_init (sd
) != SIM_RC_OK
)
132 /* Install all modules.
133 If this fails, no modules are left installed. */
136 sim_module_install (SIM_DESC sd
)
138 MODULE_INSTALL_FN
* const *modp
;
140 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
141 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
143 STATE_MODULES (sd
) = ZALLOC (struct module_list
);
144 for (modp
= modules
; *modp
!= NULL
; ++modp
)
146 if ((*modp
) (sd
) != SIM_RC_OK
)
148 sim_module_uninstall (sd
);
149 SIM_ASSERT (STATE_MODULES (sd
) == NULL
);
156 /* Called after all modules have been installed and after argv
157 has been processed. */
160 sim_module_init (SIM_DESC sd
)
162 struct module_list
*modules
= STATE_MODULES (sd
);
163 MODULE_INIT_LIST
*modp
;
165 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
166 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
168 for (modp
= modules
->init_list
; modp
!= NULL
; modp
= modp
->next
)
170 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
176 /* Called when ever the simulator is resumed */
179 sim_module_resume (SIM_DESC sd
)
181 struct module_list
*modules
= STATE_MODULES (sd
);
182 MODULE_RESUME_LIST
*modp
;
184 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
185 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
187 for (modp
= modules
->resume_list
; modp
!= NULL
; modp
= modp
->next
)
189 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
195 /* Called when ever the simulator is suspended */
198 sim_module_suspend (SIM_DESC sd
)
200 struct module_list
*modules
= STATE_MODULES (sd
);
201 MODULE_SUSPEND_LIST
*modp
;
203 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
204 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
206 for (modp
= modules
->suspend_list
; modp
!= NULL
; modp
= modp
->next
)
208 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
214 /* Uninstall installed modules, called by sim_close. */
217 sim_module_uninstall (SIM_DESC sd
)
219 struct module_list
*modules
= STATE_MODULES (sd
);
220 MODULE_UNINSTALL_LIST
*modp
;
222 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
223 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
225 /* Uninstall the modules. */
226 for (modp
= modules
->uninstall_list
; modp
!= NULL
; modp
= modp
->next
)
229 /* clean-up init list */
231 MODULE_INIT_LIST
*n
, *d
;
232 for (d
= modules
->init_list
; d
!= NULL
; d
= n
)
239 /* clean-up resume list */
241 MODULE_RESUME_LIST
*n
, *d
;
242 for (d
= modules
->resume_list
; d
!= NULL
; d
= n
)
249 /* clean-up suspend list */
251 MODULE_SUSPEND_LIST
*n
, *d
;
252 for (d
= modules
->suspend_list
; d
!= NULL
; d
= n
)
259 /* clean-up uninstall list */
261 MODULE_UNINSTALL_LIST
*n
, *d
;
262 for (d
= modules
->uninstall_list
; d
!= NULL
; d
= n
)
269 /* clean-up info list */
271 MODULE_INFO_LIST
*n
, *d
;
272 for (d
= modules
->info_list
; d
!= NULL
; d
= n
)
280 STATE_MODULES (sd
) = NULL
;
283 /* Called when ever simulator info is needed */
286 sim_module_info (SIM_DESC sd
, int verbose
)
288 struct module_list
*modules
= STATE_MODULES (sd
);
289 MODULE_INFO_LIST
*modp
;
291 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
292 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
294 for (modp
= modules
->info_list
; modp
!= NULL
; modp
= modp
->next
)
296 (*modp
->fn
) (sd
, verbose
);
300 /* Add FN to the init handler list.
301 init in the same order as the install. */
304 sim_module_add_init_fn (SIM_DESC sd
, MODULE_INIT_FN fn
)
306 struct module_list
*modules
= STATE_MODULES (sd
);
307 MODULE_INIT_LIST
*l
= ZALLOC (MODULE_INIT_LIST
);
308 MODULE_INIT_LIST
**last
;
310 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
311 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
313 last
= &modules
->init_list
;
314 while (*last
!= NULL
)
315 last
= &((*last
)->next
);
322 /* Add FN to the resume handler list.
323 resume in the same order as the install. */
326 sim_module_add_resume_fn (SIM_DESC sd
, MODULE_RESUME_FN fn
)
328 struct module_list
*modules
= STATE_MODULES (sd
);
329 MODULE_RESUME_LIST
*l
= ZALLOC (MODULE_RESUME_LIST
);
330 MODULE_RESUME_LIST
**last
;
332 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
333 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
335 last
= &modules
->resume_list
;
336 while (*last
!= NULL
)
337 last
= &((*last
)->next
);
344 /* Add FN to the init handler list.
345 suspend in the reverse order to install. */
348 sim_module_add_suspend_fn (SIM_DESC sd
, MODULE_SUSPEND_FN fn
)
350 struct module_list
*modules
= STATE_MODULES (sd
);
351 MODULE_SUSPEND_LIST
*l
= ZALLOC (MODULE_SUSPEND_LIST
);
352 MODULE_SUSPEND_LIST
**last
;
354 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
355 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
357 last
= &modules
->suspend_list
;
358 while (*last
!= NULL
)
359 last
= &((*last
)->next
);
362 l
->next
= modules
->suspend_list
;
363 modules
->suspend_list
= l
;
366 /* Add FN to the uninstall handler list.
367 Uninstall in reverse order to install. */
370 sim_module_add_uninstall_fn (SIM_DESC sd
, MODULE_UNINSTALL_FN fn
)
372 struct module_list
*modules
= STATE_MODULES (sd
);
373 MODULE_UNINSTALL_LIST
*l
= ZALLOC (MODULE_UNINSTALL_LIST
);
375 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
376 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
379 l
->next
= modules
->uninstall_list
;
380 modules
->uninstall_list
= l
;
383 /* Add FN to the info handler list.
384 Report info in the same order as the install. */
387 sim_module_add_info_fn (SIM_DESC sd
, MODULE_INFO_FN fn
)
389 struct module_list
*modules
= STATE_MODULES (sd
);
390 MODULE_INFO_LIST
*l
= ZALLOC (MODULE_INFO_LIST
);
391 MODULE_INFO_LIST
**last
;
393 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
394 SIM_ASSERT (STATE_MODULES (sd
) != NULL
);
396 last
= &modules
->info_list
;
397 while (*last
!= NULL
)
398 last
= &((*last
)->next
);