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

Subversion Repositories or1200_hp

[/] [or1200_hp/] [trunk/] [rtl/] [rtl_cm2/] [verilog/] [or1200_except.v] - Blame information for rev 2

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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