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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [sim/] [scarts_32/] [scarts_32-sim.c] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 jlechner
/* SCARTS (32-bit) target-dependent code for the GNU simulator.
2
   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3
   Free Software Foundation, Inc.
4
   Contributed by Martin Walter <mwalter@opencores.org>
5
 
6
   This file is part of the GNU simulators.
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
 
22
#ifndef PARAMS
23
#define PARAMS(ARGS) ARGS
24
#endif
25
 
26
#include <signal.h>
27
#include <stdlib.h>
28
#include <gdb/callback.h>
29
#include <gdb/remote-sim.h>
30
 
31
#include "scarts_32-tdep.h"
32
#include "scarts_32-sim.h"
33
#include "scarts_32-iss.h"
34
#include "scarts_32-mad.h"
35
 
36
#ifdef HAVE_CONFIG_H
37
#include "tconfig.h"
38
#endif
39
 
40
volatile int async_sim_stop = 0;
41
struct sim_state scarts_sim_state = {NULL, sim_stopped, SIGTRAP};
42
 
43
static host_callback *scarts_callback = NULL;
44
static int _sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length);
45
 
46
static int
47
_sim_write (SIM_DESC       sd,
48
            SIM_ADDR       mem,
49
            unsigned char *buf,
50
            int            length)
51
{
52
  int i;
53
 
54
  for (i = 0; i < length; ++i)
55
  {
56
    if (scarts_mem_write (mem + i, buf[i]) == 0)
57
      return i;
58
  }
59
 
60
  return length;
61
}
62
 
63
/* Destory a simulator instance.
64
 
65
   QUITTING is non-zero if we cannot hang on errors.
66
 
67
   This may involve freeing target memory and closing any open files
68
   and mmap'd areas.  You cannot assume sim_kill has already been
69
   called. */
70
void
71
sim_close (SIM_DESC sd,
72
           int      quitting)
73
{
74
  return;
75
}
76
 
77
/* Prepare to run the simulated program.
78
 
79
   ABFD, if not NULL, provides initial processor state information.
80
   ARGV and ENV, if non NULL, are NULL terminated lists of pointers.
81
 
82
   Hardware simulator: This function shall initialize the processor
83
   registers to a known value.  The program counter and possibly stack
84
   pointer shall be set using information obtained from ABFD (or
85
   hardware reset defaults).  ARGV and ENV, dependant on the target
86
   ABI, may be written to memory.
87
 
88
   Process simulator: After a call to this function, a new process
89
   instance shall exist. The TEXT, DATA, BSS and stack regions shall
90
   all be initialized, ARGV and ENV shall be written to process
91
   address space (according to the applicable ABI) and the program
92
   counter and stack pointer set accordingly. */
93
SIM_RC
94
sim_create_inferior (SIM_DESC     sd,
95
                     struct bfd  *abfd,
96
                     char       **argv,
97
                     char       **env)
98
{
99
  return SIM_RC_OK;
100
}
101
 
102
/* Passthru for other commands that the simulator might support.
103
   Simulators should be prepared to deal with any combination of NULL
104
   or empty CMD. */
105
void
106
sim_do_command (SIM_DESC  sd,
107
                char     *cmd)
108
{
109
  return;
110
}
111
 
112
/* Fetch register REGNO storing its raw (target endian) value in the
113
   LENGTH byte buffer BUF. Return the actual size of the register or
114
   zero if REGNO is not applicable.
115
 
116
   If LENGTH does not match the size of REGNO no data is transfered
117
   (the actual register size is still returned). */
118
int
119
sim_fetch_register (SIM_DESC       sd,
120
                    int            regno,
121
                    unsigned char *buf,
122
                    int            length)
123
{
124
  if (regno < 0 || regno >= SCARTS_TOTAL_NUM_REGS)
125
    return 0;
126
 
127
  /* All registers are SCARTS_WORD_SIZE bytes long. */
128
  if (length != SCARTS_WORD_SIZE)
129
    return SCARTS_WORD_SIZE;
130
 
131
  *((uint32_t *) buf) = scarts_regfile_read (regno);
132
  return SCARTS_WORD_SIZE;
133
}
134
 
135
/* Print whatever statistics the simulator has collected.
136
   VERBOSE is currently unused and must always be zero. */
137
void
138
sim_info (SIM_DESC sd,
139
          int      verbose)
140
{
141
  return;
142
}
143
 
144
/* Load program PROG into the simulators memory.
145
 
146
   If ABFD is non-NULL, the bfd for the file has already been opened.
147
   The result is a return code indicating success.
148
 
149
   Hardware simulator: Normally, each program section is written into
150
   memory according to that sections LMA using physical (direct)
151
   addressing.  The exception being systems, such as PPC/CHRP, which
152
   support more complicated program loaders.  A call to this function
153
   should not effect the state of the processor registers.  Multiple
154
   calls to this function are permitted and have an accumulative
155
   effect. */
156
SIM_RC
157
sim_load (SIM_DESC    sd,
158
          char       *prog,
159
          struct bfd *abfd,
160
          int         from_tty)
161
{
162
#ifndef SIM_HANDLES_LMA
163
#define SIM_HANDLES_LMA 0
164
#endif
165
 
166
  sim_load_file (sd, "", scarts_callback, prog, abfd, 1, SIM_HANDLES_LMA, _sim_write);
167
  return SIM_RC_OK;
168
}
169
 
170
/* Create a fully initialized simulator instance.
171
 
172
   (This function is called when the simulator is selected from the
173
   gdb command line.)
174
 
175
   KIND specifies how the simulator shall be used.  Currently there
176
   are only two kinds: stand-alone and debug.
177
 
178
   CALLBACK specifies a standard host callback (defined in callback.h).
179
 
180
   ABFD, when non NULL, designates a target program.  The program is
181
   not loaded.
182
 
183
   ARGV is a standard ARGV pointer such as that passed from the
184
   command line.  The syntax of the argument list is is assumed to be
185
   ``SIM-PROG { SIM-OPTION } [ TARGET-PROGRAM { TARGET-OPTION } ]''.
186
   The trailing TARGET-PROGRAM and args are only valid for a
187
   stand-alone simulator.
188
 
189
   On success, the result is a non NULL descriptor that shall be
190
   passed to the other sim_foo functions.  While the simulator
191
   configuration can be parameterized by (in decreasing precedence)
192
   ARGV's SIM-OPTION, ARGV's TARGET-PROGRAM and the ABFD argument, the
193
   successful creation of the simulator shall not dependent on the
194
   presence of any of these arguments/options.
195
 
196
   Hardware simulator: The created simulator shall be sufficiently
197
   initialized to handle, with out restrictions any client requests
198
   (including memory reads/writes, register fetch/stores and a
199
   resume). */
200
SIM_DESC
201
sim_open (SIM_OPEN_KIND   kind,
202
          host_callback  *callback,
203
          struct bfd     *abfd,
204
          char          **argv)
205
{
206
  scarts_callback = callback;
207
 
208
  scarts_init ();
209
  return &scarts_sim_state;
210
}
211
 
212
/* Fetch LENGTH bytes of the simulated program's memory.  Start fetch
213
   at virtual address MEM and store in BUF.  Result is number of bytes
214
   read, or zero if error.  */
215
int
216
sim_read (SIM_DESC       sd,
217
          SIM_ADDR       mem,
218
          unsigned char *buf,
219
          int            length)
220
{
221
  int i;
222
  uint8_t temp;
223
 
224
  for (i = 0; i < length; ++i)
225
  {
226
    if (scarts_mem_read (mem + i, &temp) == 0)
227
      return i;
228
 
229
    buf[i] = temp;
230
  }
231
 
232
  return length;
233
}
234
 
235
/* Run (or resume) the simulated program.
236
 
237
   STEP, when non-zero indicates that only a single simulator cycle
238
   should be emulated.
239
 
240
   SIGGNAL, if non-zero is a (HOST) SIGRC value indicating the type of
241
   event (hardware interrupt, signal) to be delivered to the simulated
242
   program.
243
 
244
   Hardware simulator: If the SIGRC value returned by
245
   sim_stop_reason() is passed back to the simulator via SIGGNAL then
246
   the hardware simulator shall correctly deliver the hardware event
247
   indicated by that signal.  If a value of zero is passed in then the
248
   simulation will continue as if there were no outstanding signal.
249
   The effect of any other SIGGNAL value is is implementation
250
   dependant.
251
 
252
   Process simulator: If SIGRC is non-zero then the corresponding
253
   signal is delivered to the simulated program and execution is then
254
   continued.  A zero SIGRC value indicates that the program should
255
   continue as normal. */
256
void
257
sim_resume (SIM_DESC sd,
258
            int      step,
259
            int      siggnal)
260
{
261
  uint16_t insn;
262
  uint32_t addr;
263
  scarts_codemem_read_fptr_t read_fptr;
264
  scarts_codemem_write_fptr_t write_fptr;
265
 
266
  async_sim_stop = 0;
267
 
268
  while (!async_sim_stop)
269
  {
270
    insn = 0;
271
 
272
    /* Read the current instruction from the PC. */
273
    scarts_codemem_vma_decode (scarts_regfile_read (SCARTS_PC_REGNUM), &read_fptr, &write_fptr, &addr);
274
    (void) (*read_fptr) (addr, &insn);
275
 
276
    /* The SCARTS_ILLOP_INSN is interpreted as a breakpoint. */
277
    if (insn == SCARTS_ILLOP_INSN)
278
    {
279
      sd->sim_stop_reason = sim_stopped;
280
      sd->sigrc = SIGTRAP;
281
      return;
282
    }
283
 
284
    sd->sigrc = scarts_tick();
285
 
286
    if (step || sd->sigrc != 0)
287
      /* Execute only a single simulator step. */
288
      break;
289
  }
290
 
291
  async_sim_stop = 0;
292
 
293
  sd->sim_stop_reason = sim_stopped;
294
  sd->sigrc = (sd->sigrc != 0 ? sd->sigrc : SIGTRAP);
295
}
296
 
297
void
298
sim_set_callbacks (host_callback *callback)
299
{
300
  return;
301
}
302
 
303
void
304
sim_size (int i)
305
{
306
  return;
307
}
308
 
309
/* Asynchronous request to stop the simulation.
310
   A nonzero return indicates that the simulator is able to handle
311
   the request */
312
int
313
sim_stop (SIM_DESC sd)
314
{
315
  async_sim_stop = 1;
316
  return sim_stopped;
317
}
318
 
319
/* Fetch the REASON why the program stopped.
320
 
321
   SIM_EXITED: The program has terminated. SIGRC indicates the target
322
   dependant exit status.
323
 
324
   SIM_STOPPED: The program has stopped.  SIGRC uses the host's signal
325
   numbering as a way of identifying the reaon: program interrupted by
326
   user via a sim_stop request (SIGINT); a breakpoint instruction
327
   (SIGTRAP); a completed single step (SIGTRAP); an internal error
328
   condition (SIGABRT); an illegal instruction (SIGILL); Access to an
329
   undefined memory region (SIGSEGV); Mis-aligned memory access
330
   (SIGBUS).  For some signals information in addition to the signal
331
   number may be retained by the simulator (e.g. offending address),
332
   that information is not directly accessable via this interface.
333
 
334
   SIM_SIGNALLED: The program has been terminated by a signal. The
335
   simulator has encountered target code that causes the the program
336
   to exit with signal SIGRC.
337
 
338
   SIM_RUNNING, SIM_POLLING: The return of one of these values
339
   indicates a problem internal to the simulator. */
340
void
341
sim_stop_reason (SIM_DESC       sd,
342
                 enum sim_stop *reason,
343
                 int           *sigrc)
344
{
345
  *reason = sd->sim_stop_reason;
346
  *sigrc  = sd->sigrc;
347
}
348
 
349
/* Store register REGNO from the raw (target endian) value in BUF.
350
   Return the actual size of the register or zero if REGNO is not
351
   applicable.
352
 
353
   If LENGTH does not match the size of REGNO no data is transfered
354
   (the actual register size is still returned). */
355
int
356
sim_store_register (SIM_DESC       sd,
357
                    int            regno,
358
                    unsigned char *buf,
359
                    int            length)
360
{
361
  if (regno < 0 || regno >= SCARTS_TOTAL_NUM_REGS)
362
    return 0;
363
 
364
  /* All registers are SCARTS_WORD_SIZE bytes long. */
365
  if (length != SCARTS_WORD_SIZE)
366
    return SCARTS_WORD_SIZE;
367
 
368
  scarts_regfile_write (regno, *((uint32_t *) buf));
369
  return SCARTS_WORD_SIZE;
370
}
371
 
372
int
373
sim_trace (SIM_DESC sd)
374
{
375
  return 0;
376
}
377
 
378
/* Store LENGTH bytes from BUF into the simulated program's
379
   memory. Store bytes starting at virtual address MEM. Result is
380
   number of bytes write, or zero if error.  */
381
int
382
sim_write (SIM_DESC       sd,
383
           SIM_ADDR       mem,
384
           unsigned char *buf,
385
           int            length)
386
{
387
  return _sim_write (sd, mem, buf, length);
388
}
389
 

powered by: WebSVN 2.1.0

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