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 */ | |
149 | if (STATE_PROG_BFD (sd) == NULL) | |
150 | prefered_target_byte_order = 0; | |
151 | else | |
152 | prefered_target_byte_order = (bfd_little_endian(STATE_PROG_BFD (sd)) | |
153 | ? LITTLE_ENDIAN | |
154 | : BIG_ENDIAN); | |
155 | ||
156 | /* set the host byte order */ | |
157 | current_host_byte_order = 1; | |
158 | if (*(char*)(¤t_host_byte_order)) | |
159 | current_host_byte_order = LITTLE_ENDIAN; | |
160 | else | |
161 | current_host_byte_order = BIG_ENDIAN; | |
162 | ||
163 | /* verify the host byte order */ | |
164 | if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order) | |
165 | { | |
166 | sim_io_eprintf (sd, "host (%s) and configured (%s) byte order in conflict", | |
167 | config_byte_order_to_a (current_host_byte_order), | |
168 | config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER)); | |
169 | return SIM_RC_FAIL; | |
170 | } | |
171 | ||
172 | ||
173 | /* set the target byte order */ | |
174 | #if (WITH_TREE_PROPERTIES) | |
175 | if (current_target_byte_order == 0) | |
176 | current_target_byte_order | |
177 | = (tree_find_boolean_property (root, "/options/little-endian?") | |
178 | ? LITTLE_ENDIAN | |
179 | : BIG_ENDIAN); | |
180 | #endif | |
181 | if (current_target_byte_order == 0 | |
182 | && prefered_target_byte_order != 0) | |
183 | current_target_byte_order = prefered_target_byte_order; | |
184 | if (current_target_byte_order == 0) | |
185 | current_target_byte_order = WITH_TARGET_BYTE_ORDER; | |
186 | if (current_target_byte_order == 0) | |
187 | current_target_byte_order = WITH_DEFAULT_TARGET_BYTE_ORDER; | |
188 | ||
189 | /* verify the target byte order */ | |
190 | if (CURRENT_TARGET_BYTE_ORDER == 0) | |
191 | { | |
192 | sim_io_eprintf (sd, "Target byte order unspecified\n"); | |
193 | return SIM_RC_FAIL; | |
194 | } | |
195 | if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order) | |
196 | sim_io_eprintf (sd, "Target (%s) and configured (%s) byte order in conflict\n", | |
197 | config_byte_order_to_a (current_target_byte_order), | |
198 | config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER)); | |
199 | if (prefered_target_byte_order != 0 | |
200 | && CURRENT_TARGET_BYTE_ORDER != prefered_target_byte_order) | |
201 | sim_io_eprintf (sd, "Target (%s) and specified (%s) byte order in conflict\n", | |
202 | config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER), | |
203 | config_byte_order_to_a (prefered_target_byte_order)); | |
204 | ||
205 | ||
206 | /* set the stdio */ | |
207 | if (current_stdio == 0) | |
208 | current_stdio = WITH_STDIO; | |
209 | if (current_stdio == 0) | |
210 | current_stdio = DO_USE_STDIO; | |
211 | ||
212 | /* verify the stdio */ | |
213 | if (CURRENT_STDIO == 0) | |
214 | { | |
215 | sim_io_eprintf (sd, "Target standard IO unspecified\n"); | |
216 | return SIM_RC_FAIL; | |
217 | } | |
218 | if (CURRENT_STDIO != current_stdio) | |
219 | { | |
220 | sim_io_eprintf (sd, "Target (%s) and configured (%s) standard IO in conflict\n", | |
221 | config_stdio_to_a (CURRENT_STDIO), | |
222 | config_stdio_to_a (current_stdio)); | |
223 | return SIM_RC_FAIL; | |
224 | } | |
225 | ||
226 | ||
227 | /* check the value of MSB */ | |
228 | if (WITH_TARGET_WORD_MSB != 0 | |
229 | && WITH_TARGET_WORD_MSB != (WITH_TARGET_WORD_BITSIZE - 1)) | |
230 | { | |
231 | sim_io_eprintf (sd, "Target bitsize (%d) contradicts target most significant bit (%d)\n", | |
232 | WITH_TARGET_WORD_BITSIZE, WITH_TARGET_WORD_MSB); | |
233 | return SIM_RC_FAIL; | |
234 | } | |
235 | ||
236 | ||
237 | /* set the environment */ | |
238 | #if (WITH_TREE_PROPERTIES) | |
239 | if (STATE_ENVIRONMENT (sd) == ALL_ENVIRONMENT) | |
240 | { | |
241 | const char *env = | |
242 | tree_find_string_property(root, "/openprom/options/env"); | |
243 | STATE_ENVIRONMENT (sd) = ((strcmp(env, "user") == 0 | |
244 | || strcmp(env, "uea") == 0) | |
245 | ? USER_ENVIRONMENT | |
246 | : (strcmp(env, "virtual") == 0 | |
247 | || strcmp(env, "vea") == 0) | |
248 | ? VIRTUAL_ENVIRONMENT | |
249 | : (strcmp(env, "operating") == 0 | |
250 | || strcmp(env, "oea") == 0) | |
251 | ? OPERATING_ENVIRONMENT | |
252 | : ALL_ENVIRONMENT); | |
253 | } | |
254 | #endif | |
255 | if (STATE_ENVIRONMENT (sd) == ALL_ENVIRONMENT) | |
256 | STATE_ENVIRONMENT (sd) = DEFAULT_ENVIRONMENT; | |
257 | ||
258 | ||
259 | /* set the alignment */ | |
260 | #if (WITH_TREE_PROPERTIES) | |
261 | if (current_alignment == 0) | |
262 | current_alignment = | |
263 | (tree_find_boolean_property(root, "/openprom/options/strict-alignment?") | |
264 | ? STRICT_ALIGNMENT | |
265 | : NONSTRICT_ALIGNMENT); | |
266 | #endif | |
267 | if (current_alignment == 0) | |
268 | current_alignment = WITH_ALIGNMENT; | |
269 | if (current_alignment == 0) | |
270 | current_alignment = WITH_DEFAULT_ALIGNMENT; | |
271 | ||
272 | /* verify the alignment */ | |
273 | if (CURRENT_ALIGNMENT == 0) | |
274 | { | |
275 | sim_io_eprintf (sd, "Target alignment unspecified\n"); | |
276 | return SIM_RC_FAIL; | |
277 | } | |
278 | if (CURRENT_ALIGNMENT != current_alignment) | |
279 | { | |
280 | sim_io_eprintf (sd, "Target (%s) and configured (%s) alignment in conflict\n", | |
281 | config_alignment_to_a (CURRENT_ALIGNMENT), | |
282 | config_alignment_to_a (current_alignment)); | |
283 | return SIM_RC_FAIL; | |
284 | } | |
285 | ||
286 | #if defined (WITH_FLOATING_POINT) | |
287 | ||
288 | /* set the floating point */ | |
289 | if (current_floating_point == 0) | |
290 | current_floating_point = WITH_FLOATING_POINT; | |
291 | ||
292 | /* verify the floating point */ | |
293 | if (CURRENT_FLOATING_POINT == 0) | |
294 | { | |
295 | sim_io_eprintf (sd, "Target floating-point unspecified\n"); | |
296 | return SIM_RC_FAIL; | |
297 | } | |
298 | if (CURRENT_FLOATING_POINT != current_floating_point) | |
299 | { | |
300 | sim_io_eprintf (sd, "Target (%s) and configured (%s) floating-point in conflict\n", | |
301 | config_alignment_to_a (CURRENT_FLOATING_POINT), | |
302 | config_alignment_to_a (current_floating_point)); | |
303 | return SIM_RC_FAIL; | |
304 | } | |
305 | ||
306 | #endif | |
307 | return SIM_RC_OK; | |
308 | } | |
309 | ||
310 | ||
311 | void | |
312 | print_sim_config (SIM_DESC sd) | |
313 | { | |
314 | #if defined (__GNUC__) && defined (__VERSION__) | |
315 | sim_io_printf (sd, "Compiled by GCC %s on %s %s\n", | |
316 | __VERSION__, __DATE__, __TIME__); | |
317 | #else | |
318 | sim_io_printf (sd, "Compiled on %s %s\n", __DATE__, __TIME__); | |
319 | #endif | |
320 | ||
321 | sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n", | |
322 | config_byte_order_to_a (WITH_TARGET_BYTE_ORDER)); | |
323 | ||
324 | sim_io_printf (sd, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n", | |
325 | config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER)); | |
326 | ||
327 | sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n", | |
328 | config_byte_order_to_a (WITH_HOST_BYTE_ORDER)); | |
329 | ||
330 | sim_io_printf (sd, "WITH_STDIO = %s\n", | |
331 | config_stdio_to_a (WITH_STDIO)); | |
332 | ||
333 | sim_io_printf (sd, "WITH_TARGET_WORD_MSB = %d\n", | |
334 | WITH_TARGET_WORD_MSB); | |
335 | ||
336 | sim_io_printf (sd, "WITH_TARGET_WORD_BITSIZE = %d\n", | |
337 | WITH_TARGET_WORD_BITSIZE); | |
338 | ||
339 | sim_io_printf (sd, "WITH_TARGET_ADDRESS_BITSIZE = %d\n", | |
340 | WITH_TARGET_ADDRESS_BITSIZE); | |
341 | ||
342 | sim_io_printf (sd, "WITH_TARGET_CELL_BITSIZE = %d\n", | |
343 | WITH_TARGET_CELL_BITSIZE); | |
344 | ||
345 | sim_io_printf (sd, "WITH_TARGET_FLOATING_POINT_BITSIZE = %d\n", | |
346 | WITH_TARGET_FLOATING_POINT_BITSIZE); | |
347 | ||
348 | sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n", | |
349 | config_environment_to_a (WITH_ENVIRONMENT)); | |
350 | ||
351 | sim_io_printf (sd, "WITH_ALIGNMENT = %s\n", | |
352 | config_alignment_to_a (WITH_ALIGNMENT)); | |
353 | ||
354 | #if defined (WITH_DEFAULT_ALIGNMENT) | |
355 | sim_io_printf (sd, "WITH_DEFAULT_ALIGNMENT = %s\n", | |
356 | config_alignment_to_a (WITH_DEFAULT_ALIGNMENT)); | |
357 | #endif | |
358 | ||
359 | #if defined (WITH_XOR_ENDIAN) | |
360 | sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN); | |
361 | #endif | |
362 | ||
363 | #if defined (WITH_FLOATING_POINT) | |
364 | sim_io_printf (sd, "WITH_FLOATING_POINT = %s\n", | |
365 | config_floating_point_to_a (WITH_FLOATING_POINT)); | |
366 | #endif | |
367 | ||
368 | #if defined (WITH_SMP) | |
369 | sim_io_printf (sd, "WITH_SMP = %d\n", WITH_SMP); | |
370 | #endif | |
371 | ||
372 | #if defined (WITH_RESERVED_BITS) | |
373 | sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS); | |
374 | #endif | |
375 | ||
376 | #if defined (WITH_PROFILE) | |
377 | sim_io_printf (sd, "WITH_PROFILE = %d\n", WITH_PROFILE); | |
378 | #endif | |
379 | ||
380 | } |