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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [sim/] [or32/] [wrapper.c] - Blame information for rev 855

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 147 jeremybenn
/* GDB Simulator wrapper for Or1ksim, the OpenRISC architectural simulator
2
 
3
   Copyright 1988-2008, Free Software Foundation, Inc.
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of GDB.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
 
23
/*---------------------------------------------------------------------------*/
24
/* This is a wrapper for Or1ksim, suitable for use as a GDB simulator.
25
 
26
   The code tries to follow the GDB coding style.
27
 
28
   Commenting is Doxygen compatible.                                         */
29
/*---------------------------------------------------------------------------*/
30
 
31
#include <errno.h>
32
#include <stdlib.h>
33
#include <stdio.h>
34
#include <signal.h>
35 225 jeremybenn
#include <string.h>
36 147 jeremybenn
#include <sys/socket.h>
37
#include <sys/types.h>
38
#include <sys/un.h>
39
#include <unistd.h>
40
 
41
#include "ansidecl.h"
42
#include "gdb/callback.h"
43
#include "gdb/remote-sim.h"
44
#include "sim-utils.h"
45
#include "targ-vals.h"
46
 
47
#include "or1ksim.h"
48
#include "or32sim.h"
49
 
50
 
51
/* ------------------------------------------------------------------------- */
52
/*!Create a fully initialized simulator instance.
53
 
54
   This function is called when the simulator is selected from the gdb command
55
   line.
56
 
57
   While the simulator configuration can be parameterized by (in decreasing
58
   precedence) argv's SIM-OPTION, argv's TARGET-PROGRAM and the abfd argument,
59
   the successful creation of the simulator shall not dependent on the
60
   presence of any of these arguments/options.
61
 
62
   For a hardware simulator the created simulator shall be sufficiently
63
   initialized to handle, without restrictions any client requests (including
64
   memory reads/writes, register fetch/stores and a resume).
65
 
66
   For a process simulator, the process is not created until a call to
67
   sim_create_inferior.
68
 
69 225 jeremybenn
   We do the following on a first call.
70
   - parse the options
71
   -
72
   @todo Eventually we should use the option parser built into the GDB
73
         simulator (see common/sim-options.h). However since this is minimally
74
         documented, and we have only the one option, for now we do it
75
         ourselves.
76 147 jeremybenn
 
77
   @note We seem to capable of being called twice. We use the static
78
         "global_sd" variable to keep track of this. Second and subsequent
79
         calls do nothing, but return the previously opened simulator
80
         description.
81
 
82
   @param[in] kind  Specifies how the simulator shall be used.  Currently
83
                    there are only two kinds: stand-alone and debug.
84
 
85
   @param[in] callback  Specifies a standard host callback (defined in
86
                        callback.h).
87
 
88
   @param[in] abfd      When non NULL, designates a target program.  The
89
                        program is not loaded.
90
 
91
   @param[in] argv      A standard ARGV pointer such as that passed from the
92
                        command line.  The syntax of the argument list is is
93
                        assumed to be ``SIM-PROG { SIM-OPTION } [
94
                        TARGET-PROGRAM { TARGET-OPTION } ]''.
95
 
96
                        The trailing TARGET-PROGRAM and args are only valid
97
                        for a stand-alone simulator.
98
 
99
                        The argument list is null terminated!
100
 
101
   @return On success, the result is a non NULL descriptor that shall be
102
           passed to the other sim_foo functions.                            */
103
/* ------------------------------------------------------------------------- */
104
SIM_DESC
105
sim_open (SIM_OPEN_KIND                kind,
106
          struct host_callback_struct *callback,
107
          struct bfd                  *abfd,
108
          char                        *argv[])
109
{
110 225 jeremybenn
  /*!A global record of the simulator description */
111
  static SIM_DESC  static_sd = NULL;
112 147 jeremybenn
 
113 225 jeremybenn
  int    local_argc;                    /* Our local argv with extra args */
114
  char **local_argv;
115
 
116
  /* If static_sd is not yet allocated, we allocate it and mark the simulator
117
     as not yet open. */
118
  if (NULL == static_sd)
119 147 jeremybenn
    {
120 225 jeremybenn
      static_sd = (SIM_DESC) malloc (sizeof (*static_sd));
121
      static_sd->sim_open = 0;
122 147 jeremybenn
    }
123
 
124 225 jeremybenn
  /* If this is a second call, we cannot take any new configuration
125
     arguments. We silently ignore them. */
126
  if (!static_sd->sim_open)
127
    {
128
      int    argc;                      /* How many args originally */
129
      int    i;                         /* For local argv */
130
      int    mem_defined_p = 0;          /* Have we requested a memory size? */
131 147 jeremybenn
 
132 225 jeremybenn
      /* Count the number of arguments and see if we have specified either a
133
         config file or a memory size. */
134
      for (argc = 1; NULL != argv[argc]; argc++)
135
        {
136
          /* printf ("argv[%d] = %s\n", argc, argv[argc]); */
137
 
138
          if ((0 == strcmp (argv[argc], "-f"))    ||
139
              (0 == strcmp (argv[argc], "-file")) ||
140
              (0 == strcmp (argv[argc], "-m"))    ||
141
              (0 == strcmp (argv[argc], "-memory")))
142
            {
143
              mem_defined_p = 1;
144
            }
145
        }
146
 
147
      /* If we have no memory defined, we give it a default 8MB. We also always
148
         run quiet. So we must define our own argument vector */
149
      local_argc = mem_defined_p ? argc + 1 : argc + 3;
150
      local_argv = malloc ((local_argc + 1) * sizeof (char *));
151
 
152
      for (i = 0 ; i < argc; i++)
153
        {
154
          local_argv[i] = argv[i];
155
        }
156
 
157
      local_argv[i++] = "--quiet";
158
 
159
      if (!mem_defined_p)
160
        {
161
          local_argv[i++] = "--memory";
162
          local_argv[i++] = "8M";
163
        }
164
 
165
      local_argv[i] = NULL;
166 147 jeremybenn
    }
167
 
168 225 jeremybenn
  /* We just pass the arguments to the simulator initialization. No class
169
     image nor upcalls. Having initialized, stall the processor, free the
170
     argument vector and return the SD (or NULL on failure) */
171
  if (0 == or1ksim_init (local_argc, local_argv, NULL, NULL, NULL))
172 147 jeremybenn
    {
173 225 jeremybenn
 
174
      static_sd->callback    = callback;
175
      static_sd->is_debug    = (kind == SIM_OPEN_DEBUG);
176
      static_sd->myname      = (char *)xstrdup (argv[0]);
177
      static_sd->sim_open    = 1;
178
      static_sd->last_reason = sim_running;
179
      static_sd->last_rc     = TARGET_SIGNAL_NONE;
180
      static_sd->entry_point = OR32_RESET_EXCEPTION;
181
      static_sd->resume_npc  = OR32_RESET_EXCEPTION;
182
 
183
      or1ksim_set_stall_state (0);
184
      free (local_argv);
185
      return  static_sd;
186 147 jeremybenn
    }
187
  else
188
    {
189 225 jeremybenn
      /* On failure return a NULL sd */
190
      free (local_argv);
191
      return  NULL;
192 147 jeremybenn
    }
193
}       /* sim_open () */
194
 
195
 
196
/* ------------------------------------------------------------------------- */
197
/*!Destroy a simulator instance.
198
 
199 225 jeremybenn
   We only have one instance, but we mark it as closed, so it can be reused.
200 147 jeremybenn
 
201
   @param[in] sd        Simulation descriptor from sim_open ().
202
   @param[in] quitting  Non-zero if we cannot hang on errors.                */
203
/* ------------------------------------------------------------------------- */
204
void
205
sim_close (SIM_DESC  sd,
206
           int       quitting)
207
{
208 225 jeremybenn
  if (NULL == sd)
209 147 jeremybenn
    {
210 225 jeremybenn
      fprintf (stderr,
211
               "Warning: Attempt to close non-open simulation: ignored.\n");
212
    }
213
  else
214
    {
215 147 jeremybenn
      free (sd->myname);
216 225 jeremybenn
      sd->sim_open = 0;
217 147 jeremybenn
    }
218
}       /* sim_close () */
219
 
220
 
221
/* ------------------------------------------------------------------------- */
222
/*!Load program PROG into the simulators memory.
223
 
224
   Hardware simulator: Normally, each program section is written into
225
   memory according to that sections LMA using physical (direct)
226
   addressing.  The exception being systems, such as PPC/CHRP, which
227
   support more complicated program loaders.  A call to this function
228
   should not effect the state of the processor registers.  Multiple
229
   calls to this function are permitted and have an accumulative
230
   effect.
231
 
232
   Process simulator: Calls to this function may be ignored.
233
 
234
   @todo Most hardware simulators load the image at the VMA using
235
         virtual addressing.
236
 
237
   @todo For some hardware targets, before a loaded program can be executed,
238
         it requires the manipulation of VM registers and tables.  Such
239
         manipulation should probably (?) occure in sim_create_inferior ().
240
 
241
   @param[in] sd        Simulation descriptor from sim_open ().
242
   @param[in] prog      The name of the program
243
   @param[in] abfd      If non-NULL, the BFD for the file has already been
244
                        opened.
245
   @param[in] from_tty  Not sure what this does. Probably indicates this is a
246
                        command line load? Anyway we don't use it.
247
 
248
   @return  A return code indicating success.                                */
249
/* ------------------------------------------------------------------------- */
250
SIM_RC
251
sim_load (SIM_DESC    sd,
252
          char       *prog,
253
          struct bfd *abfd,
254
          int         from_tty)
255
{
256
  bfd *prog_bfd;
257
 
258
  /* Use the built in loader, which will in turn use our write function. */
259
  prog_bfd = sim_load_file (sd, sd->myname, sd->callback, prog, abfd,
260
                            sd->is_debug, 0, sim_write);
261
 
262
  if (NULL == prog_bfd)
263
    {
264
      return SIM_RC_FAIL;
265
    }
266
 
267
  /* If the BFD was not already open, then close the loaded program. */
268
  if (NULL == abfd)
269
    {
270
      bfd_close (prog_bfd);
271
    }
272
 
273
  return  SIM_RC_OK;
274
 
275
}       /* sim_load () */
276
 
277
 
278
/* ------------------------------------------------------------------------- */
279
/*!Prepare to run the simulated program.
280
 
281
   Hardware simulator: This function shall initialize the processor
282
   registers to a known value.  The program counter and possibly stack
283
   pointer shall be set using information obtained from ABFD (or
284
   hardware reset defaults).  ARGV and ENV, dependant on the target
285
   ABI, may be written to memory.
286
 
287
   Process simulator: After a call to this function, a new process
288
   instance shall exist. The TEXT, DATA, BSS and stack regions shall
289
   all be initialized, ARGV and ENV shall be written to process
290
   address space (according to the applicable ABI) and the program
291
   counter and stack pointer set accordingly.
292
 
293
   ABFD, if not NULL, provides initial processor state information.
294
   ARGV and ENV, if non NULL, are NULL terminated lists of pointers.
295
 
296 225 jeremybenn
   We perform the following steps:
297
   - stall the processor
298
   - set the entry point to the entry point in the BFD, or the reset
299
     vector if the BFD is not available.
300
   - set the resumption NPC to the reset vector. We always do this, to ensure
301
     the library is initialized.
302
 
303 147 jeremybenn
   @param[in] sd    Simulation descriptor from sim_open ().
304
   @param[in] abfd  If non-NULL provides initial processor state information.
305
   @param[in] argv  Vector of arguments to the program. We don't use this
306
   @param[in] env   Vector of environment data. We don't use this.
307
 
308
   @return  A return code indicating success.                                */
309
/* ------------------------------------------------------------------------- */
310
SIM_RC
311
sim_create_inferior (SIM_DESC     sd,
312
                     struct bfd  *abfd,
313
                     char       **argv  ATTRIBUTE_UNUSED,
314
                     char       **env   ATTRIBUTE_UNUSED)
315
{
316 225 jeremybenn
  or1ksim_set_stall_state (1);
317
  sd->entry_point = (NULL == abfd) ? OR32_RESET_EXCEPTION :
318
                                    bfd_get_start_address (abfd);
319
  sd->resume_npc  = OR32_RESET_EXCEPTION;
320
 
321 147 jeremybenn
  return  SIM_RC_OK;
322
 
323
}       /* sim_create_inferior () */
324
 
325
 
326
/* ------------------------------------------------------------------------- */
327
/*!Fetch bytes from the simulated program's memory.
328
 
329
   @param[in]  sd   Simulation descriptor from sim_open (). We don't use
330
                    this.
331
   @param[in]  mem  The address in memory to fetch from.
332
   @param[out] buf  Where to put the read data
333
   @param[in]  len  Number of bytes to fetch
334
 
335
   @return  Number of bytes read, or zero if error.                          */
336
/* ------------------------------------------------------------------------- */
337
int
338
sim_read (SIM_DESC       sd  ATTRIBUTE_UNUSED,
339
          SIM_ADDR       mem,
340
          unsigned char *buf,
341
          int            len)
342
{
343 225 jeremybenn
  int res = or1ksim_read_mem (mem, buf, len);
344 147 jeremybenn
 
345 225 jeremybenn
  /* printf ("Reading %d bytes from 0x%08p\n", len, mem); */
346
 
347
  return  res;
348
 
349 147 jeremybenn
}      /* sim_read () */
350
 
351
 
352
/* ------------------------------------------------------------------------- */
353
/*!Store bytes to the simulated program's memory.
354
 
355
   @param[in] sd   Simulation descriptor from sim_open (). We don't use
356
                   this.
357
   @param[in] mem  The address in memory to write to.
358
   @param[in] buf  The data to write
359
   @param[in] len  Number of bytes to write
360
 
361
   @return  Number of byte written, or zero if error.                        */
362
/* ------------------------------------------------------------------------- */
363
int
364
sim_write (SIM_DESC       sd  ATTRIBUTE_UNUSED,
365
           SIM_ADDR       mem,
366
           unsigned char *buf,
367
           int            len)
368
{
369 225 jeremybenn
  /* printf ("Writing %d bytes to 0x%08p\n", len, mem); */
370 147 jeremybenn
 
371 225 jeremybenn
  return  or1ksim_write_mem ((unsigned int) mem, buf, len);
372
 
373 147 jeremybenn
}       /* sim_write () */
374
 
375
 
376
/* ------------------------------------------------------------------------- */
377
/*!Fetch a register from the simulation
378
 
379 225 jeremybenn
   We get the register back as a 32-bit value. However we must convert it to a
380
   character array <em>in target endian order</em>.
381
 
382
   The exception is if the register is the NPC, which is only written just
383
   before resumption, to avoid pipeline confusion. It is fetched from the SD.
384
 
385 147 jeremybenn
   @param[in]  sd     Simulation descriptor from sim_open (). We don't use
386
                      this.
387
   @param[in]  regno  The register to fetch
388
   @param[out] buf    Buffer of length bytes to store the result. Data is
389
                      only transferred if length matches the register length
390
                      (the actual register size is still returned).
391
   @param[in]  len    Size of buf, which should match the size of the
392
                      register.
393
 
394
   @return  The actual size of the register, or zero if regno is not
395
            applicable. Legacy implementations return -1.
396
/* ------------------------------------------------------------------------- */
397
int
398 225 jeremybenn
sim_fetch_register (SIM_DESC       sd,
399 147 jeremybenn
                    int            regno,
400
                    unsigned char *buf,
401
                    int            len)
402
{
403 225 jeremybenn
  unsigned int  regval;
404
  int           res;
405 147 jeremybenn
 
406 225 jeremybenn
  if (4 != len)
407
    {
408
      fprintf (stderr, "Invalid register length %d\n");
409
      return  0;
410
    }
411
 
412
  if (OR32_NPC_REGNUM == regno)
413
    {
414
      regval = sd->resume_npc;
415
      res    = 4;
416
    }
417
  else
418
    {
419
      int res = or1ksim_read_reg (regno, &regval) ? 4 : 0;
420
    }
421
 
422
  /* Convert to target (big) endian */
423
  if (res)
424
    {
425
      buf[0] = (regval >> 24) & 0xff;
426
      buf[1] = (regval >> 16) & 0xff;
427
      buf[2] = (regval >>  8) & 0xff;
428
      buf[3] =  regval        & 0xff;
429
    }
430
 
431
  /* printf ("Read register 0x%02x, value 0x%08x\n", regno, regval); */
432
  return  res;
433
 
434 147 jeremybenn
}       /* sim_fetch_register () */
435
 
436
 
437
/* ------------------------------------------------------------------------- */
438
/*!Store a register to the simulation
439
 
440 225 jeremybenn
   We write the register back as a 32-bit value. However we must convert it from
441
   a character array <em>in target endian order</em>.
442
 
443
   The exception is if the register is the NPC, which is only written just
444
   before resumption, to avoid pipeline confusion. It is saved in the SD.
445
 
446 147 jeremybenn
   @param[in] sd     Simulation descriptor from sim_open (). We don't use
447
                     this.
448
   @param[in] regno  The register to store
449
   @param[in] buf    Buffer of length bytes with the data to store. Data is
450
                     only transferred if length matches the register length
451
                     (the actual register size is still returned).
452
   @param[in] len    Size of buf, which should match the size of the
453
                     register.
454
 
455
   @return  The actual size of the register, or zero if regno is not
456
            applicable. Legacy implementations return -1.
457
/* ------------------------------------------------------------------------- */
458
int
459 225 jeremybenn
sim_store_register (SIM_DESC       sd,
460 147 jeremybenn
                    int            regno,
461
                    unsigned char *buf,
462
                    int            len)
463
{
464 225 jeremybenn
  unsigned int  regval;
465 147 jeremybenn
 
466 225 jeremybenn
  if (4 != len)
467
    {
468
      fprintf (stderr, "Invalid register length %d\n");
469
      return  0;
470
    }
471
 
472
  /* Convert from target (big) endian */
473
  regval = (((unsigned int) buf[0]) << 24) |
474
           (((unsigned int) buf[1]) << 16) |
475
           (((unsigned int) buf[2]) <<  8) |
476
           (((unsigned int) buf[3])      );
477
 
478
  /* printf ("Writing register 0x%02x, value 0x%08x\n", regno, regval); */
479
 
480
  if (OR32_NPC_REGNUM == regno)
481
    {
482
      sd->resume_npc = regval;
483
      return  4;                        /* Reg length in bytes */
484
    }
485
  else
486
    {
487
      return  or1ksim_write_reg (regno, regval) ? 4 : 0;
488
    }
489 147 jeremybenn
}       /* sim_store_register () */
490
 
491
 
492
/* ------------------------------------------------------------------------- */
493
/* Print whatever statistics the simulator has collected.
494
 
495
   @param[in] sd       Simulation descriptor from sim_open (). We don't use
496
                       this.
497
   @param[in] verbose  Currently unused, and should always be zero.          */
498
/* ------------------------------------------------------------------------- */
499
void
500
sim_info (SIM_DESC  sd       ATTRIBUTE_UNUSED,
501
          int       verbose  ATTRIBUTE_UNUSED)
502
{
503
}       /* sim_info () */
504
 
505
 
506
/* ------------------------------------------------------------------------- */
507
/*!Run (or resume) the simulated program.
508
 
509
   Hardware simulator: If the SIGRC value returned by
510
   sim_stop_reason() is passed back to the simulator via siggnal then
511
   the hardware simulator shall correctly deliver the hardware event
512
   indicated by that signal.  If a value of zero is passed in then the
513
   simulation will continue as if there were no outstanding signal.
514
   The effect of any other siggnal value is is implementation
515
   dependant.
516
 
517
   Process simulator: If SIGRC is non-zero then the corresponding
518
   signal is delivered to the simulated program and execution is then
519
   continued.  A zero SIGRC value indicates that the program should
520
   continue as normal.
521
 
522 225 jeremybenn
   We carry out the following
523
   - Clear the debug reason register
524
   - Clear watchpoing break generation in debug mode register 2
525
   - Set the debug unit to handle TRAP exceptions
526
   - If stepping, set the single step trigger in debug mode register 1
527
   - Write the resume_npc if it differs from the actual NPC.
528
   - Unstall the processor
529
   - Run the processor.
530
 
531
   On execution completion, we determine the reason for the halt. If it is a
532
   breakpoint, we mark the resumption NPC to be the PPC (so we redo the NPC
533
   location).
534
 
535 147 jeremybenn
   @param[in] sd       Simulation descriptor from sim_open ().
536
   @param[in] step     When non-zero indicates that only a single simulator
537
                       cycle should be emulated.
538
   @param[in] siggnal  If non-zero is a (HOST) SIGRC value indicating the type
539
                       of event (hardware interrupt, signal) to be delivered
540
                       to the simulated program.                             */
541
/* ------------------------------------------------------------------------- */
542
void
543
sim_resume (SIM_DESC  sd,
544
            int       step,
545
            int       siggnal)
546
{
547 225 jeremybenn
  unsigned int  npc;                    /* Next Program Counter */
548
  unsigned int  drr;                    /* Debug Reason Register */
549
  unsigned int  dsr;                    /* Debug Stop Register */
550
  unsigned int  dmr1;                   /* Debug Mode Register 1*/
551
  unsigned int  dmr2;                   /* Debug Mode Register 2*/
552 147 jeremybenn
 
553 225 jeremybenn
  int                res;               /* Result of a run. */
554 147 jeremybenn
 
555 225 jeremybenn
  /* Clear Debug Reason Register and watchpoint break generation in Debug Mode
556
     Register 2 */
557
  (void) or1ksim_write_spr (OR32_SPR_DRR, 0);
558
 
559
  (void) or1ksim_read_spr (OR32_SPR_DMR2, &dmr2);
560
  dmr2 &= ~OR32_SPR_DMR2_WGB;
561
  (void) or1ksim_write_spr (OR32_SPR_DMR2, dmr2);
562
 
563
  /* Set debug unit to handle TRAP exceptions */
564
  (void) or1ksim_read_spr (OR32_SPR_DSR, &dsr);
565
  dsr |= OR32_SPR_DSR_TE;
566
  (void) or1ksim_write_spr (OR32_SPR_DSR, dsr);
567
 
568
  /* Set the single step trigger in Debug Mode Register 1 if we are stepping. */
569
  if (step)
570
    {
571
      (void) or1ksim_read_spr (OR32_SPR_DMR1, &dmr1);
572
      dmr1 |= OR32_SPR_DMR1_ST;
573
      (void) or1ksim_write_spr (OR32_SPR_DMR1, dmr1);
574
    }
575
 
576
  /* Set the NPC if it has changed */
577
  (void) or1ksim_read_reg (OR32_NPC_REGNUM, &npc);
578
 
579
  if (npc != sd->resume_npc)
580
    {
581
      (void) or1ksim_write_reg (OR32_NPC_REGNUM, sd->resume_npc);
582
    }
583
 
584
  /* Unstall and run */
585
  or1ksim_set_stall_state (0);
586
  res = or1ksim_run (-1.0);
587
 
588
  /* Determine the reason for stopping. If we hit a breakpoint, then the
589
     resumption NPC must be set to the PPC to allow re-execution of the
590
     trapped instruction. */
591 147 jeremybenn
  switch (res)
592
    {
593
    case OR1KSIM_RC_HALTED:
594 225 jeremybenn
      sd->last_reason = sim_exited;
595
      (void) or1ksim_read_reg (OR32_FIRST_ARG_REGNUM, &(sd->last_rc));
596
      sd->resume_npc  = OR32_RESET_EXCEPTION;
597 147 jeremybenn
      break;
598
 
599
    case OR1KSIM_RC_BRKPT:
600 225 jeremybenn
      sd->last_reason = sim_stopped;
601
      sd->last_rc     = TARGET_SIGNAL_TRAP;
602
      (void) or1ksim_read_reg (OR32_PPC_REGNUM, &(sd->resume_npc));
603 147 jeremybenn
      break;
604 225 jeremybenn
 
605
    case OR1KSIM_RC_OK:
606
      /* Should not happen */
607
      fprintf (stderr, "Ooops. Didn't expect OK return from Or1ksim.\n");
608
 
609
      sd->last_reason = sim_running;            /* Should trigger an error! */
610
      sd->last_rc     = TARGET_SIGNAL_NONE;
611
      (void) or1ksim_read_reg (OR32_NPC_REGNUM, &(sd->resume_npc));
612
      break;
613 147 jeremybenn
    }
614
}       /* sim_resume () */
615
 
616
 
617
/* ------------------------------------------------------------------------- */
618
/*!Asynchronous request to stop the simulation.
619
 
620
   @param[in] sd  Simulation descriptor from sim_open (). We don't use this.
621
 
622
   @return  Non-zero indicates that the simulator is able to handle the
623
            request.                                                         */
624
/* ------------------------------------------------------------------------- */
625
int sim_stop (SIM_DESC  sd  ATTRIBUTE_UNUSED)
626
{
627
  return  0;                     /* We don't support this */
628
 
629
}       /* sim_stop () */
630
 
631
 
632
/* ------------------------------------------------------------------------- */
633
/*!Fetch the REASON why the program stopped.
634
 
635
   The reason enumeration indicates why:
636
 
637
   - sim_exited:    The program has terminated. sigrc indicates the target
638
                    dependant exit status.
639
 
640
   - sim_stopped:   The program has stopped.  sigrc uses the host's signal
641
                    numbering as a way of identifying the reaon: program
642
                    interrupted by user via a sim_stop request (SIGINT); a
643
                    breakpoint instruction (SIGTRAP); a completed single step
644
                    (SIGTRAP); an internal error condition (SIGABRT); an
645
                    illegal instruction (SIGILL); Access to an undefined
646
                    memory region (SIGSEGV); Mis-aligned memory access
647
                    (SIGBUS).
648
 
649
                    For some signals information in addition to the signal
650
                    number may be retained by the simulator (e.g. offending
651
                    address), that information is not directly accessable via
652
                    this interface.
653
 
654
   - sim_signalled: The program has been terminated by a signal. The
655
                    simulator has encountered target code that causes the the
656
                    program to exit with signal sigrc.
657
 
658
   - sim_running:
659
   - sim_polling:   The return of one of these values indicates a problem
660
                    internal to the simulator.
661
 
662 225 jeremybenn
   @param[in]  sd      Simulation descriptor from sim_open ().
663 147 jeremybenn
   @param[out] reason  The reason for stopping
664
   @param[out] sigrc   Supplementary information for some values of reason.  */
665
/* ------------------------------------------------------------------------- */
666
void
667 225 jeremybenn
sim_stop_reason (SIM_DESC       sd,
668 147 jeremybenn
                 enum sim_stop *reason,
669
                 int           *sigrc)
670
 {
671 225 jeremybenn
   *reason = sd->last_reason;
672
   *sigrc  = sd->last_rc;
673 147 jeremybenn
 
674
}       /* sim_stop_reason () */
675
 
676
 
677
/* ------------------------------------------------------------------------- */
678
/* Passthru for other commands that the simulator might support.
679
 
680
   Simulators should be prepared to deal with any combination of NULL
681
   or empty command.
682
 
683
   This implementation currently does nothing.
684
 
685
   @param[in] sd  Simulation descriptor from sim_open (). We don't use this.
686
   @param[in] cmd The command to pass through.                               */
687
/* ------------------------------------------------------------------------- */
688
void
689
sim_do_command (SIM_DESC  sd   ATTRIBUTE_UNUSED,
690
                char     *cmd  ATTRIBUTE_UNUSED)
691
{
692
}       /* sim_do_command () */
693
 
694
 
695
/* ------------------------------------------------------------------------- */
696
/* Set the default host_callback_struct
697
 
698
   @note Deprecated, but implemented, since it is still required for linking.
699
 
700
   This implementation currently does nothing.
701
 
702
   @param[in] ptr  The host_callback_struct pointer. Unused here.            */
703
/* ------------------------------------------------------------------------- */
704
void
705
sim_set_callbacks (struct host_callback_struct *ptr ATTRIBUTE_UNUSED)
706
{
707
}       /* sim_set_callbacks () */
708
 
709
 
710
/* ------------------------------------------------------------------------- */
711
/* Set the size of the simulator memory array.
712
 
713
   @note Deprecated, but implemented, since it is still required for linking.
714
 
715
   This implementation currently does nothing.
716
 
717
   @param[in] size  The memory size to use. Unused here.                     */
718
/* ------------------------------------------------------------------------- */
719
void
720
sim_size (int  size  ATTRIBUTE_UNUSED)
721
{
722
}       /* sim_size () */
723
 
724
 
725
/* ------------------------------------------------------------------------- */
726
/* Single step the simulator with tracing enabled.
727
 
728
   @note Deprecated, but implemented, since it is still required for linking.
729
 
730
   This implementation currently does nothing.
731
 
732
   @param[in] sd  The simulator description struct. Unused here.             */
733
/* ------------------------------------------------------------------------- */
734
void
735
sim_trace (SIM_DESC  sd  ATTRIBUTE_UNUSED)
736
{
737
}       /* sim_trace () */

powered by: WebSVN 2.1.0

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