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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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