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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_12/] [rtl/] [verilog/] [dbg_cpu.v] - Blame information for rev 158

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 100 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  dbg_cpu.v                                                   ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the SoC/OpenRISC Development Interface ////
7
////  http://www.opencores.org/projects/DebugInterface/           ////
8
////                                                              ////
9
////  Author(s):                                                  ////
10
////       Igor Mohor (igorm@opencores.org)                       ////
11
////                                                              ////
12
////                                                              ////
13
////  All additional information is avaliable in the README.txt   ////
14
////  file.                                                       ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2000 - 2004 Authors                            ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
//
43
// CVS Revision History
44
//
45
// $Log: not supported by cvs2svn $
46 102 mohor
// Revision 1.2  2004/01/17 17:01:14  mohor
47
// Almost finished.
48
//
49 101 mohor
// Revision 1.1  2004/01/16 14:53:31  mohor
50
// *** empty log message ***
51 100 mohor
//
52
//
53 101 mohor
//
54 100 mohor
 
55
// synopsys translate_off
56
`include "timescale.v"
57
// synopsys translate_on
58
`include "dbg_cpu_defines.v"
59
 
60
// Top module
61
module dbg_cpu(
62
                // JTAG signals
63
                tck_i,
64
                tdi_i,
65
                tdo_o,
66
 
67
                // TAP states
68
                shift_dr_i,
69
                pause_dr_i,
70
                update_dr_i,
71
 
72
                cpu_ce_i,
73
                crc_match_i,
74
                crc_en_o,
75
                shift_crc_o,
76
                rst_i,
77
 
78 101 mohor
                // CPU signals
79
                cpu_clk_i,
80
                cpu_addr_o,
81
                cpu_data_i,
82
                cpu_data_o,
83
                cpu_bp_i,
84
                cpu_stall_o,
85
                cpu_stall_all_o,
86
                cpu_stb_o,
87
                cpu_sel_o,          // Not synchronized
88
                cpu_we_o,
89
                cpu_ack_i,
90
                cpu_rst_o
91 100 mohor
 
92 101 mohor
 
93 100 mohor
              );
94
 
95
// JTAG signals
96
input         tck_i;
97
input         tdi_i;
98
output        tdo_o;
99
 
100
// TAP states
101
input         shift_dr_i;
102
input         pause_dr_i;
103
input         update_dr_i;
104
 
105
input         cpu_ce_i;
106
input         crc_match_i;
107
output        crc_en_o;
108
output        shift_crc_o;
109
input         rst_i;
110 101 mohor
 
111
 
112
// CPU signals
113
input         cpu_clk_i;
114
output [31:0] cpu_addr_o;
115
input  [31:0] cpu_data_i;
116
output [31:0] cpu_data_o;
117
input         cpu_bp_i;
118
output        cpu_stall_o;
119
output        cpu_stall_all_o;
120
output        cpu_stb_o;
121
output [`CPU_NUM -1:0]  cpu_sel_o;
122
output        cpu_we_o;
123
input         cpu_ack_i;
124
output        cpu_rst_o;
125
 
126
 
127 100 mohor
 
128
reg           tdo_o;
129 102 mohor
reg   [799:0] tdo_text;
130 100 mohor
 
131
wire          cmd_cnt_en;
132
reg     [1:0] cmd_cnt;
133
wire          cmd_cnt_end;
134
reg           cmd_cnt_end_q;
135
wire          addr_cnt_en;
136
reg     [5:0] addr_cnt;
137
reg     [5:0] addr_cnt_limit;
138
wire          addr_cnt_end;
139
wire          crc_cnt_en;
140
reg     [5:0] crc_cnt;
141
wire          crc_cnt_end;
142
reg           crc_cnt_end_q;
143
wire          data_cnt_en;
144
reg     [5:0] data_cnt;
145
reg     [5:0] data_cnt_limit;
146
wire          data_cnt_end;
147
reg           data_cnt_end_q;
148
wire          status_cnt_end;
149
reg           status_cnt1, status_cnt2, status_cnt3, status_cnt4;
150
reg     [3:0] status;
151 102 mohor
reg   [199:0] status_text;
152 100 mohor
 
153 102 mohor
reg           crc_match_reg;
154 100 mohor
wire          enable;
155
 
156
reg           read_cycle_reg;
157 101 mohor
reg           read_cycle_reg_q;
158 100 mohor
reg           read_cycle_cpu;
159 101 mohor
reg           read_cycle_cpu_q;
160 100 mohor
reg           write_cycle_reg;
161
reg           write_cycle_cpu;
162
wire          read_cycle;
163
wire          write_cycle;
164
 
165
reg    [34:0] dr;
166 101 mohor
wire    [7:0] reg_data_out;
167 100 mohor
 
168
wire          dr_read_reg;
169
wire          dr_write_reg;
170
wire          dr_read_cpu8;
171
wire          dr_read_cpu32;
172
wire          dr_write_cpu8;
173
wire          dr_write_cpu32;
174
wire          dr_go;
175
 
176
reg           dr_read_reg_latched;
177
reg           dr_write_reg_latched;
178
reg           dr_read_cpu8_latched;
179
reg           dr_read_cpu32_latched;
180
reg           dr_write_cpu8_latched;
181
reg           dr_write_cpu32_latched;
182
reg           dr_go_latched;
183
 
184
reg           cmd_read_reg;
185
reg           cmd_read_cpu;
186
reg           cmd_write_reg;
187
reg           cmd_write_cpu;
188 101 mohor
reg           cycle_32_bit;
189
reg           reg_access;
190 100 mohor
 
191 101 mohor
reg [31:0] adr;
192
reg set_addr;
193
reg [199:0] latching_data_text;
194
reg cpu_ack_sync;
195
reg cpu_ack_tck;
196
reg cpu_ack_tck_q;
197
reg cpu_stb;
198
reg cpu_stb_sync;
199
reg cpu_stb_o;
200
 
201 100 mohor
wire          go_prelim;
202
wire          crc_cnt_31;
203
 
204
 
205 101 mohor
 
206 100 mohor
assign enable = cpu_ce_i & shift_dr_i;
207
assign crc_en_o = enable & crc_cnt_end & (~status_cnt_end);
208
assign shift_crc_o = enable & status_cnt_end;  // Signals dbg module to shift out the CRC
209
 
210
 
211
assign cmd_cnt_en = enable & (~cmd_cnt_end);
212
 
213
 
214
// Command counter
215
always @ (posedge tck_i or posedge rst_i)
216
begin
217
  if (rst_i)
218
    cmd_cnt <= #1 'h0;
219
  else if (update_dr_i)
220
    cmd_cnt <= #1 'h0;
221
  else if (cmd_cnt_en)
222
    cmd_cnt <= #1 cmd_cnt + 1'b1;
223
end
224
 
225
 
226
assign addr_cnt_en = enable & cmd_cnt_end & (~addr_cnt_end);
227
 
228
 
229
// Address/length counter
230
always @ (posedge tck_i or posedge rst_i)
231
begin
232
  if (rst_i)
233
    addr_cnt <= #1 'h0;
234
  else if (update_dr_i)
235
    addr_cnt <= #1 'h0;
236
  else if (addr_cnt_en)
237
    addr_cnt <= #1 addr_cnt + 1'b1;
238
end
239
 
240
 
241
assign data_cnt_en = enable & (~data_cnt_end) & (cmd_cnt_end & write_cycle | crc_cnt_end & read_cycle);
242
 
243
 
244
// Data counter
245
always @ (posedge tck_i or posedge rst_i)
246
begin
247
  if (rst_i)
248
    data_cnt <= #1 'h0;
249
  else if (update_dr_i)
250
    data_cnt <= #1 'h0;
251
  else if (data_cnt_en)
252
    data_cnt <= #1 data_cnt + 1'b1;
253
end
254
 
255
 
256
assign crc_cnt_en = enable & (~crc_cnt_end) & (cmd_cnt_end & addr_cnt_end  & (~write_cycle) | (data_cnt_end & write_cycle));
257
 
258
 
259
// crc counter
260
always @ (posedge tck_i or posedge rst_i)
261
begin
262
  if (rst_i)
263
    crc_cnt <= #1 'h0;
264
  else if(crc_cnt_en)
265
    crc_cnt <= #1 crc_cnt + 1'b1;
266
  else if (update_dr_i)
267
    crc_cnt <= #1 'h0;
268
end
269
 
270
 
271
// Upper limit. Address/length counter counts until this value is reached
272
always @ (posedge tck_i)
273
begin
274
  if (cmd_cnt == 2'h2)
275
    begin
276
      if ((~dr[0])  & (~tdi_i))                                   // (current command is WB_STATUS or WB_GO)
277
        addr_cnt_limit = 6'd0;
278
      else                                                        // (current command is WB_WRITEx or WB_READx)
279
        addr_cnt_limit = 6'd32;
280
    end
281
end
282
 
283
 
284
assign cmd_cnt_end  = cmd_cnt  == 2'h3;
285
assign addr_cnt_end = addr_cnt == addr_cnt_limit;
286
assign crc_cnt_end  = crc_cnt  == 6'd32;
287
assign crc_cnt_31 = crc_cnt  == 6'd31;
288
assign data_cnt_end = (data_cnt == data_cnt_limit);
289
 
290
always @ (posedge tck_i)
291
begin
292
  crc_cnt_end_q  <= #1 crc_cnt_end;
293
  cmd_cnt_end_q  <= #1 cmd_cnt_end;
294
  data_cnt_end_q <= #1 data_cnt_end;
295
end
296
 
297
 
298
// Status counter is made of 4 serialy connected registers
299
always @ (posedge tck_i or posedge rst_i)
300
begin
301
  if (rst_i)
302
    status_cnt1 <= #1 1'b0;
303
  else if (update_dr_i)
304
    status_cnt1 <= #1 1'b0;
305
  else if (data_cnt_end & read_cycle |
306
           crc_cnt_end & (~read_cycle)
307
          )
308
    status_cnt1 <= #1 1'b1;
309
end
310
 
311
 
312
always @ (posedge tck_i or posedge rst_i)
313
begin
314
  if (rst_i)
315
    begin
316
      status_cnt2 <= #1 1'b0;
317
      status_cnt3 <= #1 1'b0;
318
      status_cnt4 <= #1 1'b0;
319
    end
320
  else if (update_dr_i)
321
    begin
322
      status_cnt2 <= #1 1'b0;
323
      status_cnt3 <= #1 1'b0;
324
      status_cnt4 <= #1 1'b0;
325
    end
326
  else
327
    begin
328
      status_cnt2 <= #1 status_cnt1;
329
      status_cnt3 <= #1 status_cnt2;
330
      status_cnt4 <= #1 status_cnt3;
331
    end
332
end
333
 
334
 
335
assign status_cnt_end = status_cnt4;
336
 
337
 
338
 
339
 
340
// Latching address
341
always @ (posedge tck_i)
342
begin
343
  if(crc_cnt_end & (~crc_cnt_end_q) & crc_match_i)
344
    begin
345
      if (~dr_go_latched)
346
        begin
347
          adr <= #1 dr[31:0];
348
          set_addr <= #1 1'b1;
349
        end
350
    end
351
  else
352
    set_addr <= #1 1'b0;
353
end
354
 
355
 
356 101 mohor
assign cpu_addr_o = adr;
357 100 mohor
 
358 101 mohor
 
359 100 mohor
// Shift register for shifting in and out the data
360
always @ (posedge tck_i)
361
begin
362 101 mohor
  if (reg_access)
363 100 mohor
    begin
364 101 mohor
      dr[31:24] <= #1 reg_data_out;
365
      latching_data_text = "Latch reg data";
366
    end
367
  else if (cpu_ack_tck & (~cpu_ack_tck_q) & read_cycle_cpu)
368
    begin
369
      if (cycle_32_bit)
370
        dr[31:0] <= #1 cpu_data_i;
371
      else
372
        dr[31:24] <= #1 cpu_data_i[7:0];
373
      latching_data_text = "Latch cpu data";
374
    end
375
  else if (enable & ((~addr_cnt_end) | (~cmd_cnt_end) | ((~data_cnt_end) & write_cycle) | (crc_cnt_end & (~data_cnt_end) & read_cycle)))
376
    begin
377 100 mohor
      dr <= #1 {dr[33:0], tdi_i};
378 101 mohor
      latching_data_text = "shifting data";
379 100 mohor
    end
380
  else
381
    latching_data_text = "nothing";
382
end
383
 
384
 
385
assign dr_read_reg    = dr[2:0] == `CPU_READ_REG;
386
assign dr_write_reg   = dr[2:0] == `CPU_WRITE_REG;
387
assign dr_read_cpu8   = dr[2:0] == `CPU_READ8;
388
assign dr_read_cpu32  = dr[2:0] == `CPU_READ32;
389
assign dr_write_cpu8  = dr[2:0] == `CPU_WRITE8;
390
assign dr_write_cpu32 = dr[2:0] == `CPU_WRITE32;
391
assign dr_go          = dr[2:0] == `CPU_GO;
392
 
393
 
394
// Latching instruction
395
always @ (posedge tck_i)
396
begin
397
  if (update_dr_i)
398
    begin
399
      dr_read_reg_latched  <= #1 1'b0;
400
      dr_read_cpu8_latched  <= #1 1'b0;
401
      dr_read_cpu32_latched  <= #1 1'b0;
402
      dr_write_reg_latched  <= #1 1'b0;
403
      dr_write_cpu8_latched  <= #1 1'b0;
404
      dr_write_cpu32_latched  <= #1 1'b0;
405
      dr_go_latched  <= #1 1'b0;
406
    end
407
  else if (cmd_cnt_end & (~cmd_cnt_end_q))
408
    begin
409
      dr_read_reg_latched <= #1 dr_read_reg;
410
      dr_read_cpu8_latched <= #1 dr_read_cpu8;
411
      dr_read_cpu32_latched <= #1 dr_read_cpu32;
412
      dr_write_reg_latched <= #1 dr_write_reg;
413
      dr_write_cpu8_latched <= #1 dr_write_cpu8;
414
      dr_write_cpu32_latched <= #1 dr_write_cpu32;
415
      dr_go_latched <= #1 dr_go;
416
    end
417
end
418
 
419
// Latching instruction
420
always @ (posedge tck_i or posedge rst_i)
421
begin
422
  if (rst_i)
423
    begin
424
      cmd_read_reg    <= #1 1'b0;
425
      cmd_read_cpu    <= #1 1'b0;
426
      cmd_write_reg   <= #1 1'b0;
427 101 mohor
      cmd_write_cpu   <= #1 1'b0;
428
      cycle_32_bit    <= #1 1'b0;
429 100 mohor
    end
430
  else if(crc_cnt_end & (~crc_cnt_end_q) & crc_match_i)
431
    begin
432
      cmd_read_reg    <= #1 dr_read_reg_latched;
433
      cmd_read_cpu    <= #1 dr_read_cpu8_latched | dr_read_cpu32_latched;
434
      cmd_write_reg   <= #1 dr_write_reg_latched;
435
      cmd_write_cpu   <= #1 dr_write_cpu8_latched | dr_write_cpu32_latched;
436 101 mohor
      cycle_32_bit    <= #1 dr_read_cpu32_latched | dr_write_cpu32_latched;
437 100 mohor
    end
438
end
439
 
440
 
441
// Upper limit. Data counter counts until this value is reached.
442
always @ (posedge tck_i or posedge rst_i)
443
begin
444
  if (rst_i)
445
    data_cnt_limit <= #1 6'h0;
446 101 mohor
  else if(crc_cnt_end & (~crc_cnt_end_q) & crc_match_i & (~dr_go_latched))
447 100 mohor
    begin
448
      if (dr_read_cpu32_latched | dr_write_cpu32_latched)
449
        data_cnt_limit <= #1 6'd32;
450
      else
451
        data_cnt_limit <= #1 6'd8;
452
    end
453
end
454
 
455
 
456
assign go_prelim = (cmd_cnt == 2'h2) & dr[1] & (~dr[0]) & (~tdi_i);
457
 
458
 
459
always @ (posedge tck_i)
460
begin
461
  if (update_dr_i)
462
    read_cycle_reg <= #1 1'b0;
463
  else if (cmd_read_reg & go_prelim)
464
    read_cycle_reg <= #1 1'b1;
465
end
466
 
467
 
468
always @ (posedge tck_i)
469
begin
470
  if (update_dr_i)
471
    read_cycle_cpu <= #1 1'b0;
472
  else if (cmd_read_cpu & go_prelim)
473
    read_cycle_cpu <= #1 1'b1;
474
end
475
 
476
 
477
always @ (posedge tck_i)
478
begin
479 101 mohor
  read_cycle_reg_q <= #1 read_cycle_reg;
480
  read_cycle_cpu_q <= #1 read_cycle_cpu;
481
end
482
 
483
 
484
always @ (posedge tck_i)
485
begin
486 100 mohor
  if (update_dr_i)
487
    write_cycle_reg <= #1 1'b0;
488
  else if (cmd_write_reg & go_prelim)
489
    write_cycle_reg <= #1 1'b1;
490
end
491
 
492
 
493
always @ (posedge tck_i)
494
begin
495
  if (update_dr_i)
496
    write_cycle_cpu <= #1 1'b0;
497
  else if (cmd_write_cpu & go_prelim)
498
    write_cycle_cpu <= #1 1'b1;
499
end
500
 
501
 
502
assign read_cycle = read_cycle_reg | read_cycle_cpu;
503
assign write_cycle = write_cycle_reg | write_cycle_cpu;
504
 
505
 
506 101 mohor
 
507
// Start register access cycle
508 100 mohor
always @ (posedge tck_i)
509
begin
510 101 mohor
  if (write_cycle_reg & data_cnt_end & (~data_cnt_end_q) | read_cycle_reg & (~read_cycle_reg_q))
511 100 mohor
    begin
512
      reg_access <= #1 1'b1;
513
    end
514
  else
515
    reg_access <= #1 1'b0;
516
end
517
 
518
 
519
 
520
// Connecting dbg_cpu_registers
521
dbg_cpu_registers i_dbg_cpu_registers
522
     (
523 101 mohor
      .data_i           (dr[7:0]),
524
      .data_o           (reg_data_out),
525
      .addr_i           (adr[1:0]),
526
      .we_i             (write_cycle_reg),
527
      .en_i             (reg_access),
528
      .clk_i            (tck_i),
529
      .bp_i             (cpu_bp_i),
530
      .rst_i            (rst_i),
531
      .cpu_clk_i        (cpu_clk_i),
532
      .cpu_stall_o      (cpu_stall_o),
533
      .cpu_stall_all_o  (cpu_stall_all_o),
534
      .cpu_sel_o        (cpu_sel_o),
535
      .cpu_rst_o        (cpu_rst_o)
536 100 mohor
     );
537
 
538
 
539
 
540 101 mohor
assign cpu_we_o   = write_cycle_cpu;
541
assign cpu_data_o = dr[31:0];
542 100 mohor
 
543
 
544 101 mohor
 
545
 
546
// Synchronizing ack signal from cpu
547
always @ (posedge tck_i)
548
begin
549
  cpu_ack_sync      <= #1 cpu_ack_i;
550
  cpu_ack_tck       <= #1 cpu_ack_sync;
551
  cpu_ack_tck_q     <= #1 cpu_ack_tck;
552
end
553
 
554
 
555
 
556
// Start cpu access cycle
557
always @ (posedge tck_i)
558
begin
559
  if (update_dr_i)
560
    cpu_stb <= #1 1'b0;
561
  else if (cpu_ack_tck)
562
    cpu_stb <= #1 1'b0;
563
  else if (write_cycle_cpu & data_cnt_end & (~data_cnt_end_q) | read_cycle_cpu & (~read_cycle_cpu_q))
564
    cpu_stb <= #1 1'b1;
565
end
566
 
567
 
568
 
569 102 mohor
// Synchronizing cpu_stb to cpu_clk_i clock
570
always @ (posedge cpu_clk_i)
571 101 mohor
begin
572
  cpu_stb_sync  <= #1 cpu_stb;
573
  cpu_stb_o     <= #1 cpu_stb_sync;
574
end
575
 
576
 
577 102 mohor
// Latching crc
578
always @ (posedge tck_i)
579
begin
580
  if(crc_cnt_end & (~crc_cnt_end_q))
581
    crc_match_reg <= #1 crc_match_i;
582
end
583 101 mohor
 
584
 
585
 
586 102 mohor
// Status register
587
always @ (posedge tck_i or posedge rst_i)
588
begin
589
  if (rst_i)
590
    begin
591
    status <= #1 'h0;
592
    status_text <= #1 "reset";
593
    end
594
  else if(crc_cnt_end & (~crc_cnt_end_q) & (~read_cycle))
595
    begin
596
    status <= #1 {crc_match_i, 1'b0, 1'b1, 1'b0};
597
    status_text <= #1 "!!!READ";
598
    end
599
  else if (data_cnt_end & (~data_cnt_end_q) & read_cycle)
600
    begin
601
    status <= #1 {crc_match_reg, 1'b0, 1'b1, 1'b0};
602
    status_text <= #1 "READ";
603
    end
604
  else if (shift_dr_i & (~status_cnt_end))
605
    begin
606
    status <= #1 {status[0], status[3:1]};
607
    status_text <= #1 "shift";
608
    end
609
end
610
// Following status is shifted out:
611
// 1. bit:          1 if crc is OK, else 0
612
// 2. bit:          1'b0
613
// 3. bit:          1'b1
614
// 4. bit:          1'b0
615 101 mohor
 
616 102 mohor
 
617
 
618
// TDO multiplexer
619
always @ (crc_cnt_end or crc_cnt_end_q or crc_match_i or data_cnt_end or data_cnt_end_q or
620
          read_cycle or crc_match_reg or status or dr)
621
begin
622
  if (crc_cnt_end & (~crc_cnt_end_q) & (~(read_cycle)))
623
    begin
624
      tdo_o = crc_match_i;
625
      tdo_text = "crc_match_i";
626
    end
627
  else if (read_cycle & crc_cnt_end & (~data_cnt_end))
628
    begin
629
    tdo_o = dr[31];
630
    tdo_text = "read data";
631
    end
632
  else if (read_cycle & data_cnt_end & (~data_cnt_end_q))     // cmd is already updated
633
    begin
634
      tdo_o = crc_match_reg;
635
      tdo_text = "crc_match_reg";
636
    end
637
  else if (crc_cnt_end)
638
    begin
639
      tdo_o = status[0];
640
      tdo_text = "status";
641
    end
642
  else
643
    begin
644
      tdo_o = 1'b0;
645
      tdo_text = "zero while CRC is shifted in";
646
    end
647
end
648
 
649
 
650
 
651
 
652
 
653
 
654
 
655 100 mohor
endmodule
656
 

powered by: WebSVN 2.1.0

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