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
[] = {
42 #ifndef SIM_HAVE_FLATMEM
43 /* FIXME: should handle flatmem as well FLATMEM */
47 sim_watchpoint_install
,
55 #ifdef SIM_HAVE_BREAKPOINTS
58 /* Configured in [simulator specific] additional modules. */
65 /* Functions called from sim_open. */
67 /* Initialize common parts before argument processing. */
70 sim_pre_argv_init (SIM_DESC sd
, const char *myname
)
72 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
73 STATE_MY_NAME (sd
) = myname
+ strlen (myname
);
74 while (STATE_MY_NAME (sd
) > myname
&& STATE_MY_NAME (sd
)[-1] != '/')
77 /* Install all configured in modules. */
78 if (sim_module_install (sd
) != SIM_RC_OK
)
84 /* Initialize common parts after argument processing. */
87 sim_post_argv_init (SIM_DESC sd
)
90 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
92 if (sim_module_init (sd
) != SIM_RC_OK
)
95 /* Set the cpu->state backlinks for each cpu. */
96 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
97 CPU_STATE (STATE_CPU (sd
, i
)) = sd
;
102 /* Install all modules.
103 If this fails, no modules are left installed. */
106 sim_module_install (SIM_DESC sd
)
108 MODULE_INSTALL_FN
* const *modp
;
109 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
111 for (modp
= modules
; *modp
!= NULL
; ++modp
)
113 if ((*modp
) (sd
) != SIM_RC_OK
)
115 sim_module_uninstall (sd
);
122 /* Called after all modules have been installed and after argv
123 has been processed. */
126 sim_module_init (SIM_DESC sd
)
128 MODULE_INIT_LIST
*modp
;
129 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
131 for (modp
= STATE_INIT_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
133 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
139 /* Called when ever the simulator is resumed */
142 sim_module_resume (SIM_DESC sd
)
144 MODULE_RESUME_LIST
*modp
;
145 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
147 for (modp
= STATE_RESUME_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
149 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
155 /* Called when ever the simulator is suspended */
158 sim_module_suspend (SIM_DESC sd
)
160 MODULE_SUSPEND_LIST
*modp
;
161 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
163 for (modp
= STATE_SUSPEND_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
165 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
171 /* Uninstall installed modules, called by sim_close. */
174 sim_module_uninstall (SIM_DESC sd
)
176 MODULE_UNINSTALL_LIST
*modp
;
177 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
179 /* Uninstall the modules. */
180 for (modp
= STATE_UNINSTALL_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
184 /* Add FN to the init handler list.
185 init in the same order as the install. */
188 sim_module_add_init_fn (SIM_DESC sd
, MODULE_INIT_FN fn
)
190 MODULE_INIT_LIST
*l
=
191 (MODULE_INIT_LIST
*) xmalloc (sizeof (MODULE_INIT_LIST
));
192 MODULE_INIT_LIST
**last
= &STATE_INIT_LIST (sd
);
193 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
195 while (*last
!= NULL
)
196 last
= &((*last
)->next
);
203 /* Add FN to the resume handler list.
204 resume in the same order as the install. */
207 sim_module_add_resume_fn (SIM_DESC sd
, MODULE_RESUME_FN fn
)
209 MODULE_RESUME_LIST
*l
= ZALLOC (MODULE_RESUME_LIST
);
210 MODULE_RESUME_LIST
**last
;
211 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
213 last
= &STATE_RESUME_LIST (sd
);
214 while (*last
!= NULL
)
215 last
= &((*last
)->next
);
222 /* Add FN to the init handler list.
223 suspend in the reverse order to install. */
226 sim_module_add_suspend_fn (SIM_DESC sd
, MODULE_SUSPEND_FN fn
)
228 MODULE_SUSPEND_LIST
*l
= ZALLOC (MODULE_SUSPEND_LIST
);
229 MODULE_SUSPEND_LIST
**last
;
230 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
232 last
= &STATE_SUSPEND_LIST (sd
);
233 while (*last
!= NULL
)
234 last
= &((*last
)->next
);
237 l
->next
= STATE_SUSPEND_LIST (sd
);
238 STATE_SUSPEND_LIST (sd
) = l
;
241 /* Add FN to the uninstall handler list.
242 Uninstall in reverse order to install. */
245 sim_module_add_uninstall_fn (SIM_DESC sd
, MODULE_UNINSTALL_FN fn
)
247 MODULE_UNINSTALL_LIST
*l
=
248 (MODULE_UNINSTALL_LIST
*) xmalloc (sizeof (MODULE_UNINSTALL_LIST
));
251 l
->next
= STATE_UNINSTALL_LIST (sd
);
252 STATE_UNINSTALL_LIST (sd
) = l
;