Commit | Line | Data |
---|---|---|
b85e4829 AC |
1 | /* The common simulator framework for GDB, the GNU Debugger. |
2 | ||
3 | Copyright 2002 Free Software Foundation, Inc. | |
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 | |
11 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
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. */ | |
c906108c SS |
23 | |
24 | ||
25 | #include "sim-main.h" | |
26 | #include "sim-assert.h" | |
27 | #include "bfd.h" | |
28 | ||
29 | ||
30 | int current_host_byte_order; | |
31 | int current_target_byte_order; | |
32 | int current_stdio; | |
33 | ||
34 | enum sim_alignments current_alignment; | |
35 | ||
36 | #if defined (WITH_FLOATING_POINT) | |
37 | int current_floating_point; | |
38 | #endif | |
39 | ||
40 | ||
41 | ||
42 | /* map a byte order onto a textual string */ | |
43 | ||
44 | static const char * | |
45 | config_byte_order_to_a (int byte_order) | |
46 | { | |
47 | switch (byte_order) | |
48 | { | |
49 | case LITTLE_ENDIAN: | |
50 | return "LITTLE_ENDIAN"; | |
51 | case BIG_ENDIAN: | |
52 | return "BIG_ENDIAN"; | |
53 | case 0: | |
54 | return "0"; | |
55 | } | |
56 | return "UNKNOWN"; | |
57 | } | |
58 | ||
59 | ||
60 | static const char * | |
61 | config_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 | ||
76 | static const char * | |
77 | config_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 | ||
94 | static const char * | |
95 | config_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) | |
113 | static const char * | |
114 | config_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 | ||
131 | void | |
132 | sim_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 | ||
142 | SIM_RC | |
143 | sim_config (SIM_DESC sd) | |
144 | { | |
145 | int prefered_target_byte_order; | |
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)))) | |
c906108c SS |
154 | prefered_target_byte_order = 0; |
155 | else | |
156 | prefered_target_byte_order = (bfd_little_endian(STATE_PROG_BFD (sd)) | |
157 | ? LITTLE_ENDIAN | |
158 | : BIG_ENDIAN); | |
159 | ||
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; | |
164 | else | |
165 | current_host_byte_order = BIG_ENDIAN; | |
166 | ||
167 | /* verify the host byte order */ | |
168 | if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order) | |
169 | { | |
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)); | |
173 | return SIM_RC_FAIL; | |
174 | } | |
175 | ||
176 | ||
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?") | |
182 | ? LITTLE_ENDIAN | |
183 | : BIG_ENDIAN); | |
184 | #endif | |
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; | |
192 | ||
193 | /* verify the target byte order */ | |
194 | if (CURRENT_TARGET_BYTE_ORDER == 0) | |
195 | { | |
196 | sim_io_eprintf (sd, "Target byte order unspecified\n"); | |
197 | return SIM_RC_FAIL; | |
198 | } | |
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)); | |
208 | ||
209 | ||
210 | /* set the stdio */ | |
211 | if (current_stdio == 0) | |
212 | current_stdio = WITH_STDIO; | |
213 | if (current_stdio == 0) | |
214 | current_stdio = DO_USE_STDIO; | |
215 | ||
216 | /* verify the stdio */ | |
217 | if (CURRENT_STDIO == 0) | |
218 | { | |
219 | sim_io_eprintf (sd, "Target standard IO unspecified\n"); | |
220 | return SIM_RC_FAIL; | |
221 | } | |
222 | if (CURRENT_STDIO != current_stdio) | |
223 | { | |
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)); | |
227 | return SIM_RC_FAIL; | |
228 | } | |
229 | ||
230 | ||
231 | /* check the value of MSB */ | |
232 | if (WITH_TARGET_WORD_MSB != 0 | |
233 | && WITH_TARGET_WORD_MSB != (WITH_TARGET_WORD_BITSIZE - 1)) | |
234 | { | |
235 | sim_io_eprintf (sd, "Target bitsize (%d) contradicts target most significant bit (%d)\n", | |
236 | WITH_TARGET_WORD_BITSIZE, WITH_TARGET_WORD_MSB); | |
237 | return SIM_RC_FAIL; | |
238 | } | |
239 | ||
240 | ||
241 | /* set the environment */ | |
242 | #if (WITH_TREE_PROPERTIES) | |
243 | if (STATE_ENVIRONMENT (sd) == ALL_ENVIRONMENT) | |
244 | { | |
245 | const char *env = | |
246 | tree_find_string_property(root, "/openprom/options/env"); | |
247 | STATE_ENVIRONMENT (sd) = ((strcmp(env, "user") == 0 | |
248 | || strcmp(env, "uea") == 0) | |
249 | ? USER_ENVIRONMENT | |
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 | |
256 | : ALL_ENVIRONMENT); | |
257 | } | |
258 | #endif | |
259 | if (STATE_ENVIRONMENT (sd) == ALL_ENVIRONMENT) | |
260 | STATE_ENVIRONMENT (sd) = DEFAULT_ENVIRONMENT; | |
261 | ||
262 | ||
263 | /* set the alignment */ | |
264 | #if (WITH_TREE_PROPERTIES) | |
265 | if (current_alignment == 0) | |
266 | current_alignment = | |
267 | (tree_find_boolean_property(root, "/openprom/options/strict-alignment?") | |
268 | ? STRICT_ALIGNMENT | |
269 | : NONSTRICT_ALIGNMENT); | |
270 | #endif | |
271 | if (current_alignment == 0) | |
272 | current_alignment = WITH_ALIGNMENT; | |
273 | if (current_alignment == 0) | |
274 | current_alignment = WITH_DEFAULT_ALIGNMENT; | |
275 | ||
276 | /* verify the alignment */ | |
277 | if (CURRENT_ALIGNMENT == 0) | |
278 | { | |
279 | sim_io_eprintf (sd, "Target alignment unspecified\n"); | |
280 | return SIM_RC_FAIL; | |
281 | } | |
282 | if (CURRENT_ALIGNMENT != current_alignment) | |
283 | { | |
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)); | |
287 | return SIM_RC_FAIL; | |
288 | } | |
289 | ||
290 | #if defined (WITH_FLOATING_POINT) | |
291 | ||
292 | /* set the floating point */ | |
293 | if (current_floating_point == 0) | |
294 | current_floating_point = WITH_FLOATING_POINT; | |
295 | ||
296 | /* verify the floating point */ | |
297 | if (CURRENT_FLOATING_POINT == 0) | |
298 | { | |
299 | sim_io_eprintf (sd, "Target floating-point unspecified\n"); | |
300 | return SIM_RC_FAIL; | |
301 | } | |
302 | if (CURRENT_FLOATING_POINT != current_floating_point) | |
303 | { | |
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)); | |
307 | return SIM_RC_FAIL; | |
308 | } | |
309 | ||
310 | #endif | |
311 | return SIM_RC_OK; | |
312 | } | |
313 | ||
314 | ||
315 | void | |
316 | print_sim_config (SIM_DESC sd) | |
317 | { | |
318 | #if defined (__GNUC__) && defined (__VERSION__) | |
319 | sim_io_printf (sd, "Compiled by GCC %s on %s %s\n", | |
320 | __VERSION__, __DATE__, __TIME__); | |
321 | #else | |
322 | sim_io_printf (sd, "Compiled on %s %s\n", __DATE__, __TIME__); | |
323 | #endif | |
324 | ||
325 | sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n", | |
326 | config_byte_order_to_a (WITH_TARGET_BYTE_ORDER)); | |
327 | ||
328 | sim_io_printf (sd, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n", | |
329 | config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER)); | |
330 | ||
331 | sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n", | |
332 | config_byte_order_to_a (WITH_HOST_BYTE_ORDER)); | |
333 | ||
334 | sim_io_printf (sd, "WITH_STDIO = %s\n", | |
335 | config_stdio_to_a (WITH_STDIO)); | |
336 | ||
337 | sim_io_printf (sd, "WITH_TARGET_WORD_MSB = %d\n", | |
338 | WITH_TARGET_WORD_MSB); | |
339 | ||
340 | sim_io_printf (sd, "WITH_TARGET_WORD_BITSIZE = %d\n", | |
341 | WITH_TARGET_WORD_BITSIZE); | |
342 | ||
343 | sim_io_printf (sd, "WITH_TARGET_ADDRESS_BITSIZE = %d\n", | |
344 | WITH_TARGET_ADDRESS_BITSIZE); | |
345 | ||
346 | sim_io_printf (sd, "WITH_TARGET_CELL_BITSIZE = %d\n", | |
347 | WITH_TARGET_CELL_BITSIZE); | |
348 | ||
349 | sim_io_printf (sd, "WITH_TARGET_FLOATING_POINT_BITSIZE = %d\n", | |
350 | WITH_TARGET_FLOATING_POINT_BITSIZE); | |
351 | ||
352 | sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n", | |
353 | config_environment_to_a (WITH_ENVIRONMENT)); | |
354 | ||
355 | sim_io_printf (sd, "WITH_ALIGNMENT = %s\n", | |
356 | config_alignment_to_a (WITH_ALIGNMENT)); | |
357 | ||
358 | #if defined (WITH_DEFAULT_ALIGNMENT) | |
359 | sim_io_printf (sd, "WITH_DEFAULT_ALIGNMENT = %s\n", | |
360 | config_alignment_to_a (WITH_DEFAULT_ALIGNMENT)); | |
361 | #endif | |
362 | ||
363 | #if defined (WITH_XOR_ENDIAN) | |
364 | sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN); | |
365 | #endif | |
366 | ||
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)); | |
370 | #endif | |
371 | ||
372 | #if defined (WITH_SMP) | |
373 | sim_io_printf (sd, "WITH_SMP = %d\n", WITH_SMP); | |
374 | #endif | |
375 | ||
376 | #if defined (WITH_RESERVED_BITS) | |
377 | sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS); | |
378 | #endif | |
379 | ||
380 | #if defined (WITH_PROFILE) | |
381 | sim_io_printf (sd, "WITH_PROFILE = %d\n", WITH_PROFILE); | |
382 | #endif | |
383 | ||
384 | } |