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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [or1200/] [rtl/] [verilog/] [or1200_except.v] - Blame information for rev 12

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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