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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_21/] [rtl/] [verilog/] [dbg_cpu.v] - Blame information for rev 104

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

powered by: WebSVN 2.1.0

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