Commit | Line | Data |
---|---|---|
a35e91c3 AC |
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 | ||
247fccde | 22 | #include "sim-main.h" |
6dbaff8f | 23 | #include "sim-assert.h" |
247fccde | 24 | #include "bfd.h" |
a35e91c3 AC |
25 | |
26 | ||
27 | int current_host_byte_order; | |
28 | int current_target_byte_order; | |
29 | int current_stdio; | |
30 | ||
31 | #if defined (WITH_ENVIRONMENT) | |
32 | int current_environment; | |
33 | #endif | |
34 | ||
35 | #if defined (WITH_ALIGNMENT) | |
247fccde | 36 | enum sim_alignments current_alignment; |
a35e91c3 AC |
37 | #endif |
38 | ||
39 | #if defined (WITH_FLOATING_POINT) | |
40 | int current_floating_point; | |
41 | #endif | |
42 | ||
43 | ||
44 | ||
45 | /* map a byte order onto a textual string */ | |
46 | ||
47 | static const char * | |
48 | config_byte_order_to_a (int byte_order) | |
49 | { | |
50 | switch (byte_order) | |
51 | { | |
52 | case LITTLE_ENDIAN: | |
53 | return "LITTLE_ENDIAN"; | |
54 | case BIG_ENDIAN: | |
55 | return "BIG_ENDIAN"; | |
56 | case 0: | |
57 | return "0"; | |
58 | } | |
59 | return "UNKNOWN"; | |
60 | } | |
61 | ||
62 | ||
63 | static const char * | |
64 | config_stdio_to_a (int stdio) | |
65 | { | |
66 | switch (stdio) | |
67 | { | |
68 | case DONT_USE_STDIO: | |
69 | return "DONT_USE_STDIO"; | |
70 | case DO_USE_STDIO: | |
71 | return "DO_USE_STDIO"; | |
72 | case 0: | |
73 | return "0"; | |
74 | } | |
75 | return "UNKNOWN"; | |
76 | } | |
77 | ||
78 | ||
79 | #if defined (WITH_ENVIRONMENT) | |
80 | static const char * | |
81 | config_environment_to_a (int environment) | |
82 | { | |
83 | switch (environment) | |
84 | { | |
85 | case USER_ENVIRONMENT: | |
86 | return "USER_ENVIRONMENT"; | |
87 | case VIRTUAL_ENVIRONMENT: | |
88 | return "VIRTUAL_ENVIRONMENT"; | |
89 | case OPERATING_ENVIRONMENT: | |
90 | return "OPERATING_ENVIRONMENT"; | |
91 | case 0: | |
92 | return "0"; | |
93 | } | |
94 | return "UNKNOWN"; | |
95 | } | |
96 | #endif | |
97 | ||
98 | ||
a35e91c3 AC |
99 | static const char * |
100 | config_alignment_to_a (int alignment) | |
101 | { | |
102 | switch (alignment) | |
103 | { | |
247fccde AC |
104 | case MIXED_ALIGNMENT: |
105 | return "MIXED_ALIGNMENT"; | |
a35e91c3 AC |
106 | case NONSTRICT_ALIGNMENT: |
107 | return "NONSTRICT_ALIGNMENT"; | |
108 | case STRICT_ALIGNMENT: | |
109 | return "STRICT_ALIGNMENT"; | |
247fccde AC |
110 | case FORCED_ALIGNMENT: |
111 | return "FORCED_ALIGNMENT"; | |
a35e91c3 AC |
112 | } |
113 | return "UNKNOWN"; | |
114 | } | |
a35e91c3 AC |
115 | |
116 | ||
117 | #if defined (WITH_FLOATING_POINT) | |
118 | static const char * | |
119 | config_floating_point_to_a (int floating_point) | |
120 | { | |
121 | switch (floating_point) | |
122 | { | |
123 | case SOFT_FLOATING_POINT: | |
124 | return "SOFT_FLOATING_POINT"; | |
125 | case HARD_FLOATING_POINT: | |
126 | return "HARD_FLOATING_POINT"; | |
127 | case 0: | |
128 | return "0"; | |
129 | } | |
130 | return "UNKNOWN"; | |
131 | } | |
132 | #endif | |
133 | ||
134 | ||
247fccde | 135 | SIM_RC |
fafce69a | 136 | sim_config (SIM_DESC sd) |
a35e91c3 | 137 | { |
247fccde | 138 | int prefered_target_byte_order; |
6dbaff8f | 139 | SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); |
247fccde | 140 | |
247fccde | 141 | /* extract all relevant information */ |
fafce69a | 142 | if (STATE_PROG_BFD (sd) == NULL) |
247fccde AC |
143 | prefered_target_byte_order = 0; |
144 | else | |
fafce69a | 145 | prefered_target_byte_order = (bfd_little_endian(STATE_PROG_BFD (sd)) |
247fccde AC |
146 | ? LITTLE_ENDIAN |
147 | : BIG_ENDIAN); | |
a35e91c3 AC |
148 | |
149 | /* set the host byte order */ | |
150 | current_host_byte_order = 1; | |
151 | if (*(char*)(¤t_host_byte_order)) | |
152 | current_host_byte_order = LITTLE_ENDIAN; | |
153 | else | |
154 | current_host_byte_order = BIG_ENDIAN; | |
155 | ||
156 | /* verify the host byte order */ | |
157 | if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order) | |
247fccde AC |
158 | { |
159 | sim_io_eprintf (sd, "host (%s) and configured (%s) byte order in conflict", | |
160 | config_byte_order_to_a (current_host_byte_order), | |
161 | config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER)); | |
162 | return SIM_RC_FAIL; | |
163 | } | |
a35e91c3 AC |
164 | |
165 | ||
166 | /* set the target byte order */ | |
167 | #if (WITH_DEVICES) | |
168 | if (current_target_byte_order == 0) | |
169 | current_target_byte_order | |
247fccde | 170 | = (tree_find_boolean_property (root, "/options/little-endian?") |
a35e91c3 AC |
171 | ? LITTLE_ENDIAN |
172 | : BIG_ENDIAN); | |
173 | #endif | |
174 | if (current_target_byte_order == 0 | |
175 | && prefered_target_byte_order != 0) | |
176 | current_target_byte_order = prefered_target_byte_order; | |
177 | if (current_target_byte_order == 0) | |
178 | current_target_byte_order = WITH_TARGET_BYTE_ORDER; | |
247fccde AC |
179 | if (current_target_byte_order == 0) |
180 | current_target_byte_order = WITH_DEFAULT_TARGET_BYTE_ORDER; | |
a35e91c3 AC |
181 | |
182 | /* verify the target byte order */ | |
183 | if (CURRENT_TARGET_BYTE_ORDER == 0) | |
247fccde | 184 | { |
fafce69a | 185 | sim_io_eprintf (sd, "Target byte order unspecified\n"); |
247fccde AC |
186 | return SIM_RC_FAIL; |
187 | } | |
a35e91c3 | 188 | if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order) |
fafce69a | 189 | sim_io_eprintf (sd, "Target (%s) and configured (%s) byte order in conflict\n", |
a35e91c3 AC |
190 | config_byte_order_to_a (current_target_byte_order), |
191 | config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER)); | |
192 | if (prefered_target_byte_order != 0 | |
193 | && CURRENT_TARGET_BYTE_ORDER != prefered_target_byte_order) | |
fafce69a | 194 | sim_io_eprintf (sd, "Target (%s) and specified (%s) byte order in conflict\n", |
a35e91c3 AC |
195 | config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER), |
196 | config_byte_order_to_a (prefered_target_byte_order)); | |
197 | ||
198 | ||
199 | /* set the stdio */ | |
200 | if (current_stdio == 0) | |
201 | current_stdio = WITH_STDIO; | |
202 | if (current_stdio == 0) | |
203 | current_stdio = DO_USE_STDIO; | |
204 | ||
205 | /* verify the stdio */ | |
206 | if (CURRENT_STDIO == 0) | |
247fccde | 207 | { |
fafce69a | 208 | sim_io_eprintf (sd, "Target standard IO unspecified\n"); |
247fccde AC |
209 | return SIM_RC_FAIL; |
210 | } | |
a35e91c3 | 211 | if (CURRENT_STDIO != current_stdio) |
247fccde | 212 | { |
fafce69a | 213 | sim_io_eprintf (sd, "Target (%s) and configured (%s) standard IO in conflict\n", |
247fccde AC |
214 | config_stdio_to_a (CURRENT_STDIO), |
215 | config_stdio_to_a (current_stdio)); | |
216 | return SIM_RC_FAIL; | |
217 | } | |
218 | ||
219 | ||
220 | /* check the value of MSB */ | |
221 | if (WITH_TARGET_WORD_MSB != 0 | |
222 | && WITH_TARGET_WORD_MSB != (WITH_TARGET_WORD_BITSIZE - 1)) | |
223 | { | |
fafce69a | 224 | sim_io_eprintf (sd, "Target bitsize (%d) contradicts target most significant bit (%d)\n", |
247fccde AC |
225 | WITH_TARGET_WORD_BITSIZE, WITH_TARGET_WORD_MSB); |
226 | return SIM_RC_FAIL; | |
227 | } | |
228 | ||
229 | ||
a35e91c3 | 230 | #if defined (WITH_ENVIRONMENT) |
247fccde | 231 | |
a35e91c3 AC |
232 | /* set the environment */ |
233 | #if (WITH_DEVICES) | |
234 | if (current_environment == 0) | |
235 | { | |
236 | const char *env = | |
237 | tree_find_string_property(root, "/openprom/options/env"); | |
238 | current_environment = ((strcmp(env, "user") == 0 | |
239 | || strcmp(env, "uea") == 0) | |
240 | ? USER_ENVIRONMENT | |
241 | : (strcmp(env, "virtual") == 0 | |
242 | || strcmp(env, "vea") == 0) | |
243 | ? VIRTUAL_ENVIRONMENT | |
244 | : (strcmp(env, "operating") == 0 | |
245 | || strcmp(env, "oea") == 0) | |
246 | ? OPERATING_ENVIRONMENT | |
247 | : 0); | |
248 | } | |
249 | #endif | |
250 | if (current_environment == 0) | |
251 | current_environment = WITH_ENVIRONMENT; | |
247fccde | 252 | |
a35e91c3 AC |
253 | /* verify the environment */ |
254 | if (CURRENT_ENVIRONMENT == 0) | |
247fccde | 255 | { |
fafce69a | 256 | sim_io_eprintf (sd, "Target environment unspecified\n"); |
247fccde AC |
257 | return SIM_RC_FAIL; |
258 | } | |
a35e91c3 | 259 | if (CURRENT_ENVIRONMENT != current_environment) |
247fccde | 260 | { |
fafce69a | 261 | sim_io_eprintf (sd, "Target (%s) and configured (%s) environment in conflict\n", |
247fccde AC |
262 | config_environment_to_a (CURRENT_ENVIRONMENT), |
263 | config_environment_to_a (current_environment)); | |
264 | return SIM_RC_FAIL; | |
265 | } | |
a35e91c3 | 266 | #endif |
247fccde AC |
267 | |
268 | ||
a35e91c3 | 269 | #if defined (WITH_ALIGNMENT) |
247fccde | 270 | |
a35e91c3 AC |
271 | /* set the alignment */ |
272 | #if defined (WITH_DEVICES) | |
273 | if (current_alignment == 0) | |
274 | current_alignment = | |
275 | (tree_find_boolean_property(root, "/openprom/options/strict-alignment?") | |
276 | ? STRICT_ALIGNMENT | |
277 | : NONSTRICT_ALIGNMENT); | |
278 | #endif | |
279 | if (current_alignment == 0) | |
280 | current_alignment = WITH_ALIGNMENT; | |
247fccde | 281 | |
a35e91c3 AC |
282 | /* verify the alignment */ |
283 | if (CURRENT_ALIGNMENT == 0) | |
247fccde | 284 | { |
fafce69a | 285 | sim_io_eprintf (sd, "Target alignment unspecified\n"); |
247fccde AC |
286 | return SIM_RC_FAIL; |
287 | } | |
a35e91c3 | 288 | if (CURRENT_ALIGNMENT != current_alignment) |
247fccde | 289 | { |
fafce69a | 290 | sim_io_eprintf (sd, "Target (%s) and configured (%s) alignment in conflict\n", |
247fccde AC |
291 | config_alignment_to_a (CURRENT_ALIGNMENT), |
292 | config_alignment_to_a (current_alignment)); | |
293 | return SIM_RC_FAIL; | |
294 | } | |
a35e91c3 | 295 | #endif |
247fccde AC |
296 | |
297 | ||
a35e91c3 | 298 | #if defined (WITH_FLOAING_POINT) |
247fccde | 299 | |
a35e91c3 AC |
300 | /* set the floating point */ |
301 | if (current_floating_point == 0) | |
302 | current_floating_point = WITH_FLOATING_POINT; | |
247fccde | 303 | |
a35e91c3 AC |
304 | /* verify the floating point */ |
305 | if (CURRENT_FLOATING_POINT == 0) | |
247fccde | 306 | { |
fafce69a | 307 | sim_io_eprintf (sd, "Target floating-point unspecified\n"); |
247fccde AC |
308 | return SIM_RC_FAIL; |
309 | } | |
a35e91c3 | 310 | if (CURRENT_FLOATING_POINT != current_floating_point) |
247fccde | 311 | { |
fafce69a | 312 | sim_io_eprintf (sd, "Target (%s) and configured (%s) floating-point in conflict\n", |
247fccde AC |
313 | config_alignment_to_a (CURRENT_FLOATING_POINT), |
314 | config_alignment_to_a (current_floating_point)); | |
315 | return SIM_RC_FAIL; | |
316 | } | |
317 | ||
a35e91c3 | 318 | #endif |
247fccde | 319 | return SIM_RC_OK; |
a35e91c3 AC |
320 | } |
321 | ||
322 | ||
323 | void | |
324 | print_sim_config (SIM_DESC sd) | |
325 | { | |
326 | #if defined (__GNUC__) && defined (__VERSION__) | |
327 | sim_io_printf (sd, "Compiled by GCC %s on %s %s\n", | |
328 | __VERSION__, __DATE__, __TIME__); | |
329 | #else | |
330 | sim_io_printf (sd, "Compiled on %s %s\n", __DATE__, __TIME__); | |
331 | #endif | |
332 | ||
247fccde | 333 | sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n", |
a35e91c3 AC |
334 | config_byte_order_to_a (WITH_TARGET_BYTE_ORDER)); |
335 | ||
247fccde AC |
336 | sim_io_printf (sd, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n", |
337 | config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER)); | |
338 | ||
339 | sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n", | |
a35e91c3 AC |
340 | config_byte_order_to_a (WITH_HOST_BYTE_ORDER)); |
341 | ||
247fccde | 342 | sim_io_printf (sd, "WITH_STDIO = %s\n", |
a35e91c3 AC |
343 | config_stdio_to_a (WITH_STDIO)); |
344 | ||
247fccde AC |
345 | sim_io_printf (sd, "WITH_TARGET_WORD_BITSIZE = %d\n", |
346 | WITH_TARGET_WORD_BITSIZE); | |
347 | ||
348 | sim_io_printf (sd, "WITH_TARGET_WORD_MSB = %d\n", | |
349 | WITH_TARGET_WORD_MSB); | |
350 | ||
a35e91c3 AC |
351 | #if defined (WITH_XOR_ENDIAN) |
352 | sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN); | |
353 | #endif | |
354 | ||
355 | #if defined (WITH_ENVIRONMENT) | |
356 | sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n", | |
357 | config_environment_to_a (WITH_ENVIRONMENT)); | |
358 | #endif | |
359 | ||
360 | #if defined (WITH_ALIGNMENT) | |
361 | sim_io_printf (sd, "WITH_ALIGNMENT = %s\n", | |
362 | config_alignment_to_a (WITH_ALIGNMENT)); | |
363 | #endif | |
364 | ||
365 | #if defined (WITH_FLOATING_POINT) | |
366 | sim_io_printf (sd, "WITH_FLOATING_POINT = %s\n", | |
367 | config_floating_point_to_a (WITH_FLOATING_POINT)); | |
368 | #endif | |
369 | ||
370 | #if defined (WITH_SMP) | |
371 | sim_io_printf (sd, "WITH_SMP = %d\n", WITH_SMP); | |
372 | #endif | |
373 | ||
374 | #if defined (WITH_RESERVED_BITS) | |
375 | sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS); | |
376 | #endif | |
377 | ||
378 | } |