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