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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [common/] [sim-model.c] - Blame information for rev 842

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 227 jeremybenn
/* Model support.
2
   Copyright (C) 1996, 1997, 1998, 2007, 2008, 2009, 2010
3
   Free Software Foundation, Inc.
4
   Contributed by Cygnus Support.
5
 
6
This file is part of GDB, the GNU debugger.
7
 
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 3 of the License, or
11
(at your option) any later version.
12
 
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
 
21
#include "sim-main.h"
22
#include "sim-model.h"
23
#include "libiberty.h"
24
#include "sim-options.h"
25
#include "sim-io.h"
26
#include "sim-assert.h"
27
#include "bfd.h"
28
 
29
static void model_set (sim_cpu *, const MODEL *);
30
 
31
static DECLARE_OPTION_HANDLER (model_option_handler);
32
 
33
static MODULE_INIT_FN sim_model_init;
34
 
35
#define OPTION_MODEL (OPTION_START + 0)
36
 
37
static const OPTION model_options[] = {
38
  { {"model", required_argument, NULL, OPTION_MODEL},
39
      '\0', "MODEL", "Specify model to simulate",
40
      model_option_handler },
41
  { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
42
};
43
 
44
static SIM_RC
45
model_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
46
                      char *arg, int is_command)
47
{
48
  switch (opt)
49
    {
50
    case OPTION_MODEL :
51
      {
52
        const MODEL *model = sim_model_lookup (arg);
53
        if (! model)
54
          {
55
            sim_io_eprintf (sd, "unknown model `%s'\n", arg);
56
            return SIM_RC_FAIL;
57
          }
58
        sim_model_set (sd, cpu, model);
59
        break;
60
      }
61
    }
62
 
63
  return SIM_RC_OK;
64
}
65
 
66
SIM_RC
67
sim_model_install (SIM_DESC sd)
68
{
69
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
70
 
71
  sim_add_option_table (sd, NULL, model_options);
72
  sim_module_add_init_fn (sd, sim_model_init);
73
 
74
  return SIM_RC_OK;
75
}
76
 
77
/* Subroutine of sim_model_set to set the model for one cpu.  */
78
 
79
static void
80
model_set (sim_cpu *cpu, const MODEL *model)
81
{
82
  CPU_MACH (cpu) = MODEL_MACH (model);
83
  CPU_MODEL (cpu) = model;
84
  (* MACH_INIT_CPU (MODEL_MACH (model))) (cpu);
85
  (* MODEL_INIT (model)) (cpu);
86
}
87
 
88
/* Set the current model of CPU to MODEL.
89
   If CPU is NULL, all cpus are set to MODEL.  */
90
 
91
void
92
sim_model_set (SIM_DESC sd, sim_cpu *cpu, const MODEL *model)
93
{
94
  if (! cpu)
95
    {
96
      int c;
97
 
98
      for (c = 0; c < MAX_NR_PROCESSORS; ++c)
99
        if (STATE_CPU (sd, c))
100
          model_set (STATE_CPU (sd, c), model);
101
    }
102
  else
103
    {
104
      model_set (cpu, model);
105
    }
106
}
107
 
108
/* Look up model named NAME.
109
   Result is pointer to MODEL entry or NULL if not found.  */
110
 
111
const MODEL *
112
sim_model_lookup (const char *name)
113
{
114
  const MACH **machp;
115
  const MODEL *model;
116
 
117
  for (machp = & sim_machs[0]; *machp != NULL; ++machp)
118
    {
119
      for (model = MACH_MODELS (*machp); MODEL_NAME (model) != NULL; ++model)
120
        {
121
          if (strcmp (MODEL_NAME (model), name) == 0)
122
            return model;
123
        }
124
    }
125
  return NULL;
126
}
127
 
128
/* Look up machine named NAME.
129
   Result is pointer to MACH entry or NULL if not found.  */
130
 
131
const MACH *
132
sim_mach_lookup (const char *name)
133
{
134
  const MACH **machp;
135
 
136
  for (machp = & sim_machs[0]; *machp != NULL; ++machp)
137
    {
138
      if (strcmp (MACH_NAME (*machp), name) == 0)
139
        return *machp;
140
    }
141
  return NULL;
142
}
143
 
144
/* Look up a machine via its bfd name.
145
   Result is pointer to MACH entry or NULL if not found.  */
146
 
147
const MACH *
148
sim_mach_lookup_bfd_name (const char *name)
149
{
150
  const MACH **machp;
151
 
152
  for (machp = & sim_machs[0]; *machp != NULL; ++machp)
153
    {
154
      if (strcmp (MACH_BFD_NAME (*machp), name) == 0)
155
        return *machp;
156
    }
157
  return NULL;
158
}
159
 
160
/* Initialize model support.  */
161
 
162
static SIM_RC
163
sim_model_init (SIM_DESC sd)
164
{
165
  SIM_CPU *cpu;
166
 
167
  /* If both cpu model and state architecture are set, ensure they're
168
     compatible.  If only one is set, set the other.  If neither are set,
169
     use the default model.  STATE_ARCHITECTURE is the bfd_arch_info data
170
     for the selected "mach" (bfd terminology).  */
171
 
172
  /* Only check cpu 0.  STATE_ARCHITECTURE is for that one only.  */
173
  /* ??? At present this only supports homogeneous multiprocessors.  */
174
  cpu = STATE_CPU (sd, 0);
175
 
176
  if (! STATE_ARCHITECTURE (sd)
177
      && ! CPU_MACH (cpu))
178
    {
179
      /* Set the default model.  */
180
      const MODEL *model = sim_model_lookup (WITH_DEFAULT_MODEL);
181
      sim_model_set (sd, NULL, model);
182
    }
183
 
184
  if (STATE_ARCHITECTURE (sd)
185
      && CPU_MACH (cpu))
186
    {
187
      if (strcmp (STATE_ARCHITECTURE (sd)->printable_name,
188
                  MACH_BFD_NAME (CPU_MACH (cpu))) != 0)
189
        {
190
          sim_io_eprintf (sd, "invalid model `%s' for `%s'\n",
191
                          MODEL_NAME (CPU_MODEL (cpu)),
192
                          STATE_ARCHITECTURE (sd)->printable_name);
193
          return SIM_RC_FAIL;
194
        }
195
    }
196
  else if (STATE_ARCHITECTURE (sd))
197
    {
198
      /* Use the default model for the selected machine.
199
         The default model is the first one in the list.  */
200
      const MACH *mach = sim_mach_lookup_bfd_name (STATE_ARCHITECTURE (sd)->printable_name);
201
 
202
      if (mach == NULL)
203
        {
204
          sim_io_eprintf (sd, "unsupported machine `%s'\n",
205
                          STATE_ARCHITECTURE (sd)->printable_name);
206
          return SIM_RC_FAIL;
207
        }
208
      sim_model_set (sd, NULL, MACH_MODELS (mach));
209
    }
210
  else
211
    {
212
      STATE_ARCHITECTURE (sd) = bfd_scan_arch (MACH_BFD_NAME (CPU_MACH (cpu)));
213
    }
214
 
215
  return SIM_RC_OK;
216
}

powered by: WebSVN 2.1.0

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