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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_except.v] - Blame information for rev 1267

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

powered by: WebSVN 2.1.0

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