* Makefile.in (sim-options_h): Define.
[binutils-gdb.git] / sim / common / sim-module.c
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"
24
25 /* List of all modules. */
26 static MODULE_INSTALL_FN * const modules[] = {
27 standard_install,
28 trace_install,
29 profile_install,
30 sim_core_install,
31 #if WITH_SCACHE
32 scache_install,
33 #endif
34 #ifdef SIM_HAVE_MODEL /* FIXME: temporary */
35 model_install,
36 #endif
37 /* Configured in [simulator specific] additional modules. */
38 #ifdef MODULE_LIST
39 MODULE_LIST
40 #endif
41 0
42 };
43 \f
44 /* Functions called from sim_open. */
45
46 /* Initialize common parts before argument processing. */
47
48 SIM_RC
49 sim_pre_argv_init (SIM_DESC sd, const char *myname)
50 {
51 STATE_MY_NAME (sd) = myname + strlen (myname);
52 while (STATE_MY_NAME (sd) > myname && STATE_MY_NAME (sd)[-1] != '/')
53 --STATE_MY_NAME (sd);
54
55 /* Install all configured in modules. */
56 if (sim_module_install (sd) != SIM_RC_OK)
57 return SIM_RC_FAIL;
58
59 return SIM_RC_OK;
60 }
61
62 /* Initialize common parts after argument processing. */
63
64 SIM_RC
65 sim_post_argv_init (SIM_DESC sd)
66 {
67 int i;
68
69 if (sim_module_init (sd) != SIM_RC_OK)
70 return SIM_RC_FAIL;
71
72 /* Set the cpu->state backlinks for each cpu. */
73 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
74 CPU_STATE (STATE_CPU (sd, i)) = sd;
75
76 return SIM_RC_OK;
77 }
78 \f
79 /* Install all modules. */
80
81 SIM_RC
82 sim_module_install (SIM_DESC sd)
83 {
84 MODULE_INSTALL_FN * const *modp;
85
86 for (modp = modules; *modp != NULL; ++modp)
87 {
88 if ((*modp) (sd) != SIM_RC_OK)
89 return SIM_RC_FAIL;
90 }
91 return SIM_RC_OK;
92 }
93
94 /* Called after all modules have been installed and after argv
95 has been processed. */
96
97 SIM_RC
98 sim_module_init (SIM_DESC sd)
99 {
100 MODULE_INIT_LIST *modp;
101
102 for (modp = STATE_INIT_LIST (sd); modp != NULL; modp = modp->next)
103 {
104 if ((*modp->fn) (sd) != SIM_RC_OK)
105 return SIM_RC_FAIL;
106 }
107 return SIM_RC_OK;
108 }
109
110 /* Uninstall installed modules, called by sim_close. */
111
112 void
113 sim_module_uninstall (SIM_DESC sd)
114 {
115 MODULE_UNINSTALL_LIST *modp;
116
117 /* Uninstall the modules. */
118 for (modp = STATE_UNINSTALL_LIST (sd); modp != NULL; modp = modp->next)
119 (*modp->fn) (sd);
120 }
121 \f
122 /* Add FN to the init handler list. */
123
124 void
125 sim_module_add_init_fn (SIM_DESC sd, MODULE_INIT_FN fn)
126 {
127 MODULE_INIT_LIST *l =
128 (MODULE_INIT_LIST *) xmalloc (sizeof (MODULE_INIT_LIST));
129
130 l->fn = fn;
131 l->next = STATE_INIT_LIST (sd);
132 STATE_INIT_LIST (sd) = l;
133 }
134
135 /* Add FN to the uninstall handler list. */
136
137 void
138 sim_module_add_uninstall_fn (SIM_DESC sd, MODULE_UNINSTALL_FN fn)
139 {
140 MODULE_UNINSTALL_LIST *l =
141 (MODULE_UNINSTALL_LIST *) xmalloc (sizeof (MODULE_UNINSTALL_LIST));
142
143 l->fn = fn;
144 l->next = STATE_UNINSTALL_LIST (sd);
145 STATE_UNINSTALL_LIST (sd) = l;
146 }