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

Subversion Repositories or1k

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

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 977 lampret
// Revision 1.10  2002/07/14 22:17:17  lampret
48
// Added simple trace buffer [only for Xilinx Virtex target]. Fixed instruction fetch abort when new exception is recognized.
49
//
50 895 lampret
// Revision 1.9  2002/02/11 04:33:17  lampret
51
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
52
//
53 660 lampret
// Revision 1.8  2002/01/28 01:16:00  lampret
54
// 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.
55
//
56 617 lampret
// Revision 1.7  2002/01/23 07:52:36  lampret
57
// Changed default reset values for SR and ESR to match or1ksim's. Fixed flop model in or1200_dpram_32x32 when OR1200_XILINX_RAM32X1D is defined.
58
//
59 610 lampret
// Revision 1.6  2002/01/18 14:21:43  lampret
60
// Fixed 'the NPC single-step fix'.
61
//
62 595 lampret
// Revision 1.5  2002/01/18 07:56:00  lampret
63
// No more low/high priority interrupts (PICPR removed). Added tick timer exception. Added exception prefix (SR[EPH]). Fixed single-step bug whenreading NPC.
64
//
65 589 lampret
// Revision 1.4  2002/01/14 21:11:50  lampret
66
// Changed alignment exception EPCR. Not tested yet.
67
//
68 571 lampret
// Revision 1.3  2002/01/14 19:09:57  lampret
69
// Fixed order of syscall and range exceptions.
70
//
71 570 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
72
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
73
//
74 562 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
75
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
76
//
77 504 lampret
// Revision 1.15  2001/11/27 23:13:11  lampret
78
// Fixed except_stop width and fixed EX PC for 1400444f no-ops.
79
//
80
// Revision 1.14  2001/11/23 08:38:51  lampret
81
// Changed DSR/DRR behavior and exception detection.
82
//
83
// Revision 1.13  2001/11/20 18:46:15  simons
84
// Break point bug fixed
85
//
86
// Revision 1.12  2001/11/18 09:58:28  lampret
87
// Fixed some l.trap typos.
88
//
89
// Revision 1.11  2001/11/18 08:36:28  lampret
90
// For GDB changed single stepping and disabled trap exception.
91
//
92
// Revision 1.10  2001/11/13 10:02:21  lampret
93
// Added 'setpc'. Renamed some signals (except_flushpipe into flushpipe etc)
94
//
95
// Revision 1.9  2001/11/10 03:43:57  lampret
96
// Fixed exceptions.
97
//
98
// Revision 1.8  2001/10/21 17:57:16  lampret
99
// 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.
100
//
101
// Revision 1.7  2001/10/14 13:12:09  lampret
102
// MP3 version.
103
//
104
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
105
// no message
106
//
107
// Revision 1.2  2001/08/09 13:39:33  lampret
108
// Major clean-up.
109
//
110
// Revision 1.1  2001/07/20 00:46:03  lampret
111
// Development version of RTL. Libraries are missing.
112
//
113
//
114
 
115
// synopsys translate_off
116
`include "timescale.v"
117
// synopsys translate_on
118
`include "or1200_defines.v"
119
 
120
`define OR1200_EXCEPTFSM_WIDTH 3
121
`define OR1200_EXCEPTFSM_IDLE   `OR1200_EXCEPTFSM_WIDTH'd0
122
`define OR1200_EXCEPTFSM_FLU1   `OR1200_EXCEPTFSM_WIDTH'd1
123
`define OR1200_EXCEPTFSM_FLU2   `OR1200_EXCEPTFSM_WIDTH'd2
124
`define OR1200_EXCEPTFSM_FLU3   `OR1200_EXCEPTFSM_WIDTH'd3
125
`define OR1200_EXCEPTFSM_FLU4   `OR1200_EXCEPTFSM_WIDTH'd4
126
`define OR1200_EXCEPTFSM_FLU5   `OR1200_EXCEPTFSM_WIDTH'd5
127
 
128
//
129
// Exception recognition and sequencing
130
//
131
 
132
module or1200_except(
133
        // Clock and reset
134
        clk, rst,
135
 
136
        // Internal i/f
137
        sig_ibuserr, sig_dbuserr, sig_illegal, sig_align, sig_range, sig_dtlbmiss, sig_dmmufault,
138 589 lampret
        sig_int, sig_syscall, sig_trap, sig_itlbmiss, sig_immufault, sig_tick,
139 895 lampret
        branch_taken, genpc_freeze, id_freeze, ex_freeze, wb_freeze, if_stall,
140 504 lampret
        if_pc, lr_sav, flushpipe, extend_flush, except_type, except_start,
141 595 lampret
        except_started, except_stop, ex_void,
142 589 lampret
        spr_dat_ppc, spr_dat_npc, datain, du_dsr, epcr_we, eear_we, esr_we, pc_we, epcr, eear,
143 895 lampret
        esr, sr, lsu_addr, abort_ex, icpu_ack_i, icpu_err_i, dcpu_ack_i, dcpu_err_i
144 504 lampret
);
145
 
146
//
147
// I/O
148
//
149
input                           clk;
150
input                           rst;
151
input                           sig_ibuserr;
152
input                           sig_dbuserr;
153
input                           sig_illegal;
154
input                           sig_align;
155
input                           sig_range;
156
input                           sig_dtlbmiss;
157
input                           sig_dmmufault;
158 589 lampret
input                           sig_int;
159 504 lampret
input                           sig_syscall;
160
input                           sig_trap;
161
input                           sig_itlbmiss;
162
input                           sig_immufault;
163 589 lampret
input                           sig_tick;
164 504 lampret
input                           branch_taken;
165 895 lampret
input                           genpc_freeze;
166 504 lampret
input                           id_freeze;
167
input                           ex_freeze;
168
input                           wb_freeze;
169
input                           if_stall;
170
input   [31:0]                   if_pc;
171
output  [31:2]                  lr_sav;
172
input   [31:0]                   datain;
173
input   [`OR1200_DU_DSR_WIDTH-1:0]     du_dsr;
174
input                           epcr_we;
175
input                           eear_we;
176
input                           esr_we;
177
input                           pc_we;
178
output  [31:0]                   epcr;
179
output  [31:0]                   eear;
180
output  [`OR1200_SR_WIDTH-1:0]           esr;
181
input   [`OR1200_SR_WIDTH-1:0]           sr;
182
input   [31:0]                   lsu_addr;
183
output                          flushpipe;
184
output                          extend_flush;
185
output  [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
186
output                          except_start;
187
output                          except_started;
188
output  [12:0]                   except_stop;
189 595 lampret
input                           ex_void;
190 589 lampret
output  [31:0]                   spr_dat_ppc;
191
output  [31:0]                   spr_dat_npc;
192 617 lampret
output                          abort_ex;
193 895 lampret
input                           icpu_ack_i;
194
input                           icpu_err_i;
195
input                           dcpu_ack_i;
196
input                           dcpu_err_i;
197 504 lampret
 
198
//
199
// Internal regs and wires
200
//
201
reg     [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
202
reg     [31:0]                   id_pc;
203
reg     [31:0]                   ex_pc;
204
reg     [31:0]                   wb_pc;
205
reg     [31:0]                   epcr;
206
reg     [31:0]                   eear;
207
reg     [`OR1200_SR_WIDTH-1:0]           esr;
208 589 lampret
reg     [2:0]                    id_exceptflags;
209
reg     [2:0]                    ex_exceptflags;
210 504 lampret
reg     [`OR1200_EXCEPTFSM_WIDTH-1:0]    state;
211
reg                             extend_flush;
212
reg                             extend_flush_last;
213
reg                             ex_dslot;
214
reg                             delayed1_ex_dslot;
215
reg                             delayed2_ex_dslot;
216
wire                            except_started;
217
wire    [12:0]                   except_trig;
218
wire                            except_flushpipe;
219 589 lampret
reg     [2:0]                    delayed_iee;
220
reg     [2:0]                    delayed_tee;
221
wire                            int_pending;
222
wire                            tick_pending;
223 504 lampret
 
224
//
225
// Simple combinatorial logic
226
//
227
assign except_started = extend_flush & except_start;
228
assign lr_sav = ex_pc[31:2];
229 589 lampret
assign spr_dat_ppc = wb_pc;
230 595 lampret
assign spr_dat_npc = ex_void ? id_pc : ex_pc;
231 562 lampret
//assign except_start = (except_type != `OR1200_EXCEPT_NONE);  // damjan
232
assign except_start = (except_type != `OR1200_EXCEPT_NONE) & extend_flush;
233 589 lampret
assign int_pending = sig_int & sr[`OR1200_SR_IEE] & delayed_iee[2] & ~ex_freeze & ~branch_taken & ~ex_dslot;
234 617 lampret
//assign tick_pending = sig_tick & sr[`OR1200_SR_TEE] & delayed_tee[2] & ~ex_freeze & ~branch_taken & ~ex_dslot; // works with uclinux. except_test fails
235
//assign tick_pending = sig_tick & sr[`OR1200_SR_TEE] & ~ex_freeze & ~branch_taken & ~ex_dslot; // works with uclinux, except_tets almost works (priority fails)
236 610 lampret
assign tick_pending = sig_tick & sr[`OR1200_SR_TEE] & ~ex_freeze & ~branch_taken & ~ex_dslot;
237 617 lampret
assign abort_ex = sig_dbuserr | sig_dmmufault | sig_dtlbmiss | sig_align | sig_illegal;         // Abort write into RF by load & other instructions
238 504 lampret
 
239
//
240
// Order defines exception detection priority
241
//
242
assign except_trig = {
243 617 lampret
                        tick_pending            & ~du_dsr[`OR1200_DU_DSR_TTE],
244 589 lampret
                        int_pending             & ~du_dsr[`OR1200_DU_DSR_IE],
245
                        ex_exceptflags[1]       & ~du_dsr[`OR1200_DU_DSR_IME],
246
                        ex_exceptflags[0]        & ~du_dsr[`OR1200_DU_DSR_IPFE],
247
                        ex_exceptflags[2]       & ~du_dsr[`OR1200_DU_DSR_BUSEE],
248 504 lampret
                        sig_illegal             & ~du_dsr[`OR1200_DU_DSR_IIE],
249
                        sig_align               & ~du_dsr[`OR1200_DU_DSR_AE],
250
                        sig_dtlbmiss            & ~du_dsr[`OR1200_DU_DSR_DME],
251
                        sig_dmmufault           & ~du_dsr[`OR1200_DU_DSR_DPFE],
252
                        sig_dbuserr             & ~du_dsr[`OR1200_DU_DSR_BUSEE],
253 570 lampret
                        sig_range               & ~du_dsr[`OR1200_DU_DSR_RE],
254 562 lampret
                        sig_trap                & ~du_dsr[`OR1200_DU_DSR_TE] & ~ex_freeze,
255 570 lampret
                        sig_syscall             & ~du_dsr[`OR1200_DU_DSR_SCE] & ~ex_freeze
256 504 lampret
                };
257
assign except_stop = {
258 617 lampret
                        tick_pending            & du_dsr[`OR1200_DU_DSR_TTE],
259 589 lampret
                        int_pending             & du_dsr[`OR1200_DU_DSR_IE],
260
                        ex_exceptflags[1]       & du_dsr[`OR1200_DU_DSR_IME],
261
                        ex_exceptflags[0]        & du_dsr[`OR1200_DU_DSR_IPFE],
262
                        ex_exceptflags[2]       & du_dsr[`OR1200_DU_DSR_BUSEE],
263 504 lampret
                        sig_illegal             & du_dsr[`OR1200_DU_DSR_IIE],
264
                        sig_align               & du_dsr[`OR1200_DU_DSR_AE],
265
                        sig_dtlbmiss            & du_dsr[`OR1200_DU_DSR_DME],
266
                        sig_dmmufault           & du_dsr[`OR1200_DU_DSR_DPFE],
267
                        sig_dbuserr             & du_dsr[`OR1200_DU_DSR_BUSEE],
268 570 lampret
                        sig_range               & du_dsr[`OR1200_DU_DSR_RE],
269 562 lampret
                        sig_trap                & du_dsr[`OR1200_DU_DSR_TE] & ~ex_freeze,
270 570 lampret
                        sig_syscall             & du_dsr[`OR1200_DU_DSR_SCE] & ~ex_freeze
271 504 lampret
                };
272
 
273
//
274
// PC and Exception flags pipelines
275
//
276
always @(posedge clk or posedge rst) begin
277
        if (rst) begin
278
                id_pc <= #1 32'd0;
279 589 lampret
                id_exceptflags <= #1 3'b000;
280 504 lampret
        end
281 562 lampret
        else if (flushpipe) begin
282
                id_pc <= #1 32'h0000_0000;
283 589 lampret
                id_exceptflags <= #1 3'b000;
284 562 lampret
        end
285 504 lampret
        else if (!id_freeze) begin
286
                id_pc <= #1 if_pc;
287 589 lampret
                id_exceptflags <= #1 { sig_ibuserr, sig_itlbmiss, sig_immufault };
288 504 lampret
        end
289
end
290
 
291
//
292 589 lampret
// delayed_iee
293 504 lampret
//
294 589 lampret
// SR[IEE] should not enable interrupts right away
295
// when it is restored with l.rfe. Instead delayed_iee
296
// together with SR[IEE] enables interrupts once
297 504 lampret
// pipeline is again ready.
298
//
299
always @(posedge rst or posedge clk)
300
        if (rst)
301 589 lampret
                delayed_iee <= #1 3'b000;
302
        else if (!sr[`OR1200_SR_IEE])
303
                delayed_iee <= #1 3'b000;
304 504 lampret
        else
305 589 lampret
                delayed_iee <= #1 {delayed_iee[1:0], 1'b1};
306 504 lampret
 
307
//
308 589 lampret
// delayed_tee
309
//
310
// SR[TEE] should not enable tick exceptions right away
311
// when it is restored with l.rfe. Instead delayed_tee
312
// together with SR[TEE] enables tick exceptions once
313
// pipeline is again ready.
314
//
315
always @(posedge rst or posedge clk)
316
        if (rst)
317
                delayed_tee <= #1 3'b000;
318
        else if (!sr[`OR1200_SR_TEE])
319
                delayed_tee <= #1 3'b000;
320
        else
321
                delayed_tee <= #1 {delayed_tee[1:0], 1'b1};
322
 
323
//
324 504 lampret
// PC and Exception flags pipelines
325
//
326
always @(posedge clk or posedge rst) begin
327
        if (rst) begin
328
                ex_dslot <= #1 1'b0;
329
                ex_pc <= #1 32'd0;
330 589 lampret
                ex_exceptflags <= #1 3'b000;
331 504 lampret
                delayed1_ex_dslot <= #1 1'b0;
332
                delayed2_ex_dslot <= #1 1'b0;
333
        end
334 562 lampret
        else if (flushpipe) begin
335
                ex_dslot <= #1 1'b0;
336
                ex_pc <= #1 32'h0000_0000;
337 589 lampret
                ex_exceptflags <= #1 3'b000;
338 562 lampret
                delayed1_ex_dslot <= #1 1'b0;
339
                delayed2_ex_dslot <= #1 1'b0;
340
        end
341 504 lampret
        else if (!ex_freeze & id_freeze) begin
342
                ex_dslot <= #1 1'b0;
343
                ex_pc <= #1 id_pc;
344 589 lampret
                ex_exceptflags <= #1 3'b000;
345 504 lampret
                delayed1_ex_dslot <= #1 ex_dslot;
346
                delayed2_ex_dslot <= #1 delayed1_ex_dslot;
347
        end
348
        else if (!ex_freeze) begin
349
`ifdef OR1200_VERBOSE
350
// synopsys translate_off
351
                $display("%t: ex_pc <= %h", $time, id_pc);
352
// synopsys translate_on
353
`endif
354
                ex_dslot <= #1 branch_taken;
355
                ex_pc <= #1 id_pc;
356
                ex_exceptflags <= #1 id_exceptflags;
357
                delayed1_ex_dslot <= #1 ex_dslot;
358
                delayed2_ex_dslot <= #1 delayed1_ex_dslot;
359
        end
360
end
361
 
362
//
363
// PC and Exception flags pipelines
364
//
365
always @(posedge clk or posedge rst) begin
366
        if (rst) begin
367
                wb_pc <= #1 32'd0;
368
        end
369
        else if (!wb_freeze) begin
370
                wb_pc <= #1 ex_pc;
371
        end
372
end
373
 
374
//
375
// Flush pipeline
376
//
377 562 lampret
assign flushpipe = except_flushpipe | pc_we | extend_flush;
378 504 lampret
 
379
//
380
// We have started execution of exception handler:
381
//  1. Asserted for 3 clock cycles
382
//  2. Don't execute any instruction that is still in pipeline and is not part of exception handler
383
//
384 562 lampret
assign except_flushpipe = |except_trig & !state;
385 504 lampret
 
386
//
387
// Exception FSM that sequences execution of exception handler
388
//
389
// except_type signals which exception handler we start fetching in:
390
//  1. Asserted in next clock cycle after exception is recognized
391
//
392
always @(posedge clk or posedge rst) begin
393
        if (rst) begin
394
                state <= #1 `OR1200_EXCEPTFSM_IDLE;
395
                except_type <= #1 `OR1200_EXCEPT_NONE;
396
                extend_flush <= #1 1'b0;
397
                epcr <= #1 32'b0;
398
                eear <= #1 32'b0;
399 660 lampret
                esr <= #1 {1'b1, {`OR1200_SR_WIDTH-2{1'b0}}, 1'b1};
400 504 lampret
                extend_flush_last <= #1 1'b0;
401
        end
402
        else begin
403
                case (state)    // synopsys full_case parallel_case
404
                        `OR1200_EXCEPTFSM_IDLE:
405
                                if (except_flushpipe) begin
406
                                        state <= #1 `OR1200_EXCEPTFSM_FLU1;
407
                                        extend_flush <= #1 1'b1;
408
                                        if (ex_dslot) begin
409
`ifdef OR1200_VERBOSE
410
// synopsys translate_off
411
                                                $display(" INFO: Exception during first delay slot instruction.");
412
// synopsys translate_on
413
`endif
414
                                        end
415
                                        else if (delayed1_ex_dslot) begin
416
`ifdef OR1200_VERBOSE
417
// synopsys translate_off
418
                                                $display(" INFO: Exception during second (NOP) delay slot instruction.");
419
// synopsys translate_on
420
`endif
421
                                        end
422
                                        else if (delayed2_ex_dslot) begin
423
`ifdef OR1200_VERBOSE
424
// synopsys translate_off
425
                                                $display(" INFO: Exception during third delay slot (SHOULD NOT HAPPEN).");
426
// synopsys translate_on
427
`endif
428
                                        end
429
                                        else begin
430
`ifdef OR1200_VERBOSE
431
// synopsys translate_off
432
                                                $display(" INFO: Exception during normal (no delay slot) instruction.");
433
// synopsys translate_on
434
`endif
435
                                        end
436
 
437
                                        esr <= #1 sr;
438
                                        casex (except_trig)
439
                                                13'b1_xxxx_xxxx_xxxx: begin
440 617 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_TICK;
441 504 lampret
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
442
                                                end
443
                                                13'b0_1xxx_xxxx_xxxx: begin
444 617 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_INT;
445 504 lampret
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
446
                                                end
447
                                                13'b0_01xx_xxxx_xxxx: begin
448 617 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_ITLBMISS;
449 977 lampret
//
450
// itlb miss exception and active ex_dslot caused wb_pc to put into eear instead of +4 address of ex_pc (or id_pc since it was equal to ex_pc?)
451
//                                                      eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
452
                                                        eear <= #1 ex_dslot ? ex_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
453 504 lampret
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
454
                                                end
455
                                                13'b0_001x_xxxx_xxxx: begin
456 617 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_IPF;
457 977 lampret
//
458
// ipf exception and active ex_dslot caused wb_pc to put into eear instead of +4 address of ex_pc (or id_pc since it was equal to ex_pc?)
459
//                                                      eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
460
                                                        eear <= #1 ex_dslot ? ex_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
461 504 lampret
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
462
                                                end
463
                                                13'b0_0001_xxxx_xxxx: begin
464 617 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_BUSERR;
465
                                                        eear <= #1 ex_dslot ? wb_pc : ex_pc;
466
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
467
                                                end
468
                                                13'b0_0000_1xxx_xxxx: begin
469 504 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_ILLEGAL;
470 610 lampret
                                                        eear <= #1 ex_pc;
471
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
472 504 lampret
                                                end
473 617 lampret
                                                13'b0_0000_01xx_xxxx: begin
474 504 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_ALIGN;
475
                                                        eear <= #1 lsu_addr;
476 571 lampret
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
477 504 lampret
                                                end
478 617 lampret
                                                13'b0_0000_001x_xxxx: begin
479 504 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_DTLBMISS;
480
                                                        eear <= #1 lsu_addr;
481
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
482
                                                end
483 617 lampret
                                                13'b0_0000_0001_xxxx: begin
484 504 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_DPF;
485
                                                        eear <= #1 lsu_addr;
486
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
487
                                                end
488 617 lampret
                                                13'b0_0000_0000_1xxx: begin     // Data Bus Error
489 504 lampret
                                                        except_type <= #1 `OR1200_EXCEPT_BUSERR;
490
                                                        eear <= #1 lsu_addr;
491 562 lampret
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
492 504 lampret
                                                end
493
                                                13'b0_0000_0000_01xx: begin
494
                                                        except_type <= #1 `OR1200_EXCEPT_RANGE;
495
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
496
                                                end
497
                                                13'b0_0000_0000_001x: begin
498
                                                        except_type <= #1 `OR1200_EXCEPT_TRAP;
499 610 lampret
                                                        epcr <= #1 ex_dslot ? wb_pc : ex_pc;
500 504 lampret
                                                end
501
                                                13'b0_0000_0000_0001: begin
502
                                                        except_type <= #1 `OR1200_EXCEPT_SYSCALL;
503
                                                        epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
504
                                                end
505
                                                default:
506
                                                        except_type <= #1 `OR1200_EXCEPT_NONE;
507
                                        endcase
508
                                end
509
                                else if (pc_we) begin
510
                                        state <= #1 `OR1200_EXCEPTFSM_FLU1;
511
                                        extend_flush <= #1 1'b1;
512
                                end
513
                                else begin
514
                                        if (epcr_we)
515
                                                epcr <= #1 datain;
516
                                        if (eear_we)
517
                                                eear <= #1 datain;
518
                                        if (esr_we)
519 589 lampret
                                                esr <= #1 {1'b1, datain[`OR1200_SR_WIDTH-2:0]};
520 504 lampret
                                end
521
                        `OR1200_EXCEPTFSM_FLU1:
522 895 lampret
                                if (icpu_ack_i | icpu_err_i | genpc_freeze)
523
//                              if (!if_stall | genpc_freeze)
524 504 lampret
                                        state <= #1 `OR1200_EXCEPTFSM_FLU2;
525
                        `OR1200_EXCEPTFSM_FLU2:
526
                                if (except_type == `OR1200_EXCEPT_TRAP) begin
527
                                        state <= #1 `OR1200_EXCEPTFSM_IDLE;
528
                                        extend_flush <= #1 1'b0;
529
                                        extend_flush_last <= #1 1'b0;
530
                                        except_type <= #1 `OR1200_EXCEPT_NONE;
531
                                end
532 562 lampret
                                else
533
//                              if (!if_stall & !id_freeze)
534 504 lampret
                                        state <= #1 `OR1200_EXCEPTFSM_FLU3;
535
                        `OR1200_EXCEPTFSM_FLU3:
536 562 lampret
//                              if (!if_stall && !id_freeze)
537 504 lampret
                                        begin
538
`ifdef OR1200_VERBOSE
539
// synopsys translate_off
540
                                                if (except_flushpipe)
541
                                                        $display(" INFO: EPCR0 %h  EEAR %h  ESR %h", epcr, eear, esr);
542
// synopsys translate_on
543
`endif
544
                                                state <= #1 `OR1200_EXCEPTFSM_FLU4;
545
                                        end
546
                        `OR1200_EXCEPTFSM_FLU4: begin
547 562 lampret
                                        state <= #1 `OR1200_EXCEPTFSM_FLU5;
548
                                        extend_flush <= #1 1'b0;
549
                                        extend_flush_last <= #1 1'b0; // damjan
550
                                end
551 504 lampret
                        `OR1200_EXCEPTFSM_FLU5: begin
552 562 lampret
                                if (!if_stall && !id_freeze) begin
553 504 lampret
`ifdef OR1200_VERBOSE
554
// synopsys translate_off
555
                                $display(" INFO: Just finished flushing pipeline.");
556
// synopsys translate_on
557
`endif
558
                                state <= #1 `OR1200_EXCEPTFSM_IDLE;
559
                                except_type <= #1 `OR1200_EXCEPT_NONE;
560
                                extend_flush_last <= #1 1'b0;
561
                        end
562 562 lampret
                        end
563 504 lampret
                endcase
564
        end
565
end
566
 
567
endmodule

powered by: WebSVN 2.1.0

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