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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_26/] [or1200/] [rtl/] [verilog/] [or1200_du.v] - Blame information for rev 737

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Debug Unit                                         ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Basic OR1200 debug unit.                                    ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   - make it smaller and faster                               ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Damjan Lampret, lampret@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47 737 lampret
// Revision 1.5  2002/02/11 04:33:17  lampret
48
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
49
//
50 660 lampret
// Revision 1.4  2002/01/28 01:16:00  lampret
51
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
52
//
53 617 lampret
// Revision 1.3  2002/01/18 07:56:00  lampret
54
// No more low/high priority interrupts (PICPR removed). Added tick timer exception. Added exception prefix (SR[EPH]). Fixed single-step bug whenreading NPC.
55
//
56 589 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
57
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
58
//
59 562 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
60
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
61
//
62 504 lampret
// Revision 1.12  2001/11/30 18:58:00  simons
63
// Trap insn couses break after exits ex_insn.
64
//
65
// Revision 1.11  2001/11/23 08:38:51  lampret
66
// Changed DSR/DRR behavior and exception detection.
67
//
68
// Revision 1.10  2001/11/20 21:25:44  lampret
69
// Fixed dbg_is_o assignment width.
70
//
71
// Revision 1.9  2001/11/20 18:46:14  simons
72
// Break point bug fixed
73
//
74
// Revision 1.8  2001/11/18 08:36:28  lampret
75
// For GDB changed single stepping and disabled trap exception.
76
//
77
// Revision 1.7  2001/10/21 18:09:53  lampret
78
// Fixed sensitivity list.
79
//
80
// Revision 1.6  2001/10/14 13:12:09  lampret
81
// MP3 version.
82
//
83
//
84
 
85
// synopsys translate_off
86
`include "timescale.v"
87
// synopsys translate_on
88
`include "or1200_defines.v"
89
 
90
//
91
// Debug unit
92
//
93
 
94
module or1200_du(
95
        // RISC Internal Interface
96
        clk, rst,
97 660 lampret
        dcpu_cycstb_i, dcpu_we_i,
98
        icpu_cycstb_i, ex_freeze, branch_op, ex_insn, du_dsr,
99 504 lampret
        du_stall, du_addr, du_dat_i, du_dat_o, du_read, du_write, du_except,
100
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
101
 
102
        // External Debug Interface
103
        dbg_stall_i, dbg_dat_i, dbg_adr_i, dbg_op_i, dbg_ewt_i,
104
        dbg_lss_o, dbg_is_o, dbg_wp_o, dbg_bp_o, dbg_dat_o
105
);
106
 
107
parameter dw = `OR1200_OPERAND_WIDTH;
108
parameter aw = `OR1200_OPERAND_WIDTH;
109
 
110
//
111
// I/O
112
//
113
 
114
//
115
// RISC Internal Interface
116
//
117
input                           clk;            // Clock
118
input                           rst;            // Reset
119 660 lampret
input                           dcpu_cycstb_i;  // LSU status
120 504 lampret
input                           dcpu_we_i;      // LSU status
121 660 lampret
input   [`OR1200_FETCHOP_WIDTH-1:0]      icpu_cycstb_i;  // IFETCH unit status
122 504 lampret
input                           ex_freeze;      // EX stage freeze
123
input   [`OR1200_BRANCHOP_WIDTH-1:0]     branch_op;      // Branch op
124
input   [dw-1:0]         ex_insn;        // EX insn
125
output  [`OR1200_DU_DSR_WIDTH-1:0]     du_dsr;           // DSR
126
output                          du_stall;       // Debug Unit Stall
127
output  [aw-1:0]         du_addr;        // Debug Unit Address
128
input   [dw-1:0]         du_dat_i;       // Debug Unit Data In
129
output  [dw-1:0]         du_dat_o;       // Debug Unit Data Out
130
output                          du_read;        // Debug Unit Read Enable
131
output                          du_write;       // Debug Unit Write Enable
132
input   [12:0]                   du_except;      // Exception masked by DSR
133
input                           spr_cs;         // SPR Chip Select
134
input                           spr_write;      // SPR Read/Write
135
input   [aw-1:0]         spr_addr;       // SPR Address
136
input   [dw-1:0]         spr_dat_i;      // SPR Data Input
137
output  [dw-1:0]         spr_dat_o;      // SPR Data Output
138
 
139
//
140
// External Debug Interface
141
//
142
input                           dbg_stall_i;    // External Stall Input
143
input   [dw-1:0]         dbg_dat_i;      // External Data Input
144
input   [aw-1:0]         dbg_adr_i;      // External Address Input
145
input   [2:0]                    dbg_op_i;       // External Operation Select Input
146
input                           dbg_ewt_i;      // External Watchpoint Trigger Input
147
output  [3:0]                    dbg_lss_o;      // External Load/Store Unit Status
148
output  [1:0]                    dbg_is_o;       // External Insn Fetch Status
149
output  [10:0]                   dbg_wp_o;       // Watchpoints Outputs
150
output                          dbg_bp_o;       // Breakpoint Output
151
output  [dw-1:0]         dbg_dat_o;      // External Data Output
152
 
153
 
154
//
155
// Some connections go directly from the CPU through DU to Debug I/F
156
//
157 737 lampret
`ifdef OR1200_DU_STATUS_UNIMPLEMENTED
158
assign dbg_lss_o = 4'b0000;
159
assign dbg_is_o = 2'b00;
160
`else
161 660 lampret
assign dbg_lss_o = dcpu_cycstb_i ? {dcpu_we_i, 3'b000} : 4'b0000;
162
assign dbg_is_o = {1'b0, icpu_cycstb_i};
163 737 lampret
`endif
164 504 lampret
assign dbg_wp_o = 11'b000_0000_0000;
165
assign dbg_dat_o = du_dat_i;
166
 
167
//
168
// Some connections go directly from Debug I/F through DU to the CPU
169
//
170
assign du_stall = dbg_stall_i;
171
assign du_addr = dbg_adr_i;
172
assign du_dat_o = dbg_dat_i;
173
assign du_read = (dbg_op_i == `OR1200_DU_OP_READSPR);
174
assign du_write = (dbg_op_i == `OR1200_DU_OP_WRITESPR);
175
 
176
`ifdef OR1200_DU_IMPLEMENTED
177
 
178
//
179
// Debug Mode Register 1 (only ST and BT implemented)
180
//
181
`ifdef OR1200_DU_DMR1
182
reg     [23:22]                 dmr1;           // DMR1 implemented (ST & BT)
183
`else
184
wire    [23:22]                 dmr1;           // DMR1 not implemented
185
`endif
186
 
187
//
188
// Debug Mode Register 2 (not implemented)
189
//
190
`ifdef OR1200_DU_DMR2
191
wire    [31:0]                   dmr2;           // DMR not implemented
192
`endif
193
 
194
//
195
// Debug Stop Register
196
//
197
`ifdef OR1200_DU_DSR
198
reg     [`OR1200_DU_DSR_WIDTH-1:0]       dsr;            // DSR implemented
199
`else
200
wire    [`OR1200_DU_DSR_WIDTH-1:0]       dsr;            // DSR not implemented
201
`endif
202
 
203
//
204
// Debug Reason Register
205
//
206
`ifdef OR1200_DU_DRR
207
reg     [13:0]                   drr;            // DRR implemented
208
`else
209
wire    [13:0]                   drr;            // DRR not implemented
210
`endif
211
 
212
//
213
// Internal wires
214
//
215
wire                            dmr1_sel;       // DMR1 select
216
wire                            dsr_sel;        // DSR select
217
wire                            drr_sel;        // DRR select
218
reg                             dbg_bp_r;
219
`ifdef OR1200_DU_READREGS
220
reg     [31:0]                   spr_dat_o;
221
`endif
222
reg     [13:0]                   except_stop;    // Exceptions that stop because of DSR
223
 
224
//
225
// DU registers address decoder
226
//
227
`ifdef OR1200_DU_DMR1
228
assign dmr1_sel = (spr_cs && (spr_addr[`OR1200_SPR_OFS_BITS] == `OR1200_DU_OFS_DMR1));
229
`endif
230
`ifdef OR1200_DU_DSR
231
assign dsr_sel = (spr_cs && (spr_addr[`OR1200_SPR_OFS_BITS] == `OR1200_DU_OFS_DSR));
232
`endif
233
`ifdef OR1200_DU_DRR
234
assign drr_sel = (spr_cs && (spr_addr[`OR1200_SPR_OFS_BITS] == `OR1200_DU_OFS_DRR));
235
`endif
236
 
237
//
238
// Decode started exception
239
//
240
always @(du_except) begin
241
        except_stop = 14'b0000_0000_0000;
242
        casex (du_except)
243 617 lampret
                13'b1_xxxx_xxxx_xxxx:
244
                        except_stop[`OR1200_DU_DRR_TTE] = 1'b1;
245
                13'b0_1xxx_xxxx_xxxx: begin
246 589 lampret
                        except_stop[`OR1200_DU_DRR_IE] = 1'b1;
247 504 lampret
                end
248 617 lampret
                13'b0_01xx_xxxx_xxxx: begin
249 504 lampret
                        except_stop[`OR1200_DU_DRR_IME] = 1'b1;
250
                end
251 617 lampret
                13'b0_001x_xxxx_xxxx:
252 504 lampret
                        except_stop[`OR1200_DU_DRR_IPFE] = 1'b1;
253 617 lampret
                13'b0_0001_xxxx_xxxx: begin
254 504 lampret
                        except_stop[`OR1200_DU_DRR_BUSEE] = 1'b1;
255
                end
256 617 lampret
                13'b0_0000_1xxx_xxxx:
257 504 lampret
                        except_stop[`OR1200_DU_DRR_IIE] = 1'b1;
258 617 lampret
                13'b0_0000_01xx_xxxx: begin
259 504 lampret
                        except_stop[`OR1200_DU_DRR_AE] = 1'b1;
260
                end
261 617 lampret
                13'b0_0000_001x_xxxx: begin
262 504 lampret
                        except_stop[`OR1200_DU_DRR_DME] = 1'b1;
263
                end
264 617 lampret
                13'b0_0000_0001_xxxx:
265 504 lampret
                        except_stop[`OR1200_DU_DRR_DPFE] = 1'b1;
266 617 lampret
                13'b0_0000_0000_1xxx:
267 504 lampret
                        except_stop[`OR1200_DU_DRR_BUSEE] = 1'b1;
268
                13'b0_0000_0000_01xx: begin
269
                        except_stop[`OR1200_DU_DRR_RE] = 1'b1;
270
                end
271
                13'b0_0000_0000_001x: begin
272
                        except_stop[`OR1200_DU_DRR_TE] = 1'b1;
273
                end
274
                13'b0_0000_0000_0001:
275
                        except_stop[`OR1200_DU_DRR_SCE] = 1'b1;
276
                default:
277
                        except_stop = 14'b0000_0000_0000;
278
        endcase
279
end
280
 
281
//
282
// dbg_bp_o is registered
283
//
284
assign dbg_bp_o = dbg_bp_r;
285
 
286
//
287
// Breakpoint activation register
288
//
289
always @(posedge clk or posedge rst)
290
        if (rst)
291
                dbg_bp_r <= #1 1'b0;
292
        else if (!ex_freeze)
293
                dbg_bp_r <= #1 |except_stop
294
`ifdef OR1200_DU_DMR1_ST
295 617 lampret
                        | ~((ex_insn[31:26] == `OR1200_OR32_NOP) & ex_insn[16]) & dmr1[`OR1200_DU_DMR1_ST]
296 504 lampret
`endif
297
`ifdef OR1200_DU_DMR1_BT
298
                        | (branch_op != `OR1200_BRANCHOP_NOP) & dmr1[`OR1200_DU_DMR1_BT]
299
`endif
300
                        ;
301
        else
302 562 lampret
                dbg_bp_r <= #1 |except_stop;
303 504 lampret
 
304
//
305
// Write to DMR1
306
//
307
`ifdef OR1200_DU_DMR1
308
always @(posedge clk or posedge rst)
309
        if (rst)
310
                dmr1 <= 2'b00;
311
        else if (dmr1_sel && spr_write)
312
                dmr1 <= #1 spr_dat_i[23:22];
313
`else
314
assign dmr1 = 2'b00;
315
`endif
316
 
317
//
318
// DMR2 bits tied to zero
319
//
320
`ifdef OR1200_DU_DMR2
321
assign dmr2 = 32'h0000_0000;
322
`endif
323
 
324
//
325
// Write to DSR
326
//
327
`ifdef OR1200_DU_DSR
328
always @(posedge clk or posedge rst)
329
        if (rst)
330
                dsr <= {`OR1200_DU_DSR_WIDTH{1'b0}};
331
        else if (dsr_sel && spr_write)
332
                dsr <= #1 spr_dat_i[`OR1200_DU_DSR_WIDTH-1:0];
333
`else
334
assign dsr = {`OR1200_DU_DSR_WIDTH{1'b0}};
335
`endif
336
 
337
//
338
// Write to DRR
339
//
340
`ifdef OR1200_DU_DRR
341
always @(posedge clk or posedge rst)
342
        if (rst)
343
                drr <= 14'b0;
344
        else if (drr_sel && spr_write)
345
                drr <= #1 spr_dat_i[13:0];
346
        else
347
                drr <= #1 drr | except_stop;
348
`else
349
assign drr = 14'b0;
350
`endif
351
 
352
//
353
// Read DU registers
354
//
355
`ifdef OR1200_DU_READREGS
356
always @(spr_addr or dsr or drr or dmr1 or dmr2)
357
        case (spr_addr[`OR1200_SPR_OFS_BITS])
358
`ifdef OR1200_DU_DMR1
359
                `OR1200_DU_OFS_DMR1:
360
                        spr_dat_o = {8'b0, dmr1, 22'b0};
361
`endif
362
`ifdef OR1200_DU_DMR2
363
                `OR1200_DU_OFS_DMR2:
364
                        spr_dat_o = dmr2;
365
`endif
366
`ifdef OR1200_DU_DSR
367
                `OR1200_DU_OFS_DSR:
368
                        spr_dat_o = {18'b0, dsr};
369
`endif
370
`ifdef OR1200_DU_DRR
371
                `OR1200_DU_OFS_DRR:
372
                        spr_dat_o = {18'b0, drr};
373
`endif
374
                default:
375
                        spr_dat_o = 32'h0000_0000;
376
        endcase
377
`endif
378
 
379
//
380
// DSR alias
381
//
382
assign du_dsr = dsr;
383
 
384
`else
385
 
386
//
387
// When DU is not implemented, drive all outputs as would when DU is disabled
388
//
389
assign dbg_bp_o = 1'b0;
390
assign du_dsr = {`OR1200_DU_DSR_WIDTH{1'b0}};
391
 
392
//
393
// Read DU registers
394
//
395
`ifdef OR1200_DU_READREGS
396
assign spr_dat_o = 32'h0000_0000;
397
`ifdef OR1200_DU_UNUSED_ZERO
398
`endif
399
`endif
400
 
401
`endif
402
 
403
endmodule

powered by: WebSVN 2.1.0

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