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

Subversion Repositories or1200_hp

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

powered by: WebSVN 2.1.0

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