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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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