1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002-2021 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/>. */
22 /* This must come before any other includes. */
26 #include "sim-assert.h"
30 enum bfd_endian current_target_byte_order
= BFD_ENDIAN_UNKNOWN
;
33 enum sim_alignments current_alignment
;
35 #if defined (WITH_FLOATING_POINT)
36 int current_floating_point
;
41 /* map a byte order onto a textual string */
44 config_byte_order_to_a (enum bfd_endian byte_order
)
48 case BFD_ENDIAN_LITTLE
:
49 return "LITTLE_ENDIAN";
52 case BFD_ENDIAN_UNKNOWN
:
53 return "UNKNOWN_ENDIAN";
60 config_stdio_to_a (int stdio
)
65 return "DONT_USE_STDIO";
67 return "DO_USE_STDIO";
76 config_environment_to_a (enum sim_environment environment
)
81 return "ALL_ENVIRONMENT";
82 case USER_ENVIRONMENT
:
83 return "USER_ENVIRONMENT";
84 case VIRTUAL_ENVIRONMENT
:
85 return "VIRTUAL_ENVIRONMENT";
86 case OPERATING_ENVIRONMENT
:
87 return "OPERATING_ENVIRONMENT";
94 config_alignment_to_a (enum sim_alignments alignment
)
99 return "MIXED_ALIGNMENT";
100 case NONSTRICT_ALIGNMENT
:
101 return "NONSTRICT_ALIGNMENT";
102 case STRICT_ALIGNMENT
:
103 return "STRICT_ALIGNMENT";
104 case FORCED_ALIGNMENT
:
105 return "FORCED_ALIGNMENT";
111 #if defined (WITH_FLOATING_POINT)
113 config_floating_point_to_a (int floating_point
)
115 switch (floating_point
)
117 case SOFT_FLOATING_POINT
:
118 return "SOFT_FLOATING_POINT";
119 case HARD_FLOATING_POINT
:
120 return "HARD_FLOATING_POINT";
128 /* Set the default environment, prior to parsing argv. */
131 sim_config_default (SIM_DESC sd
)
133 /* Set the current environment to ALL_ENVIRONMENT to indicate none has been
134 selected yet. This is so that after parsing argv, we know whether the
135 environment was explicitly specified or not. */
136 STATE_ENVIRONMENT (sd
) = ALL_ENVIRONMENT
;
139 /* Complete and verify the simulation environment. */
142 sim_config (SIM_DESC sd
)
144 enum bfd_endian prefered_target_byte_order
;
145 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
147 /* extract all relevant information */
148 if (STATE_PROG_BFD (sd
) == NULL
149 /* If we have a binary input file (presumably with specified
150 "--architecture"), it'll have no endianness. */
151 || (!bfd_little_endian (STATE_PROG_BFD (sd
))
152 && !bfd_big_endian (STATE_PROG_BFD (sd
))))
153 prefered_target_byte_order
= BFD_ENDIAN_UNKNOWN
;
155 prefered_target_byte_order
= (bfd_little_endian (STATE_PROG_BFD (sd
))
159 /* set the target byte order */
160 #if (WITH_TREE_PROPERTIES)
161 if (current_target_byte_order
== BFD_ENDIAN_UNKNOWN
)
162 current_target_byte_order
163 = (tree_find_boolean_property (root
, "/options/little-endian?")
167 if (current_target_byte_order
== BFD_ENDIAN_UNKNOWN
168 && prefered_target_byte_order
!= BFD_ENDIAN_UNKNOWN
)
169 current_target_byte_order
= prefered_target_byte_order
;
170 if (current_target_byte_order
== BFD_ENDIAN_UNKNOWN
)
171 current_target_byte_order
= WITH_TARGET_BYTE_ORDER
;
172 if (current_target_byte_order
== BFD_ENDIAN_UNKNOWN
)
173 current_target_byte_order
= WITH_DEFAULT_TARGET_BYTE_ORDER
;
175 /* verify the target byte order */
176 if (CURRENT_TARGET_BYTE_ORDER
== BFD_ENDIAN_UNKNOWN
)
178 sim_io_eprintf (sd
, "Target byte order unspecified\n");
181 if (CURRENT_TARGET_BYTE_ORDER
!= current_target_byte_order
)
182 sim_io_eprintf (sd
, "Target (%s) and configured (%s) byte order in conflict\n",
183 config_byte_order_to_a (current_target_byte_order
),
184 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER
));
185 if (prefered_target_byte_order
!= BFD_ENDIAN_UNKNOWN
186 && CURRENT_TARGET_BYTE_ORDER
!= prefered_target_byte_order
)
187 sim_io_eprintf (sd
, "Target (%s) and specified (%s) byte order in conflict\n",
188 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER
),
189 config_byte_order_to_a (prefered_target_byte_order
));
193 if (current_stdio
== 0)
194 current_stdio
= WITH_STDIO
;
195 if (current_stdio
== 0)
196 current_stdio
= DO_USE_STDIO
;
198 /* verify the stdio */
199 if (CURRENT_STDIO
== 0)
201 sim_io_eprintf (sd
, "Target standard IO unspecified\n");
204 if (CURRENT_STDIO
!= current_stdio
)
206 sim_io_eprintf (sd
, "Target (%s) and configured (%s) standard IO in conflict\n",
207 config_stdio_to_a (CURRENT_STDIO
),
208 config_stdio_to_a (current_stdio
));
213 /* check the value of MSB */
214 if (WITH_TARGET_WORD_MSB
!= 0
215 && WITH_TARGET_WORD_MSB
!= (WITH_TARGET_WORD_BITSIZE
- 1))
217 sim_io_eprintf (sd
, "Target bitsize (%d) contradicts target most significant bit (%d)\n",
218 WITH_TARGET_WORD_BITSIZE
, WITH_TARGET_WORD_MSB
);
223 /* set the environment */
224 #if (WITH_TREE_PROPERTIES)
225 if (STATE_ENVIRONMENT (sd
) == ALL_ENVIRONMENT
)
228 tree_find_string_property (root
, "/openprom/options/env");
229 STATE_ENVIRONMENT (sd
) = ((strcmp (env
, "user") == 0
230 || strcmp (env
, "uea") == 0)
232 : (strcmp (env
, "virtual") == 0
233 || strcmp (env
, "vea") == 0)
234 ? VIRTUAL_ENVIRONMENT
235 : (strcmp (env
, "operating") == 0
236 || strcmp (env
, "oea") == 0)
237 ? OPERATING_ENVIRONMENT
241 if (STATE_ENVIRONMENT (sd
) == ALL_ENVIRONMENT
)
242 STATE_ENVIRONMENT (sd
) = (WITH_ENVIRONMENT
!= ALL_ENVIRONMENT
?
243 WITH_ENVIRONMENT
: USER_ENVIRONMENT
);
246 /* set the alignment */
247 #if (WITH_TREE_PROPERTIES)
248 if (current_alignment
== 0)
250 (tree_find_boolean_property (root
, "/openprom/options/strict-alignment?")
252 : NONSTRICT_ALIGNMENT
);
254 if (current_alignment
== 0)
255 current_alignment
= WITH_ALIGNMENT
;
256 if (current_alignment
== 0)
257 current_alignment
= WITH_DEFAULT_ALIGNMENT
;
259 /* verify the alignment */
260 if (CURRENT_ALIGNMENT
== 0)
262 sim_io_eprintf (sd
, "Target alignment unspecified\n");
265 if (CURRENT_ALIGNMENT
!= current_alignment
)
267 sim_io_eprintf (sd
, "Target (%s) and configured (%s) alignment in conflict\n",
268 config_alignment_to_a (CURRENT_ALIGNMENT
),
269 config_alignment_to_a (current_alignment
));
273 #if defined (WITH_FLOATING_POINT)
275 /* set the floating point */
276 if (current_floating_point
== 0)
277 current_floating_point
= WITH_FLOATING_POINT
;
279 /* verify the floating point */
280 if (CURRENT_FLOATING_POINT
== 0)
282 sim_io_eprintf (sd
, "Target floating-point unspecified\n");
285 if (CURRENT_FLOATING_POINT
!= current_floating_point
)
287 sim_io_eprintf (sd
, "Target (%s) and configured (%s) floating-point in conflict\n",
288 config_alignment_to_a (CURRENT_FLOATING_POINT
),
289 config_alignment_to_a (current_floating_point
));
299 sim_config_print (SIM_DESC sd
)
301 sim_io_printf (sd
, "WITH_TARGET_BYTE_ORDER = %s\n",
302 config_byte_order_to_a (WITH_TARGET_BYTE_ORDER
));
304 sim_io_printf (sd
, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n",
305 config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER
));
307 sim_io_printf (sd
, "HOST_BYTE_ORDER = %s\n",
308 config_byte_order_to_a (HOST_BYTE_ORDER
));
310 sim_io_printf (sd
, "WITH_STDIO = %s\n",
311 config_stdio_to_a (WITH_STDIO
));
313 sim_io_printf (sd
, "WITH_TARGET_WORD_MSB = %d\n",
314 WITH_TARGET_WORD_MSB
);
316 sim_io_printf (sd
, "WITH_TARGET_WORD_BITSIZE = %d\n",
317 WITH_TARGET_WORD_BITSIZE
);
319 sim_io_printf (sd
, "WITH_TARGET_ADDRESS_BITSIZE = %d\n",
320 WITH_TARGET_ADDRESS_BITSIZE
);
322 sim_io_printf (sd
, "WITH_TARGET_CELL_BITSIZE = %d\n",
323 WITH_TARGET_CELL_BITSIZE
);
325 sim_io_printf (sd
, "WITH_TARGET_FLOATING_POINT_BITSIZE = %d\n",
326 WITH_TARGET_FLOATING_POINT_BITSIZE
);
328 sim_io_printf (sd
, "WITH_ENVIRONMENT = %s\n",
329 config_environment_to_a (WITH_ENVIRONMENT
));
331 sim_io_printf (sd
, "WITH_ALIGNMENT = %s\n",
332 config_alignment_to_a (WITH_ALIGNMENT
));
334 #if defined (WITH_DEFAULT_ALIGNMENT)
335 sim_io_printf (sd
, "WITH_DEFAULT_ALIGNMENT = %s\n",
336 config_alignment_to_a (WITH_DEFAULT_ALIGNMENT
));
339 #if defined (WITH_XOR_ENDIAN)
340 sim_io_printf (sd
, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN
);
343 #if defined (WITH_FLOATING_POINT)
344 sim_io_printf (sd
, "WITH_FLOATING_POINT = %s\n",
345 config_floating_point_to_a (WITH_FLOATING_POINT
));
348 #if defined (WITH_SMP)
349 sim_io_printf (sd
, "WITH_SMP = %d\n", WITH_SMP
);
352 #if defined (WITH_RESERVED_BITS)
353 sim_io_printf (sd
, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS
);
356 #if defined (WITH_PROFILE)
357 sim_io_printf (sd
, "WITH_PROFILE = %d\n", WITH_PROFILE
);