OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [sim/] [or32/] [wrapper.c] - Blame information for rev 237

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

Line No. Rev Author Line
1 227 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
#include <string.h>
36
#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
   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
 
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
  /*!A global record of the simulator description */
111
  static SIM_DESC  static_sd = NULL;
112
 
113
  /* If static_sd is not yet allocated, we allocate it and mark the simulator
114 232 jeremybenn
     as not yet open. This is the only time we can process any custom
115
     arguments and only time we initialize the simulator. */
116 227 jeremybenn
  if (NULL == static_sd)
117
    {
118 232 jeremybenn
      int    local_argc;                /* Our local argv with extra args */
119
      char **local_argv;
120 227 jeremybenn
 
121
      int    argc;                      /* How many args originally */
122
      int    i;                         /* For local argv */
123
      int    mem_defined_p = 0;          /* Have we requested a memory size? */
124
 
125 232 jeremybenn
      int    res;                       /* Result of initialization */
126
 
127
      static_sd = (SIM_DESC) malloc (sizeof (*static_sd));
128
      static_sd->sim_open = 0;
129
 
130 227 jeremybenn
      /* Count the number of arguments and see if we have specified either a
131
         config file or a memory size. */
132
      for (argc = 1; NULL != argv[argc]; argc++)
133
        {
134
          /* printf ("argv[%d] = %s\n", argc, argv[argc]); */
135
 
136
          if ((0 == strcmp (argv[argc], "-f"))    ||
137
              (0 == strcmp (argv[argc], "-file")) ||
138
              (0 == strcmp (argv[argc], "-m"))    ||
139
              (0 == strcmp (argv[argc], "-memory")))
140
            {
141
              mem_defined_p = 1;
142
            }
143
        }
144
 
145
      /* If we have no memory defined, we give it a default 8MB. We also always
146
         run quiet. So we must define our own argument vector */
147
      local_argc = mem_defined_p ? argc + 1 : argc + 3;
148
      local_argv = malloc ((local_argc + 1) * sizeof (char *));
149
 
150
      for (i = 0 ; i < argc; i++)
151
        {
152
          local_argv[i] = argv[i];
153
        }
154
 
155
      local_argv[i++] = "--quiet";
156
 
157
      if (!mem_defined_p)
158
        {
159
          local_argv[i++] = "--memory";
160
          local_argv[i++] = "8M";
161
        }
162
 
163
      local_argv[i] = NULL;
164 232 jeremybenn
 
165
      /* Try to initialize, then we can free the local argument vector. If we
166
         fail to initialize return NULL to indicate that failure. */
167
      res == or1ksim_init (local_argc, local_argv, NULL, NULL, NULL);
168
      free (local_argv);
169
 
170
      if (res)
171
        {
172
          return  NULL;                 /* Failure */
173
        }
174 227 jeremybenn
    }
175
 
176 232 jeremybenn
  /* We have either initialized a new simulator, or already have an intialized
177
     simulator. Populate the descriptor and stall the processor, the return
178
     the descriptor. */
179
  static_sd->callback    = callback;
180
  static_sd->is_debug    = (kind == SIM_OPEN_DEBUG);
181
  static_sd->myname      = (char *)xstrdup (argv[0]);
182
  static_sd->sim_open    = 1;
183
  static_sd->last_reason = sim_running;
184
  static_sd->last_rc     = TARGET_SIGNAL_NONE;
185
  static_sd->entry_point = OR32_RESET_EXCEPTION;
186
  static_sd->resume_npc  = OR32_RESET_EXCEPTION;
187 227 jeremybenn
 
188 232 jeremybenn
  or1ksim_set_stall_state (0);
189 227 jeremybenn
 
190 232 jeremybenn
  return  static_sd;
191
 
192 227 jeremybenn
}       /* sim_open () */
193
 
194
 
195
/* ------------------------------------------------------------------------- */
196
/*!Destroy a simulator instance.
197
 
198 232 jeremybenn
   We never actually close the simulator, because we have no way to
199
   reinitialize it. Instead we just stall the processor and mark it closed.
200 227 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
  if (NULL == sd)
209
    {
210
      fprintf (stderr,
211
               "Warning: Attempt to close non-open simulation: ignored.\n");
212
    }
213
  else
214
    {
215
      free (sd->myname);
216
      sd->sim_open = 0;
217 232 jeremybenn
      or1ksim_set_stall_state (0);
218 227 jeremybenn
    }
219
}       /* sim_close () */
220
 
221
 
222
/* ------------------------------------------------------------------------- */
223
/*!Load program PROG into the simulators memory.
224
 
225
   Hardware simulator: Normally, each program section is written into
226
   memory according to that sections LMA using physical (direct)
227
   addressing.  The exception being systems, such as PPC/CHRP, which
228
   support more complicated program loaders.  A call to this function
229
   should not effect the state of the processor registers.  Multiple
230
   calls to this function are permitted and have an accumulative
231
   effect.
232
 
233
   Process simulator: Calls to this function may be ignored.
234
 
235
   @todo Most hardware simulators load the image at the VMA using
236
         virtual addressing.
237
 
238
   @todo For some hardware targets, before a loaded program can be executed,
239
         it requires the manipulation of VM registers and tables.  Such
240
         manipulation should probably (?) occure in sim_create_inferior ().
241
 
242
   @param[in] sd        Simulation descriptor from sim_open ().
243
   @param[in] prog      The name of the program
244
   @param[in] abfd      If non-NULL, the BFD for the file has already been
245
                        opened.
246
   @param[in] from_tty  Not sure what this does. Probably indicates this is a
247
                        command line load? Anyway we don't use it.
248
 
249
   @return  A return code indicating success.                                */
250
/* ------------------------------------------------------------------------- */
251
SIM_RC
252
sim_load (SIM_DESC    sd,
253
          char       *prog,
254
          struct bfd *abfd,
255
          int         from_tty)
256
{
257
  bfd *prog_bfd;
258
 
259
  /* Use the built in loader, which will in turn use our write function. */
260
  prog_bfd = sim_load_file (sd, sd->myname, sd->callback, prog, abfd,
261
                            sd->is_debug, 0, sim_write);
262
 
263
  if (NULL == prog_bfd)
264
    {
265
      return SIM_RC_FAIL;
266
    }
267
 
268
  /* If the BFD was not already open, then close the loaded program. */
269
  if (NULL == abfd)
270
    {
271
      bfd_close (prog_bfd);
272
    }
273
 
274
  return  SIM_RC_OK;
275
 
276
}       /* sim_load () */
277
 
278
 
279
/* ------------------------------------------------------------------------- */
280
/*!Prepare to run the simulated program.
281
 
282
   Hardware simulator: This function shall initialize the processor
283
   registers to a known value.  The program counter and possibly stack
284
   pointer shall be set using information obtained from ABFD (or
285
   hardware reset defaults).  ARGV and ENV, dependant on the target
286
   ABI, may be written to memory.
287
 
288
   Process simulator: After a call to this function, a new process
289
   instance shall exist. The TEXT, DATA, BSS and stack regions shall
290
   all be initialized, ARGV and ENV shall be written to process
291
   address space (according to the applicable ABI) and the program
292
   counter and stack pointer set accordingly.
293
 
294
   ABFD, if not NULL, provides initial processor state information.
295
   ARGV and ENV, if non NULL, are NULL terminated lists of pointers.
296
 
297
   We perform the following steps:
298
   - stall the processor
299
   - set the entry point to the entry point in the BFD, or the reset
300
     vector if the BFD is not available.
301
   - set the resumption NPC to the reset vector. We always do this, to ensure
302
     the library is initialized.
303
 
304
   @param[in] sd    Simulation descriptor from sim_open ().
305
   @param[in] abfd  If non-NULL provides initial processor state information.
306
   @param[in] argv  Vector of arguments to the program. We don't use this
307
   @param[in] env   Vector of environment data. We don't use this.
308
 
309
   @return  A return code indicating success.                                */
310
/* ------------------------------------------------------------------------- */
311
SIM_RC
312
sim_create_inferior (SIM_DESC     sd,
313
                     struct bfd  *abfd,
314
                     char       **argv  ATTRIBUTE_UNUSED,
315
                     char       **env   ATTRIBUTE_UNUSED)
316
{
317
  or1ksim_set_stall_state (1);
318
  sd->entry_point = (NULL == abfd) ? OR32_RESET_EXCEPTION :
319
                                    bfd_get_start_address (abfd);
320
  sd->resume_npc  = OR32_RESET_EXCEPTION;
321
 
322
  return  SIM_RC_OK;
323
 
324
}       /* sim_create_inferior () */
325
 
326
 
327
/* ------------------------------------------------------------------------- */
328
/*!Fetch bytes from the simulated program's memory.
329
 
330
   @param[in]  sd   Simulation descriptor from sim_open (). We don't use
331
                    this.
332
   @param[in]  mem  The address in memory to fetch from.
333
   @param[out] buf  Where to put the read data
334
   @param[in]  len  Number of bytes to fetch
335
 
336
   @return  Number of bytes read, or zero if error.                          */
337
/* ------------------------------------------------------------------------- */
338
int
339
sim_read (SIM_DESC       sd  ATTRIBUTE_UNUSED,
340
          SIM_ADDR       mem,
341
          unsigned char *buf,
342
          int            len)
343
{
344
  int res = or1ksim_read_mem (mem, buf, len);
345
 
346
  /* printf ("Reading %d bytes from 0x%08p\n", len, mem); */
347
 
348
  return  res;
349
 
350
}      /* sim_read () */
351
 
352
 
353
/* ------------------------------------------------------------------------- */
354
/*!Store bytes to the simulated program's memory.
355
 
356
   @param[in] sd   Simulation descriptor from sim_open (). We don't use
357
                   this.
358
   @param[in] mem  The address in memory to write to.
359
   @param[in] buf  The data to write
360
   @param[in] len  Number of bytes to write
361
 
362
   @return  Number of byte written, or zero if error.                        */
363
/* ------------------------------------------------------------------------- */
364
int
365
sim_write (SIM_DESC       sd  ATTRIBUTE_UNUSED,
366
           SIM_ADDR       mem,
367
           unsigned char *buf,
368
           int            len)
369
{
370
  /* printf ("Writing %d bytes to 0x%08p\n", len, mem); */
371
 
372
  return  or1ksim_write_mem ((unsigned int) mem, buf, len);
373
 
374
}       /* sim_write () */
375
 
376
 
377
/* ------------------------------------------------------------------------- */
378
/*!Fetch a register from the simulation
379
 
380
   We get the register back as a 32-bit value. However we must convert it to a
381
   character array <em>in target endian order</em>.
382
 
383
   The exception is if the register is the NPC, which is only written just
384
   before resumption, to avoid pipeline confusion. It is fetched from the SD.
385
 
386
   @param[in]  sd     Simulation descriptor from sim_open (). We don't use
387
                      this.
388
   @param[in]  regno  The register to fetch
389
   @param[out] buf    Buffer of length bytes to store the result. Data is
390
                      only transferred if length matches the register length
391
                      (the actual register size is still returned).
392
   @param[in]  len    Size of buf, which should match the size of the
393
                      register.
394
 
395
   @return  The actual size of the register, or zero if regno is not
396
            applicable. Legacy implementations return -1.
397
/* ------------------------------------------------------------------------- */
398
int
399
sim_fetch_register (SIM_DESC       sd,
400
                    int            regno,
401
                    unsigned char *buf,
402
                    int            len)
403
{
404 232 jeremybenn
  unsigned long int  regval;
405
  int                res;
406 227 jeremybenn
 
407
  if (4 != len)
408
    {
409
      fprintf (stderr, "Invalid register length %d\n");
410
      return  0;
411
    }
412
 
413
  if (OR32_NPC_REGNUM == regno)
414
    {
415
      regval = sd->resume_npc;
416
      res    = 4;
417
    }
418
  else
419
    {
420
      int res = or1ksim_read_reg (regno, &regval) ? 4 : 0;
421
    }
422
 
423
  /* Convert to target (big) endian */
424
  if (res)
425
    {
426
      buf[0] = (regval >> 24) & 0xff;
427
      buf[1] = (regval >> 16) & 0xff;
428
      buf[2] = (regval >>  8) & 0xff;
429
      buf[3] =  regval        & 0xff;
430
    }
431
 
432
  /* printf ("Read register 0x%02x, value 0x%08x\n", regno, regval); */
433
  return  res;
434
 
435
}       /* sim_fetch_register () */
436
 
437
 
438
/* ------------------------------------------------------------------------- */
439
/*!Store a register to the simulation
440
 
441
   We write the register back as a 32-bit value. However we must convert it from
442
   a character array <em>in target endian order</em>.
443
 
444
   The exception is if the register is the NPC, which is only written just
445
   before resumption, to avoid pipeline confusion. It is saved in the SD.
446
 
447
   @param[in] sd     Simulation descriptor from sim_open (). We don't use
448
                     this.
449
   @param[in] regno  The register to store
450
   @param[in] buf    Buffer of length bytes with the data to store. Data is
451
                     only transferred if length matches the register length
452
                     (the actual register size is still returned).
453
   @param[in] len    Size of buf, which should match the size of the
454
                     register.
455
 
456
   @return  The actual size of the register, or zero if regno is not
457
            applicable. Legacy implementations return -1.
458
/* ------------------------------------------------------------------------- */
459
int
460
sim_store_register (SIM_DESC       sd,
461
                    int            regno,
462
                    unsigned char *buf,
463
                    int            len)
464
{
465
  unsigned int  regval;
466
 
467
  if (4 != len)
468
    {
469
      fprintf (stderr, "Invalid register length %d\n");
470
      return  0;
471
    }
472
 
473
  /* Convert from target (big) endian */
474
  regval = (((unsigned int) buf[0]) << 24) |
475
           (((unsigned int) buf[1]) << 16) |
476
           (((unsigned int) buf[2]) <<  8) |
477
           (((unsigned int) buf[3])      );
478
 
479
  /* printf ("Writing register 0x%02x, value 0x%08x\n", regno, regval); */
480
 
481
  if (OR32_NPC_REGNUM == regno)
482
    {
483
      sd->resume_npc = regval;
484
      return  4;                        /* Reg length in bytes */
485
    }
486
  else
487
    {
488
      return  or1ksim_write_reg (regno, regval) ? 4 : 0;
489
    }
490
}       /* sim_store_register () */
491
 
492
 
493
/* ------------------------------------------------------------------------- */
494
/* Print whatever statistics the simulator has collected.
495
 
496
   @param[in] sd       Simulation descriptor from sim_open (). We don't use
497
                       this.
498
   @param[in] verbose  Currently unused, and should always be zero.          */
499
/* ------------------------------------------------------------------------- */
500
void
501
sim_info (SIM_DESC  sd       ATTRIBUTE_UNUSED,
502
          int       verbose  ATTRIBUTE_UNUSED)
503
{
504
}       /* sim_info () */
505
 
506
 
507
/* ------------------------------------------------------------------------- */
508
/*!Run (or resume) the simulated program.
509
 
510
   Hardware simulator: If the SIGRC value returned by
511
   sim_stop_reason() is passed back to the simulator via siggnal then
512
   the hardware simulator shall correctly deliver the hardware event
513
   indicated by that signal.  If a value of zero is passed in then the
514
   simulation will continue as if there were no outstanding signal.
515
   The effect of any other siggnal value is is implementation
516
   dependant.
517
 
518
   Process simulator: If SIGRC is non-zero then the corresponding
519
   signal is delivered to the simulated program and execution is then
520
   continued.  A zero SIGRC value indicates that the program should
521
   continue as normal.
522
 
523
   We carry out the following
524
   - Clear the debug reason register
525
   - Clear watchpoing break generation in debug mode register 2
526
   - Set the debug unit to handle TRAP exceptions
527
   - If stepping, set the single step trigger in debug mode register 1
528
   - Write the resume_npc if it differs from the actual NPC.
529
   - Unstall the processor
530
   - Run the processor.
531
 
532
   On execution completion, we determine the reason for the halt. If it is a
533
   breakpoint, we mark the resumption NPC to be the PPC (so we redo the NPC
534
   location).
535
 
536
   @param[in] sd       Simulation descriptor from sim_open ().
537
   @param[in] step     When non-zero indicates that only a single simulator
538
                       cycle should be emulated.
539
   @param[in] siggnal  If non-zero is a (HOST) SIGRC value indicating the type
540
                       of event (hardware interrupt, signal) to be delivered
541
                       to the simulated program.                             */
542
/* ------------------------------------------------------------------------- */
543
void
544
sim_resume (SIM_DESC  sd,
545
            int       step,
546
            int       siggnal)
547
{
548 232 jeremybenn
  unsigned long int  npc;               /* Next Program Counter */
549
  unsigned long int  drr;               /* Debug Reason Register */
550
  unsigned long int  dsr;               /* Debug Stop Register */
551
  unsigned long int  dmr1;              /* Debug Mode Register 1*/
552
  unsigned long int  dmr2;              /* Debug Mode Register 2*/
553 227 jeremybenn
 
554 232 jeremybenn
  unsigned long int  retval;            /* Return value on Or1ksim exit */
555
 
556 227 jeremybenn
  int                res;               /* Result of a run. */
557
 
558
  /* Clear Debug Reason Register and watchpoint break generation in Debug Mode
559
     Register 2 */
560
  (void) or1ksim_write_spr (OR32_SPR_DRR, 0);
561
 
562
  (void) or1ksim_read_spr (OR32_SPR_DMR2, &dmr2);
563
  dmr2 &= ~OR32_SPR_DMR2_WGB;
564
  (void) or1ksim_write_spr (OR32_SPR_DMR2, dmr2);
565
 
566
  /* Set debug unit to handle TRAP exceptions */
567
  (void) or1ksim_read_spr (OR32_SPR_DSR, &dsr);
568
  dsr |= OR32_SPR_DSR_TE;
569
  (void) or1ksim_write_spr (OR32_SPR_DSR, dsr);
570
 
571 237 jeremybenn
  /* Set the single step trigger in Debug Mode Register 1 if we are
572
     stepping. Otherwise clear it! */
573 227 jeremybenn
  if (step)
574
    {
575
      (void) or1ksim_read_spr (OR32_SPR_DMR1, &dmr1);
576
      dmr1 |= OR32_SPR_DMR1_ST;
577
      (void) or1ksim_write_spr (OR32_SPR_DMR1, dmr1);
578
    }
579 237 jeremybenn
  else
580
    {
581
      (void) or1ksim_read_spr (OR32_SPR_DMR1, &dmr1);
582
      dmr1 &= ~OR32_SPR_DMR1_ST;
583
      (void) or1ksim_write_spr (OR32_SPR_DMR1, dmr1);
584
    }
585 227 jeremybenn
 
586
  /* Set the NPC if it has changed */
587
  (void) or1ksim_read_reg (OR32_NPC_REGNUM, &npc);
588
 
589
  if (npc != sd->resume_npc)
590
    {
591
      (void) or1ksim_write_reg (OR32_NPC_REGNUM, sd->resume_npc);
592
    }
593
 
594
  /* Unstall and run */
595
  or1ksim_set_stall_state (0);
596
  res = or1ksim_run (-1.0);
597
 
598
  /* Determine the reason for stopping. If we hit a breakpoint, then the
599
     resumption NPC must be set to the PPC to allow re-execution of the
600
     trapped instruction. */
601
  switch (res)
602
    {
603
    case OR1KSIM_RC_HALTED:
604
      sd->last_reason = sim_exited;
605 232 jeremybenn
      (void) or1ksim_read_reg (OR32_FIRST_ARG_REGNUM, &retval);
606
      sd->last_rc     = (unsigned int) retval;
607 227 jeremybenn
      sd->resume_npc  = OR32_RESET_EXCEPTION;
608
      break;
609
 
610
    case OR1KSIM_RC_BRKPT:
611
      sd->last_reason = sim_stopped;
612
      sd->last_rc     = TARGET_SIGNAL_TRAP;
613 237 jeremybenn
 
614
      /* This could have been a breakpoint or single step. */
615
      if (step)
616
        {
617
          (void) or1ksim_read_reg (OR32_NPC_REGNUM, &(sd->resume_npc));
618
        }
619
      else
620
        {
621
          (void) or1ksim_read_reg (OR32_PPC_REGNUM, &(sd->resume_npc));
622
        }
623
 
624 227 jeremybenn
      break;
625
 
626
    case OR1KSIM_RC_OK:
627
      /* Should not happen */
628
      fprintf (stderr, "Ooops. Didn't expect OK return from Or1ksim.\n");
629
 
630
      sd->last_reason = sim_running;            /* Should trigger an error! */
631
      sd->last_rc     = TARGET_SIGNAL_NONE;
632
      (void) or1ksim_read_reg (OR32_NPC_REGNUM, &(sd->resume_npc));
633
      break;
634
    }
635
}       /* sim_resume () */
636
 
637
 
638
/* ------------------------------------------------------------------------- */
639
/*!Asynchronous request to stop the simulation.
640
 
641
   @param[in] sd  Simulation descriptor from sim_open (). We don't use this.
642
 
643
   @return  Non-zero indicates that the simulator is able to handle the
644
            request.                                                         */
645
/* ------------------------------------------------------------------------- */
646
int sim_stop (SIM_DESC  sd  ATTRIBUTE_UNUSED)
647
{
648
  return  0;                     /* We don't support this */
649
 
650
}       /* sim_stop () */
651
 
652
 
653
/* ------------------------------------------------------------------------- */
654
/*!Fetch the REASON why the program stopped.
655
 
656
   The reason enumeration indicates why:
657
 
658
   - sim_exited:    The program has terminated. sigrc indicates the target
659
                    dependant exit status.
660
 
661
   - sim_stopped:   The program has stopped.  sigrc uses the host's signal
662
                    numbering as a way of identifying the reaon: program
663
                    interrupted by user via a sim_stop request (SIGINT); a
664
                    breakpoint instruction (SIGTRAP); a completed single step
665
                    (SIGTRAP); an internal error condition (SIGABRT); an
666
                    illegal instruction (SIGILL); Access to an undefined
667
                    memory region (SIGSEGV); Mis-aligned memory access
668
                    (SIGBUS).
669
 
670
                    For some signals information in addition to the signal
671
                    number may be retained by the simulator (e.g. offending
672
                    address), that information is not directly accessable via
673
                    this interface.
674
 
675
   - sim_signalled: The program has been terminated by a signal. The
676
                    simulator has encountered target code that causes the the
677
                    program to exit with signal sigrc.
678
 
679
   - sim_running:
680
   - sim_polling:   The return of one of these values indicates a problem
681
                    internal to the simulator.
682
 
683
   @param[in]  sd      Simulation descriptor from sim_open ().
684
   @param[out] reason  The reason for stopping
685
   @param[out] sigrc   Supplementary information for some values of reason.  */
686
/* ------------------------------------------------------------------------- */
687
void
688
sim_stop_reason (SIM_DESC       sd,
689
                 enum sim_stop *reason,
690
                 int           *sigrc)
691
 {
692
   *reason = sd->last_reason;
693
   *sigrc  = sd->last_rc;
694
 
695
}       /* sim_stop_reason () */
696
 
697
 
698
/* ------------------------------------------------------------------------- */
699
/* Passthru for other commands that the simulator might support.
700
 
701
   Simulators should be prepared to deal with any combination of NULL
702
   or empty command.
703
 
704
   This implementation currently does nothing.
705
 
706
   @param[in] sd  Simulation descriptor from sim_open (). We don't use this.
707
   @param[in] cmd The command to pass through.                               */
708
/* ------------------------------------------------------------------------- */
709
void
710
sim_do_command (SIM_DESC  sd   ATTRIBUTE_UNUSED,
711
                char     *cmd  ATTRIBUTE_UNUSED)
712
{
713
}       /* sim_do_command () */
714
 
715
 
716
/* ------------------------------------------------------------------------- */
717
/* Set the default host_callback_struct
718
 
719
   @note Deprecated, but implemented, since it is still required for linking.
720
 
721
   This implementation currently does nothing.
722
 
723
   @param[in] ptr  The host_callback_struct pointer. Unused here.            */
724
/* ------------------------------------------------------------------------- */
725
void
726
sim_set_callbacks (struct host_callback_struct *ptr ATTRIBUTE_UNUSED)
727
{
728
}       /* sim_set_callbacks () */
729
 
730
 
731
/* ------------------------------------------------------------------------- */
732
/* Set the size of the simulator memory array.
733
 
734
   @note Deprecated, but implemented, since it is still required for linking.
735
 
736
   This implementation currently does nothing.
737
 
738
   @param[in] size  The memory size to use. Unused here.                     */
739
/* ------------------------------------------------------------------------- */
740
void
741
sim_size (int  size  ATTRIBUTE_UNUSED)
742
{
743
}       /* sim_size () */
744
 
745
 
746
/* ------------------------------------------------------------------------- */
747
/* Single step the simulator with tracing enabled.
748
 
749
   @note Deprecated, but implemented, since it is still required for linking.
750
 
751
   This implementation currently does nothing.
752
 
753
   @param[in] sd  The simulator description struct. Unused here.             */
754
/* ------------------------------------------------------------------------- */
755
void
756
sim_trace (SIM_DESC  sd  ATTRIBUTE_UNUSED)
757
{
758
}       /* sim_trace () */

powered by: WebSVN 2.1.0

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