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 9

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

powered by: WebSVN 2.1.0

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