]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-config.c
sim: reorder header includes
[thirdparty/binutils-gdb.git] / sim / common / sim-config.c
CommitLineData
b85e4829
AC
1/* The common simulator framework for GDB, the GNU Debugger.
2
3666a048 3 Copyright 2002-2021 Free Software Foundation, Inc.
b85e4829
AC
4
5 Contributed by Andrew Cagney and Red Hat.
6
7 This file is part of GDB.
8
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
4744ac1b 11 the Free Software Foundation; either version 3 of the License, or
b85e4829
AC
12 (at your option) any later version.
13
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.
18
19 You should have received a copy of the GNU General Public License
4744ac1b 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 21
6df01ab8
MF
22/* This must come before any other includes. */
23#include "defs.h"
c906108c 24
20a8e078
MF
25#include "bfd.h"
26
c906108c
SS
27#include "sim-main.h"
28#include "sim-assert.h"
c906108c
SS
29
30
1ac72f06 31enum bfd_endian current_target_byte_order = BFD_ENDIAN_UNKNOWN;
c906108c
SS
32int current_stdio;
33
34enum sim_alignments current_alignment;
35
36#if defined (WITH_FLOATING_POINT)
37int current_floating_point;
38#endif
39
40
41
42/* map a byte order onto a textual string */
43
44static const char *
1ac72f06 45config_byte_order_to_a (enum bfd_endian byte_order)
c906108c
SS
46{
47 switch (byte_order)
48 {
1ac72f06 49 case BFD_ENDIAN_LITTLE:
c906108c 50 return "LITTLE_ENDIAN";
1ac72f06 51 case BFD_ENDIAN_BIG:
c906108c 52 return "BIG_ENDIAN";
1ac72f06
MF
53 case BFD_ENDIAN_UNKNOWN:
54 return "UNKNOWN_ENDIAN";
c906108c
SS
55 }
56 return "UNKNOWN";
57}
58
59
60static const char *
61config_stdio_to_a (int stdio)
62{
63 switch (stdio)
64 {
65 case DONT_USE_STDIO:
66 return "DONT_USE_STDIO";
67 case DO_USE_STDIO:
68 return "DO_USE_STDIO";
69 case 0:
70 return "0";
71 }
72 return "UNKNOWN";
73}
74
75
76static const char *
77config_environment_to_a (enum sim_environment environment)
78{
79 switch (environment)
80 {
81 case ALL_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";
89 }
90 return "UNKNOWN";
91}
92
93
94static const char *
95config_alignment_to_a (enum sim_alignments alignment)
96{
97 switch (alignment)
98 {
99 case MIXED_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";
107 }
108 return "UNKNOWN";
109}
110
111
112#if defined (WITH_FLOATING_POINT)
113static const char *
114config_floating_point_to_a (int floating_point)
115{
116 switch (floating_point)
117 {
118 case SOFT_FLOATING_POINT:
119 return "SOFT_FLOATING_POINT";
120 case HARD_FLOATING_POINT:
121 return "HARD_FLOATING_POINT";
122 case 0:
123 return "0";
124 }
125 return "UNKNOWN";
126}
127#endif
128
129/* Set the default environment, prior to parsing argv. */
130
131void
132sim_config_default (SIM_DESC sd)
133{
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;
138}
139
140/* Complete and verify the simulation environment. */
141
142SIM_RC
143sim_config (SIM_DESC sd)
144{
1ac72f06 145 enum bfd_endian prefered_target_byte_order;
c906108c
SS
146 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
147
148 /* extract all relevant information */
1d72487d
HPN
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))))
1ac72f06 154 prefered_target_byte_order = BFD_ENDIAN_UNKNOWN;
c906108c 155 else
34b47c38 156 prefered_target_byte_order = (bfd_little_endian (STATE_PROG_BFD (sd))
1ac72f06
MF
157 ? BFD_ENDIAN_LITTLE
158 : BFD_ENDIAN_BIG);
c906108c 159
c906108c
SS
160 /* set the target byte order */
161#if (WITH_TREE_PROPERTIES)
1ac72f06 162 if (current_target_byte_order == BFD_ENDIAN_UNKNOWN)
c906108c
SS
163 current_target_byte_order
164 = (tree_find_boolean_property (root, "/options/little-endian?")
1ac72f06
MF
165 ? BFD_ENDIAN_LITTLE
166 : BFD_ENDIAN_BIG);
c906108c 167#endif
1ac72f06
MF
168 if (current_target_byte_order == BFD_ENDIAN_UNKNOWN
169 && prefered_target_byte_order != BFD_ENDIAN_UNKNOWN)
c906108c 170 current_target_byte_order = prefered_target_byte_order;
1ac72f06 171 if (current_target_byte_order == BFD_ENDIAN_UNKNOWN)
c906108c 172 current_target_byte_order = WITH_TARGET_BYTE_ORDER;
c906108c
SS
173
174 /* verify the target byte order */
1ac72f06 175 if (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_UNKNOWN)
c906108c
SS
176 {
177 sim_io_eprintf (sd, "Target byte order unspecified\n");
178 return SIM_RC_FAIL;
179 }
180 if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order)
181 sim_io_eprintf (sd, "Target (%s) and configured (%s) byte order in conflict\n",
182 config_byte_order_to_a (current_target_byte_order),
183 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER));
1ac72f06 184 if (prefered_target_byte_order != BFD_ENDIAN_UNKNOWN
c906108c
SS
185 && CURRENT_TARGET_BYTE_ORDER != prefered_target_byte_order)
186 sim_io_eprintf (sd, "Target (%s) and specified (%s) byte order in conflict\n",
187 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER),
188 config_byte_order_to_a (prefered_target_byte_order));
189
190
191 /* set the stdio */
192 if (current_stdio == 0)
193 current_stdio = WITH_STDIO;
194 if (current_stdio == 0)
195 current_stdio = DO_USE_STDIO;
196
197 /* verify the stdio */
198 if (CURRENT_STDIO == 0)
199 {
200 sim_io_eprintf (sd, "Target standard IO unspecified\n");
201 return SIM_RC_FAIL;
202 }
203 if (CURRENT_STDIO != current_stdio)
204 {
205 sim_io_eprintf (sd, "Target (%s) and configured (%s) standard IO in conflict\n",
206 config_stdio_to_a (CURRENT_STDIO),
207 config_stdio_to_a (current_stdio));
208 return SIM_RC_FAIL;
209 }
028f6515
MF
210
211
c906108c
SS
212 /* check the value of MSB */
213 if (WITH_TARGET_WORD_MSB != 0
214 && WITH_TARGET_WORD_MSB != (WITH_TARGET_WORD_BITSIZE - 1))
215 {
216 sim_io_eprintf (sd, "Target bitsize (%d) contradicts target most significant bit (%d)\n",
217 WITH_TARGET_WORD_BITSIZE, WITH_TARGET_WORD_MSB);
218 return SIM_RC_FAIL;
219 }
028f6515
MF
220
221
c906108c
SS
222 /* set the environment */
223#if (WITH_TREE_PROPERTIES)
224 if (STATE_ENVIRONMENT (sd) == ALL_ENVIRONMENT)
225 {
226 const char *env =
34b47c38
MF
227 tree_find_string_property (root, "/openprom/options/env");
228 STATE_ENVIRONMENT (sd) = ((strcmp (env, "user") == 0
229 || strcmp (env, "uea") == 0)
c906108c 230 ? USER_ENVIRONMENT
34b47c38
MF
231 : (strcmp (env, "virtual") == 0
232 || strcmp (env, "vea") == 0)
c906108c 233 ? VIRTUAL_ENVIRONMENT
34b47c38
MF
234 : (strcmp (env, "operating") == 0
235 || strcmp (env, "oea") == 0)
c906108c
SS
236 ? OPERATING_ENVIRONMENT
237 : ALL_ENVIRONMENT);
238 }
239#endif
240 if (STATE_ENVIRONMENT (sd) == ALL_ENVIRONMENT)
ce39bd38
MF
241 STATE_ENVIRONMENT (sd) = (WITH_ENVIRONMENT != ALL_ENVIRONMENT ?
242 WITH_ENVIRONMENT : USER_ENVIRONMENT);
028f6515
MF
243
244
c906108c
SS
245 /* set the alignment */
246#if (WITH_TREE_PROPERTIES)
247 if (current_alignment == 0)
248 current_alignment =
34b47c38 249 (tree_find_boolean_property (root, "/openprom/options/strict-alignment?")
c906108c
SS
250 ? STRICT_ALIGNMENT
251 : NONSTRICT_ALIGNMENT);
252#endif
253 if (current_alignment == 0)
254 current_alignment = WITH_ALIGNMENT;
ba307cdd 255 /* If the port hasn't specified an alignment, default to not enforcing. */
c906108c 256 if (current_alignment == 0)
ba307cdd 257 current_alignment = NONSTRICT_ALIGNMENT;
028f6515 258
c906108c
SS
259 /* verify the alignment */
260 if (CURRENT_ALIGNMENT == 0)
261 {
262 sim_io_eprintf (sd, "Target alignment unspecified\n");
263 return SIM_RC_FAIL;
264 }
265 if (CURRENT_ALIGNMENT != current_alignment)
266 {
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));
270 return SIM_RC_FAIL;
271 }
028f6515 272
c906108c 273#if defined (WITH_FLOATING_POINT)
028f6515 274
c906108c
SS
275 /* set the floating point */
276 if (current_floating_point == 0)
277 current_floating_point = WITH_FLOATING_POINT;
028f6515 278
c906108c
SS
279 /* verify the floating point */
280 if (CURRENT_FLOATING_POINT == 0)
281 {
282 sim_io_eprintf (sd, "Target floating-point unspecified\n");
283 return SIM_RC_FAIL;
284 }
285 if (CURRENT_FLOATING_POINT != current_floating_point)
286 {
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));
290 return SIM_RC_FAIL;
291 }
028f6515 292
c906108c
SS
293#endif
294 return SIM_RC_OK;
295}
296
297
298void
2b667e32 299sim_config_print (SIM_DESC sd)
c906108c 300{
34ac507d 301 sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n",
c906108c
SS
302 config_byte_order_to_a (WITH_TARGET_BYTE_ORDER));
303
34ac507d 304 sim_io_printf (sd, "HOST_BYTE_ORDER = %s\n",
0cb8d851 305 config_byte_order_to_a (HOST_BYTE_ORDER));
c906108c 306
34ac507d 307 sim_io_printf (sd, "WITH_STDIO = %s\n",
c906108c
SS
308 config_stdio_to_a (WITH_STDIO));
309
34ac507d 310 sim_io_printf (sd, "WITH_TARGET_WORD_MSB = %d\n",
c906108c
SS
311 WITH_TARGET_WORD_MSB);
312
313 sim_io_printf (sd, "WITH_TARGET_WORD_BITSIZE = %d\n",
314 WITH_TARGET_WORD_BITSIZE);
315
316 sim_io_printf (sd, "WITH_TARGET_ADDRESS_BITSIZE = %d\n",
317 WITH_TARGET_ADDRESS_BITSIZE);
318
319 sim_io_printf (sd, "WITH_TARGET_CELL_BITSIZE = %d\n",
320 WITH_TARGET_CELL_BITSIZE);
321
322 sim_io_printf (sd, "WITH_TARGET_FLOATING_POINT_BITSIZE = %d\n",
323 WITH_TARGET_FLOATING_POINT_BITSIZE);
324
325 sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n",
326 config_environment_to_a (WITH_ENVIRONMENT));
327
328 sim_io_printf (sd, "WITH_ALIGNMENT = %s\n",
329 config_alignment_to_a (WITH_ALIGNMENT));
330
c906108c
SS
331#if defined (WITH_XOR_ENDIAN)
332 sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN);
333#endif
334
335#if defined (WITH_FLOATING_POINT)
336 sim_io_printf (sd, "WITH_FLOATING_POINT = %s\n",
337 config_floating_point_to_a (WITH_FLOATING_POINT));
338#endif
339
340#if defined (WITH_SMP)
341 sim_io_printf (sd, "WITH_SMP = %d\n", WITH_SMP);
342#endif
343
344#if defined (WITH_RESERVED_BITS)
345 sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS);
346#endif
028f6515 347
c906108c
SS
348#if defined (WITH_PROFILE)
349 sim_io_printf (sd, "WITH_PROFILE = %d\n", WITH_PROFILE);
350#endif
028f6515 351
c906108c 352}