o Add modulo argument to sim_core_attach
[deliverable/binutils-gdb.git] / sim / common / sim-module.c
CommitLineData
c967f187
DE
1/* Module support.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4
5This file is part of GDB, the GNU debugger.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License along
18with this program; if not, write to the Free Software Foundation, Inc.,
1959 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21#include "sim-main.h"
22#include "sim-io.h"
23#include "sim-options.h"
fdd64f95
AC
24#include "sim-assert.h"
25
26#include "libiberty.h"
c967f187
DE
27
28/* List of all modules. */
29static MODULE_INSTALL_FN * const modules[] = {
30 standard_install,
fdd64f95
AC
31#if WITH_ENGINE
32 sim_engine_install,
33#endif
34#if WITH_TRACE
c967f187 35 trace_install,
fdd64f95
AC
36#endif
37#if WITH_PROFILE
c967f187 38 profile_install,
fdd64f95 39#endif
c967f187 40 sim_core_install,
a34abff8
AC
41#ifndef SIM_HAVE_FLATMEM
42 /* FIXME: should handle flatmem as well FLATMEM */
43 sim_memopt_install,
44#endif
fdd64f95
AC
45 sim_events_install,
46#if WITH_WATCHPOINTS
47 sim_watchpoint_install,
48#endif
c967f187
DE
49#if WITH_SCACHE
50 scache_install,
51#endif
52#ifdef SIM_HAVE_MODEL /* FIXME: temporary */
53 model_install,
54#endif
55 /* Configured in [simulator specific] additional modules. */
56#ifdef MODULE_LIST
57 MODULE_LIST
58#endif
59 0
60};
61\f
62/* Functions called from sim_open. */
63
64/* Initialize common parts before argument processing. */
65
66SIM_RC
67sim_pre_argv_init (SIM_DESC sd, const char *myname)
68{
fdd64f95 69 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
c967f187
DE
70 STATE_MY_NAME (sd) = myname + strlen (myname);
71 while (STATE_MY_NAME (sd) > myname && STATE_MY_NAME (sd)[-1] != '/')
72 --STATE_MY_NAME (sd);
73
74 /* Install all configured in modules. */
75 if (sim_module_install (sd) != SIM_RC_OK)
76 return SIM_RC_FAIL;
77
78 return SIM_RC_OK;
79}
80
81/* Initialize common parts after argument processing. */
82
83SIM_RC
84sim_post_argv_init (SIM_DESC sd)
85{
86 int i;
fdd64f95 87 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
c967f187
DE
88
89 if (sim_module_init (sd) != SIM_RC_OK)
90 return SIM_RC_FAIL;
91
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;
95
96 return SIM_RC_OK;
97}
98\f
99/* Install all modules. */
100
101SIM_RC
102sim_module_install (SIM_DESC sd)
103{
104 MODULE_INSTALL_FN * const *modp;
fdd64f95 105 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
c967f187
DE
106
107 for (modp = modules; *modp != NULL; ++modp)
108 {
109 if ((*modp) (sd) != SIM_RC_OK)
110 return SIM_RC_FAIL;
111 }
112 return SIM_RC_OK;
113}
114
115/* Called after all modules have been installed and after argv
116 has been processed. */
117
118SIM_RC
119sim_module_init (SIM_DESC sd)
120{
121 MODULE_INIT_LIST *modp;
fdd64f95 122 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
c967f187
DE
123
124 for (modp = STATE_INIT_LIST (sd); modp != NULL; modp = modp->next)
125 {
126 if ((*modp->fn) (sd) != SIM_RC_OK)
127 return SIM_RC_FAIL;
128 }
129 return SIM_RC_OK;
130}
131
fdd64f95
AC
132/* Called when ever the simulator is resumed */
133
134SIM_RC
135sim_module_resume (SIM_DESC sd)
136{
137 MODULE_RESUME_LIST *modp;
138 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
139
140 for (modp = STATE_RESUME_LIST (sd); modp != NULL; modp = modp->next)
141 {
142 if ((*modp->fn) (sd) != SIM_RC_OK)
143 return SIM_RC_FAIL;
144 }
145 return SIM_RC_OK;
146}
147
148/* Called when ever the simulator is suspended */
149
150SIM_RC
151sim_module_suspend (SIM_DESC sd)
152{
153 MODULE_SUSPEND_LIST *modp;
154 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
155
156 for (modp = STATE_SUSPEND_LIST (sd); modp != NULL; modp = modp->next)
157 {
158 if ((*modp->fn) (sd) != SIM_RC_OK)
159 return SIM_RC_FAIL;
160 }
161 return SIM_RC_OK;
162}
163
c967f187
DE
164/* Uninstall installed modules, called by sim_close. */
165
166void
167sim_module_uninstall (SIM_DESC sd)
168{
169 MODULE_UNINSTALL_LIST *modp;
fdd64f95 170 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
c967f187
DE
171
172 /* Uninstall the modules. */
173 for (modp = STATE_UNINSTALL_LIST (sd); modp != NULL; modp = modp->next)
174 (*modp->fn) (sd);
175}
176\f
fdd64f95
AC
177/* Add FN to the init handler list.
178 init in the same order as the install. */
c967f187
DE
179
180void
181sim_module_add_init_fn (SIM_DESC sd, MODULE_INIT_FN fn)
182{
183 MODULE_INIT_LIST *l =
184 (MODULE_INIT_LIST *) xmalloc (sizeof (MODULE_INIT_LIST));
fdd64f95
AC
185 MODULE_INIT_LIST **last = &STATE_INIT_LIST (sd);
186 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
187
188 while (*last != NULL)
189 last = &((*last)->next);
190
191 l->fn = fn;
192 l->next = NULL;
193 *last = l;
194}
195
196/* Add FN to the resume handler list.
197 resume in the same order as the install. */
198
199void
200sim_module_add_resume_fn (SIM_DESC sd, MODULE_RESUME_FN fn)
201{
202 MODULE_RESUME_LIST *l = ZALLOC (MODULE_RESUME_LIST);
203 MODULE_RESUME_LIST **last;
204 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
205
206 last = &STATE_RESUME_LIST (sd);
207 while (*last != NULL)
208 last = &((*last)->next);
209
210 l->fn = fn;
211 l->next = NULL;
212 *last = l;
213}
214
215/* Add FN to the init handler list.
216 suspend in the reverse order to install. */
217
218void
219sim_module_add_suspend_fn (SIM_DESC sd, MODULE_SUSPEND_FN fn)
220{
221 MODULE_SUSPEND_LIST *l = ZALLOC (MODULE_SUSPEND_LIST);
222 MODULE_SUSPEND_LIST **last;
223 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
224
225 last = &STATE_SUSPEND_LIST (sd);
226 while (*last != NULL)
227 last = &((*last)->next);
c967f187
DE
228
229 l->fn = fn;
fdd64f95
AC
230 l->next = STATE_SUSPEND_LIST (sd);
231 STATE_SUSPEND_LIST (sd) = l;
c967f187
DE
232}
233
fdd64f95
AC
234/* Add FN to the uninstall handler list.
235 Uninstall in reverse order to install. */
c967f187
DE
236
237void
238sim_module_add_uninstall_fn (SIM_DESC sd, MODULE_UNINSTALL_FN fn)
239{
240 MODULE_UNINSTALL_LIST *l =
241 (MODULE_UNINSTALL_LIST *) xmalloc (sizeof (MODULE_UNINSTALL_LIST));
242
243 l->fn = fn;
244 l->next = STATE_UNINSTALL_LIST (sd);
245 STATE_UNINSTALL_LIST (sd) = l;
246}
This page took 0.041228 seconds and 4 git commands to generate.