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
[] = {
41 #ifndef SIM_HAVE_FLATMEM
42 /* FIXME: should handle flatmem as well FLATMEM */
47 sim_watchpoint_install
,
52 #ifdef SIM_HAVE_MODEL /* FIXME: temporary */
55 /* Configured in [simulator specific] additional modules. */
62 /* Functions called from sim_open. */
64 /* Initialize common parts before argument processing. */
67 sim_pre_argv_init (SIM_DESC sd
, const char *myname
)
69 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
70 STATE_MY_NAME (sd
) = myname
+ strlen (myname
);
71 while (STATE_MY_NAME (sd
) > myname
&& STATE_MY_NAME (sd
)[-1] != '/')
74 /* Install all configured in modules. */
75 if (sim_module_install (sd
) != SIM_RC_OK
)
81 /* Initialize common parts after argument processing. */
84 sim_post_argv_init (SIM_DESC sd
)
87 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
89 if (sim_module_init (sd
) != SIM_RC_OK
)
92 /* Set the cpu->state backlinks for each cpu. */
93 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
94 CPU_STATE (STATE_CPU (sd
, i
)) = sd
;
99 /* Install all modules. */
102 sim_module_install (SIM_DESC sd
)
104 MODULE_INSTALL_FN
* const *modp
;
105 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
107 for (modp
= modules
; *modp
!= NULL
; ++modp
)
109 if ((*modp
) (sd
) != SIM_RC_OK
)
115 /* Called after all modules have been installed and after argv
116 has been processed. */
119 sim_module_init (SIM_DESC sd
)
121 MODULE_INIT_LIST
*modp
;
122 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
124 for (modp
= STATE_INIT_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
126 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
132 /* Called when ever the simulator is resumed */
135 sim_module_resume (SIM_DESC sd
)
137 MODULE_RESUME_LIST
*modp
;
138 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
140 for (modp
= STATE_RESUME_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
142 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
148 /* Called when ever the simulator is suspended */
151 sim_module_suspend (SIM_DESC sd
)
153 MODULE_SUSPEND_LIST
*modp
;
154 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
156 for (modp
= STATE_SUSPEND_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
158 if ((*modp
->fn
) (sd
) != SIM_RC_OK
)
164 /* Uninstall installed modules, called by sim_close. */
167 sim_module_uninstall (SIM_DESC sd
)
169 MODULE_UNINSTALL_LIST
*modp
;
170 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
172 /* Uninstall the modules. */
173 for (modp
= STATE_UNINSTALL_LIST (sd
); modp
!= NULL
; modp
= modp
->next
)
177 /* Add FN to the init handler list.
178 init in the same order as the install. */
181 sim_module_add_init_fn (SIM_DESC sd
, MODULE_INIT_FN fn
)
183 MODULE_INIT_LIST
*l
=
184 (MODULE_INIT_LIST
*) xmalloc (sizeof (MODULE_INIT_LIST
));
185 MODULE_INIT_LIST
**last
= &STATE_INIT_LIST (sd
);
186 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
188 while (*last
!= NULL
)
189 last
= &((*last
)->next
);
196 /* Add FN to the resume handler list.
197 resume in the same order as the install. */
200 sim_module_add_resume_fn (SIM_DESC sd
, MODULE_RESUME_FN fn
)
202 MODULE_RESUME_LIST
*l
= ZALLOC (MODULE_RESUME_LIST
);
203 MODULE_RESUME_LIST
**last
;
204 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
206 last
= &STATE_RESUME_LIST (sd
);
207 while (*last
!= NULL
)
208 last
= &((*last
)->next
);
215 /* Add FN to the init handler list.
216 suspend in the reverse order to install. */
219 sim_module_add_suspend_fn (SIM_DESC sd
, MODULE_SUSPEND_FN fn
)
221 MODULE_SUSPEND_LIST
*l
= ZALLOC (MODULE_SUSPEND_LIST
);
222 MODULE_SUSPEND_LIST
**last
;
223 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
225 last
= &STATE_SUSPEND_LIST (sd
);
226 while (*last
!= NULL
)
227 last
= &((*last
)->next
);
230 l
->next
= STATE_SUSPEND_LIST (sd
);
231 STATE_SUSPEND_LIST (sd
) = l
;
234 /* Add FN to the uninstall handler list.
235 Uninstall in reverse order to install. */
238 sim_module_add_uninstall_fn (SIM_DESC sd
, MODULE_UNINSTALL_FN fn
)
240 MODULE_UNINSTALL_LIST
*l
=
241 (MODULE_UNINSTALL_LIST
*) xmalloc (sizeof (MODULE_UNINSTALL_LIST
));
244 l
->next
= STATE_UNINSTALL_LIST (sd
);
245 STATE_UNINSTALL_LIST (sd
) = l
;