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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [debug/] [debug-unit.c] - Blame information for rev 1751

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

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

powered by: WebSVN 2.1.0

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