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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc1/] [or1ksim/] [debug/] [debug-unit.c] - Blame information for rev 1765

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

powered by: WebSVN 2.1.0

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