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