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

Subversion Repositories or1k

[/] [or1k/] [tags/] [first/] [orp/] [orp_soc/] [rtl/] [verilog/] [dbg_interface/] [dbg_trace.v] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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