* cgen-trace.c (trace_insn): Pass pc to trace_prefix for virtual insns.
[deliverable/binutils-gdb.git] / sim / common / sim-config.c
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
22 #include "sim-main.h"
23 #include "sim-assert.h"
24 #include "bfd.h"
25
26
27 int current_host_byte_order;
28 int current_target_byte_order;
29 int current_stdio;
30
31 /* The currently selected environment.
32 This isn't used unless the choice is runtime selectable.
33 The proper way to determine the currently selected environment
34 is with the CURRENT_ENVIRONMENT macro.
35 This is set to ALL_ENVIRONMENT to indicate none has been selected yet. */
36 enum sim_environment current_environment = ALL_ENVIRONMENT;
37
38 enum sim_alignments current_alignment;
39
40 #if defined (WITH_FLOATING_POINT)
41 int current_floating_point;
42 #endif
43
44
45
46 /* map a byte order onto a textual string */
47
48 static const char *
49 config_byte_order_to_a (int byte_order)
50 {
51 switch (byte_order)
52 {
53 case LITTLE_ENDIAN:
54 return "LITTLE_ENDIAN";
55 case BIG_ENDIAN:
56 return "BIG_ENDIAN";
57 case 0:
58 return "0";
59 }
60 return "UNKNOWN";
61 }
62
63
64 static const char *
65 config_stdio_to_a (int stdio)
66 {
67 switch (stdio)
68 {
69 case DONT_USE_STDIO:
70 return "DONT_USE_STDIO";
71 case DO_USE_STDIO:
72 return "DO_USE_STDIO";
73 case 0:
74 return "0";
75 }
76 return "UNKNOWN";
77 }
78
79
80 static const char *
81 config_environment_to_a (enum sim_environment environment)
82 {
83 switch (environment)
84 {
85 case ALL_ENVIRONMENT:
86 return "ALL_ENVIRONMENT";
87 case USER_ENVIRONMENT:
88 return "USER_ENVIRONMENT";
89 case VIRTUAL_ENVIRONMENT:
90 return "VIRTUAL_ENVIRONMENT";
91 case OPERATING_ENVIRONMENT:
92 return "OPERATING_ENVIRONMENT";
93 }
94 return "UNKNOWN";
95 }
96
97
98 static const char *
99 config_alignment_to_a (enum sim_alignments alignment)
100 {
101 switch (alignment)
102 {
103 case MIXED_ALIGNMENT:
104 return "MIXED_ALIGNMENT";
105 case NONSTRICT_ALIGNMENT:
106 return "NONSTRICT_ALIGNMENT";
107 case STRICT_ALIGNMENT:
108 return "STRICT_ALIGNMENT";
109 case FORCED_ALIGNMENT:
110 return "FORCED_ALIGNMENT";
111 }
112 return "UNKNOWN";
113 }
114
115
116 #if defined (WITH_FLOATING_POINT)
117 static const char *
118 config_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
134 SIM_RC
135 sim_config (SIM_DESC sd)
136 {
137 int prefered_target_byte_order;
138 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
139
140 /* extract all relevant information */
141 if (STATE_PROG_BFD (sd) == NULL)
142 prefered_target_byte_order = 0;
143 else
144 prefered_target_byte_order = (bfd_little_endian(STATE_PROG_BFD (sd))
145 ? LITTLE_ENDIAN
146 : BIG_ENDIAN);
147
148 /* set the host byte order */
149 current_host_byte_order = 1;
150 if (*(char*)(&current_host_byte_order))
151 current_host_byte_order = LITTLE_ENDIAN;
152 else
153 current_host_byte_order = BIG_ENDIAN;
154
155 /* verify the host byte order */
156 if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order)
157 {
158 sim_io_eprintf (sd, "host (%s) and configured (%s) byte order in conflict",
159 config_byte_order_to_a (current_host_byte_order),
160 config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER));
161 return SIM_RC_FAIL;
162 }
163
164
165 /* set the target byte order */
166 #if (WITH_TREE_PROPERTIES)
167 if (current_target_byte_order == 0)
168 current_target_byte_order
169 = (tree_find_boolean_property (root, "/options/little-endian?")
170 ? LITTLE_ENDIAN
171 : BIG_ENDIAN);
172 #endif
173 if (current_target_byte_order == 0
174 && prefered_target_byte_order != 0)
175 current_target_byte_order = prefered_target_byte_order;
176 if (current_target_byte_order == 0)
177 current_target_byte_order = WITH_TARGET_BYTE_ORDER;
178 if (current_target_byte_order == 0)
179 current_target_byte_order = WITH_DEFAULT_TARGET_BYTE_ORDER;
180
181 /* verify the target byte order */
182 if (CURRENT_TARGET_BYTE_ORDER == 0)
183 {
184 sim_io_eprintf (sd, "Target byte order unspecified\n");
185 return SIM_RC_FAIL;
186 }
187 if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order)
188 sim_io_eprintf (sd, "Target (%s) and configured (%s) byte order in conflict\n",
189 config_byte_order_to_a (current_target_byte_order),
190 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER));
191 if (prefered_target_byte_order != 0
192 && CURRENT_TARGET_BYTE_ORDER != prefered_target_byte_order)
193 sim_io_eprintf (sd, "Target (%s) and specified (%s) byte order in conflict\n",
194 config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER),
195 config_byte_order_to_a (prefered_target_byte_order));
196
197
198 /* set the stdio */
199 if (current_stdio == 0)
200 current_stdio = WITH_STDIO;
201 if (current_stdio == 0)
202 current_stdio = DO_USE_STDIO;
203
204 /* verify the stdio */
205 if (CURRENT_STDIO == 0)
206 {
207 sim_io_eprintf (sd, "Target standard IO unspecified\n");
208 return SIM_RC_FAIL;
209 }
210 if (CURRENT_STDIO != current_stdio)
211 {
212 sim_io_eprintf (sd, "Target (%s) and configured (%s) standard IO in conflict\n",
213 config_stdio_to_a (CURRENT_STDIO),
214 config_stdio_to_a (current_stdio));
215 return SIM_RC_FAIL;
216 }
217
218
219 /* check the value of MSB */
220 if (WITH_TARGET_WORD_MSB != 0
221 && WITH_TARGET_WORD_MSB != (WITH_TARGET_WORD_BITSIZE - 1))
222 {
223 sim_io_eprintf (sd, "Target bitsize (%d) contradicts target most significant bit (%d)\n",
224 WITH_TARGET_WORD_BITSIZE, WITH_TARGET_WORD_MSB);
225 return SIM_RC_FAIL;
226 }
227
228
229 /* set the environment */
230 #if (WITH_TREE_PROPERTIES)
231 if (current_environment == ALL_ENVIRONMENT)
232 {
233 const char *env =
234 tree_find_string_property(root, "/openprom/options/env");
235 current_environment = ((strcmp(env, "user") == 0
236 || strcmp(env, "uea") == 0)
237 ? USER_ENVIRONMENT
238 : (strcmp(env, "virtual") == 0
239 || strcmp(env, "vea") == 0)
240 ? VIRTUAL_ENVIRONMENT
241 : (strcmp(env, "operating") == 0
242 || strcmp(env, "oea") == 0)
243 ? OPERATING_ENVIRONMENT
244 : ALL_ENVIRONMENT);
245 }
246 #endif
247 if (current_environment == ALL_ENVIRONMENT)
248 current_environment = DEFAULT_ENVIRONMENT;
249
250
251 /* set the alignment */
252 #if (WITH_TREE_PROPERTIES)
253 if (current_alignment == 0)
254 current_alignment =
255 (tree_find_boolean_property(root, "/openprom/options/strict-alignment?")
256 ? STRICT_ALIGNMENT
257 : NONSTRICT_ALIGNMENT);
258 #endif
259 if (current_alignment == 0)
260 current_alignment = WITH_ALIGNMENT;
261 if (current_alignment == 0)
262 current_alignment = WITH_DEFAULT_ALIGNMENT;
263
264 /* verify the alignment */
265 if (CURRENT_ALIGNMENT == 0)
266 {
267 sim_io_eprintf (sd, "Target alignment unspecified\n");
268 return SIM_RC_FAIL;
269 }
270 if (CURRENT_ALIGNMENT != current_alignment)
271 {
272 sim_io_eprintf (sd, "Target (%s) and configured (%s) alignment in conflict\n",
273 config_alignment_to_a (CURRENT_ALIGNMENT),
274 config_alignment_to_a (current_alignment));
275 return SIM_RC_FAIL;
276 }
277
278 #if defined (WITH_FLOATING_POINT)
279
280 /* set the floating point */
281 if (current_floating_point == 0)
282 current_floating_point = WITH_FLOATING_POINT;
283
284 /* verify the floating point */
285 if (CURRENT_FLOATING_POINT == 0)
286 {
287 sim_io_eprintf (sd, "Target floating-point unspecified\n");
288 return SIM_RC_FAIL;
289 }
290 if (CURRENT_FLOATING_POINT != current_floating_point)
291 {
292 sim_io_eprintf (sd, "Target (%s) and configured (%s) floating-point in conflict\n",
293 config_alignment_to_a (CURRENT_FLOATING_POINT),
294 config_alignment_to_a (current_floating_point));
295 return SIM_RC_FAIL;
296 }
297
298 #endif
299 return SIM_RC_OK;
300 }
301
302
303 void
304 print_sim_config (SIM_DESC sd)
305 {
306 #if defined (__GNUC__) && defined (__VERSION__)
307 sim_io_printf (sd, "Compiled by GCC %s on %s %s\n",
308 __VERSION__, __DATE__, __TIME__);
309 #else
310 sim_io_printf (sd, "Compiled on %s %s\n", __DATE__, __TIME__);
311 #endif
312
313 sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n",
314 config_byte_order_to_a (WITH_TARGET_BYTE_ORDER));
315
316 sim_io_printf (sd, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n",
317 config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER));
318
319 sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n",
320 config_byte_order_to_a (WITH_HOST_BYTE_ORDER));
321
322 sim_io_printf (sd, "WITH_STDIO = %s\n",
323 config_stdio_to_a (WITH_STDIO));
324
325 sim_io_printf (sd, "WITH_TARGET_WORD_MSB = %d\n",
326 WITH_TARGET_WORD_MSB);
327
328 sim_io_printf (sd, "WITH_TARGET_WORD_BITSIZE = %d\n",
329 WITH_TARGET_WORD_BITSIZE);
330
331 sim_io_printf (sd, "WITH_TARGET_ADDRESS_BITSIZE = %d\n",
332 WITH_TARGET_ADDRESS_BITSIZE);
333
334 sim_io_printf (sd, "WITH_TARGET_CELL_BITSIZE = %d\n",
335 WITH_TARGET_CELL_BITSIZE);
336
337 sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n",
338 config_environment_to_a (WITH_ENVIRONMENT));
339
340 sim_io_printf (sd, "WITH_ALIGNMENT = %s\n",
341 config_alignment_to_a (WITH_ALIGNMENT));
342
343 #if defined (WITH_DEFAULT_ALIGNMENT)
344 sim_io_printf (sd, "WITH_DEFAULT_ALIGNMENT = %s\n",
345 config_alignment_to_a (WITH_DEFAULT_ALIGNMENT));
346 #endif
347
348 #if defined (WITH_XOR_ENDIAN)
349 sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN);
350 #endif
351
352 #if defined (WITH_FLOATING_POINT)
353 sim_io_printf (sd, "WITH_FLOATING_POINT = %s\n",
354 config_floating_point_to_a (WITH_FLOATING_POINT));
355 #endif
356
357 #if defined (WITH_SMP)
358 sim_io_printf (sd, "WITH_SMP = %d\n", WITH_SMP);
359 #endif
360
361 #if defined (WITH_RESERVED_BITS)
362 sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS);
363 #endif
364
365 #if defined (WITH_PROFILE)
366 sim_io_printf (sd, "WITH_PROFILE = %d\n", WITH_PROFILE);
367 #endif
368
369 }
This page took 0.043659 seconds and 4 git commands to generate.