OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [sim/] [common/] [sim-module.c] - Blame information for rev 856

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* Module support.
2
 
3
   Copyright 1996, 1997, 1998, 2003, 2007, 2008 Free Software Foundation, Inc.
4
 
5
   Contributed by Cygnus Support.
6
 
7
This file is part of GDB, the GNU debugger.
8
 
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 3 of the License, or
12
(at your option) any later version.
13
 
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
GNU General Public License for more details.
18
 
19
You should have received a copy of the GNU General Public License
20
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
 
22
#include "sim-main.h"
23
#include "sim-io.h"
24
#include "sim-options.h"
25
#include "sim-assert.h"
26
 
27
#if WITH_HW
28
#include "sim-hw.h"
29
#endif
30
 
31
#include "libiberty.h"
32
 
33
/* List of all modules.  */
34
static MODULE_INSTALL_FN * const modules[] = {
35
  standard_install,
36
  sim_events_install,
37
#ifdef SIM_HAVE_MODEL
38
  sim_model_install,
39
#endif
40
#if WITH_ENGINE
41
  sim_engine_install,
42
#endif
43
#if WITH_TRACE
44
  trace_install,
45
#endif
46
#if WITH_PROFILE
47
  profile_install,
48
#endif
49
  sim_core_install,
50
#ifndef SIM_HAVE_FLATMEM
51
  /* FIXME: should handle flatmem as well FLATMEM */
52
  sim_memopt_install,
53
#endif
54
#if WITH_WATCHPOINTS
55
  sim_watchpoint_install,
56
#endif
57
#if WITH_SCACHE
58
  scache_install,
59
#endif
60
#if WITH_HW
61
  sim_hw_install,
62
#endif
63
  /* Configured in [simulator specific] additional modules.  */
64
#ifdef MODULE_LIST
65
  MODULE_LIST
66
#endif
67
 
68
};
69
 
70
/* Functions called from sim_open.  */
71
 
72
/* Initialize common parts before argument processing.  */
73
 
74
SIM_RC
75
sim_pre_argv_init (SIM_DESC sd, const char *myname)
76
{
77
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
78
  SIM_ASSERT (STATE_MODULES (sd) == NULL);
79
 
80
  STATE_MY_NAME (sd) = myname + strlen (myname);
81
  while (STATE_MY_NAME (sd) > myname && STATE_MY_NAME (sd)[-1] != '/')
82
    --STATE_MY_NAME (sd);
83
 
84
  /* Set the cpu names to default values.  */
85
  {
86
    int i;
87
    for (i = 0; i < MAX_NR_PROCESSORS; ++i)
88
      {
89
        char *name;
90
        asprintf (&name, "cpu%d", i);
91
        CPU_NAME (STATE_CPU (sd, i)) = name;
92
      }
93
  }
94
 
95
  sim_config_default (sd);
96
 
97
  /* Install all configured in modules.  */
98
  if (sim_module_install (sd) != SIM_RC_OK)
99
    return SIM_RC_FAIL;
100
 
101
  return SIM_RC_OK;
102
}
103
 
104
/* Initialize common parts after argument processing.  */
105
 
106
SIM_RC
107
sim_post_argv_init (SIM_DESC sd)
108
{
109
  int i;
110
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
111
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
112
 
113
  /* Set the cpu->state backlinks for each cpu.  */
114
  for (i = 0; i < MAX_NR_PROCESSORS; ++i)
115
    {
116
      CPU_STATE (STATE_CPU (sd, i)) = sd;
117
      CPU_INDEX (STATE_CPU (sd, i)) = i;
118
    }
119
 
120
  if (sim_module_init (sd) != SIM_RC_OK)
121
    return SIM_RC_FAIL;
122
 
123
  return SIM_RC_OK;
124
}
125
 
126
/* Install all modules.
127
   If this fails, no modules are left installed.  */
128
 
129
SIM_RC
130
sim_module_install (SIM_DESC sd)
131
{
132
  MODULE_INSTALL_FN * const *modp;
133
 
134
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
135
  SIM_ASSERT (STATE_MODULES (sd) == NULL);
136
 
137
  STATE_MODULES (sd) = ZALLOC (struct module_list);
138
  for (modp = modules; *modp != NULL; ++modp)
139
    {
140
      if ((*modp) (sd) != SIM_RC_OK)
141
        {
142
          sim_module_uninstall (sd);
143
          SIM_ASSERT (STATE_MODULES (sd) == NULL);
144
          return SIM_RC_FAIL;
145
        }
146
    }
147
  return SIM_RC_OK;
148
}
149
 
150
/* Called after all modules have been installed and after argv
151
   has been processed.  */
152
 
153
SIM_RC
154
sim_module_init (SIM_DESC sd)
155
{
156
  struct module_list *modules = STATE_MODULES (sd);
157
  MODULE_INIT_LIST *modp;
158
 
159
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
160
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
161
 
162
  for (modp = modules->init_list; modp != NULL; modp = modp->next)
163
    {
164
      if ((*modp->fn) (sd) != SIM_RC_OK)
165
        return SIM_RC_FAIL;
166
    }
167
  return SIM_RC_OK;
168
}
169
 
170
/* Called when ever the simulator is resumed */
171
 
172
SIM_RC
173
sim_module_resume (SIM_DESC sd)
174
{
175
  struct module_list *modules = STATE_MODULES (sd);
176
  MODULE_RESUME_LIST *modp;
177
 
178
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
179
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
180
 
181
  for (modp = modules->resume_list; modp != NULL; modp = modp->next)
182
    {
183
      if ((*modp->fn) (sd) != SIM_RC_OK)
184
        return SIM_RC_FAIL;
185
    }
186
  return SIM_RC_OK;
187
}
188
 
189
/* Called when ever the simulator is suspended */
190
 
191
SIM_RC
192
sim_module_suspend (SIM_DESC sd)
193
{
194
  struct module_list *modules = STATE_MODULES (sd);
195
  MODULE_SUSPEND_LIST *modp;
196
 
197
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
198
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
199
 
200
  for (modp = modules->suspend_list; modp != NULL; modp = modp->next)
201
    {
202
      if ((*modp->fn) (sd) != SIM_RC_OK)
203
        return SIM_RC_FAIL;
204
    }
205
  return SIM_RC_OK;
206
}
207
 
208
/* Uninstall installed modules, called by sim_close.  */
209
 
210
void
211
sim_module_uninstall (SIM_DESC sd)
212
{
213
  struct module_list *modules = STATE_MODULES (sd);
214
  MODULE_UNINSTALL_LIST *modp;
215
 
216
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
217
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
218
 
219
  /* Uninstall the modules.  */
220
  for (modp = modules->uninstall_list; modp != NULL; modp = modp->next)
221
    (*modp->fn) (sd);
222
 
223
  /* clean-up init list */
224
  {
225
    MODULE_INIT_LIST *n, *d;
226
    for (d = modules->init_list; d != NULL; d = n)
227
      {
228
        n = d->next;
229
        zfree (d);
230
      }
231
  }
232
 
233
  /* clean-up resume list */
234
  {
235
    MODULE_RESUME_LIST *n, *d;
236
    for (d = modules->resume_list; d != NULL; d = n)
237
      {
238
        n = d->next;
239
        zfree (d);
240
      }
241
  }
242
 
243
  /* clean-up suspend list */
244
  {
245
    MODULE_SUSPEND_LIST *n, *d;
246
    for (d = modules->suspend_list; d != NULL; d = n)
247
      {
248
        n = d->next;
249
        zfree (d);
250
      }
251
  }
252
 
253
  /* clean-up uninstall list */
254
  {
255
    MODULE_UNINSTALL_LIST *n, *d;
256
    for (d = modules->uninstall_list; d != NULL; d = n)
257
      {
258
        n = d->next;
259
        zfree (d);
260
      }
261
  }
262
 
263
  /* clean-up info list */
264
  {
265
    MODULE_INFO_LIST *n, *d;
266
    for (d = modules->info_list; d != NULL; d = n)
267
      {
268
        n = d->next;
269
        zfree (d);
270
      }
271
  }
272
 
273
  zfree (modules);
274
  STATE_MODULES (sd) = NULL;
275
}
276
 
277
/* Called when ever simulator info is needed */
278
 
279
void
280
sim_module_info (SIM_DESC sd, int verbose)
281
{
282
  struct module_list *modules = STATE_MODULES (sd);
283
  MODULE_INFO_LIST *modp;
284
 
285
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
286
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
287
 
288
  for (modp = modules->info_list; modp != NULL; modp = modp->next)
289
    {
290
      (*modp->fn) (sd, verbose);
291
    }
292
}
293
 
294
/* Add FN to the init handler list.
295
   init in the same order as the install. */
296
 
297
void
298
sim_module_add_init_fn (SIM_DESC sd, MODULE_INIT_FN fn)
299
{
300
  struct module_list *modules = STATE_MODULES (sd);
301
  MODULE_INIT_LIST *l = ZALLOC (MODULE_INIT_LIST);
302
  MODULE_INIT_LIST **last;
303
 
304
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
305
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
306
 
307
  last = &modules->init_list;
308
  while (*last != NULL)
309
    last = &((*last)->next);
310
 
311
  l->fn = fn;
312
  l->next = NULL;
313
  *last = l;
314
}
315
 
316
/* Add FN to the resume handler list.
317
   resume in the same order as the install. */
318
 
319
void
320
sim_module_add_resume_fn (SIM_DESC sd, MODULE_RESUME_FN fn)
321
{
322
  struct module_list *modules = STATE_MODULES (sd);
323
  MODULE_RESUME_LIST *l = ZALLOC (MODULE_RESUME_LIST);
324
  MODULE_RESUME_LIST **last;
325
 
326
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
327
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
328
 
329
  last = &modules->resume_list;
330
  while (*last != NULL)
331
    last = &((*last)->next);
332
 
333
  l->fn = fn;
334
  l->next = NULL;
335
  *last = l;
336
}
337
 
338
/* Add FN to the init handler list.
339
   suspend in the reverse order to install. */
340
 
341
void
342
sim_module_add_suspend_fn (SIM_DESC sd, MODULE_SUSPEND_FN fn)
343
{
344
  struct module_list *modules = STATE_MODULES (sd);
345
  MODULE_SUSPEND_LIST *l = ZALLOC (MODULE_SUSPEND_LIST);
346
  MODULE_SUSPEND_LIST **last;
347
 
348
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
349
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
350
 
351
  last = &modules->suspend_list;
352
  while (*last != NULL)
353
    last = &((*last)->next);
354
 
355
  l->fn = fn;
356
  l->next = modules->suspend_list;
357
  modules->suspend_list = l;
358
}
359
 
360
/* Add FN to the uninstall handler list.
361
   Uninstall in reverse order to install.  */
362
 
363
void
364
sim_module_add_uninstall_fn (SIM_DESC sd, MODULE_UNINSTALL_FN fn)
365
{
366
  struct module_list *modules = STATE_MODULES (sd);
367
  MODULE_UNINSTALL_LIST *l = ZALLOC (MODULE_UNINSTALL_LIST);
368
 
369
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
370
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
371
 
372
  l->fn = fn;
373
  l->next = modules->uninstall_list;
374
  modules->uninstall_list = l;
375
}
376
 
377
/* Add FN to the info handler list.
378
   Report info in the same order as the install. */
379
 
380
void
381
sim_module_add_info_fn (SIM_DESC sd, MODULE_INFO_FN fn)
382
{
383
  struct module_list *modules = STATE_MODULES (sd);
384
  MODULE_INFO_LIST *l = ZALLOC (MODULE_INFO_LIST);
385
  MODULE_INFO_LIST **last;
386
 
387
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
388
  SIM_ASSERT (STATE_MODULES (sd) != NULL);
389
 
390
  last = &modules->info_list;
391
  while (*last != NULL)
392
    last = &((*last)->next);
393
 
394
  l->fn = fn;
395
  l->next = NULL;
396
  *last = l;
397
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.