OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [gdb-5.0/] [sim/] [common/] [sim-config.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.