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 17

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

powered by: WebSVN 2.1.0

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