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