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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [libtoplevel.c] - Blame information for rev 385

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

Line No. Rev Author Line
1 19 jeremybenn
/* libtoplevel.c -- Top level simulator library source file
2
 
3
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
4
   Copyright (C) 2008 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of OpenRISC 1000 Architectural Simulator.
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
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
 
27
/* Autoconf and/or portability configuration */
28
#include "config.h"
29
 
30
/* System includes */
31
#include <stdlib.h>
32
#include <unistd.h>
33
#include <signal.h>
34
 
35
/* Package includes */
36
#include "or1ksim.h"
37
#include "sim-config.h"
38
#include "toplevel-support.h"
39 224 jeremybenn
#include "debug-unit.h"
40 19 jeremybenn
#include "sched.h"
41
#include "execute.h"
42
#include "pic.h"
43 82 jeremybenn
#include "jtag.h"
44 224 jeremybenn
#include "spr-defs.h"
45
#include "sprs.h"
46 19 jeremybenn
 
47 224 jeremybenn
 
48 143 jeremybenn
/* Indices of GDB registers that are not GPRs. Must match GDB settings! */
49
#define MAX_GPRS    32                  /*!< Maximum GPRs */
50
#define PPC_REGNUM  (MAX_GPRS + 0)      /*!< Previous PC */
51
#define NPC_REGNUM  (MAX_GPRS + 1)      /*!< Next PC */
52
#define SR_REGNUM   (MAX_GPRS + 2)      /*!< Supervision Register */
53 19 jeremybenn
 
54 143 jeremybenn
 
55 19 jeremybenn
/*---------------------------------------------------------------------------*/
56
/*!Initialize the simulator.
57
 
58 220 jeremybenn
   The user can pass in any arguments acceptable to the standalone
59
   simulator. Not all make any sense in a library environment.
60 19 jeremybenn
 
61 220 jeremybenn
   @param[in] argc         Size of argument vector
62
   @param[in] argv         Argument vector
63 19 jeremybenn
   @param[in] class_ptr    Pointer to a C++ class instance (for use when
64
                           called by C++)
65
   @param[in] upr          Upcall routine for reads
66
   @param[in] upw          Upcall routine for writes
67
 
68
   @return  0 on success and an error code on failure                        */
69
/*---------------------------------------------------------------------------*/
70
int
71 220 jeremybenn
or1ksim_init (int         argc,
72
              char       *argv[],
73 19 jeremybenn
              void       *class_ptr,
74 93 jeremybenn
              int       (*upr) (void              *class_ptr,
75
                                unsigned long int  addr,
76
                                unsigned char      mask[],
77
                                unsigned char      rdata[],
78
                                int                data_len),
79
              int       (*upw) (void              *class_ptr,
80
                                unsigned long int  addr,
81
                                unsigned char      mask[],
82
                                unsigned char      wdata[],
83
                                int                data_len))
84 19 jeremybenn
{
85
  /* Initialization copied from existing main() */
86
  srand (getpid ());
87
  init_defconfig ();
88
  reg_config_secs ();
89
 
90 220 jeremybenn
  if (parse_args (argc, argv))
91 19 jeremybenn
    {
92
      return OR1KSIM_RC_BADINIT;
93
    }
94
 
95 143 jeremybenn
  config.sim.is_library = 1;    /* Library operation */
96
  config.sim.profile    = 0;     /* No profiling */
97
  config.sim.mprofile   = 0;
98 19 jeremybenn
 
99 143 jeremybenn
  config.ext.class_ptr  = class_ptr;    /* SystemC linkage */
100
  config.ext.read_up    = upr;
101
  config.ext.write_up   = upw;
102 19 jeremybenn
 
103
  print_config ();              /* Will go eventually */
104
  signal (SIGINT, ctrl_c);      /* Not sure we want this really */
105
 
106
  do_stats = config.cpu.superscalar ||
107
             config.cpu.dependstats ||
108
             config.sim.history     ||
109
             config.sim.exe_log;
110
 
111
  sim_init ();
112
 
113
  runtime.sim.ext_int_set = 0;   /* No interrupts pending to be set */
114
  runtime.sim.ext_int_clr = 0;   /* No interrupts pending to be cleared */
115
 
116
  return OR1KSIM_RC_OK;
117
 
118 143 jeremybenn
}       /* or1ksim_init () */
119 19 jeremybenn
 
120
 
121
/*---------------------------------------------------------------------------*/
122
/*!Run the simulator
123
 
124
   The argument is a time in seconds, which is converted to a number of
125
   cycles, if positive. A negative value means "run for ever".
126
 
127 97 jeremybenn
   With the JTAG interface, it is possible to stall the processor between
128
   calls of this function (but not during upcalls). In which case we return
129
   immediately.
130
 
131
   @todo Is it possible (or desirable) to permit JTAG activity during upcalls,
132
         in which case we could stall mid-run.
133
 
134
   @todo Should the JTAG functionality require enabling?
135
 
136 19 jeremybenn
   The semantics are that the duration for which the run may occur may be
137
   changed mid-run by a call to or1ksim_reset_duration(). This is to allow for
138
   the upcalls to generic components adding time, and reducing the time
139
   permitted for ISS execution before synchronization of the parent SystemC
140
   wrapper.
141
 
142
   This is over-ridden if the call was for a negative duration, which means
143
   run forever!
144
 
145
   Uses a simplified version of the old main program loop. Returns success if
146
   the requested number of cycles were run and an error code otherwise.
147
 
148
   @param[in] duration  Time to execute for (seconds)
149
 
150
   @return  OR1KSIM_RC_OK if we run to completion, OR1KSIM_RC_BRKPT if we hit
151
            a breakpoint (not clear how this can be set without CLI access)  */
152
/*---------------------------------------------------------------------------*/
153
int
154
or1ksim_run (double duration)
155
{
156
  const int  num_ints = sizeof (runtime.sim.ext_int_set) * 8;
157
 
158 97 jeremybenn
  /* If we are stalled we can't do anything. We treat this as hitting a
159 143 jeremybenn
     breakpoint or halting. */
160 97 jeremybenn
  if(runtime.cpu.stalled)
161
    {
162 143 jeremybenn
      return runtime.cpu.halted ? OR1KSIM_RC_HALTED : OR1KSIM_RC_BRKPT;
163 97 jeremybenn
    }
164
 
165
  /* Reset the duration */
166 19 jeremybenn
  or1ksim_reset_duration (duration);
167
 
168
  /* Loop until we have done enough cycles (or forever if we had a negative
169
     duration) */
170
  while (duration < 0.0 || (runtime.sim.cycles < runtime.sim.end_cycles))
171
    {
172
      long long int time_start = runtime.sim.cycles;
173
      int i;                    /* Interrupt # */
174
 
175
      /* Each cycle has counter of mem_cycles; this value is joined with cycles
176
       * at the end of the cycle; no sim originated memory accesses should be
177 82 jeremybenn
       * performed in between. */
178 19 jeremybenn
      runtime.sim.mem_cycles = 0;
179
 
180
      if (cpu_clock ())
181
        {
182 143 jeremybenn
          /* This is probably wrong. This is an Or1ksim breakpoint, not a GNU
183
             one. */
184
          return runtime.cpu.halted ? OR1KSIM_RC_HALTED : OR1KSIM_RC_BRKPT;
185 19 jeremybenn
        }
186
 
187 385 jeremybenn
      /* If we are tracing, dump after each instruction. */
188
      if (!runtime.sim.hush)
189
        {
190
          dumpreg ();
191
        }
192
 
193 236 jeremybenn
      /* If we were single stepping, stall immediately. */
194
      if (cpu_state.sprs[SPR_DMR1] & SPR_DMR1_ST)
195
        {
196
          set_stall_state (1);
197
        }
198
 
199 143 jeremybenn
      /* If we are stalled we can't do anything. We treat this as hitting a
200
         breakpoint or halting. */
201
      if(runtime.cpu.stalled)
202
        {
203
          return runtime.cpu.halted ? OR1KSIM_RC_HALTED : OR1KSIM_RC_BRKPT;
204
        }
205
 
206 19 jeremybenn
      runtime.sim.cycles += runtime.sim.mem_cycles;
207
 
208
      /* Take any external interrupts. Outer test is for the common case for
209
         efficiency. */
210
      if (0 != runtime.sim.ext_int_set)
211
        {
212
          for (i = 0; i < num_ints; i++)
213
            {
214
              if (0x1 == ((runtime.sim.ext_int_set >> i) & 0x1))
215
                {
216
                  report_interrupt (i);
217
                  runtime.sim.ext_int_set &= ~(1 << i); /* Clear req flag */
218
                }
219
            }
220
        }
221
 
222
      /* Clear any interrupts as requested. For edge triggered interrupts this
223
         will happen in the same cycle. For level triggered, it must be an
224
         explicit call. */
225
      if (0 != runtime.sim.ext_int_clr)
226
        {
227
          for (i = 0; i < num_ints; i++)
228
            {
229
              /* Only clear interrupts that have been explicitly cleared */
230
              if(0x1 == ((runtime.sim.ext_int_clr >> i) & 0x1))
231
                {
232
                  clear_interrupt(i);
233
                  runtime.sim.ext_int_clr &= ~(1 << i); /* Clear clr flag */
234
                }
235
            }
236
        }
237
 
238
      /* Update the scheduler queue */
239
      scheduler.job_queue->time -= (runtime.sim.cycles - time_start);
240
 
241
      if (scheduler.job_queue->time <= 0)
242
        {
243
          do_scheduler ();
244
        }
245
    }
246
 
247
  return  OR1KSIM_RC_OK;
248
 
249 143 jeremybenn
}       /* or1ksim_run () */
250 19 jeremybenn
 
251
 
252
/*---------------------------------------------------------------------------*/
253
/*!Reset the run-time simulation end point
254
 
255
  Reset the time for which the simulation should run to the specified duration
256
  from NOW (i.e. NOT from when the run started).
257
 
258
  @param[in] duration  Time to run for in seconds                            */
259
/*---------------------------------------------------------------------------*/
260
void
261
or1ksim_reset_duration (double duration)
262
{
263
  runtime.sim.end_cycles =
264
    runtime.sim.cycles +
265
    (long long int) (duration * 1.0e12 / (double) config.sim.clkcycle_ps);
266
 
267 143 jeremybenn
}       /* or1ksim_reset_duration () */
268 19 jeremybenn
 
269
 
270
/*---------------------------------------------------------------------------*/
271
/*!Return time executed so far
272
 
273
   Internal utility to return the time executed so far. Note that this is a
274
   re-entrant routine.
275
 
276
   @return  Time executed so far in seconds                                  */
277
/*---------------------------------------------------------------------------*/
278
static double
279
internal_or1ksim_time ()
280
{
281
  return (double) runtime.sim.cycles * (double) config.sim.clkcycle_ps /
282
    1.0e12;
283
 
284
}       // or1ksim_cycle_count()
285
 
286
 
287
/*---------------------------------------------------------------------------*/
288
/*!Mark a time point in the simulation
289
 
290
   Sets the internal parameter recording this point in the simulation        */
291
/*---------------------------------------------------------------------------*/
292
void
293
or1ksim_set_time_point ()
294
{
295
  runtime.sim.time_point = internal_or1ksim_time ();
296
 
297 143 jeremybenn
}       /* or1ksim_set_time_point () */
298 19 jeremybenn
 
299
 
300
/*---------------------------------------------------------------------------*/
301
/*!Return the time since the time point was set
302
 
303
  Get the value from the internal parameter                                  */
304
/*---------------------------------------------------------------------------*/
305
double
306
or1ksim_get_time_period ()
307
{
308
  return internal_or1ksim_time () - runtime.sim.time_point;
309
 
310 143 jeremybenn
}       /* or1ksim_get_time_period () */
311 19 jeremybenn
 
312
 
313
/*---------------------------------------------------------------------------*/
314
/*!Return the endianism of the model
315
 
316
   Note that this is a re-entrant routine.
317
 
318
   @return 1 if the model is little endian, 0 otherwise.                     */
319
/*---------------------------------------------------------------------------*/
320
int
321
or1ksim_is_le ()
322
{
323
#ifdef OR32_BIG_ENDIAN
324
  return 0;
325
#else
326
  return 1;
327
#endif
328
 
329 143 jeremybenn
}       /* or1ksim_is_le () */
330 19 jeremybenn
 
331
 
332
/*---------------------------------------------------------------------------*/
333
/*!Return the clock rate
334
 
335
   Value is part of the configuration
336
 
337
   @return  Clock rate in Hz.                                                */
338
/*---------------------------------------------------------------------------*/
339
unsigned long int
340
or1ksim_clock_rate ()
341
{
342
  return (unsigned long int) (1000000000000ULL /
343
                              (unsigned long long int) (config.sim.
344
                                                        clkcycle_ps));
345 143 jeremybenn
}       /* or1ksim_clock_rate () */
346 19 jeremybenn
 
347
 
348
/*---------------------------------------------------------------------------*/
349
/*!Trigger an edge triggered interrupt
350
 
351
   This function is appropriate for edge triggered interrupts, which are taken
352
   and then immediately cleared.
353
 
354
   @note There is no check that the specified interrupt number is reasonable
355
   (i.e. <= 31).
356
 
357
   @param[in] i  The interrupt number                                        */
358
/*---------------------------------------------------------------------------*/
359
void
360
or1ksim_interrupt (int i)
361
{
362
  if (!config.pic.edge_trigger)
363
    {
364
      fprintf (stderr, "Warning: or1ksim_interrupt should not be used for "
365 93 jeremybenn
               "level triggered interrupts. Ignored\n");
366 19 jeremybenn
    }
367
  else
368
    {
369
      runtime.sim.ext_int_set |= 1 << i;        // Better not be > 31!
370
      runtime.sim.ext_int_clr |= 1 << i;        // Better not be > 31!
371
    }
372 143 jeremybenn
}       /* or1ksim_interrupt () */
373 19 jeremybenn
 
374
 
375
/*---------------------------------------------------------------------------*/
376
/*!Set a level triggered interrupt
377
 
378
   This function is appropriate for level triggered interrupts, which must be
379
   explicitly cleared in a separate call.
380
 
381
   @note There is no check that the specified interrupt number is reasonable
382
   (i.e. <= 31).
383
 
384
   @param[in] i  The interrupt number to set                                 */
385
/*---------------------------------------------------------------------------*/
386
void
387
or1ksim_interrupt_set (int i)
388
{
389
  if (config.pic.edge_trigger)
390
    {
391
      fprintf (stderr, "Warning: or1ksim_interrupt_set should not be used for "
392 93 jeremybenn
               "edge triggered interrupts. Ignored\n");
393 19 jeremybenn
    }
394
  else
395
    {
396
      runtime.sim.ext_int_set |= 1 << i;        // Better not be > 31!
397
    }
398 143 jeremybenn
}       /* or1ksim_interrupt () */
399 19 jeremybenn
 
400
 
401
/*---------------------------------------------------------------------------*/
402
/*!Clear a level triggered interrupt
403
 
404
   This function is appropriate for level triggered interrupts, which must be
405
   explicitly set first in a separate call.
406
 
407
   @note There is no check that the specified interrupt number is reasonable
408
   (i.e. <= 31).
409
 
410
   @param[in] i  The interrupt number to clear                               */
411
/*---------------------------------------------------------------------------*/
412
void
413
or1ksim_interrupt_clear (int i)
414
{
415
  if (config.pic.edge_trigger)
416
    {
417
      fprintf (stderr, "Warning: or1ksim_interrupt_clear should not be used "
418 93 jeremybenn
               "for edge triggered interrupts. Ignored\n");
419 19 jeremybenn
    }
420
  else
421
    {
422
      runtime.sim.ext_int_clr |= 1 << i;        // Better not be > 31!
423
    }
424 143 jeremybenn
}       /* or1ksim_interrupt () */
425 82 jeremybenn
 
426
 
427
/*---------------------------------------------------------------------------*/
428
/*!Reset the JTAG interface
429
 
430
   @note Like all the JTAG interface functions, this must not be called
431
         re-entrantly while a call to any other function (e.g. or1kim_run ())
432
         is in progress. It is the responsibility of the caller to ensure this
433
         constraint is met, for example by use of a SystemC mutex.
434
 
435
   @return  The time in seconds which the reset took.                        */
436
/*---------------------------------------------------------------------------*/
437
double
438
or1ksim_jtag_reset ()
439
{
440 98 jeremybenn
  /* Number of JTAG clock cycles a reset sequence takes */
441
  const double  JTAG_RESET_CYCLES = 5.0;
442 82 jeremybenn
 
443 98 jeremybenn
  jtag_reset ();
444
 
445
  return  JTAG_RESET_CYCLES  * (double) config.debug.jtagcycle_ps / 1.0e12;
446
 
447 82 jeremybenn
}       /* or1ksim_jtag_reset () */
448
 
449
 
450
/*---------------------------------------------------------------------------*/
451
/*!Shift a JTAG instruction register
452
 
453
   @note Like all the JTAG interface functions, this must not be called
454
         re-entrantly while a call to any other function (e.g. or1kim_run ())
455
         is in progress. It is the responsibility of the caller to ensure this
456
         constraint is met, for example by use of a SystemC mutex.
457
 
458
   The register is represented as a vector of bytes, with the byte at offset
459
   zero being shifted first, and the least significant bit in each byte being
460
   shifted first. Where the register will not fit in an exact number of bytes,
461
   the odd bits are in the highest numbered byte, shifted to the low end.
462
 
463
   The only JTAG instruction for which we have any significant behavior in
464
   this model is DEBUG. For completeness the register is parsed and a warning
465
   given if any register other than DEBUG is shifted.
466
 
467 98 jeremybenn
   @param[in,out] jreg      The register to shift in, and the register shifted
468
                            back out.
469
   @param[in]     num_bits  The number of bits in the register. Just for
470
                            sanity check (it should always be 4).
471 82 jeremybenn
 
472
   @return  The time in seconds which the shift took.                        */
473
/*---------------------------------------------------------------------------*/
474
double
475 98 jeremybenn
or1ksim_jtag_shift_ir (unsigned char *jreg,
476
                       int            num_bits)
477 82 jeremybenn
{
478 98 jeremybenn
  jtag_shift_ir (jreg, num_bits);
479 82 jeremybenn
 
480 98 jeremybenn
  return  (double) num_bits * (double) config.debug.jtagcycle_ps / 1.0e12;
481
 
482 82 jeremybenn
}       /* or1ksim_jtag_shift_ir () */
483
 
484
 
485
/*---------------------------------------------------------------------------*/
486
/*!Shift a JTAG data register
487
 
488
   @note Like all the JTAG interface functions, this must not be called
489
         re-entrantly while a call to any other function (e.g. or1kim_run ())
490
         is in progress. It is the responsibility of the caller to ensure this
491
         constraint is met, for example by use of a SystemC mutex.
492
 
493
   The register is represented as a vector of bytes, with the byte at offset
494
   zero being shifted first, and the least significant bit in each byte being
495
   shifted first. Where the register will not fit in an exact number of bytes,
496
   the odd bits are in the highest numbered byte, shifted to the low end.
497
 
498
   The register is parsed to determine which of the six possible register
499
   types it could be.
500
   - MODULE_SELECT
501
   - WRITE_COMMNAND
502
   - READ_COMMAND
503
   - GO_COMMAND
504
   - WRITE_CONTROL
505
   - READ_CONTROL
506
 
507
   @note In practice READ_COMMAND is not used. However the functionality is
508
         provided for future compatibility.
509
 
510 98 jeremybenn
   @param[in,out] jreg      The register to shift in, and the register shifted
511
                            back out.
512
   @param[in]     num_bits  The number of bits in the register. This is
513
                            essential to prevent bugs where the size of
514
                            register supplied is incorrect.
515 82 jeremybenn
 
516
   @return  The time in seconds which the shift took.                        */
517
/*---------------------------------------------------------------------------*/
518
double
519 98 jeremybenn
or1ksim_jtag_shift_dr (unsigned char *jreg,
520
                       int            num_bits)
521 82 jeremybenn
{
522 98 jeremybenn
  jtag_shift_dr (jreg, num_bits);
523 82 jeremybenn
 
524 98 jeremybenn
  return  (double) num_bits * (double) config.debug.jtagcycle_ps / 1.0e12;
525
 
526 82 jeremybenn
}       /* or1ksim_jtag_shift_dr () */
527 143 jeremybenn
 
528
 
529
/*---------------------------------------------------------------------------*/
530
/*!Read a block of memory.
531
 
532 224 jeremybenn
   @param[in]  addr  The address to read from.
533 143 jeremybenn
   @param[out] buf   Where to put the data.
534
   @param[in]  len   The number of bytes to read.
535
 
536
   @return  Number of bytes read, or zero if error.                          */
537
/*---------------------------------------------------------------------------*/
538
int
539 230 jeremybenn
or1ksim_read_mem (unsigned long int  addr,
540
                  unsigned char     *buf,
541
                  int                len)
542 143 jeremybenn
{
543
  int             off;                  /* Offset into the memory */
544
 
545
  /* Fill the buffer with data */
546
  for (off = 0; off < len; off++)
547
    {
548
      /* Check memory area is valid */
549
      if (NULL == verify_memoryarea (addr + off))
550
        {
551
          /* Fail silently - others can raise any error message. */
552
          return  0;
553
        }
554
      else
555
        {
556
          /* Get the memory direct - no translation. */
557
          buf[off] = eval_direct8 (addr + off, 0, 0);
558
        }
559
    }
560
 
561
  return  len;
562
 
563
}       /* or1ksim_read_mem () */
564
 
565
 
566
/*---------------------------------------------------------------------------*/
567
/*!Write a block of memory.
568
 
569 224 jeremybenn
   @param[in] addr  The address to write to.
570 143 jeremybenn
   @param[in] buf   Where to get the data from.
571
   @param[in] len   The number of bytes to write.
572
 
573
   @return  Number of bytes written, or zero if error.                       */
574
/*---------------------------------------------------------------------------*/
575
int
576 385 jeremybenn
or1ksim_write_mem (unsigned long int    addr,
577
                   const unsigned char *buf,
578
                   int                  len)
579 143 jeremybenn
{
580
  int             off;                  /* Offset into the memory */
581
 
582
  /* Write the bytes to memory */
583
  for (off = 0; off < len; off++)
584
    {
585
      if (NULL == verify_memoryarea (addr + off))
586
        {
587
          /* Fail silently - others can raise any error message. */
588
          return  0;
589
        }
590
      else
591
        {
592
          /* circumvent the read-only check usually done for mem accesses data
593
             is in host order, because that's what set_direct32 needs */
594
          set_program8 (addr + off, buf[off]);
595
        }
596
    }
597
 
598
  return  len;
599
 
600
}       /* or1ksim_write_mem () */
601
 
602
 
603
/*---------------------------------------------------------------------------*/
604 224 jeremybenn
/*!Read a SPR
605 143 jeremybenn
 
606 224 jeremybenn
   @param[in]  sprnum      The SPR to read.
607
   @param[out] sprval_ptr  Where to put the data.
608 143 jeremybenn
 
609 224 jeremybenn
   @return  Non-zero (TRUE) on success, zero (FALSE) otherwise.              */
610 143 jeremybenn
/*---------------------------------------------------------------------------*/
611
int
612 230 jeremybenn
or1ksim_read_spr (int                sprnum,
613
                  unsigned long int *sprval_ptr)
614 143 jeremybenn
{
615 224 jeremybenn
  /* SPR numbers are up to 16 bits long */
616
  if ((unsigned int) sprnum <= 0xffff)
617 143 jeremybenn
    {
618 224 jeremybenn
      *sprval_ptr = (unsigned int) mfspr ((uint16_t) sprnum);
619
      return  1;
620 143 jeremybenn
    }
621 224 jeremybenn
  else
622 143 jeremybenn
    {
623 224 jeremybenn
      return  0;                 /* Silent failure */
624 143 jeremybenn
    }
625 224 jeremybenn
}       /* or1skim_read_spr () */
626
 
627
 
628
/*---------------------------------------------------------------------------*/
629
/*!Write a SPR
630
 
631
   @param[in] sprnum  The SPR to write.
632
   @param[in] sprval  The data to write.
633
 
634
   @return  Non-zero (TRUE) on success, zero (FALSE) otherwise.              */
635
/*---------------------------------------------------------------------------*/
636
int
637 230 jeremybenn
or1ksim_write_spr (int                sprnum,
638
                   unsigned long int  sprval)
639 224 jeremybenn
{
640
  /* SPR numbers are up to 16 bits long */
641
  if ((unsigned int) sprnum <= 0xffff)
642 143 jeremybenn
    {
643 224 jeremybenn
      mtspr ((uint16_t) sprnum, sprval);
644
      return  1;
645 143 jeremybenn
    }
646 224 jeremybenn
  else
647 143 jeremybenn
    {
648 224 jeremybenn
      return  0;                 /* Silent failure */
649 143 jeremybenn
    }
650 224 jeremybenn
}       /* or1ksim_write_spr () */
651
 
652
 
653
/*---------------------------------------------------------------------------*/
654
/*!Read a single register
655
 
656
   The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PC
657
   (i.e. SPR NPC) and SR (i.e. SPR SR).
658
 
659
   Map to the corresponding SPR.
660
 
661
   @param[in]  regnum      The register to read.
662
   @param[out] regval_ptr  Where to put the data.
663
 
664
   @return  Non-zero (TRUE) on success, zero (FALSE) otherwise.              */
665
/*---------------------------------------------------------------------------*/
666
int
667 230 jeremybenn
or1ksim_read_reg (int                 regnum,
668
                  unsigned long int  *regval_ptr)
669 224 jeremybenn
{
670
  /* GPR's */
671
  if (regnum < MAX_GPRS)
672 143 jeremybenn
    {
673 224 jeremybenn
      return or1ksim_read_spr (regnum + SPR_GPR_BASE, regval_ptr);
674 143 jeremybenn
    }
675 224 jeremybenn
 
676
  /* SPR's or unknown */
677
  switch (regnum)
678 143 jeremybenn
    {
679 224 jeremybenn
    case PPC_REGNUM: return or1ksim_read_spr (SPR_PPC, regval_ptr);
680
    case NPC_REGNUM: return or1ksim_read_spr (SPR_NPC, regval_ptr);
681
    case SR_REGNUM:  return or1ksim_read_spr (SPR_SR, regval_ptr);
682
    default:
683 143 jeremybenn
      /* Silent error response if we don't know the register */
684
      return  0;
685
    }
686
}       /* or1ksim_read_reg () */
687
 
688
 
689
/*---------------------------------------------------------------------------*/
690
/*!Write a single register
691
 
692
   The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PC
693 224 jeremybenn
   (i.e. SPR NPC) and SR (i.e. SPR SR).
694 143 jeremybenn
 
695 224 jeremybenn
   Map to the corresponding SPR
696 143 jeremybenn
 
697 224 jeremybenn
   @param[in] regval  The register to write.
698 143 jeremybenn
   @param[in] regnum  The register to write.
699
 
700 224 jeremybenn
   @return  Non-zero (TRUE) on success, zero (FALSE) otherwise.              */
701 143 jeremybenn
/*---------------------------------------------------------------------------*/
702
int
703 230 jeremybenn
or1ksim_write_reg (int                regnum,
704
                   unsigned long int  regval)
705 143 jeremybenn
{
706 224 jeremybenn
  /* GPR's */
707
  if (regnum < MAX_GPRS)
708 143 jeremybenn
    {
709 224 jeremybenn
      return or1ksim_write_spr (regnum + SPR_GPR_BASE, regval);
710 143 jeremybenn
    }
711
 
712 224 jeremybenn
  /* SPR's or unknown */
713
  switch (regnum)
714 143 jeremybenn
    {
715 224 jeremybenn
    case PPC_REGNUM: return or1ksim_write_spr (SPR_PPC, regval);
716
    case NPC_REGNUM: return or1ksim_write_spr (SPR_NPC, regval);
717
    case SR_REGNUM:  return or1ksim_write_spr (SPR_SR,  regval);
718
    default:
719 143 jeremybenn
      /* Silent error response if we don't know the register */
720
      return  0;
721
    }
722 224 jeremybenn
}       /* or1ksim_write_reg () */
723 143 jeremybenn
 
724 224 jeremybenn
 
725
/*---------------------------------------------------------------------------*/
726
/*!Set the simulator stall state.
727 143 jeremybenn
 
728 224 jeremybenn
   @param[in] state  The stall state to set.                                 */
729
/*---------------------------------------------------------------------------*/
730
void
731
or1ksim_set_stall_state (int  state)
732
{
733
  set_stall_state (state ? 1 : 0);
734 143 jeremybenn
 
735 224 jeremybenn
}       /* or1ksim_set_stall_state () */

powered by: WebSVN 2.1.0

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