OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [sim/] [common/] [sim-module.c] - Blame information for rev 227

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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