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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [debug/] [debug-unit.c] - Blame information for rev 861

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

Line No. Rev Author Line
1 19 jeremybenn
/* debug_unit.c -- Simulation of Or1k debug unit
2
 
3
   Copyright (C) 2001 Chris Ziomkowski, chris@asics.ws
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
/* This is an architectural level simulation of the Or1k debug unit as
27
   described in OpenRISC 1000 System Architecture Manual, v. 0.1 on 22 April,
28
   2001. This unit is described in Section 13.
29
 
30
   Every attempt has been made to be as accurate as possible with respect to
31
   the registers and the behavior. There are no known limitations at this
32
   time.
33
 
34
   Note in particular that there is an alternative (smaller) debug unit on the
35
   OpenCores website, designed by Igor Mohor. At present this interface is NOT
36
   supported here. */
37
 
38
/* Autoconf and/or portability configuration */
39
#include "config.h"
40
#include "port.h"
41
 
42
/* System includes */
43
#include <stdlib.h>
44
#include <stdio.h>
45
#include <assert.h>
46
 
47
/* Package includes */
48
#include "arch.h"
49
#include "debug-unit.h"
50
#include "sim-config.h"
51
#include "except.h"
52
#include "abstract.h"
53
#include "parse.h"
54
#include "gdb.h"
55
#include "except.h"
56
#include "opcode/or32.h"
57
#include "spr-defs.h"
58
#include "execute.h"
59
#include "sprs.h"
60
#include "toplevel-support.h"
61
#include "rsp-server.h"
62
 
63
 
64
/*! The fields for the RISCOP register in the development interface scan chain
65
    (JTAG_CHAIN_DEVELOPMENT). */
66
#define RISCOP_STALL  0x00000001        /*!< Stall processor */
67
#define RISCOP_RESET  0x00000002        /*!< Reset processor (clears stall) */
68
 
69
/*! The various addresses in the development interface scan chain
70
    (JTAG_CHAIN_DEVELOPMENT). Only documents the ones we actually have*/
71
enum development_interface_address_space
72
{
73
  DEVELOPINT_RISCOP  =  4,
74
  DEVELOPINT_MAX     = 27,
75
};
76
 
77
/*! Data structure holding debug registers and their bits */
78
unsigned long  development[DEVELOPINT_MAX + 1];
79
 
80
/*! The current scan chain being accessed */
81
static enum debug_scan_chain_ids current_scan_chain = JTAG_CHAIN_GLOBAL;
82
 
83
/*! External STALL signal to debug interface */
84
static int in_reset = 0;
85
 
86
/*! Forward declaration of static functions */
87
static int calculate_watchpoints (enum debug_unit_action action,
88
                                  unsigned long          udata);
89
static int get_devint_reg (unsigned int   addr,
90
                           unsigned long *data);
91
static int set_devint_reg (unsigned int   addr,
92
                           unsigned long  data);
93
static int debug_set_mem (oraddr_t address, uorreg_t data);
94
static int debug_get_mem (oraddr_t address, uorreg_t * data);
95
 
96
 
97
 
98
/*---------------------------------------------------------------------------*/
99
/*!Reset the debug unit
100
 
101
   Clear all development inteface registers                                  */
102
/*---------------------------------------------------------------------------*/
103
void
104
du_reset ()
105
{
106
  int  i;
107
 
108
  for (i = 0; i <= DEVELOPINT_MAX; i++)
109
    {
110
      development[i] = 0;
111
    }
112
 
113
  set_stall_state (0);
114
 
115
}       /* du_reset () */
116
 
117
 
118
/*---------------------------------------------------------------------------*/
119
/*!Set the stall state of the processor
120
 
121
   @param[in] state  If non-zero stall the processor.                        */
122
/*---------------------------------------------------------------------------*/
123
void
124
set_stall_state (int state)
125
{
126
#if DYNAMIC_EXECUTION
127
  if (state)
128
    {
129
      PRINTF("FIXME: Emulating a stalled cpu not implemented "
130
             "(in the dynamic execution model)\n");
131
    }
132
#endif
133
 
134
  development[DEVELOPINT_RISCOP] &= ~RISCOP_STALL;
135
  development[DEVELOPINT_RISCOP] |= state ? RISCOP_STALL : 0;
136
 
137
  runtime.cpu.stalled             = state;
138
 
139 532 jeremybenn
  /* If we unstall, any changed NPC becomes valid again and we cannot be
140
     halted. */
141 19 jeremybenn
 
142
  if (!runtime.cpu.stalled)
143
    {
144
      cpu_state.npc_not_valid = 0;
145 532 jeremybenn
      runtime.cpu.halted      = 0;
146 19 jeremybenn
    }
147
}       /* set_stall_state () */
148
 
149
 
150
/*---------------------------------------------------------------------------*/
151
/*!Check for a breakpoint on this action
152
 
153
   @note This does not include single-stepping - that will be picked up in the
154
   main loop AFTER the instruction has executed.
155
 
156
   @param[in] action  The action to be checked
157
   @param[in] udata   The data to compare against (for some actions)
158
 
159
   @return  Non-zero if there was a breakpoint, 0 otherwise.                 */
160
/*---------------------------------------------------------------------------*/
161
int
162
check_debug_unit (enum debug_unit_action  action,
163
                  unsigned long           udata)
164
{
165
  /* Do not stop if we have debug module disabled or during reset */
166
  if (!config.debug.enabled || in_reset)
167
    {
168
      return 0;
169
    }
170
 
171
  /* is any watchpoint enabled to generate a break or count? If not, ignore */
172
  if (cpu_state.sprs[SPR_DMR2] & (SPR_DMR2_WGB | SPR_DMR2_AWTC))
173
    {
174
      return  calculate_watchpoints (action, udata);
175
    }
176
 
177
  return 0;                      /* No breakpoint */
178
 
179
}       /* check_debug_unit () */
180
 
181
 
182
/*---------------------------------------------------------------------------*/
183
/*!Check whether we should stall the RISC or cause an exception.
184
 
185
   Rewritten by JPB for current architecture.
186
 
187
   @param[in] action  The action to be checked
188
   @param[in] udata   The data to compare against (for some actions)
189
 
190
   @return  Non-zero if this should generate a breakpoint                    */
191
/*---------------------------------------------------------------------------*/
192
static int
193
calculate_watchpoints (enum debug_unit_action  action,
194
                       unsigned long           udata)
195
{
196
  int  i;
197
  int  match_found      = 0;             /* Flag if we found any matchpoint */
198
  int  breakpoint_found;                /* Flag if we found any breakpoint */
199
 
200
  /* Debug registers */
201
  unsigned long  dmr1;
202
  unsigned long  dmr2;
203
 
204
  /* Debug bit fields */
205
  unsigned char  counter0_enabled;
206
  unsigned char  counter1_enabled;
207
  unsigned char  counter0_matched;
208
  unsigned char  counter1_matched;
209
 
210
  unsigned char  mp[MAX_MATCHPOINTS];   /* Which matchpoints matched */
211
  unsigned char  wp[MAX_WATCHPOINTS];   /* Which watchpoints matched */
212
 
213 82 jeremybenn
  memset (mp, 0, sizeof (mp));
214
  memset (wp, 0, sizeof (wp));
215 19 jeremybenn
 
216
  /* First find the matchpoints */
217
 
218
  for (i = 0; i < MAX_MATCHPOINTS; i++)
219
    {
220
      unsigned long  dcr    = cpu_state.sprs[SPR_DCR (i)];
221
      unsigned char  dcr_dp = dcr & SPR_DCR_DP;
222
      unsigned char  dcr_cc;
223
      unsigned char  dcr_sc;
224
      unsigned char  dcr_ct;
225
      int            match_so_far;
226
 
227
      if (SPR_DCR_DP != dcr_dp)
228
        {
229
          continue;
230
        }
231
 
232
      dcr_ct       = dcr & SPR_DCR_CT;
233
      match_so_far = 0;
234
 
235
      switch (dcr_ct)
236
        {
237
        case SPR_DCR_CT_IFEA:
238
          match_so_far = (DebugInstructionFetch == action);
239
          break;
240
 
241
        case SPR_DCR_CT_LEA:
242
          match_so_far = (DebugLoadAddress == action);
243
          break;
244
 
245
        case SPR_DCR_CT_SEA:
246
          match_so_far = (DebugStoreAddress == action);
247
          break;
248
 
249
        case SPR_DCR_CT_LD:
250
          match_so_far = (DebugLoadData == action);
251
          break;
252
 
253
        case SPR_DCR_CT_SD:
254
          match_so_far = (DebugStoreData == action);
255
          break;
256
 
257
        case SPR_DCR_CT_LSEA:
258
          match_so_far = (DebugLoadAddress == action) ||
259
            (DebugStoreAddress == action);
260
          break;
261
 
262
        case SPR_DCR_CT_LSD:
263
          match_so_far = (DebugLoadData == action) ||
264
            (DebugStoreData == action);
265
          break;
266
 
267
        default:
268
          break;
269
        }
270
 
271
      if (!match_so_far)
272
        {
273
          continue;                     /* Skip to the end of the loop */
274
        }
275
 
276
      dcr_sc = dcr & SPR_DCR_SC;
277
      dcr_cc = dcr & SPR_DCR_CC;
278
 
279
      /* Perform signed comparison?  */
280
      if (SPR_DCR_SC == dcr_sc)
281
        {
282
          long int sop1 = udata;
283
          long int sop2 = cpu_state.sprs[SPR_DVR (i)];
284
 
285
          switch (dcr & SPR_DCR_CC)
286
            {
287
            case SPR_DCR_CC_MASKED:
288
              mp[i] = sop1 & sop2;
289
              break;
290
 
291
            case SPR_DCR_CC_EQUAL:
292
              mp[i] = sop1 == sop2;
293
              break;
294
 
295
            case SPR_DCR_CC_NEQUAL:
296
              mp[i] = sop1 != sop2;
297
              break;
298
 
299
            case SPR_DCR_CC_LESS:
300
              mp[i] = sop1 < sop2;
301
              break;
302
 
303
            case SPR_DCR_CC_LESSE:
304
              mp[i] = sop1 <= sop2;
305
              break;
306
 
307
            case SPR_DCR_CC_GREAT:
308
              mp[i] = sop1 > sop2;
309
              break;
310
 
311
            case SPR_DCR_CC_GREATE:
312
              mp[i] = sop1 >= sop2;
313
              break;
314
 
315
            default:
316
              break;
317
            }
318
        }
319
      else
320
        {
321
          unsigned long int op1 = udata;
322
          unsigned long int op2 = cpu_state.sprs[SPR_DVR (i)];
323
 
324
          switch (dcr & SPR_DCR_CC)
325
            {
326
            case SPR_DCR_CC_MASKED:
327
              mp[i] = op1 & op2;
328
              break;
329
 
330
            case SPR_DCR_CC_EQUAL:
331
              mp[i] = op1 == op2;
332
              break;
333
 
334
            case SPR_DCR_CC_NEQUAL:
335
              mp[i] = op1 != op2;
336
              break;
337
 
338
            case SPR_DCR_CC_LESS:
339
              mp[i] = op1 < op2;
340
              break;
341
 
342
            case SPR_DCR_CC_LESSE:
343
              mp[i] = op1 <= op2;
344
              break;
345
 
346
            case SPR_DCR_CC_GREAT:
347
              mp[i] = op1 > op2;
348
              break;
349
 
350
            case SPR_DCR_CC_GREATE:
351
              mp[i] = op1 >= op2;
352
              break;
353
 
354
            default:
355
              break;
356
            }
357
        }
358
 
359
      if (mp[i])
360
        {
361
          match_found = 1;      /* A match was found */
362
        }
363
    }
364
 
365
  /* If no match was found, give up here, since none of the watchpoints will
366
     change. */
367
 
368
  if (!match_found)
369
    {
370
      return 0;
371
    }
372
 
373
  /* Compute the non-counting watchpoints. Done by slog, since each one is
374
     different. The counting watchpoints will be done AFTER the counts have
375
     been incremented. Done in order, so the chaining works correctly. This
376
     code expects the number of matchpoints to be 8. As a precaution, that is
377
     asserted here.
378
 
379
     IMPORTANT.....
380
 
381
     The architecture manual appears to be wrong, in suggesting that
382
     watchpoint 4 chains with external watchpoint in the same way as
383
     watchpoint 0. The Verilog source code suggests it chains with watchpoint
384
     3. */
385
 
386
  assert (MAX_MATCHPOINTS == 8);
387
 
388
  dmr1 = cpu_state.sprs[SPR_DMR1];
389
 
390
  switch (dmr1 & SPR_DMR1_CW0)
391
    {
392
    case 0:
393
      wp[0] = mp[0];
394
      break;
395
 
396
    case SPR_DMR1_CW0_AND:
397
      printf ("External watchpoint not supported\n");
398
      break;
399
 
400
    case SPR_DMR1_CW0_OR:
401
      printf ("External watchpoint not supported\n");
402
      break;
403
 
404
    case SPR_DMR1_CW0:
405
      printf ("SPR DMR1_CW0=11 reserved\n");
406
      break;
407
    }
408
 
409
  switch (dmr1 & SPR_DMR1_CW1)
410
    {
411
    case 0:
412
      wp[1] = mp[1];
413
      break;
414
 
415
    case SPR_DMR1_CW1_AND:
416
      wp[1] = mp[1] && wp[0];
417
      break;
418
 
419
    case SPR_DMR1_CW1_OR:
420
      wp[1] = mp[1] || wp[0];
421
      break;
422
 
423
    case SPR_DMR1_CW1:
424
      printf ("SPR DMR1_CW1=11 reserved\n");
425
      break;
426
    }
427
 
428
  switch (dmr1 & SPR_DMR1_CW2)
429
    {
430
    case 0:
431
      wp[2] = mp[2];
432
      break;
433
 
434
    case SPR_DMR1_CW2_AND:
435
      wp[2] = mp[2] && wp[1];
436
      break;
437
 
438
    case SPR_DMR1_CW2_OR:
439
      wp[2] = mp[2] || wp[1];
440
      break;
441
 
442
    case SPR_DMR1_CW2:
443
      printf ("SPR DMR1_CW2=11 reserved\n");
444
      break;
445
    }
446
 
447
  switch (dmr1 & SPR_DMR1_CW3)
448
    {
449
    case 0:
450
      wp[3] = mp[3];
451
      break;
452
 
453
    case SPR_DMR1_CW3_AND:
454
      wp[3] = mp[3] && wp[2];
455
      break;
456
 
457
    case SPR_DMR1_CW3_OR:
458
      wp[3] = mp[3] || wp[2];
459
      break;
460
 
461
    case SPR_DMR1_CW3:
462
      printf ("SPR DMR1_CW3=11 reserved\n");
463
      break;
464
    }
465
 
466
  switch (dmr1 & SPR_DMR1_CW4)
467
    {
468
    case 0:
469
      wp[4] = mp[4];
470
      break;
471
 
472
    case SPR_DMR1_CW4_AND:
473
      wp[4] = mp[4] && wp[3];
474
      break;
475
 
476
    case SPR_DMR1_CW4_OR:
477
      wp[4] = mp[4] || wp[3];
478
      break;
479
 
480
    case SPR_DMR1_CW4:
481
      printf ("SPR DMR1_CW4=11 reserved\n");
482
      break;
483
    }
484
 
485
  switch (dmr1 & SPR_DMR1_CW5)
486
    {
487
    case 0:
488
      wp[5] = mp[5];
489
      break;
490
 
491
    case SPR_DMR1_CW5_AND:
492
      wp[5] = mp[5] && wp[4];
493
      break;
494
 
495
    case SPR_DMR1_CW5_OR:
496
      wp[5] = mp[5] || wp[4];
497
      break;
498
 
499
    case SPR_DMR1_CW5:
500
      printf ("SPR DMR1_CW5=11 reserved\n");
501
      break;
502
    }
503
 
504
  switch (dmr1 & SPR_DMR1_CW6)
505
    {
506
    case 0:
507
      wp[6] = mp[6];
508
      break;
509
 
510
    case SPR_DMR1_CW6_AND:
511
      wp[6] = mp[6] && wp[5];
512
      break;
513
 
514
    case SPR_DMR1_CW6_OR:
515
      wp[6] = mp[6] || wp[5];
516
      break;
517
 
518
    case SPR_DMR1_CW6:
519
      printf ("SPR DMR1_CW6=11 reserved\n");
520
      break;
521
    }
522
 
523
  switch (dmr1 & SPR_DMR1_CW7)
524
    {
525
    case 0:
526
      wp[7] = mp[7];
527
      break;
528
 
529
    case SPR_DMR1_CW7_AND:
530
      wp[7] = mp[7] && wp[6];
531
      break;
532
 
533
    case SPR_DMR1_CW7_OR:
534
      wp[7] = mp[7] || wp[6];
535
      break;
536
 
537
    case SPR_DMR1_CW7:
538
      printf ("SPR DMR1_CW7=11 reserved\n");
539
      break;
540
    }
541
 
542
  /* Increment counters. Note the potential ambiguity, if the last two
543
     watchpoints, which depend on the counters, also increment the
544
     counters. Since they cannot yet be set, they are not tested here. */
545
 
546
  dmr2             = cpu_state.sprs[SPR_DMR2];
547
 
548
  counter0_enabled = SPR_DMR2_WCE0 == (dmr2 & SPR_DMR2_WCE0);
549
  counter1_enabled = SPR_DMR2_WCE1 == (dmr2 & SPR_DMR2_WCE1);
550
 
551
  if (counter0_enabled || counter1_enabled)
552
    {
553
      short int  counter0 = cpu_state.sprs[SPR_DWCR0] & SPR_DWCR_COUNT;
554
      short int  counter1 = cpu_state.sprs[SPR_DWCR1] & SPR_DWCR_COUNT;
555
 
556
      for (i = 0; i < MAX_WATCHPOINTS - 2; i++)
557
        {
558
          int  use_counter_0 = (dmr2 >> (SPR_DMR2_AWTC_OFF + i) & 1) != 1;
559
 
560
          if (use_counter_0)
561
            {
562
              if (counter0_enabled && wp[i])
563
                {
564
                  counter0++;
565
                }
566
            }
567
          else
568
            {
569
              if (counter1_enabled && wp[i])
570
                {
571
                  counter1++;
572
                }
573
            }
574
        }
575
 
576
      cpu_state.sprs[SPR_DWCR0] &= ~SPR_DWCR_COUNT;
577
      cpu_state.sprs[SPR_DWCR0] |= counter0;
578
      cpu_state.sprs[SPR_DWCR1] &= ~SPR_DWCR_COUNT;
579
      cpu_state.sprs[SPR_DWCR1] |= counter1;
580
    }
581
 
582
  /* Sort out the last two matchpoints, which depend on counters
583
 
584
     IMPORTANT.....
585
 
586
     The architecture manual appears to be wrong, in suggesting that
587
     watchpoint 8 chains with watchpoint 3 and watchpoint 9 chains with
588
     watchpoint 7. The Verilog source code suggests watchpoint 8 chains with
589
     watchpoint 7 and watchpoint 9 chains with watchpoint 8. */
590
 
591
  counter0_matched =
592
    ((cpu_state.sprs[SPR_DWCR0] & SPR_DWCR_COUNT) ==
593
     ((cpu_state.sprs[SPR_DWCR0] & SPR_DWCR_MATCH) >> SPR_DWCR_MATCH_OFF));
594
  counter1_matched =
595
    ((cpu_state.sprs[SPR_DWCR1] & SPR_DWCR_COUNT) ==
596
     ((cpu_state.sprs[SPR_DWCR1] & SPR_DWCR_MATCH) >> SPR_DWCR_MATCH_OFF));
597
 
598
  switch (dmr1 & SPR_DMR1_CW8)
599
    {
600
    case 0:
601
      wp[8] = counter0_matched;
602
      break;
603
 
604
    case SPR_DMR1_CW8_AND:
605
      wp[8] = counter0_matched && wp[7];
606
      break;
607
 
608
    case SPR_DMR1_CW8_OR:
609
      wp[8] = counter0_matched || wp[7];
610
      break;
611
 
612
    case SPR_DMR1_CW8:
613
      printf ("SPR DMR1_CW8=11 reserved\n");
614
      break;
615
    }
616
 
617
  switch (dmr1 & SPR_DMR1_CW9)
618
    {
619
    case 0:
620
      wp[9] = counter1_matched;
621
      break;
622
 
623
    case SPR_DMR1_CW9_AND:
624
      wp[9] = counter1_matched && wp[8];
625
      break;
626
 
627
    case SPR_DMR1_CW9_OR:
628
      wp[9] = counter1_matched || wp[8];
629
      break;
630
 
631
    case SPR_DMR1_CW9:
632
      printf ("SPR DMR1_CW9=11 reserved\n");
633
      break;
634
    }
635
 
636
  /* Now work out which watchpoints (if any) have caused a breakpoint and
637
     update the breakpoint status bits */
638
 
639
  breakpoint_found = 0;
640
 
641
  for (i = 0; i < MAX_WATCHPOINTS; i++)
642
    {
643
      if (1 == (dmr2 >> (SPR_DMR2_WGB_OFF + i) & 1))
644
        {
645
          if (wp[i])
646
            {
647
              dmr2             |= 1 << (SPR_DMR2_WBS_OFF + i);
648
              breakpoint_found  = 1;
649
            }
650
        }
651
    }
652
 
653
  cpu_state.sprs[SPR_DMR2] = dmr2;
654
 
655
  return breakpoint_found;
656
 
657
}       /* calculate_watchpoints () */
658
 
659
 
660
/*---------------------------------------------------------------------------*/
661
/*!Get a JTAG register
662
 
663
   Action depends on which scan chain is currently active.
664
 
665
   @param[in]  address  Address on the scan chain
666
   @param[out] data     Where to put the result of the read
667
 
668
   @return  An error code (including ERR_NONE) if there is no error          */
669
/*---------------------------------------------------------------------------*/
670
int
671
debug_get_register (oraddr_t  address,
672
                    uorreg_t *data)
673
{
674
  int  err = ERR_NONE;
675
 
676
  switch (current_scan_chain)
677
    {
678
    case JTAG_CHAIN_DEBUG_UNIT:
679
      *data = mfspr (address);
680
      break;
681
 
682
    case JTAG_CHAIN_TRACE:
683
      err = JTAG_PROXY_INVALID_CHAIN;   /* Not yet implemented */
684
      break;
685
 
686
    case JTAG_CHAIN_DEVELOPMENT:
687
      err = get_devint_reg (address, (unsigned long *)data);
688
      break;
689
 
690
    case JTAG_CHAIN_WISHBONE:
691
      err = debug_get_mem (address, data);
692
      break;
693
 
694
    default:
695
      err = JTAG_PROXY_INVALID_CHAIN;
696
    }
697
 
698
  return  err;
699
 
700
}       /* debug_get_register () */
701
 
702
 
703
/*---------------------------------------------------------------------------*/
704
/*!Set a JTAG register
705
 
706
   Action depends on which scan chain is currently active.
707
 
708
   @param[in]  address  Address on the scan chain
709
   @param[out] data     Data to set
710
 
711
   @return  An error code (including ERR_NONE) if there is no error          */
712
/*---------------------------------------------------------------------------*/
713
int
714
debug_set_register (oraddr_t  address,
715
                    uorreg_t  data)
716
{
717
  int  err = ERR_NONE;
718
 
719
  switch (current_scan_chain)
720
    {
721
    case JTAG_CHAIN_DEBUG_UNIT:
722
      mtspr (address, data);
723
      break;
724
 
725
    case JTAG_CHAIN_TRACE:
726
      err = JTAG_PROXY_ACCESS_EXCEPTION;        /* Not yet implemented */
727
      break;
728
 
729
    case JTAG_CHAIN_DEVELOPMENT:
730
      err = set_devint_reg (address, data);
731
      break;
732
 
733
    case JTAG_CHAIN_WISHBONE:
734
      err = debug_set_mem (address, data);
735
      break;
736
 
737
    default:
738
      err = JTAG_PROXY_INVALID_CHAIN;
739
    }
740
 
741
  return err;
742
 
743
}       /* debug_set_register () */
744
 
745
 
746
/*---------------------------------------------------------------------------*/
747
/*!Set the JTAG chain
748
 
749
   Only permit chains we support. Currently TRACE is not implemented.
750
 
751
   @param[in] chain  Chain to be set as current
752
 
753
   @return  An error code (including ERR_NONE) if there is no error          */
754
/*---------------------------------------------------------------------------*/
755
int
756
debug_set_chain (enum debug_scan_chain_ids  chain)
757
{
758
  switch (chain)
759
    {
760
    case JTAG_CHAIN_DEBUG_UNIT:
761
    case JTAG_CHAIN_DEVELOPMENT:
762
    case JTAG_CHAIN_WISHBONE:
763
      current_scan_chain = chain;
764
      break;
765
 
766
    case JTAG_CHAIN_TRACE:
767
      return  JTAG_PROXY_INVALID_CHAIN; /* Not yet implemented */
768
 
769
    default:
770
      return  JTAG_PROXY_INVALID_CHAIN; /* All other chains not implemented */
771
    }
772
 
773
  return  ERR_NONE;
774
 
775
}       /* debug_set_chain() */
776
 
777
 
778
/*---------------------------------------------------------------------------*/
779
/*!Get a development interface register
780
 
781
   No side effects on get - just return the register
782
 
783
   @param[in]  address  The register to get
784
   @param[out] data     Where to put the result
785
 
786
   @return  An error code (including ERR_NONE) if there is no error          */
787
/*---------------------------------------------------------------------------*/
788
static int
789
get_devint_reg (enum development_interface_address_space  address,
790
                unsigned long                            *data)
791
{
792
  int  err = ERR_NONE;
793
 
794
  if (address <= DEVELOPINT_MAX)
795
    {
796
      *data = development[address];
797
    }
798
  else
799
    {
800
      err = JTAG_PROXY_INVALID_ADDRESS;
801
    }
802
 
803
  return  err;
804
 
805
}       /* get_devint_reg () */
806
 
807
 
808
/*---------------------------------------------------------------------------*/
809
/*!Set a development interface register
810
 
811
   Sets the value of the corresponding register. Only RISC_OP has any
812
   side-effects. The others just store the value, so it can be read back.
813
 
814
   @param[in] address  The register to set
815
   @param[in] data     The data to set
816
 
817
   @return  An error code (including ERR_NONE) if there is no error          */
818
/*---------------------------------------------------------------------------*/
819
static int
820
set_devint_reg (enum development_interface_address_space  address,
821
                unsigned long                             data)
822
{
823
  int err =  ERR_NONE;
824
 
825
  if (DEVELOPINT_RISCOP == address)
826
    {
827
      int old_value = (development[DEVELOPINT_RISCOP] & RISCOP_RESET) != 0;
828
 
829
      development[DEVELOPINT_RISCOP] = data;
830
      in_reset                       = ((data & RISCOP_RESET) != 0);
831
 
832
      /* Reset the cpu on the negative edge of RESET */
833
      if (old_value && !in_reset)
834
        {
835
          sim_reset ();         /* Reset all units */
836
        }
837
 
838
      set_stall_state ((development[DEVELOPINT_RISCOP] & RISCOP_STALL) != 0);
839
    }
840
  else if (address <= DEVELOPINT_MAX)
841
    {
842
      development[address] = data;
843
    }
844
  else
845
    {
846
      err = JTAG_PROXY_INVALID_ADDRESS;
847
    }
848
 
849
  return  err;
850
 
851
}       /* set_devint_reg() */
852
 
853
 
854
/*---------------------------------------------------------------------------*/
855
/*!Read from main bus
856
 
857
   @param[in]  address  Address to read from
858
   @param[out] data     Where to put the result
859
 
860
   @return  An error code (including ERR_NONE) if there is no error          */
861
/*---------------------------------------------------------------------------*/
862
static int
863
debug_get_mem (oraddr_t  address,
864
               uorreg_t *data)
865
{
866
  int  err = ERR_NONE;
867
 
868
  if (!verify_memoryarea (address))
869
    {
870
    err = JTAG_PROXY_INVALID_ADDRESS;
871
    }
872
  else
873
    {
874
      *data = eval_direct32 (address, 0, 0);
875
    }
876
 
877
  return  err;
878
 
879
}       /* debug_get_mem () */
880
 
881
 
882
/*---------------------------------------------------------------------------*/
883
/*!Write to main bus
884
 
885
   @param[in]  address  Address to write to
886
   @param[out] data     Data to write
887
 
888
   @return  An error code (including ERR_NONE) if there is no error          */
889
/*---------------------------------------------------------------------------*/
890
static int
891
debug_set_mem (oraddr_t  address,
892
               uint32_t  data)
893
{
894
  int  err = ERR_NONE;
895
 
896
  if (!verify_memoryarea (address))
897
    {
898
      err = JTAG_PROXY_INVALID_ADDRESS;
899
    }
900
  else
901
    {
902
      // circumvent the read-only check usually done for mem accesses
903
      // data is in host order, because that's what set_direct32 needs
904
      set_program32 (address, data);
905
    }
906
 
907
  return  err;
908
 
909
}       /* debug_set_mem () */
910
 
911
 
912
/*---------------------------------------------------------------------------*/
913
/*!See if an exception should be ignored
914
 
915
   @param[in] except  The exception to consider
916
 
917
   @return  Non-zero if the exception should be ignored                      */
918
/*---------------------------------------------------------------------------*/
919
int
920
debug_ignore_exception (unsigned long  except)
921
{
922
  int           result = 0;
923
  unsigned long dsr    = cpu_state.sprs[SPR_DSR];
924
 
925
  switch (except)
926
    {
927
    case EXCEPT_RESET:    result = (dsr & SPR_DSR_RSTE);  break;
928
    case EXCEPT_BUSERR:   result = (dsr & SPR_DSR_BUSEE); break;
929
    case EXCEPT_DPF:      result = (dsr & SPR_DSR_DPFE);  break;
930
    case EXCEPT_IPF:      result = (dsr & SPR_DSR_IPFE);  break;
931
    case EXCEPT_TICK:     result = (dsr & SPR_DSR_TTE);   break;
932
    case EXCEPT_ALIGN:    result = (dsr & SPR_DSR_AE);    break;
933
    case EXCEPT_ILLEGAL:  result = (dsr & SPR_DSR_IIE);   break;
934
    case EXCEPT_INT:      result = (dsr & SPR_DSR_IE);    break;
935
    case EXCEPT_DTLBMISS: result = (dsr & SPR_DSR_DME);   break;
936
    case EXCEPT_ITLBMISS: result = (dsr & SPR_DSR_IME);   break;
937
    case EXCEPT_RANGE:    result = (dsr & SPR_DSR_RE);    break;
938
    case EXCEPT_SYSCALL:  result = (dsr & SPR_DSR_SCE);   break;
939
    case EXCEPT_TRAP:     result = (dsr & SPR_DSR_TE);    break;
940
 
941
    default:                                              break;
942
    }
943
 
944
  cpu_state.sprs[SPR_DRR] |= result;
945
  set_stall_state (result != 0);
946
 
947
  /* Notify RSP if enabled. TODO: Should we actually notify ALL exceptions,
948
     not just those maked in the DSR? */
949
 
950
  if (config.debug.rsp_enabled && (0 != result))
951
    {
952
      rsp_exception (except);
953
    }
954
 
955
  return  (result != 0);
956
 
957
}       /* debug_ignore_exception () */
958
 
959
 
960
/*---------------------------------------------------------------------------*/
961
/*!Enable or disable the debug unit
962
 
963
   Set the corresponding field in the UPR
964
 
965
   @param[in] val  The value to use
966
   @param[in] dat  The config data structure (not used here)                 */
967
/*---------------------------------------------------------------------------*/
968
static void
969
debug_enabled (union param_val val, void *dat)
970
{
971
  if (val.int_val)
972
    {
973
      cpu_state.sprs[SPR_UPR] |= SPR_UPR_DUP;
974
    }
975
  else
976
    {
977
      cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_DUP;
978
    }
979
 
980
  config.debug.enabled = val.int_val;
981
 
982
}       /* debug_enabled() */
983
 
984
 
985
/*---------------------------------------------------------------------------*/
986
/*!Enable or disable Remote Serial Protocol GDB interface to the debug unit
987
 
988 235 jeremybenn
   This is the now the only interface.
989 19 jeremybenn
 
990
   @param[in] val  The value to use
991
   @param[in] dat  The config data structure (not used here)                 */
992
/*---------------------------------------------------------------------------*/
993
static void
994
debug_rsp_enabled (union param_val val, void *dat)
995
{
996
  config.debug.rsp_enabled = val.int_val;
997
 
998
}       /* debug_rsp_enabled () */
999
 
1000
 
1001
/*---------------------------------------------------------------------------*/
1002
/*!Set the Remote Serial Protocol GDB server port
1003
 
1004
   This is for use with the RSP, which is now the preferred interface.  Ensure
1005
   the value chosen is valid. Note that 0 is permitted, meaning the connection
1006
   should be to the "or1ksim-rsp" service, rather than a port.
1007
 
1008
   @param[in] val  The value to use
1009
   @param[in] dat  The config data structure (not used here)                 */
1010
/*---------------------------------------------------------------------------*/
1011
static void
1012
debug_rsp_port (union param_val val, void *dat)
1013
{
1014
  if ((val.int_val < 0) || (val.int_val > 65535))
1015
    {
1016
      fprintf (stderr, "Warning: invalid RSP GDB port specified: ignored\n");
1017
    }
1018
  else
1019
    {
1020
      config.debug.rsp_port = val.int_val;
1021
    }
1022
}       /* debug_rsp_port() */
1023
 
1024
 
1025
/*---------------------------------------------------------------------------*/
1026
/*!Set the VAPI ID for the debug unit
1027
 
1028
   @param[in] val  The value to use
1029
   @param[in] dat  The config data structure (not used here)                 */
1030
/*---------------------------------------------------------------------------*/
1031
static void
1032
debug_vapi_id (union param_val val, void *dat)
1033
{
1034
  config.debug.vapi_id = val.int_val;
1035
 
1036
}       /* debug_vapi_id () */
1037
 
1038
 
1039
/*---------------------------------------------------------------------------*/
1040
/*!Register the configuration functions for the debug unit                   */
1041
/*---------------------------------------------------------------------------*/
1042
void
1043
reg_debug_sec ()
1044
{
1045
  struct config_section *sec = reg_config_sec ("debug", NULL, NULL);
1046
 
1047 224 jeremybenn
  reg_config_param (sec, "enabled",     PARAMT_INT, debug_enabled);
1048
  reg_config_param (sec, "rsp_enabled", PARAMT_INT, debug_rsp_enabled);
1049
  reg_config_param (sec, "rsp_port",    PARAMT_INT, debug_rsp_port);
1050
  reg_config_param (sec, "vapi_id",     PARAMT_INT, debug_vapi_id);
1051 19 jeremybenn
 
1052
}       /* reg_debug_sec () */
1053
 

powered by: WebSVN 2.1.0

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