1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002-2014 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "sim-assert.h"
28 int current_host_byte_order;
29 int current_target_byte_order;
32 enum sim_alignments current_alignment;
34 #if defined (WITH_FLOATING_POINT)
35 int current_floating_point;
40 /* map a byte order onto a textual string */
43 config_byte_order_to_a (int byte_order)
48 return "LITTLE_ENDIAN";
59 config_stdio_to_a (int stdio)
64 return "DONT_USE_STDIO";
66 return "DO_USE_STDIO";
75 config_environment_to_a (enum sim_environment environment)
80 return "ALL_ENVIRONMENT";
81 case USER_ENVIRONMENT:
82 return "USER_ENVIRONMENT";
83 case VIRTUAL_ENVIRONMENT:
84 return "VIRTUAL_ENVIRONMENT";
85 case OPERATING_ENVIRONMENT:
86 return "OPERATING_ENVIRONMENT";
93 config_alignment_to_a (enum sim_alignments alignment)
98 return "MIXED_ALIGNMENT";
99 case NONSTRICT_ALIGNMENT:
100 return "NONSTRICT_ALIGNMENT";
101 case STRICT_ALIGNMENT:
102 return "STRICT_ALIGNMENT";
103 case FORCED_ALIGNMENT:
104 return "FORCED_ALIGNMENT";
110 #if defined (WITH_FLOATING_POINT)
112 config_floating_point_to_a (int floating_point)
114 switch (floating_point)
116 case SOFT_FLOATING_POINT:
117 return "SOFT_FLOATING_POINT";
118 case HARD_FLOATING_POINT:
119 return "HARD_FLOATING_POINT";
127 /* Set the default environment, prior to parsing argv. */
130 sim_config_default (SIM_DESC sd)
132 /* Set the current environment to ALL_ENVIRONMENT to indicate none has been
133 selected yet. This is so that after parsing argv, we know whether the
134 environment was explicitly specified or not. */
135 STATE_ENVIRONMENT (sd) = ALL_ENVIRONMENT;
138 /* Complete and verify the simulation environment. */
141 sim_config (SIM_DESC sd)
143 int prefered_target_byte_order;
144 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
146 /* extract all relevant information */
147 if (STATE_PROG_BFD (sd) == NULL
148 /* If we have a binary input file (presumably with specified
149 "--architecture"), it'll have no endianness. */
150 || (!bfd_little_endian (STATE_PROG_BFD (sd))
151 && !bfd_big_endian (STATE_PROG_BFD (sd))))
152 prefered_target_byte_order = 0;
154 prefered_target_byte_order = (bfd_little_endian (STATE_PROG_BFD (sd))
158 /* set the host byte order */
159 current_host_byte_order = 1;
160 if (*(char*)(¤t_host_byte_order))
161 current_host_byte_order = LITTLE_ENDIAN;
163 current_host_byte_order = BIG_ENDIAN;
165 /* verify the host byte order */
166 if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order)
168 sim_io_eprintf (sd, "host (%s) and configured (%s) byte order in conflict",
169 config_byte_order_to_a (current_host_byte_order),
170 config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER));
175 /* set the target byte order */
176 #if (WITH_TREE_PROPERTIES)
177 if (current_target_byte_order == 0)
178 current_target_byte_order
179 = (tree_find_boolean_property (root, "/options/little-endian?")
183 if (current_target_byte_order == 0
184 && prefered_target_byte_order != 0)
185 current_target_byte_order = prefered_target_byte_order;
186 if (current_target_byte_order == 0)
187 current_target_byte_order = WITH_TARGET_BYTE_ORDER;
188 if (current_target_byte_order == 0)
189 current_target_byte_order = WITH_DEFAULT_TARGET_BYTE_ORDER;
191 /* verify the target byte order */
192 if (CURRENT_TARGET_BYTE_ORDER == 0)
194 sim_io_eprintf (sd, "Target byte order unspecified\n");
197 if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order)
198 sim_io_eprintf (sd, "Target (%s) and configured (%s) byte order in conflict\n",
199 config_byte_order_to_a (current_target_byte_order),
200 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER));
201 if (prefered_target_byte_order != 0
202 && CURRENT_TARGET_BYTE_ORDER != prefered_target_byte_order)
203 sim_io_eprintf (sd, "Target (%s) and specified (%s) byte order in conflict\n",
204 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER),
205 config_byte_order_to_a (prefered_target_byte_order));
209 if (current_stdio == 0)
210 current_stdio = WITH_STDIO;
211 if (current_stdio == 0)
212 current_stdio = DO_USE_STDIO;
214 /* verify the stdio */
215 if (CURRENT_STDIO == 0)
217 sim_io_eprintf (sd, "Target standard IO unspecified\n");
220 if (CURRENT_STDIO != current_stdio)
222 sim_io_eprintf (sd, "Target (%s) and configured (%s) standard IO in conflict\n",
223 config_stdio_to_a (CURRENT_STDIO),
224 config_stdio_to_a (current_stdio));
229 /* check the value of MSB */
230 if (WITH_TARGET_WORD_MSB != 0
231 && WITH_TARGET_WORD_MSB != (WITH_TARGET_WORD_BITSIZE - 1))
233 sim_io_eprintf (sd, "Target bitsize (%d) contradicts target most significant bit (%d)\n",
234 WITH_TARGET_WORD_BITSIZE, WITH_TARGET_WORD_MSB);
239 /* set the environment */
240 #if (WITH_TREE_PROPERTIES)
241 if (STATE_ENVIRONMENT (sd) == ALL_ENVIRONMENT)
244 tree_find_string_property (root, "/openprom/options/env");
245 STATE_ENVIRONMENT (sd) = ((strcmp (env, "user") == 0
246 || strcmp (env, "uea") == 0)
248 : (strcmp (env, "virtual") == 0
249 || strcmp (env, "vea") == 0)
250 ? VIRTUAL_ENVIRONMENT
251 : (strcmp (env, "operating") == 0
252 || strcmp (env, "oea") == 0)
253 ? OPERATING_ENVIRONMENT
257 if (STATE_ENVIRONMENT (sd) == ALL_ENVIRONMENT)
258 STATE_ENVIRONMENT (sd) = DEFAULT_ENVIRONMENT;
261 /* set the alignment */
262 #if (WITH_TREE_PROPERTIES)
263 if (current_alignment == 0)
265 (tree_find_boolean_property (root, "/openprom/options/strict-alignment?")
267 : NONSTRICT_ALIGNMENT);
269 if (current_alignment == 0)
270 current_alignment = WITH_ALIGNMENT;
271 if (current_alignment == 0)
272 current_alignment = WITH_DEFAULT_ALIGNMENT;
274 /* verify the alignment */
275 if (CURRENT_ALIGNMENT == 0)
277 sim_io_eprintf (sd, "Target alignment unspecified\n");
280 if (CURRENT_ALIGNMENT != current_alignment)
282 sim_io_eprintf (sd, "Target (%s) and configured (%s) alignment in conflict\n",
283 config_alignment_to_a (CURRENT_ALIGNMENT),
284 config_alignment_to_a (current_alignment));
288 #if defined (WITH_FLOATING_POINT)
290 /* set the floating point */
291 if (current_floating_point == 0)
292 current_floating_point = WITH_FLOATING_POINT;
294 /* verify the floating point */
295 if (CURRENT_FLOATING_POINT == 0)
297 sim_io_eprintf (sd, "Target floating-point unspecified\n");
300 if (CURRENT_FLOATING_POINT != current_floating_point)
302 sim_io_eprintf (sd, "Target (%s) and configured (%s) floating-point in conflict\n",
303 config_alignment_to_a (CURRENT_FLOATING_POINT),
304 config_alignment_to_a (current_floating_point));
314 print_sim_config (SIM_DESC sd)
316 #if defined (__GNUC__) && defined (__VERSION__)
317 sim_io_printf (sd, "Compiled by GCC %s on %s %s\n",
318 __VERSION__, __DATE__, __TIME__);
320 sim_io_printf (sd, "Compiled on %s %s\n", __DATE__, __TIME__);
323 sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n",
324 config_byte_order_to_a (WITH_TARGET_BYTE_ORDER));
326 sim_io_printf (sd, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n",
327 config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER));
329 sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n",
330 config_byte_order_to_a (WITH_HOST_BYTE_ORDER));
332 sim_io_printf (sd, "WITH_STDIO = %s\n",
333 config_stdio_to_a (WITH_STDIO));
335 sim_io_printf (sd, "WITH_TARGET_WORD_MSB = %d\n",
336 WITH_TARGET_WORD_MSB);
338 sim_io_printf (sd, "WITH_TARGET_WORD_BITSIZE = %d\n",
339 WITH_TARGET_WORD_BITSIZE);
341 sim_io_printf (sd, "WITH_TARGET_ADDRESS_BITSIZE = %d\n",
342 WITH_TARGET_ADDRESS_BITSIZE);
344 sim_io_printf (sd, "WITH_TARGET_CELL_BITSIZE = %d\n",
345 WITH_TARGET_CELL_BITSIZE);
347 sim_io_printf (sd, "WITH_TARGET_FLOATING_POINT_BITSIZE = %d\n",
348 WITH_TARGET_FLOATING_POINT_BITSIZE);
350 sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n",
351 config_environment_to_a (WITH_ENVIRONMENT));
353 sim_io_printf (sd, "WITH_ALIGNMENT = %s\n",
354 config_alignment_to_a (WITH_ALIGNMENT));
356 #if defined (WITH_DEFAULT_ALIGNMENT)
357 sim_io_printf (sd, "WITH_DEFAULT_ALIGNMENT = %s\n",
358 config_alignment_to_a (WITH_DEFAULT_ALIGNMENT));
361 #if defined (WITH_XOR_ENDIAN)
362 sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN);
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));
370 #if defined (WITH_SMP)
371 sim_io_printf (sd, "WITH_SMP = %d\n", WITH_SMP);
374 #if defined (WITH_RESERVED_BITS)
375 sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS);
378 #if defined (WITH_PROFILE)
379 sim_io_printf (sd, "WITH_PROFILE = %d\n", WITH_PROFILE);