Commit | Line | Data |
---|---|---|
c967f187 DE |
1 | /* Module support. |
2 | Copyright (C) 1996, 1997 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support. | |
4 | ||
5 | This file is part of GDB, the GNU debugger. | |
6 | ||
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) | |
10 | any later version. | |
11 | ||
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. | |
16 | ||
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. */ | |
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. */ | |
29 | static 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, |
fdd64f95 AC |
41 | sim_events_install, |
42 | #if WITH_WATCHPOINTS | |
43 | sim_watchpoint_install, | |
44 | #endif | |
c967f187 DE |
45 | #if WITH_SCACHE |
46 | scache_install, | |
47 | #endif | |
48 | #ifdef SIM_HAVE_MODEL /* FIXME: temporary */ | |
49 | model_install, | |
50 | #endif | |
51 | /* Configured in [simulator specific] additional modules. */ | |
52 | #ifdef MODULE_LIST | |
53 | MODULE_LIST | |
54 | #endif | |
55 | 0 | |
56 | }; | |
57 | \f | |
58 | /* Functions called from sim_open. */ | |
59 | ||
60 | /* Initialize common parts before argument processing. */ | |
61 | ||
62 | SIM_RC | |
63 | sim_pre_argv_init (SIM_DESC sd, const char *myname) | |
64 | { | |
fdd64f95 | 65 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
c967f187 DE |
66 | STATE_MY_NAME (sd) = myname + strlen (myname); |
67 | while (STATE_MY_NAME (sd) > myname && STATE_MY_NAME (sd)[-1] != '/') | |
68 | --STATE_MY_NAME (sd); | |
69 | ||
70 | /* Install all configured in modules. */ | |
71 | if (sim_module_install (sd) != SIM_RC_OK) | |
72 | return SIM_RC_FAIL; | |
73 | ||
74 | return SIM_RC_OK; | |
75 | } | |
76 | ||
77 | /* Initialize common parts after argument processing. */ | |
78 | ||
79 | SIM_RC | |
80 | sim_post_argv_init (SIM_DESC sd) | |
81 | { | |
82 | int i; | |
fdd64f95 | 83 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
c967f187 DE |
84 | |
85 | if (sim_module_init (sd) != SIM_RC_OK) | |
86 | return SIM_RC_FAIL; | |
87 | ||
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; | |
91 | ||
92 | return SIM_RC_OK; | |
93 | } | |
94 | \f | |
95 | /* Install all modules. */ | |
96 | ||
97 | SIM_RC | |
98 | sim_module_install (SIM_DESC sd) | |
99 | { | |
100 | MODULE_INSTALL_FN * const *modp; | |
fdd64f95 | 101 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
c967f187 DE |
102 | |
103 | for (modp = modules; *modp != NULL; ++modp) | |
104 | { | |
105 | if ((*modp) (sd) != SIM_RC_OK) | |
106 | return SIM_RC_FAIL; | |
107 | } | |
108 | return SIM_RC_OK; | |
109 | } | |
110 | ||
111 | /* Called after all modules have been installed and after argv | |
112 | has been processed. */ | |
113 | ||
114 | SIM_RC | |
115 | sim_module_init (SIM_DESC sd) | |
116 | { | |
117 | MODULE_INIT_LIST *modp; | |
fdd64f95 | 118 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
c967f187 DE |
119 | |
120 | for (modp = STATE_INIT_LIST (sd); modp != NULL; modp = modp->next) | |
121 | { | |
122 | if ((*modp->fn) (sd) != SIM_RC_OK) | |
123 | return SIM_RC_FAIL; | |
124 | } | |
125 | return SIM_RC_OK; | |
126 | } | |
127 | ||
fdd64f95 AC |
128 | /* Called when ever the simulator is resumed */ |
129 | ||
130 | SIM_RC | |
131 | sim_module_resume (SIM_DESC sd) | |
132 | { | |
133 | MODULE_RESUME_LIST *modp; | |
134 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); | |
135 | ||
136 | for (modp = STATE_RESUME_LIST (sd); modp != NULL; modp = modp->next) | |
137 | { | |
138 | if ((*modp->fn) (sd) != SIM_RC_OK) | |
139 | return SIM_RC_FAIL; | |
140 | } | |
141 | return SIM_RC_OK; | |
142 | } | |
143 | ||
144 | /* Called when ever the simulator is suspended */ | |
145 | ||
146 | SIM_RC | |
147 | sim_module_suspend (SIM_DESC sd) | |
148 | { | |
149 | MODULE_SUSPEND_LIST *modp; | |
150 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); | |
151 | ||
152 | for (modp = STATE_SUSPEND_LIST (sd); modp != NULL; modp = modp->next) | |
153 | { | |
154 | if ((*modp->fn) (sd) != SIM_RC_OK) | |
155 | return SIM_RC_FAIL; | |
156 | } | |
157 | return SIM_RC_OK; | |
158 | } | |
159 | ||
c967f187 DE |
160 | /* Uninstall installed modules, called by sim_close. */ |
161 | ||
162 | void | |
163 | sim_module_uninstall (SIM_DESC sd) | |
164 | { | |
165 | MODULE_UNINSTALL_LIST *modp; | |
fdd64f95 | 166 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
c967f187 DE |
167 | |
168 | /* Uninstall the modules. */ | |
169 | for (modp = STATE_UNINSTALL_LIST (sd); modp != NULL; modp = modp->next) | |
170 | (*modp->fn) (sd); | |
171 | } | |
172 | \f | |
fdd64f95 AC |
173 | /* Add FN to the init handler list. |
174 | init in the same order as the install. */ | |
c967f187 DE |
175 | |
176 | void | |
177 | sim_module_add_init_fn (SIM_DESC sd, MODULE_INIT_FN fn) | |
178 | { | |
179 | MODULE_INIT_LIST *l = | |
180 | (MODULE_INIT_LIST *) xmalloc (sizeof (MODULE_INIT_LIST)); | |
fdd64f95 AC |
181 | MODULE_INIT_LIST **last = &STATE_INIT_LIST (sd); |
182 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); | |
183 | ||
184 | while (*last != NULL) | |
185 | last = &((*last)->next); | |
186 | ||
187 | l->fn = fn; | |
188 | l->next = NULL; | |
189 | *last = l; | |
190 | } | |
191 | ||
192 | /* Add FN to the resume handler list. | |
193 | resume in the same order as the install. */ | |
194 | ||
195 | void | |
196 | sim_module_add_resume_fn (SIM_DESC sd, MODULE_RESUME_FN fn) | |
197 | { | |
198 | MODULE_RESUME_LIST *l = ZALLOC (MODULE_RESUME_LIST); | |
199 | MODULE_RESUME_LIST **last; | |
200 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); | |
201 | ||
202 | last = &STATE_RESUME_LIST (sd); | |
203 | while (*last != NULL) | |
204 | last = &((*last)->next); | |
205 | ||
206 | l->fn = fn; | |
207 | l->next = NULL; | |
208 | *last = l; | |
209 | } | |
210 | ||
211 | /* Add FN to the init handler list. | |
212 | suspend in the reverse order to install. */ | |
213 | ||
214 | void | |
215 | sim_module_add_suspend_fn (SIM_DESC sd, MODULE_SUSPEND_FN fn) | |
216 | { | |
217 | MODULE_SUSPEND_LIST *l = ZALLOC (MODULE_SUSPEND_LIST); | |
218 | MODULE_SUSPEND_LIST **last; | |
219 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); | |
220 | ||
221 | last = &STATE_SUSPEND_LIST (sd); | |
222 | while (*last != NULL) | |
223 | last = &((*last)->next); | |
c967f187 DE |
224 | |
225 | l->fn = fn; | |
fdd64f95 AC |
226 | l->next = STATE_SUSPEND_LIST (sd); |
227 | STATE_SUSPEND_LIST (sd) = l; | |
c967f187 DE |
228 | } |
229 | ||
fdd64f95 AC |
230 | /* Add FN to the uninstall handler list. |
231 | Uninstall in reverse order to install. */ | |
c967f187 DE |
232 | |
233 | void | |
234 | sim_module_add_uninstall_fn (SIM_DESC sd, MODULE_UNINSTALL_FN fn) | |
235 | { | |
236 | MODULE_UNINSTALL_LIST *l = | |
237 | (MODULE_UNINSTALL_LIST *) xmalloc (sizeof (MODULE_UNINSTALL_LIST)); | |
238 | ||
239 | l->fn = fn; | |
240 | l->next = STATE_UNINSTALL_LIST (sd); | |
241 | STATE_UNINSTALL_LIST (sd) = l; | |
242 | } |