2 Copyright (C) 1996, 1997 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"
26 #include "libiberty.h"
28 /* List of all modules. */
29 static MODULE_INSTALL_FN
* const modules
[] = {
43 sim_watchpoint_install
,
48 #ifdef SIM_HAVE_MODEL /* FIXME: temporary */
51 /* Configured in [simulator specific] additional modules. */
58 /* Functions called from sim_open. */
60 /* Initialize common parts before argument processing. */
63 sim_pre_argv_init (SIM_DESC sd
, const char *myname
)
65 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
66 STATE_MY_NAME (sd
) = myname
+ strlen (myname
);
67 while (STATE_MY_NAME (sd
) > myname
&& STATE_MY_NAME (sd
)[-1] != '/')
70 /* Install all configured in modules. */
71 if (sim_module_install (sd
) != SIM_RC_OK
)
77 /* Initialize common parts after argument processing. */
80 sim_post_argv_init (SIM_DESC sd
)
83 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
85 if (sim_module_init (sd
) != SIM_RC_OK
)
88 /* Set the cpu->state backlinks for each cpu. */
89 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
90 CPU_STATE (STATE_CPU (sd
, i
)) = sd
;
95 /* Install all modules. */
98 sim_module_install (SIM_DESC sd
)
100 MODULE_INSTALL_FN
* const *modp
;
101 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
103 for (modp
= modules
; *modp
!= NULL
; ++modp
)
105 if ((*modp
) (sd
) != SIM_RC_OK
)
111 /* Called after all modules have been installed and after argv
112 has been processed. */
115 sim_module_init (SIM_DESC sd
)
117 MODULE_INIT_LIST
*modp
;
118 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
120 for (modp
= STATE_INIT_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
122 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
128 /* Called when ever the simulator is resumed */
131 sim_module_resume (SIM_DESC sd
)
133 MODULE_RESUME_LIST
*modp
;
134 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
136 for (modp
= STATE_RESUME_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
138 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
144 /* Called when ever the simulator is suspended */
147 sim_module_suspend (SIM_DESC sd
)
149 MODULE_SUSPEND_LIST
*modp
;
150 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
152 for (modp
= STATE_SUSPEND_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
154 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
160 /* Uninstall installed modules, called by sim_close. */
163 sim_module_uninstall (SIM_DESC sd
)
165 MODULE_UNINSTALL_LIST
*modp
;
166 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
168 /* Uninstall the modules. */
169 for (modp
= STATE_UNINSTALL_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
173 /* Add FN to the init handler list.
174 init in the same order as the install. */
177 sim_module_add_init_fn (SIM_DESC sd
, MODULE_INIT_FN fn
)
179 MODULE_INIT_LIST
*l
=
180 (MODULE_INIT_LIST
*) xmalloc (sizeof (MODULE_INIT_LIST
));
181 MODULE_INIT_LIST
**last
= &STATE_INIT_LIST (sd
);
182 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
184 while (*last
!= NULL
)
185 last
= &((*last
)->next
);
192 /* Add FN to the resume handler list.
193 resume in the same order as the install. */
196 sim_module_add_resume_fn (SIM_DESC sd
, MODULE_RESUME_FN fn
)
198 MODULE_RESUME_LIST
*l
= ZALLOC (MODULE_RESUME_LIST
);
199 MODULE_RESUME_LIST
**last
;
200 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
202 last
= &STATE_RESUME_LIST (sd
);
203 while (*last
!= NULL
)
204 last
= &((*last
)->next
);
211 /* Add FN to the init handler list.
212 suspend in the reverse order to install. */
215 sim_module_add_suspend_fn (SIM_DESC sd
, MODULE_SUSPEND_FN fn
)
217 MODULE_SUSPEND_LIST
*l
= ZALLOC (MODULE_SUSPEND_LIST
);
218 MODULE_SUSPEND_LIST
**last
;
219 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
221 last
= &STATE_SUSPEND_LIST (sd
);
222 while (*last
!= NULL
)
223 last
= &((*last
)->next
);
226 l
->next
= STATE_SUSPEND_LIST (sd
);
227 STATE_SUSPEND_LIST (sd
) = l
;
230 /* Add FN to the uninstall handler list.
231 Uninstall in reverse order to install. */
234 sim_module_add_uninstall_fn (SIM_DESC sd
, MODULE_UNINSTALL_FN fn
)
236 MODULE_UNINSTALL_LIST
*l
=
237 (MODULE_UNINSTALL_LIST
*) xmalloc (sizeof (MODULE_UNINSTALL_LIST
));
240 l
->next
= STATE_UNINSTALL_LIST (sd
);
241 STATE_UNINSTALL_LIST (sd
) = l
;