]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-config.c
Add ABFD argument to sim_create_inferior. Document.
[thirdparty/binutils-gdb.git] / sim / common / sim-config.c
CommitLineData
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
AC
22#include "sim-main.h"
23#include "bfd.h"
a35e91c3
AC
24
25
26int current_host_byte_order;
27int current_target_byte_order;
28int current_stdio;
29
30#if defined (WITH_ENVIRONMENT)
31int current_environment;
32#endif
33
34#if defined (WITH_ALIGNMENT)
247fccde 35enum sim_alignments current_alignment;
a35e91c3
AC
36#endif
37
38#if defined (WITH_FLOATING_POINT)
39int current_floating_point;
40#endif
41
42
43
44/* map a byte order onto a textual string */
45
46static const char *
47config_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
62static const char *
63config_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)
79static const char *
80config_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
a35e91c3
AC
98static const char *
99config_alignment_to_a (int alignment)
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)
117static const char *
118config_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 134SIM_RC
fafce69a 135sim_config (SIM_DESC sd)
a35e91c3 136{
247fccde
AC
137 int prefered_target_byte_order;
138
247fccde 139 /* extract all relevant information */
fafce69a 140 if (STATE_PROG_BFD (sd) == NULL)
247fccde
AC
141 prefered_target_byte_order = 0;
142 else
fafce69a 143 prefered_target_byte_order = (bfd_little_endian(STATE_PROG_BFD (sd))
247fccde
AC
144 ? LITTLE_ENDIAN
145 : BIG_ENDIAN);
a35e91c3
AC
146
147 /* set the host byte order */
148 current_host_byte_order = 1;
149 if (*(char*)(&current_host_byte_order))
150 current_host_byte_order = LITTLE_ENDIAN;
151 else
152 current_host_byte_order = BIG_ENDIAN;
153
154 /* verify the host byte order */
155 if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order)
247fccde
AC
156 {
157 sim_io_eprintf (sd, "host (%s) and configured (%s) byte order in conflict",
158 config_byte_order_to_a (current_host_byte_order),
159 config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER));
160 return SIM_RC_FAIL;
161 }
a35e91c3
AC
162
163
164 /* set the target byte order */
165#if (WITH_DEVICES)
166 if (current_target_byte_order == 0)
167 current_target_byte_order
247fccde 168 = (tree_find_boolean_property (root, "/options/little-endian?")
a35e91c3
AC
169 ? LITTLE_ENDIAN
170 : BIG_ENDIAN);
171#endif
172 if (current_target_byte_order == 0
173 && prefered_target_byte_order != 0)
174 current_target_byte_order = prefered_target_byte_order;
175 if (current_target_byte_order == 0)
176 current_target_byte_order = WITH_TARGET_BYTE_ORDER;
247fccde
AC
177 if (current_target_byte_order == 0)
178 current_target_byte_order = WITH_DEFAULT_TARGET_BYTE_ORDER;
a35e91c3
AC
179
180 /* verify the target byte order */
181 if (CURRENT_TARGET_BYTE_ORDER == 0)
247fccde 182 {
fafce69a 183 sim_io_eprintf (sd, "Target byte order unspecified\n");
247fccde
AC
184 return SIM_RC_FAIL;
185 }
a35e91c3 186 if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order)
fafce69a 187 sim_io_eprintf (sd, "Target (%s) and configured (%s) byte order in conflict\n",
a35e91c3
AC
188 config_byte_order_to_a (current_target_byte_order),
189 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER));
190 if (prefered_target_byte_order != 0
191 && CURRENT_TARGET_BYTE_ORDER != prefered_target_byte_order)
fafce69a 192 sim_io_eprintf (sd, "Target (%s) and specified (%s) byte order in conflict\n",
a35e91c3
AC
193 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER),
194 config_byte_order_to_a (prefered_target_byte_order));
195
196
197 /* set the stdio */
198 if (current_stdio == 0)
199 current_stdio = WITH_STDIO;
200 if (current_stdio == 0)
201 current_stdio = DO_USE_STDIO;
202
203 /* verify the stdio */
204 if (CURRENT_STDIO == 0)
247fccde 205 {
fafce69a 206 sim_io_eprintf (sd, "Target standard IO unspecified\n");
247fccde
AC
207 return SIM_RC_FAIL;
208 }
a35e91c3 209 if (CURRENT_STDIO != current_stdio)
247fccde 210 {
fafce69a 211 sim_io_eprintf (sd, "Target (%s) and configured (%s) standard IO in conflict\n",
247fccde
AC
212 config_stdio_to_a (CURRENT_STDIO),
213 config_stdio_to_a (current_stdio));
214 return SIM_RC_FAIL;
215 }
216
217
218 /* check the value of MSB */
219 if (WITH_TARGET_WORD_MSB != 0
220 && WITH_TARGET_WORD_MSB != (WITH_TARGET_WORD_BITSIZE - 1))
221 {
fafce69a 222 sim_io_eprintf (sd, "Target bitsize (%d) contradicts target most significant bit (%d)\n",
247fccde
AC
223 WITH_TARGET_WORD_BITSIZE, WITH_TARGET_WORD_MSB);
224 return SIM_RC_FAIL;
225 }
226
227
a35e91c3 228#if defined (WITH_ENVIRONMENT)
247fccde 229
a35e91c3
AC
230 /* set the environment */
231#if (WITH_DEVICES)
232 if (current_environment == 0)
233 {
234 const char *env =
235 tree_find_string_property(root, "/openprom/options/env");
236 current_environment = ((strcmp(env, "user") == 0
237 || strcmp(env, "uea") == 0)
238 ? USER_ENVIRONMENT
239 : (strcmp(env, "virtual") == 0
240 || strcmp(env, "vea") == 0)
241 ? VIRTUAL_ENVIRONMENT
242 : (strcmp(env, "operating") == 0
243 || strcmp(env, "oea") == 0)
244 ? OPERATING_ENVIRONMENT
245 : 0);
246 }
247#endif
248 if (current_environment == 0)
249 current_environment = WITH_ENVIRONMENT;
247fccde 250
a35e91c3
AC
251 /* verify the environment */
252 if (CURRENT_ENVIRONMENT == 0)
247fccde 253 {
fafce69a 254 sim_io_eprintf (sd, "Target environment unspecified\n");
247fccde
AC
255 return SIM_RC_FAIL;
256 }
a35e91c3 257 if (CURRENT_ENVIRONMENT != current_environment)
247fccde 258 {
fafce69a 259 sim_io_eprintf (sd, "Target (%s) and configured (%s) environment in conflict\n",
247fccde
AC
260 config_environment_to_a (CURRENT_ENVIRONMENT),
261 config_environment_to_a (current_environment));
262 return SIM_RC_FAIL;
263 }
a35e91c3 264#endif
247fccde
AC
265
266
a35e91c3 267#if defined (WITH_ALIGNMENT)
247fccde 268
a35e91c3
AC
269 /* set the alignment */
270#if defined (WITH_DEVICES)
271 if (current_alignment == 0)
272 current_alignment =
273 (tree_find_boolean_property(root, "/openprom/options/strict-alignment?")
274 ? STRICT_ALIGNMENT
275 : NONSTRICT_ALIGNMENT);
276#endif
277 if (current_alignment == 0)
278 current_alignment = WITH_ALIGNMENT;
247fccde 279
a35e91c3
AC
280 /* verify the alignment */
281 if (CURRENT_ALIGNMENT == 0)
247fccde 282 {
fafce69a 283 sim_io_eprintf (sd, "Target alignment unspecified\n");
247fccde
AC
284 return SIM_RC_FAIL;
285 }
a35e91c3 286 if (CURRENT_ALIGNMENT != current_alignment)
247fccde 287 {
fafce69a 288 sim_io_eprintf (sd, "Target (%s) and configured (%s) alignment in conflict\n",
247fccde
AC
289 config_alignment_to_a (CURRENT_ALIGNMENT),
290 config_alignment_to_a (current_alignment));
291 return SIM_RC_FAIL;
292 }
a35e91c3 293#endif
247fccde
AC
294
295
a35e91c3 296#if defined (WITH_FLOAING_POINT)
247fccde 297
a35e91c3
AC
298 /* set the floating point */
299 if (current_floating_point == 0)
300 current_floating_point = WITH_FLOATING_POINT;
247fccde 301
a35e91c3
AC
302 /* verify the floating point */
303 if (CURRENT_FLOATING_POINT == 0)
247fccde 304 {
fafce69a 305 sim_io_eprintf (sd, "Target floating-point unspecified\n");
247fccde
AC
306 return SIM_RC_FAIL;
307 }
a35e91c3 308 if (CURRENT_FLOATING_POINT != current_floating_point)
247fccde 309 {
fafce69a 310 sim_io_eprintf (sd, "Target (%s) and configured (%s) floating-point in conflict\n",
247fccde
AC
311 config_alignment_to_a (CURRENT_FLOATING_POINT),
312 config_alignment_to_a (current_floating_point));
313 return SIM_RC_FAIL;
314 }
315
a35e91c3 316#endif
247fccde 317 return SIM_RC_OK;
a35e91c3
AC
318}
319
320
321void
322print_sim_config (SIM_DESC sd)
323{
324#if defined (__GNUC__) && defined (__VERSION__)
325 sim_io_printf (sd, "Compiled by GCC %s on %s %s\n",
326 __VERSION__, __DATE__, __TIME__);
327#else
328 sim_io_printf (sd, "Compiled on %s %s\n", __DATE__, __TIME__);
329#endif
330
247fccde 331 sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n",
a35e91c3
AC
332 config_byte_order_to_a (WITH_TARGET_BYTE_ORDER));
333
247fccde
AC
334 sim_io_printf (sd, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n",
335 config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER));
336
337 sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n",
a35e91c3
AC
338 config_byte_order_to_a (WITH_HOST_BYTE_ORDER));
339
247fccde 340 sim_io_printf (sd, "WITH_STDIO = %s\n",
a35e91c3
AC
341 config_stdio_to_a (WITH_STDIO));
342
247fccde
AC
343 sim_io_printf (sd, "WITH_TARGET_WORD_BITSIZE = %d\n",
344 WITH_TARGET_WORD_BITSIZE);
345
346 sim_io_printf (sd, "WITH_TARGET_WORD_MSB = %d\n",
347 WITH_TARGET_WORD_MSB);
348
a35e91c3
AC
349#if defined (WITH_XOR_ENDIAN)
350 sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN);
351#endif
352
353#if defined (WITH_ENVIRONMENT)
354 sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n",
355 config_environment_to_a (WITH_ENVIRONMENT));
356#endif
357
358#if defined (WITH_ALIGNMENT)
359 sim_io_printf (sd, "WITH_ALIGNMENT = %s\n",
360 config_alignment_to_a (WITH_ALIGNMENT));
361#endif
362
363#if defined (WITH_FLOATING_POINT)
364 sim_io_printf (sd, "WITH_FLOATING_POINT = %s\n",
365 config_floating_point_to_a (WITH_FLOATING_POINT));
366#endif
367
368#if defined (WITH_SMP)
369 sim_io_printf (sd, "WITH_SMP = %d\n", WITH_SMP);
370#endif
371
372#if defined (WITH_RESERVED_BITS)
373 sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS);
374#endif
375
376}