New file common/sim-config.c sets/checks simulator configuration options.
[binutils-gdb.git] / sim / common / sim-config.c
1 /* This file is part of the GNU simulators.
2
3 Copyright (C) 1994-1995,1997, Andrew Cagney <cagney@highland.com.au>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 */
20
21
22 #include "sim-state.h"
23
24
25 int current_host_byte_order;
26 int current_target_byte_order;
27 int current_stdio;
28
29 #if defined (WITH_ENVIRONMENT)
30 int current_environment;
31 #endif
32
33 #if defined (WITH_ALIGNMENT)
34 int current_alignment;
35 #endif
36
37 #if defined (WITH_FLOATING_POINT)
38 int current_floating_point;
39 #endif
40
41
42
43 /* map a byte order onto a textual string */
44
45 static const char *
46 config_byte_order_to_a (int byte_order)
47 {
48 switch (byte_order)
49 {
50 case LITTLE_ENDIAN:
51 return "LITTLE_ENDIAN";
52 case BIG_ENDIAN:
53 return "BIG_ENDIAN";
54 case 0:
55 return "0";
56 }
57 return "UNKNOWN";
58 }
59
60
61 static const char *
62 config_stdio_to_a (int stdio)
63 {
64 switch (stdio)
65 {
66 case DONT_USE_STDIO:
67 return "DONT_USE_STDIO";
68 case DO_USE_STDIO:
69 return "DO_USE_STDIO";
70 case 0:
71 return "0";
72 }
73 return "UNKNOWN";
74 }
75
76
77 #if defined (WITH_ENVIRONMENT)
78 static const char *
79 config_environment_to_a (int environment)
80 {
81 switch (environment)
82 {
83 case USER_ENVIRONMENT:
84 return "USER_ENVIRONMENT";
85 case VIRTUAL_ENVIRONMENT:
86 return "VIRTUAL_ENVIRONMENT";
87 case OPERATING_ENVIRONMENT:
88 return "OPERATING_ENVIRONMENT";
89 case 0:
90 return "0";
91 }
92 return "UNKNOWN";
93 }
94 #endif
95
96
97 #if defined (WITH_ALIGNMENT)
98 static const char *
99 config_alignment_to_a (int alignment)
100 {
101 switch (alignment)
102 {
103 case NONSTRICT_ALIGNMENT:
104 return "NONSTRICT_ALIGNMENT";
105 case STRICT_ALIGNMENT:
106 return "STRICT_ALIGNMENT";
107 case 0:
108 return "0";
109 }
110 return "UNKNOWN";
111 }
112 #endif
113
114
115 #if defined (WITH_FLOATING_POINT)
116 static const char *
117 config_floating_point_to_a (int floating_point)
118 {
119 switch (floating_point)
120 {
121 case SOFT_FLOATING_POINT:
122 return "SOFT_FLOATING_POINT";
123 case HARD_FLOATING_POINT:
124 return "HARD_FLOATING_POINT";
125 case 0:
126 return "0";
127 }
128 return "UNKNOWN";
129 }
130 #endif
131
132
133 void
134 sim_config (SIM_DESC sd,
135 int prefered_target_byte_order)
136 {
137
138 /* set the host byte order */
139 current_host_byte_order = 1;
140 if (*(char*)(&current_host_byte_order))
141 current_host_byte_order = LITTLE_ENDIAN;
142 else
143 current_host_byte_order = BIG_ENDIAN;
144
145 /* verify the host byte order */
146 if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order)
147 sim_io_error (sd, "host (%s) and configured (%s) byte order in conflict",
148 config_byte_order_to_a (current_host_byte_order),
149 config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER));
150
151
152 /* set the target byte order */
153 #if (WITH_DEVICES)
154 if (current_target_byte_order == 0)
155 current_target_byte_order
156 = (tree_find_boolean_property(root, "/options/little-endian?")
157 ? LITTLE_ENDIAN
158 : BIG_ENDIAN);
159 #endif
160 if (current_target_byte_order == 0
161 && prefered_target_byte_order != 0)
162 current_target_byte_order = prefered_target_byte_order;
163 if (current_target_byte_order == 0)
164 current_target_byte_order = WITH_TARGET_BYTE_ORDER;
165
166 /* verify the target byte order */
167 if (CURRENT_TARGET_BYTE_ORDER == 0)
168 sim_io_error (sd, "target byte order unspecified");
169 if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order)
170 sim_io_error (sd, "target (%s) and configured (%s) byte order in conflict",
171 config_byte_order_to_a (current_target_byte_order),
172 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER));
173 if (prefered_target_byte_order != 0
174 && CURRENT_TARGET_BYTE_ORDER != prefered_target_byte_order)
175 sim_io_error (sd, "target (%s) and specified (%s) byte order in conflict",
176 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER),
177 config_byte_order_to_a (prefered_target_byte_order));
178
179
180 /* set the stdio */
181 if (current_stdio == 0)
182 current_stdio = WITH_STDIO;
183 if (current_stdio == 0)
184 current_stdio = DO_USE_STDIO;
185
186 /* verify the stdio */
187 if (CURRENT_STDIO == 0)
188 sim_io_error (sd, "target standard IO unspecified");
189 if (CURRENT_STDIO != current_stdio)
190 sim_io_error (sd, "target (%s) and configured (%s) standard IO in conflict",
191 config_stdio_to_a (CURRENT_STDIO),
192 config_stdio_to_a (current_stdio));
193
194
195 #if defined (WITH_ENVIRONMENT)
196
197 /* set the environment */
198 #if (WITH_DEVICES)
199 if (current_environment == 0)
200 {
201 const char *env =
202 tree_find_string_property(root, "/openprom/options/env");
203 current_environment = ((strcmp(env, "user") == 0
204 || strcmp(env, "uea") == 0)
205 ? USER_ENVIRONMENT
206 : (strcmp(env, "virtual") == 0
207 || strcmp(env, "vea") == 0)
208 ? VIRTUAL_ENVIRONMENT
209 : (strcmp(env, "operating") == 0
210 || strcmp(env, "oea") == 0)
211 ? OPERATING_ENVIRONMENT
212 : 0);
213 }
214 #endif
215 if (current_environment == 0)
216 current_environment = WITH_ENVIRONMENT;
217
218 /* verify the environment */
219 if (CURRENT_ENVIRONMENT == 0)
220 sim_io_error (sd, "target environment unspecified");
221 if (CURRENT_ENVIRONMENT != current_environment)
222 sim_io_error (sd, "target (%s) and configured (%s) environment in conflict",
223 config_environment_to_a (CURRENT_ENVIRONMENT),
224 config_environment_to_a (current_environment));
225 #endif
226
227
228 #if defined (WITH_ALIGNMENT)
229
230 /* set the alignment */
231 #if defined (WITH_DEVICES)
232 if (current_alignment == 0)
233 current_alignment =
234 (tree_find_boolean_property(root, "/openprom/options/strict-alignment?")
235 ? STRICT_ALIGNMENT
236 : NONSTRICT_ALIGNMENT);
237 #endif
238 if (current_alignment == 0)
239 current_alignment = WITH_ALIGNMENT;
240
241 /* verify the alignment */
242 if (CURRENT_ALIGNMENT == 0)
243 sim_io_error (sd, "target alignment unspecified");
244 if (CURRENT_ALIGNMENT != current_alignment)
245 sim_io_error (sd, "target (%s) and configured (%s) alignment in conflict",
246 config_alignment_to_a (CURRENT_ALIGNMENT),
247 config_alignment_to_a (current_alignment));
248 #endif
249
250
251 #if defined (WITH_FLOAING_POINT)
252
253 /* set the floating point */
254 if (current_floating_point == 0)
255 current_floating_point = WITH_FLOATING_POINT;
256
257 /* verify the floating point */
258 if (CURRENT_FLOATING_POINT == 0)
259 sim_io_error (sd, "target floating-point unspecified");
260 if (CURRENT_FLOATING_POINT != current_floating_point)
261 sim_io_error (sd, "target (%s) and configured (%s) floating-point in conflict",
262 config_alignment_to_a (CURRENT_FLOATING_POINT),
263 config_alignment_to_a (current_floating_point));
264
265 #endif
266
267
268 }
269
270
271 void
272 print_sim_config (SIM_DESC sd)
273 {
274 #if defined (__GNUC__) && defined (__VERSION__)
275 sim_io_printf (sd, "Compiled by GCC %s on %s %s\n",
276 __VERSION__, __DATE__, __TIME__);
277 #else
278 sim_io_printf (sd, "Compiled on %s %s\n", __DATE__, __TIME__);
279 #endif
280
281 sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n",
282 config_byte_order_to_a (WITH_TARGET_BYTE_ORDER));
283
284 sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n",
285 config_byte_order_to_a (WITH_HOST_BYTE_ORDER));
286
287 sim_io_printf (sd, "WITH_STDIO = %s\n",
288 config_stdio_to_a (WITH_STDIO));
289
290 #if defined (WITH_XOR_ENDIAN)
291 sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN);
292 #endif
293
294 #if defined (WITH_ENVIRONMENT)
295 sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n",
296 config_environment_to_a (WITH_ENVIRONMENT));
297 #endif
298
299 #if defined (WITH_ALIGNMENT)
300 sim_io_printf (sd, "WITH_ALIGNMENT = %s\n",
301 config_alignment_to_a (WITH_ALIGNMENT));
302 #endif
303
304 #if defined (WITH_FLOATING_POINT)
305 sim_io_printf (sd, "WITH_FLOATING_POINT = %s\n",
306 config_floating_point_to_a (WITH_FLOATING_POINT));
307 #endif
308
309 #if defined (WITH_SMP)
310 sim_io_printf (sd, "WITH_SMP = %d\n", WITH_SMP);
311 #endif
312
313 #if defined (WITH_RESERVED_BITS)
314 sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS);
315 #endif
316
317 }