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