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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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