1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002, 2007 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 2 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, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
26 #include "sim-assert.h"
30 int current_host_byte_order
;
31 int current_target_byte_order
;
34 enum sim_alignments current_alignment
;
36 #if defined (WITH_FLOATING_POINT)
37 int current_floating_point
;
42 /* map a byte order onto a textual string */
45 config_byte_order_to_a (int byte_order
)
50 return "LITTLE_ENDIAN";
61 config_stdio_to_a (int stdio
)
66 return "DONT_USE_STDIO";
68 return "DO_USE_STDIO";
77 config_environment_to_a (enum sim_environment environment
)
82 return "ALL_ENVIRONMENT";
83 case USER_ENVIRONMENT
:
84 return "USER_ENVIRONMENT";
85 case VIRTUAL_ENVIRONMENT
:
86 return "VIRTUAL_ENVIRONMENT";
87 case OPERATING_ENVIRONMENT
:
88 return "OPERATING_ENVIRONMENT";
95 config_alignment_to_a (enum sim_alignments alignment
)
100 return "MIXED_ALIGNMENT";
101 case NONSTRICT_ALIGNMENT
:
102 return "NONSTRICT_ALIGNMENT";
103 case STRICT_ALIGNMENT
:
104 return "STRICT_ALIGNMENT";
105 case FORCED_ALIGNMENT
:
106 return "FORCED_ALIGNMENT";
112 #if defined (WITH_FLOATING_POINT)
114 config_floating_point_to_a (int floating_point
)
116 switch (floating_point
)
118 case SOFT_FLOATING_POINT
:
119 return "SOFT_FLOATING_POINT";
120 case HARD_FLOATING_POINT
:
121 return "HARD_FLOATING_POINT";
129 /* Set the default environment, prior to parsing argv. */
132 sim_config_default (SIM_DESC sd
)
134 /* Set the current environment to ALL_ENVIRONMENT to indicate none has been
135 selected yet. This is so that after parsing argv, we know whether the
136 environment was explicitly specified or not. */
137 STATE_ENVIRONMENT (sd
) = ALL_ENVIRONMENT
;
140 /* Complete and verify the simulation environment. */
143 sim_config (SIM_DESC sd
)
145 int prefered_target_byte_order
;
146 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
148 /* extract all relevant information */
149 if (STATE_PROG_BFD (sd
) == NULL
150 /* If we have a binary input file (presumably with specified
151 "--architecture"), it'll have no endianness. */
152 || (!bfd_little_endian (STATE_PROG_BFD (sd
))
153 && !bfd_big_endian (STATE_PROG_BFD (sd
))))
154 prefered_target_byte_order
= 0;
156 prefered_target_byte_order
= (bfd_little_endian(STATE_PROG_BFD (sd
))
160 /* set the host byte order */
161 current_host_byte_order
= 1;
162 if (*(char*)(¤t_host_byte_order
))
163 current_host_byte_order
= LITTLE_ENDIAN
;
165 current_host_byte_order
= BIG_ENDIAN
;
167 /* verify the host byte order */
168 if (CURRENT_HOST_BYTE_ORDER
!= current_host_byte_order
)
170 sim_io_eprintf (sd
, "host (%s) and configured (%s) byte order in conflict",
171 config_byte_order_to_a (current_host_byte_order
),
172 config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER
));
177 /* set the target byte order */
178 #if (WITH_TREE_PROPERTIES)
179 if (current_target_byte_order
== 0)
180 current_target_byte_order
181 = (tree_find_boolean_property (root
, "/options/little-endian?")
185 if (current_target_byte_order
== 0
186 && prefered_target_byte_order
!= 0)
187 current_target_byte_order
= prefered_target_byte_order
;
188 if (current_target_byte_order
== 0)
189 current_target_byte_order
= WITH_TARGET_BYTE_ORDER
;
190 if (current_target_byte_order
== 0)
191 current_target_byte_order
= WITH_DEFAULT_TARGET_BYTE_ORDER
;
193 /* verify the target byte order */
194 if (CURRENT_TARGET_BYTE_ORDER
== 0)
196 sim_io_eprintf (sd
, "Target byte order unspecified\n");
199 if (CURRENT_TARGET_BYTE_ORDER
!= current_target_byte_order
)
200 sim_io_eprintf (sd
, "Target (%s) and configured (%s) byte order in conflict\n",
201 config_byte_order_to_a (current_target_byte_order
),
202 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER
));
203 if (prefered_target_byte_order
!= 0
204 && CURRENT_TARGET_BYTE_ORDER
!= prefered_target_byte_order
)
205 sim_io_eprintf (sd
, "Target (%s) and specified (%s) byte order in conflict\n",
206 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER
),
207 config_byte_order_to_a (prefered_target_byte_order
));
211 if (current_stdio
== 0)
212 current_stdio
= WITH_STDIO
;
213 if (current_stdio
== 0)
214 current_stdio
= DO_USE_STDIO
;
216 /* verify the stdio */
217 if (CURRENT_STDIO
== 0)
219 sim_io_eprintf (sd
, "Target standard IO unspecified\n");
222 if (CURRENT_STDIO
!= current_stdio
)
224 sim_io_eprintf (sd
, "Target (%s) and configured (%s) standard IO in conflict\n",
225 config_stdio_to_a (CURRENT_STDIO
),
226 config_stdio_to_a (current_stdio
));
231 /* check the value of MSB */
232 if (WITH_TARGET_WORD_MSB
!= 0
233 && WITH_TARGET_WORD_MSB
!= (WITH_TARGET_WORD_BITSIZE
- 1))
235 sim_io_eprintf (sd
, "Target bitsize (%d) contradicts target most significant bit (%d)\n",
236 WITH_TARGET_WORD_BITSIZE
, WITH_TARGET_WORD_MSB
);
241 /* set the environment */
242 #if (WITH_TREE_PROPERTIES)
243 if (STATE_ENVIRONMENT (sd
) == ALL_ENVIRONMENT
)
246 tree_find_string_property(root
, "/openprom/options/env");
247 STATE_ENVIRONMENT (sd
) = ((strcmp(env
, "user") == 0
248 || strcmp(env
, "uea") == 0)
250 : (strcmp(env
, "virtual") == 0
251 || strcmp(env
, "vea") == 0)
252 ? VIRTUAL_ENVIRONMENT
253 : (strcmp(env
, "operating") == 0
254 || strcmp(env
, "oea") == 0)
255 ? OPERATING_ENVIRONMENT
259 if (STATE_ENVIRONMENT (sd
) == ALL_ENVIRONMENT
)
260 STATE_ENVIRONMENT (sd
) = DEFAULT_ENVIRONMENT
;
263 /* set the alignment */
264 #if (WITH_TREE_PROPERTIES)
265 if (current_alignment
== 0)
267 (tree_find_boolean_property(root
, "/openprom/options/strict-alignment?")
269 : NONSTRICT_ALIGNMENT
);
271 if (current_alignment
== 0)
272 current_alignment
= WITH_ALIGNMENT
;
273 if (current_alignment
== 0)
274 current_alignment
= WITH_DEFAULT_ALIGNMENT
;
276 /* verify the alignment */
277 if (CURRENT_ALIGNMENT
== 0)
279 sim_io_eprintf (sd
, "Target alignment unspecified\n");
282 if (CURRENT_ALIGNMENT
!= current_alignment
)
284 sim_io_eprintf (sd
, "Target (%s) and configured (%s) alignment in conflict\n",
285 config_alignment_to_a (CURRENT_ALIGNMENT
),
286 config_alignment_to_a (current_alignment
));
290 #if defined (WITH_FLOATING_POINT)
292 /* set the floating point */
293 if (current_floating_point
== 0)
294 current_floating_point
= WITH_FLOATING_POINT
;
296 /* verify the floating point */
297 if (CURRENT_FLOATING_POINT
== 0)
299 sim_io_eprintf (sd
, "Target floating-point unspecified\n");
302 if (CURRENT_FLOATING_POINT
!= current_floating_point
)
304 sim_io_eprintf (sd
, "Target (%s) and configured (%s) floating-point in conflict\n",
305 config_alignment_to_a (CURRENT_FLOATING_POINT
),
306 config_alignment_to_a (current_floating_point
));
316 print_sim_config (SIM_DESC sd
)
318 #if defined (__GNUC__) && defined (__VERSION__)
319 sim_io_printf (sd
, "Compiled by GCC %s on %s %s\n",
320 __VERSION__
, __DATE__
, __TIME__
);
322 sim_io_printf (sd
, "Compiled on %s %s\n", __DATE__
, __TIME__
);
325 sim_io_printf (sd
, "WITH_TARGET_BYTE_ORDER = %s\n",
326 config_byte_order_to_a (WITH_TARGET_BYTE_ORDER
));
328 sim_io_printf (sd
, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n",
329 config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER
));
331 sim_io_printf (sd
, "WITH_HOST_BYTE_ORDER = %s\n",
332 config_byte_order_to_a (WITH_HOST_BYTE_ORDER
));
334 sim_io_printf (sd
, "WITH_STDIO = %s\n",
335 config_stdio_to_a (WITH_STDIO
));
337 sim_io_printf (sd
, "WITH_TARGET_WORD_MSB = %d\n",
338 WITH_TARGET_WORD_MSB
);
340 sim_io_printf (sd
, "WITH_TARGET_WORD_BITSIZE = %d\n",
341 WITH_TARGET_WORD_BITSIZE
);
343 sim_io_printf (sd
, "WITH_TARGET_ADDRESS_BITSIZE = %d\n",
344 WITH_TARGET_ADDRESS_BITSIZE
);
346 sim_io_printf (sd
, "WITH_TARGET_CELL_BITSIZE = %d\n",
347 WITH_TARGET_CELL_BITSIZE
);
349 sim_io_printf (sd
, "WITH_TARGET_FLOATING_POINT_BITSIZE = %d\n",
350 WITH_TARGET_FLOATING_POINT_BITSIZE
);
352 sim_io_printf (sd
, "WITH_ENVIRONMENT = %s\n",
353 config_environment_to_a (WITH_ENVIRONMENT
));
355 sim_io_printf (sd
, "WITH_ALIGNMENT = %s\n",
356 config_alignment_to_a (WITH_ALIGNMENT
));
358 #if defined (WITH_DEFAULT_ALIGNMENT)
359 sim_io_printf (sd
, "WITH_DEFAULT_ALIGNMENT = %s\n",
360 config_alignment_to_a (WITH_DEFAULT_ALIGNMENT
));
363 #if defined (WITH_XOR_ENDIAN)
364 sim_io_printf (sd
, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN
);
367 #if defined (WITH_FLOATING_POINT)
368 sim_io_printf (sd
, "WITH_FLOATING_POINT = %s\n",
369 config_floating_point_to_a (WITH_FLOATING_POINT
));
372 #if defined (WITH_SMP)
373 sim_io_printf (sd
, "WITH_SMP = %d\n", WITH_SMP
);
376 #if defined (WITH_RESERVED_BITS)
377 sim_io_printf (sd
, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS
);
380 #if defined (WITH_PROFILE)
381 sim_io_printf (sd
, "WITH_PROFILE = %d\n", WITH_PROFILE
);