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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_20/] [or1200/] [rtl/] [verilog/] [or1200_except.v] - Blame information for rev 504

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

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Exception logic                                    ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Handles all OR1K exceptions inside CPU block.               ////
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
// Revision 1.15  2001/11/27 23:13:11  lampret
48
// Fixed except_stop width and fixed EX PC for 1400444f no-ops.
49
//
50
// Revision 1.14  2001/11/23 08:38:51  lampret
51
// Changed DSR/DRR behavior and exception detection.
52
//
53
// Revision 1.13  2001/11/20 18:46:15  simons
54
// Break point bug fixed
55
//
56
// Revision 1.12  2001/11/18 09:58:28  lampret
57
// Fixed some l.trap typos.
58
//
59
// Revision 1.11  2001/11/18 08:36:28  lampret
60
// For GDB changed single stepping and disabled trap exception.
61
//
62
// Revision 1.10  2001/11/13 10:02:21  lampret
63
// Added 'setpc'. Renamed some signals (except_flushpipe into flushpipe etc)
64
//
65
// Revision 1.9  2001/11/10 03:43:57  lampret
66
// Fixed exceptions.
67
//
68
// Revision 1.8  2001/10/21 17:57:16  lampret
69
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
70
//
71
// Revision 1.7  2001/10/14 13:12:09  lampret
72
// MP3 version.
73
//
74
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
75
// no message
76
//
77
// Revision 1.2  2001/08/09 13:39:33  lampret
78
// Major clean-up.
79
//
80
// Revision 1.1  2001/07/20 00:46:03  lampret
81
// Development version of RTL. Libraries are missing.
82
//
83
//
84
 
85
// synopsys translate_off
86
`include "timescale.v"
87
// synopsys translate_on
88
`include "or1200_defines.v"
89
 
90
`define OR1200_EXCEPTFSM_WIDTH 3
91
`define OR1200_EXCEPTFSM_IDLE   `OR1200_EXCEPTFSM_WIDTH'd0
92
`define OR1200_EXCEPTFSM_FLU1   `OR1200_EXCEPTFSM_WIDTH'd1
93
`define OR1200_EXCEPTFSM_FLU2   `OR1200_EXCEPTFSM_WIDTH'd2
94
`define OR1200_EXCEPTFSM_FLU3   `OR1200_EXCEPTFSM_WIDTH'd3
95
`define OR1200_EXCEPTFSM_FLU4   `OR1200_EXCEPTFSM_WIDTH'd4
96
`define OR1200_EXCEPTFSM_FLU5   `OR1200_EXCEPTFSM_WIDTH'd5
97
 
98
//
99
// Exception recognition and sequencing
100
//
101
 
102
module or1200_except(
103
        // Clock and reset
104
        clk, rst,
105
 
106
        // Internal i/f
107
        sig_ibuserr, sig_dbuserr, sig_illegal, sig_align, sig_range, sig_dtlbmiss, sig_dmmufault,
108
        sig_inthigh, sig_syscall, sig_trap, sig_itlbmiss, sig_immufault, sig_intlow,
109
        branch_taken, id_freeze, ex_freeze, wb_freeze, if_stall,
110
        if_pc, lr_sav, flushpipe, extend_flush, except_type, except_start,
111
        except_started, except_stop,
112
        wb_pc, ex_pc, datain, du_dsr, epcr_we, eear_we, esr_we, pc_we, epcr, eear,
113
        esr, sr, lsu_addr
114
);
115
 
116
//
117
// I/O
118
//
119
input                           clk;
120
input                           rst;
121
input                           sig_ibuserr;
122
input                           sig_dbuserr;
123
input                           sig_illegal;
124
input                           sig_align;
125
input                           sig_range;
126
input                           sig_dtlbmiss;
127
input                           sig_dmmufault;
128
input                           sig_inthigh;
129
input                           sig_syscall;
130
input                           sig_trap;
131
input                           sig_itlbmiss;
132
input                           sig_immufault;
133
input                           sig_intlow;
134
input                           branch_taken;
135
input                           id_freeze;
136
input                           ex_freeze;
137
input                           wb_freeze;
138
input                           if_stall;
139
input   [31:0]                   if_pc;
140
output  [31:2]                  lr_sav;
141
input   [31:0]                   datain;
142
input   [`OR1200_DU_DSR_WIDTH-1:0]     du_dsr;
143
input                           epcr_we;
144
input                           eear_we;
145
input                           esr_we;
146
input                           pc_we;
147
output  [31:0]                   epcr;
148
output  [31:0]                   eear;
149
output  [`OR1200_SR_WIDTH-1:0]           esr;
150
input   [`OR1200_SR_WIDTH-1:0]           sr;
151
input   [31:0]                   lsu_addr;
152
output                          flushpipe;
153
output                          extend_flush;
154
output  [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
155
output                          except_start;
156
output                          except_started;
157
output  [12:0]                   except_stop;
158
output  [31:0]                   wb_pc;
159
output  [31:0]                   ex_pc;
160
 
161
//
162
// Internal regs and wires
163
//
164
reg     [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
165
reg     [31:0]                   id_pc;
166
reg     [31:0]                   ex_pc;
167
reg     [31:0]                   wb_pc;
168
reg     [31:0]                   epcr;
169
reg     [31:0]                   eear;
170
reg     [`OR1200_SR_WIDTH-1:0]           esr;
171
reg     [3:0]                    id_exceptflags;
172
reg     [3:0]                    ex_exceptflags;
173
reg     [`OR1200_EXCEPTFSM_WIDTH-1:0]    state;
174
reg                             extend_flush;
175
reg                             extend_flush_last;
176
reg                             ex_dslot;
177
reg                             delayed1_ex_dslot;
178
reg                             delayed2_ex_dslot;
179
wire                            except_started;
180
wire    [12:0]                   except_trig;
181
wire                            except_flushpipe;
182
reg     [2:0]                    delayed_eir;
183
wire                            inthigh_pending;
184
wire                            intlow_pending;
185
 
186
//
187
// Simple combinatorial logic
188
//
189
assign except_started = extend_flush & except_start;
190
assign lr_sav = ex_pc[31:2];
191
assign except_start = (except_type != `OR1200_EXCEPT_NONE);
192
assign inthigh_pending = sig_inthigh & sr[`OR1200_SR_EIR] & delayed_eir[2] & ~ex_freeze & ~branch_taken & ~ex_dslot & ~delayed1_ex_dslot & ~delayed2_ex_dslot;
193
assign intlow_pending = sig_intlow & sr[`OR1200_SR_EIR] & delayed_eir[2] & ~ex_freeze & ~branch_taken & ~ex_dslot & ~delayed1_ex_dslot & ~delayed2_ex_dslot;
194
 
195
//
196
// Order defines exception detection priority
197
//
198
assign except_trig = {
199
                        inthigh_pending         & ~du_dsr[`OR1200_DU_DSR_HPINTE],
200
                        ex_exceptflags[2]       & ~du_dsr[`OR1200_DU_DSR_IME],
201
                        ex_exceptflags[1]       & ~du_dsr[`OR1200_DU_DSR_IPFE],
202
                        ex_exceptflags[3]       & ~du_dsr[`OR1200_DU_DSR_BUSEE],
203
                        sig_illegal             & ~du_dsr[`OR1200_DU_DSR_IIE],
204
                        sig_align               & ~du_dsr[`OR1200_DU_DSR_AE],
205
                        sig_dtlbmiss            & ~du_dsr[`OR1200_DU_DSR_DME],
206
                        sig_dmmufault           & ~du_dsr[`OR1200_DU_DSR_DPFE],
207
                        sig_dbuserr             & ~du_dsr[`OR1200_DU_DSR_BUSEE],
208
                        ex_exceptflags[0]        & ~du_dsr[`OR1200_DU_DSR_LPINTE],
209
                        sig_syscall             & ~du_dsr[`OR1200_DU_DSR_SCE] & ~ex_freeze,
210
                        sig_trap                & ~du_dsr[`OR1200_DU_DSR_TE],
211
                        sig_range               & ~du_dsr[`OR1200_DU_DSR_RE]
212
                };
213
assign except_stop = {
214
                        inthigh_pending         & du_dsr[`OR1200_DU_DSR_HPINTE],
215
                        ex_exceptflags[2]       & du_dsr[`OR1200_DU_DSR_IME],
216
                        ex_exceptflags[1]       & du_dsr[`OR1200_DU_DSR_IPFE],
217
                        ex_exceptflags[3]       & du_dsr[`OR1200_DU_DSR_BUSEE],
218
                        sig_illegal             & du_dsr[`OR1200_DU_DSR_IIE],
219
                        sig_align               & du_dsr[`OR1200_DU_DSR_AE],
220
                        sig_dtlbmiss            & du_dsr[`OR1200_DU_DSR_DME],
221
                        sig_dmmufault           & du_dsr[`OR1200_DU_DSR_DPFE],
222
                        sig_dbuserr             & du_dsr[`OR1200_DU_DSR_BUSEE],
223
                        ex_exceptflags[0]        & du_dsr[`OR1200_DU_DSR_LPINTE],
224
                        sig_syscall             & du_dsr[`OR1200_DU_DSR_SCE] & ~ex_freeze,
225
                        sig_trap                & du_dsr[`OR1200_DU_DSR_TE],
226
                        sig_range               & du_dsr[`OR1200_DU_DSR_RE]
227
                };
228
 
229
//
230
// PC and Exception flags pipelines
231
//
232
always @(posedge clk or posedge rst) begin
233
        if (rst) begin
234
                id_pc <= #1 32'd0;
235
                id_exceptflags <= #1 4'b0000;
236
        end
237
        else if (!id_freeze) begin
238
`ifdef OR1200_VERBOSE
239
// synopsys translate_off
240
                $display("%t: id_pc <= %h", $time, if_pc);
241
// synopsys translate_on
242
`endif
243
                id_pc <= #1 if_pc;
244
                id_exceptflags <= #1 { sig_ibuserr, sig_itlbmiss, sig_immufault, intlow_pending };
245
        end
246
end
247
 
248
//
249
// delayed_eir
250
//
251
// SR[EIR] should not enable interrupts right away
252
// when it is restored with l.rfe. Instead delayed_eir
253
// together with SR[EIR] enables interrupts once
254
// pipeline is again ready.
255
//
256
always @(posedge rst or posedge clk)
257
        if (rst)
258
                delayed_eir <= #1 3'b000;
259
        else if (!sr[`OR1200_SR_EIR])
260
                delayed_eir <= #1 3'b000;
261
        else
262
                delayed_eir <= #1 {delayed_eir[1:0], 1'b1};
263
 
264
//
265
// PC and Exception flags pipelines
266
//
267
always @(posedge clk or posedge rst) begin
268
        if (rst) begin
269
                ex_dslot <= #1 1'b0;
270
                ex_pc <= #1 32'd0;
271
                ex_exceptflags <= #1 4'b0000;
272
                delayed1_ex_dslot <= #1 1'b0;
273
                delayed2_ex_dslot <= #1 1'b0;
274
        end
275
        else if (!ex_freeze & id_freeze) begin
276
                ex_dslot <= #1 1'b0;
277
                ex_pc <= #1 id_pc;
278
                ex_exceptflags <= #1 4'b0000;
279
                delayed1_ex_dslot <= #1 ex_dslot;
280
                delayed2_ex_dslot <= #1 delayed1_ex_dslot;
281
        end
282
        else if (!ex_freeze) begin
283
`ifdef OR1200_VERBOSE
284
// synopsys translate_off
285
                $display("%t: ex_pc <= %h", $time, id_pc);
286
// synopsys translate_on
287
`endif
288
                ex_dslot <= #1 branch_taken;
289
                ex_pc <= #1 id_pc;
290
                ex_exceptflags <= #1 id_exceptflags;
291
                delayed1_ex_dslot <= #1 ex_dslot;
292
                delayed2_ex_dslot <= #1 delayed1_ex_dslot;
293
        end
294
end
295
 
296
//
297
// PC and Exception flags pipelines
298
//
299
always @(posedge clk or posedge rst) begin
300
        if (rst) begin
301
                wb_pc <= #1 32'd0;
302
        end
303
        else if (!wb_freeze) begin
304
                wb_pc <= #1 ex_pc;
305
        end
306
end
307
 
308
//
309
// Flush pipeline
310
//
311
assign flushpipe = except_flushpipe | pc_we | extend_flush | extend_flush_last;
312
 
313
//
314
// We have started execution of exception handler:
315
//  1. Asserted for 3 clock cycles
316
//  2. Don't execute any instruction that is still in pipeline and is not part of exception handler
317
//
318
assign except_flushpipe = |except_trig;
319
 
320
//
321
// Exception FSM that sequences execution of exception handler
322
//
323
// except_type signals which exception handler we start fetching in:
324
//  1. Asserted in next clock cycle after exception is recognized
325
//
326
always @(posedge clk or posedge rst) begin
327
        if (rst) begin
328
                state <= #1 `OR1200_EXCEPTFSM_IDLE;
329
                except_type <= #1 `OR1200_EXCEPT_NONE;
330
                extend_flush <= #1 1'b0;
331
                epcr <= #1 32'b0;
332
                eear <= #1 32'b0;
333
                esr <= #1 `OR1200_SR_WIDTH'b010;
334
                extend_flush_last <= #1 1'b0;
335
        end
336
        else begin
337
                case (state)    // synopsys full_case parallel_case
338
                        `OR1200_EXCEPTFSM_IDLE:
339
                                if (except_flushpipe) begin
340
                                        state <= #1 `OR1200_EXCEPTFSM_FLU1;
341
                                        extend_flush <= #1 1'b1;
342
                                        if (ex_dslot) begin
343
`ifdef OR1200_VERBOSE
344
// synopsys translate_off
345
                                                $display(" INFO: Exception during first delay slot instruction.");
346
// synopsys translate_on
347
`endif
348
                                        end
349
                                        else if (delayed1_ex_dslot) begin
350
`ifdef OR1200_VERBOSE
351
// synopsys translate_off
352
                                                $display(" INFO: Exception during second (NOP) delay slot instruction.");
353
// synopsys translate_on
354
`endif
355
                                        end
356
                                        else if (delayed2_ex_dslot) begin
357
`ifdef OR1200_VERBOSE
358
// synopsys translate_off
359
                                                $display(" INFO: Exception during third delay slot (SHOULD NOT HAPPEN).");
360
// synopsys translate_on
361
`endif
362
                                        end
363
                                        else begin
364
`ifdef OR1200_VERBOSE
365
// synopsys translate_off
366
                                                $display(" INFO: Exception during normal (no delay slot) instruction.");
367
// synopsys translate_on
368
`endif
369
                                        end
370
 
371
                                        esr <= #1 sr;
372
                                        casex (except_trig)
373
                                                13'b1_xxxx_xxxx_xxxx: begin
374
                                                        except_type <= #1 `OR1200_EXCEPT_HPINT;
375
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
376
                                                end
377
                                                13'b0_1xxx_xxxx_xxxx: begin
378
                                                        except_type <= #1 `OR1200_EXCEPT_ITLBMISS;
379
                                                        eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
380
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
381
                                                end
382
                                                13'b0_01xx_xxxx_xxxx: begin
383
                                                        except_type <= #1 `OR1200_EXCEPT_IPF;
384
                                                        eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
385
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
386
                                                end
387
                                                13'b0_001x_xxxx_xxxx: begin
388
                                                        except_type <= #1 `OR1200_EXCEPT_BUSERR;
389
                                                        eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
390
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
391
                                                end
392
                                                13'b0_0001_xxxx_xxxx: begin
393
                                                        except_type <= #1 `OR1200_EXCEPT_ILLEGAL;
394
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
395
                                                end
396
                                                13'b0_0000_1xxx_xxxx: begin
397
                                                        except_type <= #1 `OR1200_EXCEPT_ALIGN;
398
                                                        eear <= #1 lsu_addr;
399
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
400
                                                end
401
                                                13'b0_0000_01xx_xxxx: begin
402
                                                        except_type <= #1 `OR1200_EXCEPT_DTLBMISS;
403
                                                        eear <= #1 lsu_addr;
404
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
405
                                                end
406
                                                13'b0_0000_001x_xxxx: begin
407
                                                        except_type <= #1 `OR1200_EXCEPT_DPF;
408
                                                        eear <= #1 lsu_addr;
409
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
410
                                                end
411
                                                13'b0_0000_0001_xxxx: begin
412
                                                        except_type <= #1 `OR1200_EXCEPT_BUSERR;
413
                                                        eear <= #1 lsu_addr;
414
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
415
                                                end
416
                                                13'b0_0000_0000_1xxx: begin
417
                                                        except_type <= #1 `OR1200_EXCEPT_LPINT;
418
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
419
                                                end
420
                                                13'b0_0000_0000_01xx: begin
421
                                                        except_type <= #1 `OR1200_EXCEPT_RANGE;
422
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
423
                                                end
424
                                                13'b0_0000_0000_001x: begin
425
                                                        except_type <= #1 `OR1200_EXCEPT_TRAP;
426
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
427
                                                end
428
                                                13'b0_0000_0000_0001: begin
429
                                                        except_type <= #1 `OR1200_EXCEPT_SYSCALL;
430
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
431
                                                end
432
                                                default:
433
                                                        except_type <= #1 `OR1200_EXCEPT_NONE;
434
                                        endcase
435
                                end
436
                                else if (pc_we) begin
437
                                        state <= #1 `OR1200_EXCEPTFSM_FLU1;
438
                                        extend_flush <= #1 1'b1;
439
                                end
440
                                else begin
441
                                        if (epcr_we)
442
                                                epcr <= #1 datain;
443
                                        if (eear_we)
444
                                                eear <= #1 datain;
445
                                        if (esr_we)
446
                                                esr <= #1 {datain[`OR1200_SR_WIDTH-1:2], 1'b1, datain[0]};
447
                                end
448
                        `OR1200_EXCEPTFSM_FLU1:
449
                                if (!if_stall & !id_freeze)
450
                                        state <= #1 `OR1200_EXCEPTFSM_FLU2;
451
                        `OR1200_EXCEPTFSM_FLU2:
452
                                if (except_type == `OR1200_EXCEPT_TRAP) begin
453
                                        state <= #1 `OR1200_EXCEPTFSM_IDLE;
454
                                        extend_flush <= #1 1'b0;
455
                                        extend_flush_last <= #1 1'b0;
456
                                        except_type <= #1 `OR1200_EXCEPT_NONE;
457
                                end
458
                                else if (!if_stall & !id_freeze)
459
                                        state <= #1 `OR1200_EXCEPTFSM_FLU3;
460
                        `OR1200_EXCEPTFSM_FLU3:
461
                                if (!if_stall && !id_freeze)
462
                                        begin
463
`ifdef OR1200_VERBOSE
464
// synopsys translate_off
465
                                                if (except_flushpipe)
466
                                                        $display(" INFO: EPCR0 %h  EEAR %h  ESR %h", epcr, eear, esr);
467
// synopsys translate_on
468
`endif
469
                                                state <= #1 `OR1200_EXCEPTFSM_FLU4;
470
                                        end
471
                        `OR1200_EXCEPTFSM_FLU4: begin
472
                                state <= #1 `OR1200_EXCEPTFSM_FLU5;
473
                                extend_flush <= #1 1'b0;
474
                                extend_flush_last <= #1 1'b1;
475
                        end
476
                        `OR1200_EXCEPTFSM_FLU5: begin
477
`ifdef OR1200_VERBOSE
478
// synopsys translate_off
479
                                $display(" INFO: Just finished flushing pipeline.");
480
// synopsys translate_on
481
`endif
482
                                state <= #1 `OR1200_EXCEPTFSM_IDLE;
483
                                except_type <= #1 `OR1200_EXCEPT_NONE;
484
                                extend_flush_last <= #1 1'b0;
485
                        end
486
                endcase
487
        end
488
end
489
 
490
endmodule

powered by: WebSVN 2.1.0

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