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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [sim/] [common/] [sim-engine.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
/* Generic simulator halt/restart.
2
   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3
   Contributed by Cygnus Support.
4
 
5
This file is part of GDB, the GNU debugger.
6
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2, or (at your option)
10
any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License along
18
with this program; if not, write to the Free Software Foundation, Inc.,
19
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
 
21
#include <stdio.h>
22
 
23
#include "sim-main.h"
24
#include "sim-assert.h"
25
 
26
/* Get the run state.
27
   REASON/SIGRC are the values returned by sim_stop_reason.
28
   ??? Should each cpu have its own copy?  */
29
 
30
void
31
sim_engine_get_run_state (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
32
{
33
  sim_engine *engine = STATE_ENGINE (sd);
34
  ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
35
  *reason = engine->reason;
36
  *sigrc = engine->sigrc;
37
}
38
 
39
/* Set the run state to REASON/SIGRC.
40
   REASON/SIGRC are the values returned by sim_stop_reason.
41
   ??? Should each cpu have its own copy?  */
42
 
43
void
44
sim_engine_set_run_state (SIM_DESC sd, enum sim_stop reason, int sigrc)
45
{
46
  sim_engine *engine = STATE_ENGINE (sd);
47
  ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
48
  engine->reason = reason;
49
  engine->sigrc = sigrc;
50
}
51
 
52
/* Generic halt */
53
 
54
void
55
sim_engine_halt (SIM_DESC sd,
56
                 sim_cpu *last_cpu,
57
                 sim_cpu *next_cpu, /* NULL - use default */
58
                 sim_cia cia,
59
                 enum sim_stop reason,
60
                 int sigrc)
61
{
62
  sim_engine *engine = STATE_ENGINE (sd);
63
  ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
64
  if (engine->jmpbuf != NULL)
65
    {
66
      jmp_buf *halt_buf = engine->jmpbuf;
67
      engine->last_cpu = last_cpu;
68
      engine->next_cpu = next_cpu;
69
      engine->reason = reason;
70
      engine->sigrc = sigrc;
71
 
72
      SIM_ENGINE_HALT_HOOK (sd, last_cpu, cia);
73
 
74
#ifdef SIM_CPU_EXCEPTION_SUSPEND
75
      if (last_cpu != NULL && reason != sim_exited)
76
        SIM_CPU_EXCEPTION_SUSPEND (sd, last_cpu, sim_signal_to_host (sd, sigrc));
77
#endif
78
 
79
      longjmp (*halt_buf, sim_engine_halt_jmpval);
80
    }
81
  else
82
    sim_io_error (sd, "sim_halt - bad long jump");
83
}
84
 
85
 
86
/* Generic restart */
87
 
88
void
89
sim_engine_restart (SIM_DESC sd,
90
                    sim_cpu *last_cpu,
91
                    sim_cpu *next_cpu,
92
                    sim_cia cia)
93
{
94
  sim_engine *engine = STATE_ENGINE (sd);
95
  ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
96
  if (engine->jmpbuf != NULL)
97
    {
98
      jmp_buf *halt_buf = engine->jmpbuf;
99
      engine->last_cpu = last_cpu;
100
      engine->next_cpu = next_cpu;
101
      SIM_ENGINE_RESTART_HOOK (sd, last_cpu, cia);
102
      longjmp (*halt_buf, sim_engine_restart_jmpval);
103
    }
104
  else
105
    sim_io_error (sd, "sim_restart - bad long jump");
106
}
107
 
108
 
109
/* Generic error code */
110
 
111
void
112
sim_engine_vabort (SIM_DESC sd,
113
                   sim_cpu *cpu,
114
                   sim_cia cia,
115
                   const char *fmt,
116
                   va_list ap)
117
{
118
  ASSERT (sd == NULL || STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
119
  if (sd == NULL)
120
    {
121
      vfprintf (stderr, fmt, ap);
122
      fprintf (stderr, "\nQuit\n");
123
      abort ();
124
    }
125
  else if (STATE_ENGINE (sd)->jmpbuf == NULL)
126
    {
127
      sim_io_evprintf (sd, fmt, ap);
128
      sim_io_eprintf (sd, "\n");
129
      sim_io_error (sd, "Quit Simulator");
130
    }
131
  else
132
    {
133
      sim_io_evprintf (sd, fmt, ap);
134
      sim_io_eprintf (sd, "\n");
135
      sim_engine_halt (sd, cpu, NULL, cia, sim_stopped, SIM_SIGABRT);
136
    }
137
}
138
 
139
void
140
sim_engine_abort (SIM_DESC sd,
141
                  sim_cpu *cpu,
142
                  sim_cia cia,
143
                  const char *fmt,
144
                  ...)
145
{
146
  va_list ap;
147
  ASSERT (sd == NULL || STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
148
  va_start(ap, fmt);
149
  sim_engine_vabort (sd, cpu, cia, fmt, ap);
150
  va_end (ap);
151
}
152
 
153
 
154
/* Generic next/last cpu */
155
 
156
int
157
sim_engine_last_cpu_nr (SIM_DESC sd)
158
{
159
  sim_engine *engine = STATE_ENGINE (sd);
160
  if (engine->last_cpu != NULL)
161
    return engine->last_cpu - STATE_CPU (sd, 0);
162
  else
163
    return MAX_NR_PROCESSORS;
164
}
165
 
166
int
167
sim_engine_next_cpu_nr (SIM_DESC sd)
168
{
169
  sim_engine *engine = STATE_ENGINE (sd);
170
  if (engine->next_cpu != NULL)
171
    return engine->next_cpu - STATE_CPU (sd, 0);
172
  else
173
    return sim_engine_last_cpu_nr (sd) + 1;
174
}
175
 
176
int
177
sim_engine_nr_cpus (SIM_DESC sd)
178
{
179
  sim_engine *engine = STATE_ENGINE (sd);
180
  return engine->nr_cpus;
181
}
182
 
183
 
184
 
185
 
186
/* Initialization */
187
 
188
static SIM_RC
189
sim_engine_init (SIM_DESC sd)
190
{
191
  /* initialize the start/stop/resume engine */
192
  sim_engine *engine = STATE_ENGINE (sd);
193
  engine->jmpbuf = NULL;
194
  engine->last_cpu = NULL;
195
  engine->next_cpu = NULL;
196
  engine->nr_cpus = MAX_NR_PROCESSORS;
197
  engine->reason = sim_running;
198
  engine->sigrc = 0;
199
  engine->stepper = NULL; /* sim_events_init will clean it up */
200
  return SIM_RC_OK;
201
}
202
 
203
 
204
SIM_RC
205
sim_engine_install (SIM_DESC sd)
206
{
207
  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
208
  sim_module_add_init_fn (sd, sim_engine_init);
209
  return SIM_RC_OK;
210
}

powered by: WebSVN 2.1.0

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