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

Subversion Repositories or1200_hp

[/] [or1200_hp/] [trunk/] [rtl/] [rtl_cm3/] [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_cm3(
154
                clk_i_cml_1,
155
                clk_i_cml_2,
156
 
157
        // Clock and reset
158
        clk, rst,
159
 
160
        // Internal i/f
161
        sig_ibuserr, sig_dbuserr, sig_illegal, sig_align, sig_range, sig_dtlbmiss, sig_dmmufault,
162
        sig_int, sig_syscall, sig_trap, sig_itlbmiss, sig_immufault, sig_tick,
163
        branch_taken, genpc_freeze, id_freeze, ex_freeze, wb_freeze, if_stall,
164
        if_pc, id_pc, lr_sav, flushpipe, extend_flush, except_type, except_start,
165
        except_started, except_stop, ex_void,
166
        spr_dat_ppc, spr_dat_npc, datain, du_dsr, epcr_we, eear_we, esr_we, pc_we, epcr, eear,
167
        esr, sr_we, to_sr, sr, lsu_addr, abort_ex, icpu_ack_i, icpu_err_i, dcpu_ack_i, dcpu_err_i
168
);
169
 
170
 
171
input clk_i_cml_1;
172
input clk_i_cml_2;
173
reg  sig_dbuserr_cml_2;
174
reg  sig_illegal_cml_2;
175
reg  sig_illegal_cml_1;
176
reg  sig_align_cml_2;
177
reg  sig_align_cml_1;
178
reg  sig_dtlbmiss_cml_2;
179
reg  sig_dmmufault_cml_2;
180
reg  sig_syscall_cml_2;
181
reg  sig_syscall_cml_1;
182
reg  sig_trap_cml_2;
183
reg  sig_trap_cml_1;
184
reg  branch_taken_cml_2;
185
reg  branch_taken_cml_1;
186
reg  ex_freeze_cml_2;
187
reg  wb_freeze_cml_2;
188
reg  if_stall_cml_2;
189
reg [ 31 : 0 ] id_pc_cml_2;
190
reg [ 31 : 0 ] id_pc_cml_1;
191
reg [ 31 : 0 ] datain_cml_2;
192
reg [ 31 : 0 ] datain_cml_1;
193
reg  pc_we_cml_2;
194
reg  pc_we_cml_1;
195
reg [ 31 : 0 ] epcr_cml_2;
196
reg [ 31 : 0 ] epcr_cml_1;
197
reg [ 31 : 0 ] eear_cml_2;
198
reg [ 31 : 0 ] eear_cml_1;
199
reg [ 16 - 1 : 0 ] esr_cml_2;
200
reg [ 16 - 1 : 0 ] esr_cml_1;
201
reg  sr_we_cml_2;
202
reg [ 16 - 1 : 0 ] sr_cml_2;
203
reg [ 16 - 1 : 0 ] sr_cml_1;
204
reg [ 31 : 0 ] lsu_addr_cml_2;
205
reg [ 31 : 0 ] lsu_addr_cml_1;
206
reg  extend_flush_cml_2;
207
reg  extend_flush_cml_1;
208
reg [ 4 - 1 : 0 ] except_type_cml_2;
209
reg [ 4 - 1 : 0 ] except_type_cml_1;
210
reg  except_start_cml_2;
211
reg  except_start_cml_1;
212
reg  icpu_ack_i_cml_2;
213
reg  icpu_ack_i_cml_1;
214
reg  icpu_err_i_cml_2;
215
reg [ 31 : 0 ] ex_pc_cml_2;
216
reg [ 31 : 0 ] ex_pc_cml_1;
217
reg [ 31 : 0 ] wb_pc_cml_2;
218
reg [ 31 : 0 ] wb_pc_cml_1;
219
reg [ 2 : 0 ] id_exceptflags_cml_2;
220
reg [ 2 : 0 ] id_exceptflags_cml_1;
221
reg [ 2 : 0 ] ex_exceptflags_cml_2;
222
reg [ 2 : 0 ] ex_exceptflags_cml_1;
223
reg [ 3 - 1 : 0 ] state_cml_2;
224
reg [ 3 - 1 : 0 ] state_cml_1;
225
reg  extend_flush_last_cml_2;
226
reg  extend_flush_last_cml_1;
227
reg  ex_dslot_cml_2;
228
reg  ex_dslot_cml_1;
229
reg  delayed1_ex_dslot_cml_2;
230
reg  delayed1_ex_dslot_cml_1;
231
reg  delayed2_ex_dslot_cml_2;
232
reg  delayed2_ex_dslot_cml_1;
233
reg [ 2 : 0 ] delayed_iee_cml_2;
234
reg [ 2 : 0 ] delayed_iee_cml_1;
235
reg [ 2 : 0 ] delayed_tee_cml_2;
236
reg [ 2 : 0 ] delayed_tee_cml_1;
237
reg  int_pending_cml_2;
238
reg  tick_pending_cml_2;
239
 
240
 
241
 
242
//
243
// I/O
244
//
245
input                           clk;
246
input                           rst;
247
input                           sig_ibuserr;
248
input                           sig_dbuserr;
249
input                           sig_illegal;
250
input                           sig_align;
251
input                           sig_range;
252
input                           sig_dtlbmiss;
253
input                           sig_dmmufault;
254
input                           sig_int;
255
input                           sig_syscall;
256
input                           sig_trap;
257
input                           sig_itlbmiss;
258
input                           sig_immufault;
259
input                           sig_tick;
260
input                           branch_taken;
261
input                           genpc_freeze;
262
input                           id_freeze;
263
input                           ex_freeze;
264
input                           wb_freeze;
265
input                           if_stall;
266
input   [31:0]                   if_pc;
267
output  [31:0]                   id_pc;
268
output  [31:2]                  lr_sav;
269
input   [31:0]                   datain;
270
input   [`OR1200_DU_DSR_WIDTH-1:0]     du_dsr;
271
input                           epcr_we;
272
input                           eear_we;
273
input                           esr_we;
274
input                           pc_we;
275
output  [31:0]                   epcr;
276
output  [31:0]                   eear;
277
output  [`OR1200_SR_WIDTH-1:0]   esr;
278
input   [`OR1200_SR_WIDTH-1:0]   to_sr;
279
input                           sr_we;
280
input   [`OR1200_SR_WIDTH-1:0]   sr;
281
input   [31:0]                   lsu_addr;
282
output                          flushpipe;
283
output                          extend_flush;
284
output  [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
285
output                          except_start;
286
output                          except_started;
287
output  [12:0]                   except_stop;
288
input                           ex_void;
289
output  [31:0]                   spr_dat_ppc;
290
output  [31:0]                   spr_dat_npc;
291
output                          abort_ex;
292
input                           icpu_ack_i;
293
input                           icpu_err_i;
294
input                           dcpu_ack_i;
295
input                           dcpu_err_i;
296
 
297
//
298
// Internal regs and wires
299
//
300
reg     [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
301
reg     [31:0]                   id_pc;
302
reg     [31:0]                   ex_pc;
303
reg     [31:0]                   wb_pc;
304
reg     [31:0]                   epcr;
305
reg     [31:0]                   eear;
306
reg     [`OR1200_SR_WIDTH-1:0]           esr;
307
reg     [2:0]                    id_exceptflags;
308
reg     [2:0]                    ex_exceptflags;
309
reg     [`OR1200_EXCEPTFSM_WIDTH-1:0]    state;
310
reg                             extend_flush;
311
reg                             extend_flush_last;
312
reg                             ex_dslot;
313
reg                             delayed1_ex_dslot;
314
reg                             delayed2_ex_dslot;
315
wire                            except_started;
316
wire    [12:0]                   except_trig;
317
wire                            except_flushpipe;
318
reg     [2:0]                    delayed_iee;
319
reg     [2:0]                    delayed_tee;
320
wire                            int_pending;
321
wire                            tick_pending;
322
 
323
//
324
// Simple combinatorial logic
325
//
326
 
327
// SynEDA CoreMultiplier
328
// assignment(s): except_started
329
// replace(s): extend_flush, except_start
330
assign except_started = extend_flush_cml_2 & except_start_cml_2;
331
assign lr_sav = ex_pc[31:2];
332
 
333
// SynEDA CoreMultiplier
334
// assignment(s): spr_dat_ppc
335
// replace(s): wb_pc
336
assign spr_dat_ppc = wb_pc_cml_1;
337
 
338
// SynEDA CoreMultiplier
339
// assignment(s): spr_dat_npc
340
// replace(s): id_pc, ex_pc
341
assign spr_dat_npc = ex_void ? id_pc_cml_1 : ex_pc_cml_1;
342
assign except_start = (except_type != `OR1200_EXCEPT_NONE) & extend_flush;
343
 
344
// SynEDA CoreMultiplier
345
// assignment(s): int_pending
346
// replace(s): branch_taken, sr, ex_dslot, delayed_iee
347
assign int_pending = sig_int & sr_cml_1[`OR1200_SR_IEE] & delayed_iee_cml_1[2] & ~ex_freeze & ~branch_taken_cml_1 & ~ex_dslot_cml_1 & ~sr_we;
348
 
349
// SynEDA CoreMultiplier
350
// assignment(s): tick_pending
351
// replace(s): branch_taken, sr, ex_dslot
352
assign tick_pending = sig_tick & sr_cml_1[`OR1200_SR_TEE] & ~ex_freeze & ~branch_taken_cml_1 & ~ex_dslot_cml_1 & ~sr_we;
353
 
354
// SynEDA CoreMultiplier
355
// assignment(s): abort_ex
356
// replace(s): sig_illegal, sig_align
357
assign abort_ex = sig_dbuserr | sig_dmmufault | sig_dtlbmiss | sig_align_cml_1 | sig_illegal_cml_1;             // Abort write into RF by load & other instructions
358
 
359
//
360
// Order defines exception detection priority
361
//
362
 
363
// SynEDA CoreMultiplier
364
// assignment(s): except_trig
365
// replace(s): sig_dbuserr, sig_illegal, sig_align, sig_dtlbmiss, sig_dmmufault, sig_syscall, sig_trap, ex_freeze, ex_exceptflags, int_pending, tick_pending
366
assign except_trig = {
367
                        tick_pending_cml_2              & ~du_dsr[`OR1200_DU_DSR_TTE],
368
                        int_pending_cml_2               & ~du_dsr[`OR1200_DU_DSR_IE],
369
                        ex_exceptflags_cml_2[1] & ~du_dsr[`OR1200_DU_DSR_IME],
370
                        ex_exceptflags_cml_2[0]  & ~du_dsr[`OR1200_DU_DSR_IPFE],
371
                        ex_exceptflags_cml_2[2] & ~du_dsr[`OR1200_DU_DSR_BUSEE],
372
                        sig_illegal_cml_2               & ~du_dsr[`OR1200_DU_DSR_IIE],
373
                        sig_align_cml_2         & ~du_dsr[`OR1200_DU_DSR_AE],
374
                        sig_dtlbmiss_cml_2              & ~du_dsr[`OR1200_DU_DSR_DME],
375
                        sig_dmmufault_cml_2             & ~du_dsr[`OR1200_DU_DSR_DPFE],
376
                        sig_dbuserr_cml_2               & ~du_dsr[`OR1200_DU_DSR_BUSEE],
377
                        sig_range               & ~du_dsr[`OR1200_DU_DSR_RE],
378
                        sig_trap_cml_2          & ~du_dsr[`OR1200_DU_DSR_TE] & ~ex_freeze_cml_2,
379
                        sig_syscall_cml_2               & ~du_dsr[`OR1200_DU_DSR_SCE] & ~ex_freeze_cml_2
380
                };
381
 
382
// SynEDA CoreMultiplier
383
// assignment(s): except_stop
384
// replace(s): sig_dbuserr, sig_illegal, sig_align, sig_dtlbmiss, sig_dmmufault, sig_syscall, sig_trap, ex_freeze, ex_exceptflags, int_pending, tick_pending
385
assign except_stop = {
386
                        tick_pending_cml_2              & du_dsr[`OR1200_DU_DSR_TTE],
387
                        int_pending_cml_2               & du_dsr[`OR1200_DU_DSR_IE],
388
                        ex_exceptflags_cml_2[1] & du_dsr[`OR1200_DU_DSR_IME],
389
                        ex_exceptflags_cml_2[0]  & du_dsr[`OR1200_DU_DSR_IPFE],
390
                        ex_exceptflags_cml_2[2] & du_dsr[`OR1200_DU_DSR_BUSEE],
391
                        sig_illegal_cml_2               & du_dsr[`OR1200_DU_DSR_IIE],
392
                        sig_align_cml_2         & du_dsr[`OR1200_DU_DSR_AE],
393
                        sig_dtlbmiss_cml_2              & du_dsr[`OR1200_DU_DSR_DME],
394
                        sig_dmmufault_cml_2             & du_dsr[`OR1200_DU_DSR_DPFE],
395
                        sig_dbuserr_cml_2               & du_dsr[`OR1200_DU_DSR_BUSEE],
396
                        sig_range               & du_dsr[`OR1200_DU_DSR_RE],
397
                        sig_trap_cml_2          & du_dsr[`OR1200_DU_DSR_TE] & ~ex_freeze_cml_2,
398
                        sig_syscall_cml_2               & du_dsr[`OR1200_DU_DSR_SCE] & ~ex_freeze_cml_2
399
                };
400
 
401
//
402
// PC and Exception flags pipelines
403
//
404
 
405
// SynEDA CoreMultiplier
406
// assignment(s): id_pc, id_exceptflags
407
// replace(s): id_pc, id_exceptflags
408
always @(posedge clk or posedge rst) begin
409
        if (rst) begin
410
                id_pc <= #1 32'd0;
411
                id_exceptflags <= #1 3'b000;
412
        end
413
        else begin  id_exceptflags <= id_exceptflags_cml_2; id_pc <= id_pc_cml_2; if (flushpipe) begin
414
                id_pc <= #1 32'h0000_0000;
415
                id_exceptflags <= #1 3'b000;
416
        end
417
        else if (!id_freeze) begin
418
                id_pc <= #1 if_pc;
419
                id_exceptflags <= #1 { sig_ibuserr, sig_itlbmiss, sig_immufault };
420
        end end
421
end
422
 
423
//
424
// delayed_iee
425
//
426
// SR[IEE] should not enable interrupts right away
427
// when it is restored with l.rfe. Instead delayed_iee
428
// together with SR[IEE] enables interrupts once
429
// pipeline is again ready.
430
//
431
 
432
// SynEDA CoreMultiplier
433
// assignment(s): delayed_iee
434
// replace(s): sr, delayed_iee
435
always @(posedge rst or posedge clk)
436
        if (rst)
437
                delayed_iee <= #1 3'b000;
438
        else begin  delayed_iee <= delayed_iee_cml_2; if (!sr_cml_2[`OR1200_SR_IEE])
439
                delayed_iee <= #1 3'b000;
440
        else
441
                delayed_iee <= #1 {delayed_iee_cml_2[1:0], 1'b1}; end
442
 
443
//
444
// delayed_tee
445
//
446
// SR[TEE] should not enable tick exceptions right away
447
// when it is restored with l.rfe. Instead delayed_tee
448
// together with SR[TEE] enables tick exceptions once
449
// pipeline is again ready.
450
//
451
 
452
// SynEDA CoreMultiplier
453
// assignment(s): delayed_tee
454
// replace(s): sr, delayed_tee
455
always @(posedge rst or posedge clk)
456
        if (rst)
457
                delayed_tee <= #1 3'b000;
458
        else begin  delayed_tee <= delayed_tee_cml_2; if (!sr_cml_2[`OR1200_SR_TEE])
459
                delayed_tee <= #1 3'b000;
460
        else
461
                delayed_tee <= #1 {delayed_tee_cml_2[1:0], 1'b1}; end
462
 
463
//
464
// PC and Exception flags pipelines
465
//
466
 
467
// SynEDA CoreMultiplier
468
// assignment(s): ex_pc, ex_exceptflags, ex_dslot, delayed1_ex_dslot, delayed2_ex_dslot
469
// replace(s): ex_freeze, id_pc, ex_pc, id_exceptflags, ex_exceptflags, branch_taken, ex_dslot, delayed1_ex_dslot, delayed2_ex_dslot
470
always @(posedge clk or posedge rst) begin
471
        if (rst) begin
472
                ex_dslot <= #1 1'b0;
473
                ex_pc <= #1 32'd0;
474
                ex_exceptflags <= #1 3'b000;
475
                delayed1_ex_dslot <= #1 1'b0;
476
                delayed2_ex_dslot <= #1 1'b0;
477
        end
478
        else begin  delayed2_ex_dslot <= delayed2_ex_dslot_cml_2; delayed1_ex_dslot <= delayed1_ex_dslot_cml_2; ex_dslot <= ex_dslot_cml_2; ex_exceptflags <= ex_exceptflags_cml_2; ex_pc <= ex_pc_cml_2; if (flushpipe) begin
479
                ex_dslot <= #1 1'b0;
480
                ex_pc <= #1 32'h0000_0000;
481
                ex_exceptflags <= #1 3'b000;
482
                delayed1_ex_dslot <= #1 1'b0;
483
                delayed2_ex_dslot <= #1 1'b0;
484
        end
485
        else if (!ex_freeze_cml_2 & id_freeze) begin
486
                ex_dslot <= #1 1'b0;
487
                ex_pc <= #1 id_pc_cml_2;
488
                ex_exceptflags <= #1 3'b000;
489
                delayed1_ex_dslot <= #1 ex_dslot_cml_2;
490
                delayed2_ex_dslot <= #1 delayed1_ex_dslot_cml_2;
491
        end
492
        else if (!ex_freeze_cml_2) begin
493
                ex_dslot <= #1 branch_taken_cml_2;
494
                ex_pc <= #1 id_pc_cml_2;
495
                ex_exceptflags <= #1 id_exceptflags_cml_2;
496
                delayed1_ex_dslot <= #1 ex_dslot_cml_2;
497
                delayed2_ex_dslot <= #1 delayed1_ex_dslot_cml_2;
498
        end end
499
end
500
 
501
//
502
// PC and Exception flags pipelines
503
//
504
 
505
// SynEDA CoreMultiplier
506
// assignment(s): wb_pc
507
// replace(s): wb_freeze, ex_pc, wb_pc
508
always @(posedge clk or posedge rst) begin
509
        if (rst) begin
510
                wb_pc <= #1 32'd0;
511
        end
512
        else begin  wb_pc <= wb_pc_cml_2; if (!wb_freeze_cml_2) begin
513
                wb_pc <= #1 ex_pc_cml_2;
514
        end end
515
end
516
 
517
//
518
// Flush pipeline
519
//
520
 
521
// SynEDA CoreMultiplier
522
// assignment(s): flushpipe
523
// replace(s): pc_we, extend_flush
524
assign flushpipe = except_flushpipe | pc_we_cml_2 | extend_flush_cml_2;
525
 
526
//
527
// We have started execution of exception handler:
528
//  1. Asserted for 3 clock cycles
529
//  2. Don't execute any instruction that is still in pipeline and is not part of exception handler
530
//
531
 
532
// SynEDA CoreMultiplier
533
// assignment(s): except_flushpipe
534
// replace(s): state
535
assign except_flushpipe = |except_trig & ~|state_cml_2;
536
 
537
//
538
// Exception FSM that sequences execution of exception handler
539
//
540
// except_type signals which exception handler we start fetching in:
541
//  1. Asserted in next clock cycle after exception is recognized
542
//
543
 
544
// SynEDA CoreMultiplier
545
// assignment(s): epcr, eear, esr, extend_flush, except_type, state, extend_flush_last
546
// 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, if_stall, icpu_ack_i, icpu_err_i, extend_flush_last
547
always @(posedge clk or posedge rst) begin
548
        if (rst) begin
549
                state <= #1 `OR1200_EXCEPTFSM_IDLE;
550
                except_type <= #1 `OR1200_EXCEPT_NONE;
551
                extend_flush <= #1 1'b0;
552
                epcr <= #1 32'b0;
553
                eear <= #1 32'b0;
554
                esr <= #1 {1'b1, {`OR1200_SR_WIDTH-2{1'b0}}, 1'b1};
555
                extend_flush_last <= #1 1'b0;
556
        end
557
        else begin begin  extend_flush_last <= extend_flush_last_cml_2; state <= state_cml_2; except_type <= except_type_cml_2; extend_flush <= extend_flush_cml_2; esr <= esr_cml_2; eear <= eear_cml_2; epcr <= epcr_cml_2;
558
`ifdef OR1200_CASE_DEFAULT
559
                case (state_cml_2)      // synopsys parallel_case
560
`else
561
                case (state_cml_2)      // synopsys full_case parallel_case
562
`endif
563
                        `OR1200_EXCEPTFSM_IDLE:
564
                                if (except_flushpipe) begin
565
                                        state <= #1 `OR1200_EXCEPTFSM_FLU1;
566
                                        extend_flush <= #1 1'b1;
567
                                        esr <= #1 sr_we_cml_2 ? to_sr : sr_cml_2;
568
                                        casex (except_trig)
569
`ifdef OR1200_EXCEPT_TICK
570
                                                13'b1_xxxx_xxxx_xxxx: begin
571
                                                        except_type <= #1 `OR1200_EXCEPT_TICK;
572
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : delayed1_ex_dslot_cml_2 ? id_pc_cml_2 : delayed2_ex_dslot_cml_2 ? id_pc_cml_2 : id_pc_cml_2;
573
                                                end
574
`endif
575
`ifdef OR1200_EXCEPT_INT
576
                                                13'b0_1xxx_xxxx_xxxx: begin
577
                                                        except_type <= #1 `OR1200_EXCEPT_INT;
578
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : delayed1_ex_dslot_cml_2 ? id_pc_cml_2 : delayed2_ex_dslot_cml_2 ? id_pc_cml_2 : id_pc_cml_2;
579
                                                end
580
`endif
581
`ifdef OR1200_EXCEPT_ITLBMISS
582
                                                13'b0_01xx_xxxx_xxxx: begin
583
                                                        except_type <= #1 `OR1200_EXCEPT_ITLBMISS;
584
//
585
// 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?)
586
//                                                      eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
587
//      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;
588
//      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;
589
                                                        eear <= #1 ex_dslot_cml_2 ? ex_pc_cml_2 : ex_pc_cml_2;
590
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
591
//                                                      eear <= #1 ex_dslot ? ex_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
592
//                                                      epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
593
                                                end
594
`endif
595
`ifdef OR1200_EXCEPT_IPF
596
                                                13'b0_001x_xxxx_xxxx: begin
597
                                                        except_type <= #1 `OR1200_EXCEPT_IPF;
598
//
599
// 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?)
600
//                                                      eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;
601
                                                        eear <= #1 ex_dslot_cml_2 ? ex_pc_cml_2 : delayed1_ex_dslot_cml_2 ? id_pc_cml_2 : delayed2_ex_dslot_cml_2 ? id_pc_cml_2 : id_pc_cml_2;
602
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : delayed1_ex_dslot_cml_2 ? id_pc_cml_2 : delayed2_ex_dslot_cml_2 ? id_pc_cml_2 : id_pc_cml_2;
603
                                                end
604
`endif
605
`ifdef OR1200_EXCEPT_BUSERR
606
                                                13'b0_0001_xxxx_xxxx: begin
607
                                                        except_type <= #1 `OR1200_EXCEPT_BUSERR;
608
                                                        eear <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
609
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
610
                                                end
611
`endif
612
`ifdef OR1200_EXCEPT_ILLEGAL
613
                                                13'b0_0000_1xxx_xxxx: begin
614
                                                        except_type <= #1 `OR1200_EXCEPT_ILLEGAL;
615
                                                        eear <= #1 ex_pc_cml_2;
616
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
617
                                                end
618
`endif
619
`ifdef OR1200_EXCEPT_ALIGN
620
                                                13'b0_0000_01xx_xxxx: begin
621
                                                        except_type <= #1 `OR1200_EXCEPT_ALIGN;
622
                                                        eear <= #1 lsu_addr_cml_2;
623
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
624
                                                end
625
`endif
626
`ifdef OR1200_EXCEPT_DTLBMISS
627
                                                13'b0_0000_001x_xxxx: begin
628
                                                        except_type <= #1 `OR1200_EXCEPT_DTLBMISS;
629
                                                        eear <= #1 lsu_addr_cml_2;
630
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
631
                                                end
632
`endif
633
`ifdef OR1200_EXCEPT_DPF
634
                                                13'b0_0000_0001_xxxx: begin
635
                                                        except_type <= #1 `OR1200_EXCEPT_DPF;
636
                                                        eear <= #1 lsu_addr_cml_2;
637
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
638
                                                end
639
`endif
640
`ifdef OR1200_EXCEPT_BUSERR
641
                                                13'b0_0000_0000_1xxx: begin     // Data Bus Error
642
                                                        except_type <= #1 `OR1200_EXCEPT_BUSERR;
643
                                                        eear <= #1 lsu_addr_cml_2;
644
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
645
                                                end
646
`endif
647
`ifdef OR1200_EXCEPT_RANGE
648
                                                13'b0_0000_0000_01xx: begin
649
                                                        except_type <= #1 `OR1200_EXCEPT_RANGE;
650
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : delayed1_ex_dslot_cml_2 ? id_pc_cml_2 : delayed2_ex_dslot_cml_2 ? id_pc_cml_2 : id_pc_cml_2;
651
                                                end
652
`endif
653
`ifdef OR1200_EXCEPT_TRAP                       13'b0_0000_0000_001x: begin
654
                                                        except_type <= #1 `OR1200_EXCEPT_TRAP;
655
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : ex_pc_cml_2;
656
                                                end
657
`endif
658
`ifdef OR1200_EXCEPT_SYSCALL
659
                                                13'b0_0000_0000_0001: begin
660
                                                        except_type <= #1 `OR1200_EXCEPT_SYSCALL;
661
                                                        epcr <= #1 ex_dslot_cml_2 ? wb_pc_cml_2 : delayed1_ex_dslot_cml_2 ? id_pc_cml_2 : delayed2_ex_dslot_cml_2 ? id_pc_cml_2 : id_pc_cml_2;
662
                                                end
663
`endif
664
                                                default:
665
                                                        except_type <= #1 `OR1200_EXCEPT_NONE;
666
                                        endcase
667
                                end
668
                                else if (pc_we_cml_2) begin
669
                                        state <= #1 `OR1200_EXCEPTFSM_FLU1;
670
                                        extend_flush <= #1 1'b1;
671
                                end
672
                                else begin
673
                                        if (epcr_we)
674
                                                epcr <= #1 datain_cml_2;
675
                                        if (eear_we)
676
                                                eear <= #1 datain_cml_2;
677
                                        if (esr_we)
678
                                                esr <= #1 {1'b1, datain_cml_2[`OR1200_SR_WIDTH-2:0]};
679
                                end
680
                        `OR1200_EXCEPTFSM_FLU1:
681
                                if (icpu_ack_i_cml_2 | icpu_err_i_cml_2 | genpc_freeze)
682
                                        state <= #1 `OR1200_EXCEPTFSM_FLU2;
683
                        `OR1200_EXCEPTFSM_FLU2:
684
`ifdef OR1200_EXCEPT_TRAP
685
                                if (except_type_cml_2 == `OR1200_EXCEPT_TRAP) begin
686
                                        state <= #1 `OR1200_EXCEPTFSM_IDLE;
687
                                        extend_flush <= #1 1'b0;
688
                                        extend_flush_last <= #1 1'b0;
689
                                        except_type <= #1 `OR1200_EXCEPT_NONE;
690
                                end
691
                                else
692
`endif
693
                                        state <= #1 `OR1200_EXCEPTFSM_FLU3;
694
                        `OR1200_EXCEPTFSM_FLU3:
695
                                        begin
696
                                                state <= #1 `OR1200_EXCEPTFSM_FLU4;
697
                                        end
698
                        `OR1200_EXCEPTFSM_FLU4: begin
699
                                        state <= #1 `OR1200_EXCEPTFSM_FLU5;
700
                                        extend_flush <= #1 1'b0;
701
                                        extend_flush_last <= #1 1'b0; // damjan
702
                                end
703
`ifdef OR1200_CASE_DEFAULT
704
                        default:
705
`else
706
                        `OR1200_EXCEPTFSM_FLU5:
707
`endif
708
                        begin   if (!if_stall_cml_2 && !id_freeze) begin
709
                                        state <= #1 `OR1200_EXCEPTFSM_IDLE;
710
                                        except_type <= #1 `OR1200_EXCEPT_NONE;
711
                                        extend_flush_last <= #1 1'b0;
712
                                end
713
                        end
714
                endcase
715
        end
716
end end
717
 
718
 
719
always @ (posedge clk_i_cml_1) begin
720
sig_illegal_cml_1 <= sig_illegal;
721
sig_align_cml_1 <= sig_align;
722
sig_syscall_cml_1 <= sig_syscall;
723
sig_trap_cml_1 <= sig_trap;
724
branch_taken_cml_1 <= branch_taken;
725
id_pc_cml_1 <= id_pc;
726
datain_cml_1 <= datain;
727
pc_we_cml_1 <= pc_we;
728
epcr_cml_1 <= epcr;
729
eear_cml_1 <= eear;
730
esr_cml_1 <= esr;
731
sr_cml_1 <= sr;
732
lsu_addr_cml_1 <= lsu_addr;
733
extend_flush_cml_1 <= extend_flush;
734
except_type_cml_1 <= except_type;
735
except_start_cml_1 <= except_start;
736
icpu_ack_i_cml_1 <= icpu_ack_i;
737
ex_pc_cml_1 <= ex_pc;
738
wb_pc_cml_1 <= wb_pc;
739
id_exceptflags_cml_1 <= id_exceptflags;
740
ex_exceptflags_cml_1 <= ex_exceptflags;
741
state_cml_1 <= state;
742
extend_flush_last_cml_1 <= extend_flush_last;
743
ex_dslot_cml_1 <= ex_dslot;
744
delayed1_ex_dslot_cml_1 <= delayed1_ex_dslot;
745
delayed2_ex_dslot_cml_1 <= delayed2_ex_dslot;
746
delayed_iee_cml_1 <= delayed_iee;
747
delayed_tee_cml_1 <= delayed_tee;
748
end
749
always @ (posedge clk_i_cml_2) begin
750
sig_dbuserr_cml_2 <= sig_dbuserr;
751
sig_illegal_cml_2 <= sig_illegal_cml_1;
752
sig_align_cml_2 <= sig_align_cml_1;
753
sig_dtlbmiss_cml_2 <= sig_dtlbmiss;
754
sig_dmmufault_cml_2 <= sig_dmmufault;
755
sig_syscall_cml_2 <= sig_syscall_cml_1;
756
sig_trap_cml_2 <= sig_trap_cml_1;
757
branch_taken_cml_2 <= branch_taken_cml_1;
758
ex_freeze_cml_2 <= ex_freeze;
759
wb_freeze_cml_2 <= wb_freeze;
760
if_stall_cml_2 <= if_stall;
761
id_pc_cml_2 <= id_pc_cml_1;
762
datain_cml_2 <= datain_cml_1;
763
pc_we_cml_2 <= pc_we_cml_1;
764
epcr_cml_2 <= epcr_cml_1;
765
eear_cml_2 <= eear_cml_1;
766
esr_cml_2 <= esr_cml_1;
767
sr_we_cml_2 <= sr_we;
768
sr_cml_2 <= sr_cml_1;
769
lsu_addr_cml_2 <= lsu_addr_cml_1;
770
extend_flush_cml_2 <= extend_flush_cml_1;
771
except_type_cml_2 <= except_type_cml_1;
772
except_start_cml_2 <= except_start_cml_1;
773
icpu_ack_i_cml_2 <= icpu_ack_i_cml_1;
774
icpu_err_i_cml_2 <= icpu_err_i;
775
ex_pc_cml_2 <= ex_pc_cml_1;
776
wb_pc_cml_2 <= wb_pc_cml_1;
777
id_exceptflags_cml_2 <= id_exceptflags_cml_1;
778
ex_exceptflags_cml_2 <= ex_exceptflags_cml_1;
779
state_cml_2 <= state_cml_1;
780
extend_flush_last_cml_2 <= extend_flush_last_cml_1;
781
ex_dslot_cml_2 <= ex_dslot_cml_1;
782
delayed1_ex_dslot_cml_2 <= delayed1_ex_dslot_cml_1;
783
delayed2_ex_dslot_cml_2 <= delayed2_ex_dslot_cml_1;
784
delayed_iee_cml_2 <= delayed_iee_cml_1;
785
delayed_tee_cml_2 <= delayed_tee_cml_1;
786
int_pending_cml_2 <= int_pending;
787
tick_pending_cml_2 <= tick_pending;
788
end
789
endmodule
790
 

powered by: WebSVN 2.1.0

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