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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [sdram_test_working/] [rtl/] [verilog/] [dbg_trace.v] - Blame information for rev 158

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  dbg_trace.v                                                 ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the SoC/OpenRISC Development Interface ////
7
////  http://www.opencores.org/cores/DebugInterface/              ////
8
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Igor Mohor                                             ////
12
////       igorm@opencores.org                                    ////
13
////                                                              ////
14
////                                                              ////
15
////  All additional information is avaliable in the README.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000,2001 Authors                              ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48 20 mohor
// Revision 1.5  2001/10/19 11:40:01  mohor
49
// dbg_timescale.v changed to timescale.v This is done for the simulation of
50
// few different cores in a single project.
51
//
52 17 mohor
// Revision 1.4  2001/09/20 10:11:25  mohor
53
// Working version. Few bugs fixed, comments added.
54
//
55 9 mohor
// Revision 1.3  2001/09/19 11:55:13  mohor
56
// Asynchronous set/reset not used in trace any more.
57
//
58 8 mohor
// Revision 1.2  2001/09/18 14:13:47  mohor
59
// Trace fixed. Some registers changed, trace simplified.
60
//
61 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
62
// Initial official release.
63
//
64 2 mohor
// Revision 1.3  2001/06/01 22:22:35  mohor
65
// This is a backup. It is not a fully working version. Not for use, yet.
66
//
67
// Revision 1.2  2001/05/18 13:10:00  mohor
68
// Headers changed. All additional information is now avaliable in the README.txt file.
69
//
70
// Revision 1.1.1.1  2001/05/18 06:35:06  mohor
71
// Initial release
72
//
73
//
74
 
75
 
76 20 mohor
// synopsys translate_off
77 17 mohor
`include "timescale.v"
78 20 mohor
// synopsys translate_on
79 2 mohor
`include "dbg_defines.v"
80
 
81
// module Trace
82 8 mohor
module dbg_trace (Wp, Bp, DataIn, OpSelect, LsStatus, IStatus, RiscStall_O,
83
                  Mclk, Reset, TraceChain, ContinMode, TraceEnable_reg,
84 2 mohor
                  WpTrigger, BpTrigger, LSSTrigger, ITrigger, TriggerOper, WpQualif,
85 5 mohor
                  BpQualif, LSSQualif, IQualif, QualifOper, RecordPC, RecordLSEA,
86
                  RecordLDATA, RecordSDATA, RecordReadSPR, RecordWriteSPR,
87
                  RecordINSTR,
88 2 mohor
                  WpTriggerValid, BpTriggerValid, LSSTriggerValid, ITriggerValid,
89
                  WpQualifValid, BpQualifValid, LSSQualifValid, IQualifValid, ReadBuffer,
90
                  WpStop, BpStop, LSSStop, IStop, StopOper, WpStopValid, BpStopValid,
91
                  LSSStopValid, IStopValid
92
                 );
93
 
94
parameter Tp = 1;
95
 
96
 
97 9 mohor
input [10:0] Wp;              // Watchpoints
98
input        Bp;              // Breakpoint
99
input [31:0] DataIn;          // Data from the RISC
100
input [3:0]  LsStatus;        // Load/Store status
101
input [1:0]  IStatus;         // Instruction status
102 2 mohor
 
103 9 mohor
input        Mclk;            // Master clock (RISC clock)
104
input        Reset;           // Reset
105
input        ReadBuffer;      // Instruction for reading a sample from the Buffer
106 2 mohor
 
107
// from registers
108 9 mohor
input ContinMode;             // Continous mode of the trace
109
input TraceEnable_reg;        // Trace is enabled (enabled by writing a bit in the register)
110 2 mohor
 
111 9 mohor
input [10:0] WpTrigger;       // Signals that come from registers to set the trigger
112
input        BpTrigger;       // Signals that come from registers to set the trigger
113
input [3:0]  LSSTrigger;      // Signals that come from registers to set the trigger
114
input [1:0]  ITrigger;        // Signals that come from registers to set the trigger
115
input [1:0]  TriggerOper;     // Signals that come from registers to set the trigger
116 2 mohor
 
117 9 mohor
input [10:0] WpQualif;        // Signals that come from registers to set the qualifier
118
input        BpQualif;        // Signals that come from registers to set the qualifier
119
input [3:0]  LSSQualif;       // Signals that come from registers to set the qualifier
120
input [1:0]  IQualif;         // Signals that come from registers to set the qualifier
121
input [1:0]  QualifOper;      // Signals that come from registers to set the qualifier
122 2 mohor
 
123 9 mohor
input [10:0] WpStop;          // Signals that come from registers to set the stop condition
124
input        BpStop;          // Signals that come from registers to set the stop condition
125
input [3:0]  LSSStop;         // Signals that come from registers to set the stop condition
126
input [1:0]  IStop;           // Signals that come from registers to set the stop condition
127
input [1:0]  StopOper;        // Signals that come from registers to set the stop condition
128 2 mohor
 
129 9 mohor
input RecordPC;               // Signals that come from registers for defining the sample for recording
130
input RecordLSEA;             // Signals that come from registers for defining the sample for recording
131
input RecordLDATA;            // Signals that come from registers for defining the sample for recording
132
input RecordSDATA;            // Signals that come from registers for defining the sample for recording
133
input RecordReadSPR;          // Signals that come from registers for defining the sample for recording
134
input RecordWriteSPR;         // Signals that come from registers for defining the sample for recording
135
input RecordINSTR;            // Signals that come from registers for defining the sample for recording
136 2 mohor
 
137 9 mohor
input WpTriggerValid;         // Signals that come from registers and indicate which trigger conditions are valid
138
input BpTriggerValid;         // Signals that come from registers and indicate which trigger conditions are valid
139
input LSSTriggerValid;        // Signals that come from registers and indicate which trigger conditions are valid
140
input ITriggerValid;          // Signals that come from registers and indicate which trigger conditions are valid
141 2 mohor
 
142 9 mohor
input WpQualifValid;          // Signals that come from registers and indicate which qualifier conditions are valid
143
input BpQualifValid;          // Signals that come from registers and indicate which qualifier conditions are valid
144
input LSSQualifValid;         // Signals that come from registers and indicate which qualifier conditions are valid
145
input IQualifValid;           // Signals that come from registers and indicate which qualifier conditions are valid
146 2 mohor
 
147 9 mohor
input WpStopValid;            // Signals that come from registers and indicate which stop conditions are valid
148
input BpStopValid;            // Signals that come from registers and indicate which stop conditions are valid
149
input LSSStopValid;           // Signals that come from registers and indicate which stop conditions are valid
150
input IStopValid;             // Signals that come from registers and indicate which stop conditions are valid
151 2 mohor
// end: from registers
152
 
153
 
154 9 mohor
output [`OPSELECTWIDTH-1:0]  OpSelect;  // Operation select (what kind of information is avaliable on the DataIn)
155
output        RiscStall_O;              // CPU stall (stalls the RISC)
156
output [39:0] TraceChain;               // Scan shain from the trace module
157 2 mohor
 
158 8 mohor
reg TraceEnable_d;
159
reg TraceEnable;
160 2 mohor
 
161 8 mohor
 
162
 
163 2 mohor
reg [`TRACECOUNTERWIDTH:0] Counter;
164
reg [`TRACECOUNTERWIDTH-1:0] WritePointer;
165
reg [`TRACECOUNTERWIDTH-1:0] ReadPointer;
166 5 mohor
reg RiscStall;
167
reg RiscStall_q;
168 2 mohor
reg [`OPSELECTWIDTH-1:0] StallCounter;
169
 
170
reg [`TRACESAMPLEWIDTH-1:0] Buffer[0:`TRACEBUFFERLENGTH-1];
171
 
172
reg TriggerLatch;
173
 
174
 
175
/**********************************************************************************
176
*                                                                                 *
177
*   Generation of the trigger                                                     *
178
*                                                                                 *
179
**********************************************************************************/
180
wire TempWpTrigger = |(Wp[10:0] & WpTrigger[10:0]);
181
wire TempBpTrigger = Bp & BpTrigger;
182
wire TempLSSTrigger = LsStatus[3:0] == LSSTrigger[3:0];
183
wire TempITrigger = IStatus[1:0] == ITrigger[1:0];
184
 
185
wire TempTriggerAND =  (  (TempWpTrigger  | ~WpTriggerValid)
186
                        & (TempBpTrigger  | ~BpTriggerValid)
187
                        & (TempLSSTrigger | ~LSSTriggerValid)
188
                        & (TempITrigger   | ~ITriggerValid)
189
                       )
190
                       & (WpTriggerValid | BpTriggerValid | LSSTriggerValid | ITriggerValid);
191
 
192
wire TempTriggerOR =   (  (TempWpTrigger  &  WpTriggerValid)
193
                        | (TempBpTrigger  &  BpTriggerValid)
194
                        | (TempLSSTrigger &  LSSTriggerValid)
195
                        | (TempITrigger   &  ITriggerValid)
196
                       );
197
 
198
wire Trigger = TraceEnable & (~TriggerOper[1]?  1 :                               // any
199
                               TriggerOper[0]?  TempTriggerAND : TempTriggerOR    // AND : OR
200
                             );
201
 
202
/**********************************************************************************
203
*                                                                                 *
204
*   Generation of the qualifier                                                   *
205
*                                                                                 *
206
**********************************************************************************/
207
wire TempWpQualifier = |(Wp[10:0] & WpQualif[10:0]);
208
wire TempBpQualifier = Bp & BpQualif;
209
wire TempLSSQualifier = LsStatus[3:0] == LSSQualif[3:0];
210
wire TempIQualifier = IStatus[1:0] == IQualif[1:0];
211
 
212
wire TempQualifierAND =  (  (TempWpQualifier  | ~WpQualifValid)
213
                          & (TempBpQualifier  | ~BpQualifValid)
214
                          & (TempLSSQualifier | ~LSSQualifValid)
215
                          & (TempIQualifier   | ~IQualifValid)
216
                         )
217
                         & (WpQualifValid | BpQualifValid | LSSQualifValid | IQualifValid);
218
 
219
wire TempQualifierOR =   (  (TempWpQualifier  &  WpQualifValid)
220
                          | (TempBpQualifier  &  BpQualifValid)
221
                          | (TempLSSQualifier &  LSSQualifValid)
222
                          | (TempIQualifier   &  IQualifValid)
223
                         );
224
 
225
 
226
wire Stop;
227
wire Qualifier = TraceEnable & ~Stop & (~QualifOper[1]? 1 :                                   // any
228
                                         QualifOper[0]? TempQualifierAND  :  TempQualifierOR  // AND : OR
229
                                       );
230
 
231
/**********************************************************************************
232
*                                                                                 *
233
*   Generation of the stop signal                                                 *
234
*                                                                                 *
235
**********************************************************************************/
236
wire TempWpStop = |(Wp[10:0] & WpStop[10:0]);
237
wire TempBpStop = Bp & BpStop;
238
wire TempLSSStop = LsStatus[3:0] == LSSStop[3:0];
239
wire TempIStop = IStatus[1:0] == IStop[1:0];
240
 
241 8 mohor
wire TempStopAND =       (  (TempWpStop  | ~WpStopValid)
242 2 mohor
                          & (TempBpStop  | ~BpStopValid)
243
                          & (TempLSSStop | ~LSSStopValid)
244
                          & (TempIStop   | ~IStopValid)
245
                         )
246
                         & (WpStopValid | BpStopValid | LSSStopValid | IStopValid);
247
 
248 8 mohor
wire TempStopOR =        (  (TempWpStop  &  WpStopValid)
249 2 mohor
                          | (TempBpStop  &  BpStopValid)
250
                          | (TempLSSStop &  LSSStopValid)
251
                          | (TempIStop   &  IStopValid)
252
                         );
253
 
254
 
255
assign Stop = TraceEnable & (~StopOper[1]? 0 :                         // nothing
256
                              StopOper[0]? TempStopAND  :  TempStopOR  // AND : OR
257
                            );
258
 
259
 
260
 
261
/**********************************************************************************
262
*                                                                                 *
263
*   Generation of the TriggerLatch                                                *
264
*                                                                                 *
265
**********************************************************************************/
266 8 mohor
always @(posedge Mclk or posedge Reset)
267 2 mohor
begin
268 8 mohor
  if(Reset)
269 2 mohor
    TriggerLatch<=#Tp 0;
270
  else
271 8 mohor
  if(TriggerLatch & ~TraceEnable)
272
    TriggerLatch<=#Tp 0;
273
  else
274 2 mohor
  if(Trigger)
275
    TriggerLatch<=#Tp 1;
276
end
277
 
278
 
279 8 mohor
 
280
 
281 2 mohor
/**********************************************************************************
282
*                                                                                 *
283 8 mohor
*   TraceEnable Synchronization                                                   *
284
*                                                                                 *
285
**********************************************************************************/
286
always @(posedge Mclk or posedge Reset)
287
begin
288
  if(Reset)
289
    begin
290
      TraceEnable_d<=#Tp 0;
291
      TraceEnable<=#Tp 0;
292
    end
293
  else
294
    begin
295
      TraceEnable_d<=#Tp TraceEnable_reg;
296
      TraceEnable<=#Tp TraceEnable_d;
297
    end
298
end
299
 
300
 
301
 
302
 
303
/**********************************************************************************
304
*                                                                                 *
305 5 mohor
*   RiscStall, counter and pointers generation                                     *
306 2 mohor
*                                                                                 *
307
**********************************************************************************/
308
reg BufferFullDetected;
309 5 mohor
wire [`OPSELECTIONCOUNTER-1:0] RecEnable;
310 2 mohor
 
311
wire BufferFull = Counter[`TRACECOUNTERWIDTH:0]==`TRACEBUFFERLENGTH;
312
wire BufferEmpty = Counter[`TRACECOUNTERWIDTH:0]==0;
313 5 mohor
wire IncrementCounter = RiscStall_q & ~(BufferFull | BufferFullDetected) & Qualifier & RecEnable[StallCounter];
314
wire IncrementPointer = RiscStall_q & (~BufferFull | ContinMode) & Qualifier & RecEnable[StallCounter];
315 2 mohor
 
316
wire WriteSample = IncrementPointer;
317
 
318
wire Decrement = ReadBuffer & ~BufferEmpty & (~ContinMode | ContinMode & ~TraceEnable);
319
wire CounterEn = IncrementCounter ^ Decrement;
320
 
321 8 mohor
wire SyncResetCpuStall;
322 2 mohor
wire ResetStallCounter;
323
reg BufferFull_q;
324
reg BufferFull_2q;
325
 
326
reg Qualifier_mclk;
327
 
328
always @(posedge Mclk)
329
begin
330
  Qualifier_mclk<=#Tp Qualifier;
331
  BufferFull_q<=#Tp BufferFull;
332
  BufferFull_2q<=#Tp BufferFull_q;
333 8 mohor
  RiscStall_q <=#Tp RiscStall_O;
334 2 mohor
end
335
 
336
 
337 8 mohor
wire FirstCpuStall =    Qualifier & ~Qualifier_mclk & TriggerLatch              |
338
                        Qualifier_mclk & Trigger & ~TriggerLatch                |
339
                        Qualifier & Trigger & ~Qualifier_mclk & ~TriggerLatch   ;
340 2 mohor
 
341
 
342 8 mohor
//wire SyncSetCpuStall = Qualifier_mclk & TriggerLatch &
343
 
344
wire SyncSetCpuStall = RiscStall_O & ~RiscStall_q |
345
                        Qualifier_mclk & TriggerLatch &
346 2 mohor
                       (
347
                        (~ContinMode & ~BufferFull & ~BufferFull_q & StallCounter==`OPSELECTIONCOUNTER-1) |
348
                        (~ContinMode & ~BufferFull_q & BufferFull_2q & StallCounter==0)                   |
349
                        ( ContinMode & StallCounter==`OPSELECTIONCOUNTER-1)
350
                       );
351
 
352 8 mohor
assign SyncResetCpuStall = (
353
                            (~ContinMode & ~BufferFull & ~BufferFull_q & StallCounter==`OPSELECTIONCOUNTER-2) |
354
                            (~ContinMode &  ~BufferFull & BufferFull_q & StallCounter==`OPSELECTIONCOUNTER-1) |
355
                            ( ContinMode & StallCounter==`OPSELECTIONCOUNTER-2)
356
                           );
357 2 mohor
 
358 8 mohor
assign RiscStall_O = FirstCpuStall | RiscStall;
359 2 mohor
 
360 8 mohor
 
361 2 mohor
always @(posedge Mclk or posedge Reset)
362
begin
363
  if(Reset)
364
    Counter<=#Tp 0;
365
  else
366
  if(CounterEn)
367
    if(IncrementCounter)
368
      Counter[`TRACECOUNTERWIDTH:0]<=#Tp Counter[`TRACECOUNTERWIDTH:0] + 1;
369
    else
370
      Counter[`TRACECOUNTERWIDTH:0]<=#Tp Counter[`TRACECOUNTERWIDTH:0] - 1;
371
end
372
 
373
 
374
always @(posedge Mclk or posedge Reset)
375
begin
376
  if(Reset)
377 8 mohor
    WritePointer<=#Tp 0;
378 2 mohor
  else
379 8 mohor
  if(IncrementPointer)
380
    WritePointer[`TRACECOUNTERWIDTH-1:0]<=#Tp WritePointer[`TRACECOUNTERWIDTH-1:0] + 1;
381 2 mohor
end
382
 
383 8 mohor
always @(posedge Mclk or posedge Reset)
384
begin
385
  if(Reset)
386
    ReadPointer<=#Tp 0;
387
  else
388
  if(Decrement & ~ContinMode | Decrement & ContinMode & ~TraceEnable)
389
    ReadPointer[`TRACECOUNTERWIDTH-1:0]<=#Tp ReadPointer[`TRACECOUNTERWIDTH-1:0] + 1;
390
  else
391
  if(ContinMode & IncrementPointer & (BufferFull | BufferFullDetected))
392
    ReadPointer[`TRACECOUNTERWIDTH-1:0]<=#Tp WritePointer[`TRACECOUNTERWIDTH-1:0] + 1;
393
end
394
 
395 2 mohor
always @(posedge Mclk)
396
begin
397
  if(~TraceEnable)
398
    BufferFullDetected<=#Tp 0;
399
  else
400
  if(ContinMode & BufferFull)
401
    BufferFullDetected<=#Tp 1;
402
end
403
 
404
 
405 8 mohor
always @(posedge Mclk or posedge Reset)
406 2 mohor
begin
407 8 mohor
  if(Reset)
408
    RiscStall<=#Tp 0;
409 2 mohor
  else
410 8 mohor
  if(SyncResetCpuStall)
411
    RiscStall<=#Tp 0;
412
  else
413 2 mohor
  if(SyncSetCpuStall)
414 5 mohor
    RiscStall<=#Tp 1;
415 2 mohor
end
416
 
417
 
418
always @(posedge Mclk)
419
begin
420
  if(ResetStallCounter)
421
    StallCounter<=#Tp 0;
422
  else
423 5 mohor
  if(RiscStall_q & (~BufferFull | ContinMode))
424 2 mohor
    StallCounter<=#Tp StallCounter+1;
425
end
426
 
427
assign ResetStallCounter = StallCounter==(`OPSELECTIONCOUNTER-1) & ~BufferFull | Reset;
428
 
429
 
430
/**********************************************************************************
431
*                                                                                 *
432
*   Valid status                                                                  *
433
*                                                                                 *
434
**********************************************************************************/
435
wire Valid = ~BufferEmpty;
436
 
437
 
438
/**********************************************************************************
439
*                                                                                 *
440
*   Writing and reading the sample to/from the buffer                             *
441
*                                                                                 *
442
**********************************************************************************/
443
always @ (posedge Mclk)
444
begin
445
  if(WriteSample)
446
    Buffer[WritePointer[`TRACECOUNTERWIDTH-1:0]]<={DataIn, 1'b0, OpSelect[`OPSELECTWIDTH-1:0]};
447
end
448
 
449
assign TraceChain = {Buffer[ReadPointer], 3'h0, Valid};
450
 
451
 
452
 
453
/**********************************************************************************
454
*                                                                                 *
455
*   Operation select (to select which kind of data appears on the DATAIN lines)   *
456
*                                                                                 *
457
**********************************************************************************/
458
assign OpSelect[`OPSELECTWIDTH-1:0] = StallCounter[`OPSELECTWIDTH-1:0];
459
 
460
 
461
 
462
/**********************************************************************************
463
*                                                                                 *
464
*   Selecting which parts are going to be recorded as part of the sample          *
465
*                                                                                 *
466
**********************************************************************************/
467 5 mohor
assign RecEnable = {1'b0, RecordINSTR,  RecordWriteSPR,  RecordReadSPR,  RecordSDATA,  RecordLDATA,  RecordLSEA,  RecordPC};
468 2 mohor
 
469
 
470 9 mohor
endmodule

powered by: WebSVN 2.1.0

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