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

Subversion Repositories s1_core

[/] [s1_core/] [trunk/] [hdl/] [rtl/] [sparc_core/] [sparc_ifu_fcl.v] - Blame information for rev 113

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 95 fafa1971
// ========== Copyright Header Begin ==========================================
2
// 
3
// OpenSPARC T1 Processor File: sparc_ifu_fcl.v
4
// Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
5
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6
// 
7
// The above named program is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU General Public
9
// License version 2 as published by the Free Software Foundation.
10
// 
11
// The above named program is distributed in the hope that it will be 
12
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
// General Public License for more details.
15
// 
16
// You should have received a copy of the GNU General Public
17
// License along with this work; if not, write to the Free Software
18
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19
// 
20
// ========== Copyright Header End ============================================
21 113 albert.wat
`ifdef SIMPLY_RISC_TWEAKS
22
`define SIMPLY_RISC_SCANIN .si(0)
23
`else
24
`define SIMPLY_RISC_SCANIN .si()
25
`endif
26 95 fafa1971
//////////////////////////////////////////////////////////////////////
27
/*
28
//  Module Name: sparc_ifu_fcl
29
//  Description:
30
//  The FCL is the fetch control logic.  It controls the PC datapath
31
//  and the fetch/next instruction datapath.  It also manages access
32
//  to the icache data, tags, vbits and to the tlb.
33
//  The FCL starts fetching from the reset PC upon reset.  It is up to
34
//  the DTU to specify which thread to fetch from.  Only T0 is set to
35
//  the reset PC.  If the decode unit specifies any other thread, it
36
//  will fetch from an indeterminate address.
37
//  The fetch block automatically stalls the machine when an Imiss is
38
//  detected and there is no thread to switch to.
39
//
40
*/
41
////////////////////////////////////////////////////////////////////////
42
// Global header file includes
43
////////////////////////////////////////////////////////////////////////
44
 
45 113 albert.wat
`include "ifu.h"
46 95 fafa1971
 
47
 
48
module sparc_ifu_fcl(/*AUTOARG*/
49
   // Outputs
50
   fcl_icd_rdreq_bf, fcl_icv_rdreq_bf, fcl_icd_wrreq_bf,
51
   fcl_ict_wrreq_bf, fcl_icv_wrreq_bf, fcl_icd_index_sel_ifq_bf,
52
   fcl_ifq_grant_bf, fcl_ifq_icmiss_s1, fcl_ifq_rdreq_s1,
53
   fcl_ifq_icache_en_s_l, fcl_ifq_thr_s1, fcl_ifq_canthr,
54
   fcl_itlb_cam_vld_bf, fcl_itlb_cam_bypass_bf, fcl_itlb_addr_mask_l,
55
   fcl_itlb_cam_real_bf, fcl_itlb_cam_pid_bf, fcl_itlb_wr_vld_bf,
56
   fcl_itlb_dmp_vld_bf, fcl_itlb_dmp_all_bf, fcl_itlb_tag_rd_vld_bf,
57
   fcl_itlb_invall_f_l, fcl_itlb_data_rd_vld_bf, fcl_erb_ievld_s1,
58
   fcl_erb_tevld_s1, fcl_erb_immuevld_s1, ifu_lsu_thrid_s,
59
   fcl_erb_asi_tid_f, fcl_erb_clear_iferr, fcl_erb_itlbrd_vld_s,
60
   fcl_erb_itlbrd_data_s, fcl_dec_dslot_s, fcl_dtu_inst_vld_e,
61
   fcl_dtu_intr_vld_e, fcl_dtu_inst_vld_d, fcl_dtu_ely_inst_vld_d,
62
   fcl_dec_intr_vld_d, fcl_erb_inst_issue_d, fcl_erb_inst_vld_d1,
63
   ifu_tlu_inst_vld_m, ifu_exu_inst_vld_e, ifu_exu_inst_vld_w,
64
   ifu_spu_inst_vld_w, ifu_tlu_inst_vld_w, ifu_tlu_flush_w,
65
   ifu_tlu_flush_m, fcl_swl_int_activate_i3, fcl_swl_flush_wake_w,
66
   fcl_swl_flush_w, fcl_dcl_regz_e, ifu_tlu_thrid_e, ifu_tlu_thrid_d,
67
   ifu_tlu_immu_miss_m, ifu_tlu_priv_violtn_m, ifu_tlu_icmiss_e,
68
   ifu_tlu_ttype_vld_m, ifu_exu_ttype_vld_m, ifu_mmu_trap_m,
69
   ifu_tlu_trap_m, ifu_tlu_ttype_m, ifu_tlu_hwint_m,
70
   ifu_tlu_sftint_m, ifu_tlu_rstint_m, fcl_dtu_rst_thr_w,
71
   fcl_dtu_resum_thr_w, ifu_tlu_itlb_done, ifu_spu_trap_ack,
72
   ifu_exu_tid_s2, ifu_exu_ren1_s, ifu_exu_ren2_s, ifu_exu_ren3_s,
73
   ifu_exu_disable_ce_e, fcl_dtu_sync_intr_d, fcl_dtu_tlzero_d,
74
   fcl_dtu_privmode_d, fcl_dtu_hprivmode_d, fcl_dtu_hprivmode_w2,
75
   fcl_dtu_nuke_thr_w, fcl_swl_swout_f, fcl_dtu_stall_bf,
76
   fcl_swl_swcvld_s, fcl_dtu_thr_f, fcl_imd_oddwin_d,
77
   fcl_fdp_oddwin_s, fcl_fdp_pcoor_vec_f, fcl_fdp_pcoor_f,
78
   fcl_fdp_mask32b_f, fcl_fdp_addr_mask_d, fcl_fdp_tctxt_sel_prim,
79
   fcl_fdp_usenir_sel_nir_s1, fcl_fdp_rbinst_sel_inste_s,
80
   fcl_fdp_thrtnpc_sel_tnpc_l, fcl_fdp_thrtnpc_sel_npcw_l,
81
   fcl_fdp_thrtnpc_sel_pcf_l, fcl_fdp_thrtnpc_sel_old_l,
82
   fcl_fdp_thr_s1_l, fcl_fdp_next_thr_bf_l, fcl_fdp_next_ctxt_bf_l,
83
   fcl_fdp_nirthr_s1_l, fcl_fdp_thr_s2_l,
84
   fcl_fdp_tpcbf_sel_pcp4_bf_l, fcl_fdp_tpcbf_sel_brpc_bf_l,
85
   fcl_fdp_tpcbf_sel_trap_bf_l, fcl_fdp_tpcbf_sel_old_bf_l,
86
   fcl_fdp_pcbf_sel_nosw_bf_l, fcl_fdp_pcbf_sel_swpc_bf_l,
87
   fcl_fdp_pcbf_sel_br_bf_l, fcl_fdp_trrbpc_sel_trap_bf_l,
88
   fcl_fdp_trrbpc_sel_rb_bf_l, fcl_fdp_trrbpc_sel_err_bf_l,
89
   fcl_fdp_trrbpc_sel_pcs_bf_l, fcl_fdp_noswpc_sel_tnpc_l_bf,
90
   fcl_fdp_noswpc_sel_old_l_bf, fcl_fdp_noswpc_sel_inc_l_bf,
91
   fcl_fdp_nextpcs_sel_pce_f_l, fcl_fdp_nextpcs_sel_pcd_f_l,
92
   fcl_fdp_nextpcs_sel_pcs_f_l, fcl_fdp_nextpcs_sel_pcf_f_l,
93
   fcl_fdp_inst_sel_curr_s_l, fcl_fdp_inst_sel_switch_s_l,
94
   fcl_fdp_inst_sel_nir_s_l, fcl_fdp_inst_sel_nop_s_l,
95
   fcl_fdp_tinst_sel_curr_s_l, fcl_fdp_tinst_sel_rb_s_l,
96
   fcl_fdp_tinst_sel_old_s_l, fcl_fdp_tinst_sel_ifq_s_l,
97
   fcl_fdp_dmpthr_l, fcl_fdp_ctxt_sel_dmp_bf_l,
98
   fcl_fdp_ctxt_sel_sw_bf_l, fcl_fdp_ctxt_sel_curr_bf_l,
99
   fcl_fdp_rdsr_sel_pc_e_l, fcl_fdp_rdsr_sel_thr_e_l,
100
   fcl_fdp_rdsr_sel_ver_e_l, so, ifu_reset_l,
101
   // Inputs
102
   rclk, grst_l, arst_l, se, sehold, si, rst_tri_en,
103
   tlu_ifu_flush_pipe_w, exu_ifu_va_oor_m, exu_ifu_oddwin_s,
104
   spu_ifu_ttype_tid_w2, spu_ifu_ttype_vld_w2, spu_ifu_ttype_w2,
105
   erb_fcl_spu_uetrap, exu_ifu_regz_e, dcl_fcl_bcregz0_e,
106
   dcl_fcl_bcregz1_e, dtu_fcl_rollback_g, dtu_fcl_retract_d,
107
   dtu_fcl_br_inst_d, dtu_fcl_sir_inst_e, dtu_fcl_privop_e,
108
   dtu_fcl_fpdis_e, dtu_fcl_imask_hit_e, dtu_fcl_illinst_e,
109
   dtu_fcl_thr_active, dec_fcl_rdsr_sel_pc_d, dec_fcl_rdsr_sel_thr_d,
110
   ifq_fcl_wrreq_bf, ifq_fcl_icd_wrreq_bf, ifq_fcl_ictv_wrreq_bf,
111
   ifq_fcl_rdreq_bf, ifq_fcl_asi_tid_bf, ifq_fcl_asird_bf,
112
   ifq_fcl_invreq_bf, erb_fcl_itlb_ce_d1, erb_dtu_ifeterr_d1,
113
   erb_fcl_ifet_uevec_d1, erb_fcl_ue_trapvec, erb_fcl_ce_trapvec,
114
   dtu_fcl_nextthr_bf, dtu_fcl_ntr_s, dtu_fcl_running_s,
115
   dtu_fcl_flush_sonly_e, fdp_fcl_swc_s2, fdp_fcl_va2_bf,
116
   itlb_fcl_tlbmiss_f_l, itlb_fcl_priv_s1, itlb_fcl_cp_s1,
117
   itlb_fcl_imiss_s_l, fdp_fcl_pc_oor_vec_f, fdp_fcl_pc_oor_e,
118
   fdp_fcl_op_s, fdp_fcl_op3_s, fdp_fcl_ibit_s, lsu_ifu_stallreq,
119 103 fafa1971
   ffu_ifu_stallreq, ifq_fcl_stallreq, dtu_inst_anull_e,
120 95 fafa1971
   ifq_fcl_fill_thr, ifq_fcl_flush_sonly_e, tlu_ifu_trap_tid_w1,
121
   tlu_ifu_trappc_vld_w1, tlu_ifu_trapnpc_vld_w1,
122
   tlu_lsu_pstate_priv, tlu_lsu_pstate_am, tlu_hpstate_priv,
123
   tlu_lsu_redmode, tlu_hpstate_enb, lsu_ifu_addr_real_l,
124
   lsu_pid_state0, lsu_pid_state1, lsu_pid_state2, lsu_pid_state3,
125
   lsu_ifu_icache_en, lsu_ifu_dc_parity_error_w2, lsu_ifu_t0_tlz,
126
   lsu_ifu_t1_tlz, lsu_ifu_t2_tlz, lsu_ifu_t3_tlz, tlu_ifu_hwint_i3,
127
   tlu_ifu_pstate_ie, tlu_ifu_sftint_vld, tlu_ifu_hintp_vld,
128
   tlu_ifu_rerr_vld, tlu_ifu_rstthr_i2, tlu_ifu_rstint_i2,
129
   tlu_ifu_resumint_i2, tlu_ifu_nukeint_i2, tlu_itlb_wr_vld_g,
130
   tlu_itlb_dmp_vld_g, tlu_itlb_dmp_all_g, tlu_itlb_data_rd_g,
131
   tlu_itlb_tag_rd_g, tlu_itlb_invalidate_all_g, tlu_fcl_dmp_pid_bf,
132
   tlu_fcl_dmp_real_bf, tlu_idtlb_dmp_thrid_g, exu_ifu_ecc_ce_m,
133
   ffu_ifu_fst_ce_w
134
   );
135
 
136
   input  rclk,
137
                grst_l,
138
          arst_l,
139
                se,
140
          sehold,
141
                si;
142
 
143
   input  rst_tri_en;
144
 
145
 
146
   input  tlu_ifu_flush_pipe_w; // flush pipe on a trap
147
   input  exu_ifu_va_oor_m;
148
   input [3:0] exu_ifu_oddwin_s;
149
 
150
   input [1:0] spu_ifu_ttype_tid_w2;
151
   input       spu_ifu_ttype_vld_w2;
152
   input       spu_ifu_ttype_w2;
153
 
154
   input [3:0] erb_fcl_spu_uetrap;  // use m3
155
 
156
//   input       dtu_fcl_brtaken_e;    // branch taken
157
   input       exu_ifu_regz_e;
158
   input       dcl_fcl_bcregz0_e,
159
               dcl_fcl_bcregz1_e;
160
 
161
   input       dtu_fcl_rollback_g;
162
   input       dtu_fcl_retract_d;
163
   input       dtu_fcl_br_inst_d;
164
   input       dtu_fcl_sir_inst_e;
165
   input       dtu_fcl_privop_e,
166
                           dtu_fcl_fpdis_e,
167
               dtu_fcl_imask_hit_e,
168
                           dtu_fcl_illinst_e;
169
   input [3:0] dtu_fcl_thr_active;
170
 
171
   input       dec_fcl_rdsr_sel_pc_d,
172
                           dec_fcl_rdsr_sel_thr_d;
173
 
174
   input       ifq_fcl_wrreq_bf;
175
   input       ifq_fcl_icd_wrreq_bf,
176
                           ifq_fcl_ictv_wrreq_bf,
177
                           ifq_fcl_rdreq_bf;
178
 
179
   input [1:0] ifq_fcl_asi_tid_bf;
180
   input       ifq_fcl_asird_bf;
181
 
182
   input       ifq_fcl_invreq_bf;
183
 
184
   input       erb_fcl_itlb_ce_d1;
185
   input       erb_dtu_ifeterr_d1;
186
   input [3:0] erb_fcl_ifet_uevec_d1,
187
                           erb_fcl_ue_trapvec,
188
                           erb_fcl_ce_trapvec;
189
 
190
   input [3:0] dtu_fcl_nextthr_bf;   // thread to switch to
191
   input       dtu_fcl_ntr_s,        // next thread ready for ex
192
               dtu_fcl_running_s;
193
 
194
   input       dtu_fcl_flush_sonly_e;
195
//               dec_fcl_kill4sta_e;
196
 
197
   input       fdp_fcl_swc_s2,       // instruction switch condition
198
                           fdp_fcl_va2_bf,       // bit 2 of vaddr
199
                           itlb_fcl_tlbmiss_f_l,  // itlb miss
200
                           itlb_fcl_priv_s1,     // privileged access page
201
                           itlb_fcl_cp_s1,       // uncached access page
202
                           itlb_fcl_imiss_s_l;     // icache miss in s1
203
 
204
   input [3:0] fdp_fcl_pc_oor_vec_f;
205
   input       fdp_fcl_pc_oor_e;
206
 
207
   input [1:0] fdp_fcl_op_s;
208
   input [5:2] fdp_fcl_op3_s;
209
   input       fdp_fcl_ibit_s;
210
 
211
   input       lsu_ifu_stallreq,
212 103 fafa1971
                     ffu_ifu_stallreq,
213 95 fafa1971
               ifq_fcl_stallreq;
214
 
215
   input       dtu_inst_anull_e;
216
 
217
   input [3:0] ifq_fcl_fill_thr;     // fill inst goes to this
218
                                         // thread instruction register
219
   input       ifq_fcl_flush_sonly_e;
220
 
221
   input [1:0] tlu_ifu_trap_tid_w1;     // thr for which trappc is sent
222
   input       tlu_ifu_trappc_vld_w1,   // ld pc on trap or done/retry
223
                           tlu_ifu_trapnpc_vld_w1;  // ld Npc for a retry
224
 
225
   input [3:0] tlu_lsu_pstate_priv;     // may need to flop these three
226
   input [3:0] tlu_lsu_pstate_am;
227
   input [3:0] tlu_hpstate_priv;
228
   input [3:0] tlu_lsu_redmode;
229
   input [3:0] tlu_hpstate_enb;
230
 
231
   input [3:0] lsu_ifu_addr_real_l;
232
   input [2:0] lsu_pid_state0,
233
               lsu_pid_state1,
234
               lsu_pid_state2,
235
               lsu_pid_state3;
236
   input [3:0] lsu_ifu_icache_en;
237
 
238
   input       lsu_ifu_dc_parity_error_w2;
239
 
240
 
241
//   input       lsu_ifu_flush_ireg;  // not needed any more
242
   input       lsu_ifu_t0_tlz,
243
                           lsu_ifu_t1_tlz,
244
                           lsu_ifu_t2_tlz,
245
                           lsu_ifu_t3_tlz;
246
 
247
   input [3:0] tlu_ifu_hwint_i3,        // normal interrupt
248
                           tlu_ifu_pstate_ie,
249
                           tlu_ifu_sftint_vld,
250
                           tlu_ifu_hintp_vld,
251
                           tlu_ifu_rerr_vld,
252
                           tlu_ifu_rstthr_i2;       // reset or idle interrupt
253
 
254
   input       tlu_ifu_rstint_i2,       // reset to a dead thread
255
                           tlu_ifu_resumint_i2,
256
                           tlu_ifu_nukeint_i2;
257
 
258
   input       tlu_itlb_wr_vld_g,
259
                           tlu_itlb_dmp_vld_g,
260
               tlu_itlb_dmp_all_g,
261
                           tlu_itlb_data_rd_g,
262
                           tlu_itlb_tag_rd_g;
263
   input       tlu_itlb_invalidate_all_g;
264
 
265
   input [2:0] tlu_fcl_dmp_pid_bf;
266
   input       tlu_fcl_dmp_real_bf;
267
   input [1:0] tlu_idtlb_dmp_thrid_g;
268
 
269
   input       exu_ifu_ecc_ce_m;
270
   input       ffu_ifu_fst_ce_w;
271
 
272
   // to icd
273
   output      fcl_icd_rdreq_bf,
274
               fcl_icv_rdreq_bf,
275
                           fcl_icd_wrreq_bf,
276
                           fcl_ict_wrreq_bf,
277
                           fcl_icv_wrreq_bf;
278
 
279
   output      fcl_icd_index_sel_ifq_bf;
280
   output      fcl_ifq_grant_bf;
281
 
282
   // to ifq
283
   output      fcl_ifq_icmiss_s1;  // if icache turned off
284
   output      fcl_ifq_rdreq_s1;
285
   output      fcl_ifq_icache_en_s_l;
286
 
287
   output [1:0] fcl_ifq_thr_s1;
288
   output [3:0] fcl_ifq_canthr;     // cancel ifetch to this thread
289
 
290
   // to itlb
291
   output       fcl_itlb_cam_vld_bf,
292
                fcl_itlb_cam_bypass_bf,
293
                            fcl_itlb_addr_mask_l,
294
                fcl_itlb_cam_real_bf;
295
 
296
   output [2:0] fcl_itlb_cam_pid_bf;
297
 
298
   output       fcl_itlb_wr_vld_bf,
299
                            fcl_itlb_dmp_vld_bf,
300
                fcl_itlb_dmp_all_bf,
301
                            fcl_itlb_tag_rd_vld_bf,
302
                            fcl_itlb_invall_f_l,
303
                            fcl_itlb_data_rd_vld_bf;
304
 
305
   // to erb
306
   output       fcl_erb_ievld_s1,
307
                            fcl_erb_tevld_s1,
308
                            fcl_erb_immuevld_s1;
309
 
310
   output [1:0] ifu_lsu_thrid_s,
311
                            fcl_erb_asi_tid_f;
312
 
313
   output [3:0] fcl_erb_clear_iferr;
314
 
315
 
316
   output       fcl_erb_itlbrd_vld_s,
317
                            fcl_erb_itlbrd_data_s;
318
 
319
   output       fcl_dec_dslot_s;
320
   output       fcl_dtu_inst_vld_e,
321
                fcl_dtu_intr_vld_e,
322
                            fcl_dtu_inst_vld_d,
323
                fcl_dtu_ely_inst_vld_d,
324
                fcl_dec_intr_vld_d,
325
                            fcl_erb_inst_issue_d,
326
                            fcl_erb_inst_vld_d1,
327
                            ifu_tlu_inst_vld_m,
328
//                          ifu_lsu_inst_vld_m,
329
                            ifu_exu_inst_vld_e,
330
                            ifu_exu_inst_vld_w,
331
                            ifu_spu_inst_vld_w,
332
                            ifu_tlu_inst_vld_w;
333
 
334
   output       ifu_tlu_flush_w;
335
   output       ifu_tlu_flush_m;
336
 
337
   output [3:0] fcl_swl_int_activate_i3;
338
   output       fcl_swl_flush_wake_w;
339
   output       fcl_swl_flush_w;
340
 
341
   output       fcl_dcl_regz_e;
342
 
343
   // to tlu
344
   output [1:0] ifu_tlu_thrid_e;
345
   output [1:0] ifu_tlu_thrid_d;
346
 
347
   output       ifu_tlu_immu_miss_m,
348
                            ifu_tlu_priv_violtn_m;
349
 
350
   output       ifu_tlu_icmiss_e;
351
   output       ifu_tlu_ttype_vld_m;
352
   output       ifu_exu_ttype_vld_m;
353
   output       ifu_mmu_trap_m;
354
   output       ifu_tlu_trap_m;
355
   output [8:0] ifu_tlu_ttype_m;
356
 
357
   output       ifu_tlu_hwint_m;
358
   output       ifu_tlu_sftint_m;
359
//   output       ifu_tlu_hintp_m;
360
//   output       ifu_tlu_rerr_m;
361
   output       ifu_tlu_rstint_m;
362
   output       fcl_dtu_rst_thr_w;
363
   output       fcl_dtu_resum_thr_w;
364
 
365
   output       ifu_tlu_itlb_done;
366
 
367
   output       ifu_spu_trap_ack;
368
 
369
   // to exu
370
   output [1:0] ifu_exu_tid_s2;
371
   output       ifu_exu_ren1_s,
372
                            ifu_exu_ren2_s,
373
                            ifu_exu_ren3_s;
374
 
375
   output       ifu_exu_disable_ce_e;  // to exu and ffu
376
 
377
 
378
   // to dtu
379
   output       fcl_dtu_sync_intr_d;
380
   output       fcl_dtu_tlzero_d;
381
   output       fcl_dtu_privmode_d;
382
   output       fcl_dtu_hprivmode_d;
383
   output       fcl_dtu_hprivmode_w2;
384
   output       fcl_dtu_nuke_thr_w;
385
   output       fcl_swl_swout_f;
386
   output       fcl_dtu_stall_bf;
387
//   output       fcl_dtu_switch_s;     // indicates to the DTU that a
388
                                      // switch took place to next_thr
389
   output       fcl_swl_swcvld_s;
390
   output [3:0] fcl_dtu_thr_f;
391
   output       fcl_imd_oddwin_d;
392
 
393
   // to fdp
394
   output       fcl_fdp_oddwin_s;
395
   output [3:0] fcl_fdp_pcoor_vec_f;
396
   output       fcl_fdp_pcoor_f;
397
   output       fcl_fdp_mask32b_f;
398
   output       fcl_fdp_addr_mask_d;
399
 
400
   output [3:0] fcl_fdp_tctxt_sel_prim;
401
 
402
 
403
   // 2:1 mux selects
404
   output       fcl_fdp_usenir_sel_nir_s1;   // same as usenir_d2
405
   output [3:0] fcl_fdp_rbinst_sel_inste_s;
406
 
407
   output [3:0] fcl_fdp_thrtnpc_sel_tnpc_l,  // load npc
408
                            fcl_fdp_thrtnpc_sel_npcw_l,
409
                            fcl_fdp_thrtnpc_sel_pcf_l,
410
                            fcl_fdp_thrtnpc_sel_old_l;
411
 
412
   output [3:0] fcl_fdp_thr_s1_l;            // s1 thr for thrNIR input mux
413
 
414
   // other mux selects   
415
   output [3:0] fcl_fdp_next_thr_bf_l,  // for thrpc output mux
416
                fcl_fdp_next_ctxt_bf_l, // for ctxt output mux
417
                            fcl_fdp_nirthr_s1_l,    // select NIR in s1 stage
418
                            fcl_fdp_thr_s2_l;       // s2 thr for thr_inst_reg
419
 
420
   output [3:0] fcl_fdp_tpcbf_sel_pcp4_bf_l, // selects for thread PC muxes
421
                            fcl_fdp_tpcbf_sel_brpc_bf_l,
422
                            fcl_fdp_tpcbf_sel_trap_bf_l,
423
                            fcl_fdp_tpcbf_sel_old_bf_l;
424
 
425
   output       fcl_fdp_pcbf_sel_nosw_bf_l,      // F stage pc mux selects
426
                            fcl_fdp_pcbf_sel_swpc_bf_l,
427
                            fcl_fdp_pcbf_sel_br_bf_l;
428
 
429
   output [3:0] fcl_fdp_trrbpc_sel_trap_bf_l,
430
                            fcl_fdp_trrbpc_sel_rb_bf_l,
431
                            fcl_fdp_trrbpc_sel_err_bf_l,
432
                            fcl_fdp_trrbpc_sel_pcs_bf_l;
433
 
434
   output       fcl_fdp_noswpc_sel_tnpc_l_bf,    // next pc select,
435
                            fcl_fdp_noswpc_sel_old_l_bf,                 // dont need anymore
436
                            fcl_fdp_noswpc_sel_inc_l_bf;
437
 
438
   output [3:0] fcl_fdp_nextpcs_sel_pce_f_l,
439
                            fcl_fdp_nextpcs_sel_pcd_f_l,
440
                            fcl_fdp_nextpcs_sel_pcs_f_l,
441
                            fcl_fdp_nextpcs_sel_pcf_f_l;
442
 
443
   output       fcl_fdp_inst_sel_curr_s_l,   // selects for inst_s2
444
                            fcl_fdp_inst_sel_switch_s_l,
445
                            fcl_fdp_inst_sel_nir_s_l,
446
                            fcl_fdp_inst_sel_nop_s_l;
447
 
448
   output [3:0] fcl_fdp_tinst_sel_curr_s_l,  // selects for tinst regs
449
                            fcl_fdp_tinst_sel_rb_s_l,
450
                            fcl_fdp_tinst_sel_old_s_l,
451
                            fcl_fdp_tinst_sel_ifq_s_l;
452
 
453
   output [3:0] fcl_fdp_dmpthr_l;
454
 
455
   output       fcl_fdp_ctxt_sel_dmp_bf_l,
456
                            fcl_fdp_ctxt_sel_sw_bf_l,
457
                            fcl_fdp_ctxt_sel_curr_bf_l;
458
 
459
   output       fcl_fdp_rdsr_sel_pc_e_l,
460
                fcl_fdp_rdsr_sel_thr_e_l,
461
                fcl_fdp_rdsr_sel_ver_e_l;
462
 
463
   output       so,
464
                ifu_reset_l;
465
 
466
 
467
   //----------------------------------------------------------------------
468
   // Declarations
469
   //----------------------------------------------------------------------
470
   reg [3:0]    fcl_fdp_tpcbf_sel_old_bf_l,
471
                            fcl_fdp_tpcbf_sel_pcp4_bf_l,
472
                            fcl_fdp_tpcbf_sel_trap_bf_l,
473
                            fcl_fdp_tpcbf_sel_brpc_bf_l;
474
 
475
   wire         fcl_fdp_inst_sel_nop_s_l,
476
                fcl_fdp_inst_sel_nir_s_l,
477
                            fcl_fdp_inst_sel_curr_s_l,
478
                            fcl_fdp_inst_sel_switch_s_l;
479
 
480
 
481
   // local signals
482
   wire         //sw_itlb_on,
483
                sw_itlb_real,
484
                            sw_itlb_am,
485
                            //this_itlb_on,
486
                this_itlb_real,
487
                            itlb_on;
488
 
489
   wire [3:0]   xlate_en,
490
                xlate_en_d1;
491
 
492
   wire [2:0]   sw_pid_bf,
493
                curr_pid_bf;
494
 
495
   wire         pid_sel_sw,
496
                pid_sel_curr,
497
                pid_sel_dmp;
498
 
499
   wire         itlb_access_gnt,
500
                            itlb_access_en,
501
                itlb_write_en,
502
                ctxt_sel_dmp,
503
                            itlb_access_done,
504
                itlb_write_done,
505
                            itlb_rd_access_done,
506
                            itlb_rd_access_done_d1,
507
                            itlb_rd_access_done_d2,
508
                            itlb_rd_req_bf,
509
                            itlb_rd_req_f,
510
                            itlb_data_rd_f,
511
                itlb_data_rd_s;
512
 
513
   wire [1:0]   asi_tid_bf;
514
   wire [1:0]   spu_tid_w2;
515
 
516
   wire         fetch_bf,       // fetch an instruction next cycle
517
                allow_ifq_access_icd_bf,
518
                inst_access_bf,
519
                ia1_bf,
520
                ia0_bf,
521
                no_instacc_bf;
522
 
523
   wire         cam_vld_bf,
524
                tlb_invall_bf,
525
                tlb_invall_f,
526
//                tlb_invall_req_bf,
527
                inst_vld_bf;
528
 
529
   wire         rdreq_bf,     // read from I$ next cycle
530
                            rdreq_f;
531
 
532
   wire         ic_wrreq_bf;
533
 
534
   wire         running_s2,
535
                valid_s,
536
                            running_s1,
537
                ely_running_s1,
538
                            running_d,
539
                            running_e,
540
                            running_m,
541
                        inst_vld_f,
542
                            inst_vld_s,
543
                inst_vld_s_crit,
544
                            inst_vld_s1,
545
                            inst_vld_s2,    // valid bit of S stage
546
                                            // instruction.  If this is 0,
547
                                            // convert inst to no-op
548
                            inst_vld_d,
549
                inst_vld_d_crit,
550
                            inst_vld_d1,
551
                            inst_vld_e,
552
                            inst_vld_qual_e,
553
                            inst_vld_m,
554
                            inst_vld_w;
555
 
556
   wire         inst_vld_w_crit;
557
 
558
   wire         no_iftrap_m,
559
                no_iftrap_w;
560
 
561
   wire         stall_f,
562
                            stall_s1,
563
                            stall_s1_nxt,
564
                ely_stall_thisthr_f,
565
                part_stall_thisthr_f,
566
                            stall_thisthr_f;
567
   wire         rdreq_s1;
568
 
569
   wire         usenir_bf,
570
                            usenir_f,
571
                            usenir_s1;
572
 
573
   wire [3:0]   tinst_vld_s,    // valid bit of thr instr register
574
                                            // in s stage
575
                            tinst_vld_nxt;
576
 
577
   wire [3:0]   val_thr_s1,
578
                            val_thr_f,
579
                thr_e_v2,
580
                            val_thr_e;
581
 
582
   wire         flush_sonly_qual_e,
583
                flush_sonly_all_m,
584
                flush_sonly_qual_m,
585
                ims_flush_sonly_m,
586
                ims_flush_sonly_w,
587
                ims_flush_coll_m,
588
                ims_flush_coll_w,
589
                flush_sonly_m;
590
 
591
   wire         flush_pipe_w;
592
 
593
   wire         kill_thread_d,
594
//                          kill_thread_e,
595
                            kill_thread_m,
596
                kill_local_m,
597
                ely_kill_thread_s2,
598
                ely_kill_thread_m,
599
                            kill_thread_s2;
600
 
601
   wire [3:0]   clear_s_d1,
602
                flush_thr_w,
603
                late_flush_w2;
604
 
605
   wire         utrap_flush_w,
606
                utrap_flush_m,
607
                flush_pipe_w2;
608
 
609
   wire         kill_curr_f,
610
                kill_curr_d,
611
                kill_curr_e,
612
                kill_curr_m;
613
 
614
   wire [3:0]   canthr_f,
615
                canthr_s_early,
616
                            canthr_s;
617
   wire         canthr_sw;
618
   wire         canthr_sm,
619
                canthr_sd;
620
 
621
   wire         forcemiss_f,   // force an icache miss (if icache is off)
622
                            forcemiss_s1,
623
                icmiss_for_perf,
624
//                ic_miss_sw_s1,
625
                            ic_miss_s1;    // icache miss (forced or not)
626
 
627
   wire [3:0]   icache_en_d1;
628
 
629
   wire         icache_on_bf,
630
                            icache_on_f,
631
                            icache_on_s1,
632
                uncached_page_s1;
633
//                          sw_icache_on,
634
//                          this_icache_on;
635
 
636
   wire         imsto_thisthr_s1,
637
                iferrto_thisthr_d1,
638
                retract_iferr_d1,
639
                retract_iferr_qual_d1,
640
                retract_inst_d,
641
                retract_iferr_e;
642
//   wire         intrto_thisthr_d;
643
//   wire         imsto_nextthr_s1;
644
 
645
   wire         mark4rb_w,
646
                mark4rb_m,
647
                mark4rb_e,
648
                mark4rb_d,
649
                mark4rb_s;
650
 
651
   wire [3:0]   tlbmiss_s2,
652
                            tlbmiss_d,
653
                            nir_tlbmiss_vec,
654
                            nir_tlbmiss_next;
655
 
656
   wire [3:0]   delay_slot_vec,
657
                delay_slot_vec_nxt;
658
 
659
   wire         tlb_cam_miss_f,
660
                tlb_cam_miss_s1,
661
                nir_tlbmiss_s1,
662
                            tlbmiss_s1_crit,
663
                            tlbmiss_s1;
664
 
665
   wire         cam_vld_f,
666
                            cam_vld_s1;
667
 
668
   wire         immu_fault_f,
669
                            immu_miss_d,
670
                            immu_miss_crit_d,
671
                            immu_miss_qual_d,
672
                            immu_miss_e,
673
//                immu_miss_qual_e,
674
                immu_miss_m,
675
                addr_real_e;
676
   wire [3:0]   itlb_addr_real_l,
677
                itlb_addr_real;
678
   wire [3:0]   pstate_am_d1;
679
 
680
   wire         pc_oor_s1,
681
                pc_oor_s2,
682
                pc_oor_s,
683
                            pc_oor_f;
684
   wire         set_oor_m;
685
   wire         addr_mask_32b_m;
686
 
687
   wire         priv_mode_s1,
688
                priv_mode_f,
689
                hpriv_mode_s1,
690
                hpriv_mode_w,
691
                hpriv_mode_w2,
692
                hpriv_mode_f;
693
 
694
   wire         inst_acc_exc_s1,
695
                            inst_acc_exc_d,
696
                            inst_acc_exc_e;
697
   wire [3:0]   inst_acc_vec_s2,
698
                            inst_acc_vec_d;
699
 
700
   wire         priv_violtn_e,
701
                priv_violtn_m;
702
 
703
   wire         trap_e,
704
                            trap_m;
705
 
706
   wire         ttype_sel_spuma_e,
707
                            ttype_sel_spuenc_e,
708
                            ttype_sel_corr_err_e,
709
                            ttype_sel_unc_err_e,
710
                            ttype_sel_res_err_e,
711
                            ttype_sel_hstk_cmp_e,
712
                            ttype_sel_pcoor_e,
713
                            ttype_sel_immu_miss_e,
714
                            ttype_sel_real_trans_e,
715
                            ttype_sel_icache_err_e,
716
                            ttype_sel_priv_viol_e,
717
                            ttype_sel_privop_e,
718
                            ttype_sel_illinst_e,
719
                            ttype_sel_ibe_e,
720
                            ttype_sel_sir_e,
721
                            ttype_sel_fpdis_e;
722
 
723
   wire [8:0]   ttype_e;
724
 
725
   wire [3:0]   next_nir_privvec,
726
                            nir_privvec;
727
   wire         nir_priv_s1,
728
                            priv_inst_s1;
729
 
730
   wire         tlzero_s2;
731
   wire [3:0]   tlzero_vec_d1;
732
 
733
   wire         nuke_thr_w,
734
                resum_thr_w,
735
                rst_thr_w;
736
 
737
   wire [3:0]   spu_thr;
738
//   wire [3:0]   rst_thr_bf;
739
 
740
   wire [3:0]   async_rst_i3,
741
                async_rst_i4,
742
                            next_rst_i2,
743
                            rstint_i2,
744
                            rstint_i3,
745
                            resumint_i2,
746
                            resumint_i3,
747
                next_resum_i2,
748
                            nuke_thr_i2,
749
                            next_nuke_i2,
750
                            nuke_thr_i3,
751
                            next_sftint_i2,
752
                next_hintp_i2,
753
                next_rerr_i2,
754
                            next_hwint_i3,
755
                            sftint_i3,
756
                hintp_i3,
757
                rerr_i3,
758
                            hwint_i4,
759
                            next_ceint_i2,
760
                            ceint_i3,
761
                            next_ueint_i2,
762
                            ueint_i3,
763
                            next_spuint0_i2,
764
                            spuint0_i3,
765
                            next_spuint1_i2,
766
                            spuint1_i3;
767
 
768
   wire [3:0]   intr_in_pipe;
769
 
770
   wire [3:0]   hypv_int_en,
771
                hypv_int_en_d1;
772
   wire [3:0]   supv_int_en,
773
                supv_int_en_d1;
774
 
775
   wire [3:0]   ifet_ue_vec_d1,
776
                            ifet_ue_vec_e;
777
   wire         ifet_ue_e;
778
 
779
   wire [3:0]   any_intr_vec_f,
780
                any_intr_vec_s,
781
                intr_pending_nxt,
782
                intr_pending_s,
783
                supv_masked_intr_s,
784
                hypv_masked_intr_s;
785
 
786
   wire         spuint0_m,
787
                spuint0_trap_m,
788
//                spuint0_qual_m,
789
                            spuint0_e,
790
                            spuint0_qual_e,
791
                spuint0_w,
792
                spuint0_trap_w,
793
                            spuint1_m,
794
                spuint1_trap_m,
795
//                spuint1_qual_m,
796
                            spuint1_e,
797
                            spuint1_qual_e,
798
                spuint1_w,
799
                spuint1_trap_w,
800
                hwint_m,
801
                hwint_e,
802
                rstint_m,
803
//                rstint_qual_m,
804
                resumint_m,
805
                resumint_qual_m,
806
                sftint_m,
807
                sftint_e,
808
                sftint_qual_e,
809
                hintp_e,
810
                hintp_qual_e,
811
                hintp_m,
812
                rerr_e,
813
                rerr_qual_e,
814
                rerr_m,
815
                nuke_thr_m,
816
                nuke_thr_qual_m,
817
                            ceint_m,
818
                ceint_trap_m,
819
                ceint_trap_w,
820
//                ceint_qual_m,
821
                ceint_qual_w,
822
                            ceint_e,
823
                            ceint_qual_e,
824
                            ueint_m,
825
                ueint_trap_m,
826
                ueint_trap_w,
827
//                ueint_qual_m,
828
                ueint_qual_w,
829
                ueint_qual_e,
830
                            ueint_e;
831
 
832
   wire         disr_trap_m,
833
                rb_intr_m,
834
                rb_intr_w,
835
                any_intr_m;
836
 
837
   wire         force_intr_s;
838
   wire         intr_vld_s,
839
                            intr_vld_d,
840
                            intr_vld_e,
841
                            intr_vld_m,
842
                            intr_vld_w,
843
                intr_vld_qual_s,
844
                            intr_vld_qual_d,
845
                            intr_vld_qual_e,
846
                            intr_vld_qual_m;
847
 
848
   wire         kill_intr_f,
849
                            kill_intr_d,
850
                            kill_intr_e;
851
 
852
//       wire         kill_intr_m;
853
 
854
   wire         rst_stallreq,
855
                rst_stallreq_l,
856
                all_stallreq,
857
                rst_itlb_stv_l,
858
                arst_vld_f,
859
                arst_vld_f_l,
860
                arst_vld_s,
861
                arst_vld_s_l,
862
                async_intr_vld_s,
863
                itlb_starv_alert,
864
                rst_sw_bf,
865
                rst_sw_bf_l,
866
                sw_for_real_rst_bf,
867
                rst_stallreq_d0,
868
                            rst_stallreq_d1,
869
                            rst_stallreq_d2;
870
 
871
   wire         lsu_stallreq_d1,
872
                ffu_stallreq_d1;
873
 
874
   wire [3:0]   rstint_penc;
875
 
876
   wire         usep_bf,
877
                set_usen_bf,
878
                usen_iso_bf,
879
                            usen_bf;
880
   wire         va2_f;
881
   wire         ntpc_thisthr;
882
 
883
   wire [3:0]   thr_usen_nxt,
884
                            thr_usen_bf;
885
 
886
   wire         brto_nxtthr_bf_l,  // intermediate signal for icadr sel
887
//                brto_nxtthr_bf,
888
//                thr_match_ne_norst,
889
                sw_match_ne_norst,
890
                brtaken_buf_e,
891
                brtaken_unq_e,
892
                brtaken_e,
893
                brtaken_m;
894
 
895
   wire         switch_bf,   // switch in next cycle unless stall
896
                switch_qual_bf,
897
                            switch_s2;  // switch in this cycle
898
 
899
   wire         rstt,       // set thr_f to the reset pkt thread
900
                            swt,        // switch to nextthr_bf
901
                            samet;      // don't change thread
902
 
903
   wire [3:0]   thr_f_crit,
904
                thr_f_dec,
905
                thr_f_flop;
906
 
907
   wire [3:0]   thr_f,      // = thr_s2
908
                            thr_bf,
909
                            thr_s1,     // = thr_d
910
                            thr_s1_next,
911
                dec_thr_s1_l,
912
                            thr_d,
913
                            thr_e,
914
                            thr_m,
915
                            thr_w2,
916
                            thr_w;
917
 
918
   wire         tm_fd_l;
919
 
920
   wire         thr_match_fw,
921
                            thr_match_fw2,
922
                            thr_match_dw,
923
                            thr_match_dw2,
924
                            thr_match_em,
925
                            thr_match_ew,
926
                            thr_match_ew2,
927
                            same_thr_mw2,
928
                            thr_match_mw,
929
                            thr_match_fm,
930
                            thr_match_de,
931
                            thr_match_dm,
932
                            thr_match_fe,
933
                            thr_match_fd,
934
                            thr_match_fs1,
935
                            thr_match_nw,
936
                            thr_match_nd,
937
                            thr_match_ne;
938
//                          thr_match_ft;
939
 
940
   wire         rb2_inst_d,
941
                            rb2_inst_e,
942
                            rb1_inst_s,
943
                            rb1_inst_d,
944
                            rb0_inst_bf,
945
                            rb0_inst_s,
946
                            rt2_inst_e,
947
                            rt1_inst_s,
948
                            rt1_inst_d,
949
                            rt0_inst_bf,
950
                            rt0_inst_s;
951
 
952
   wire [3:0]   rb_w2,
953
                rb_for_iferr_e,
954
                            rb_froms,
955
                            rb_frome,
956
                            rb_fromd;
957
 
958
   wire         rb_stg_s,
959
                            rb_stg_d,
960
                rb_stg_d_crit,
961
                            rb_stg_e;
962
 
963
   wire         icadr_selbr_l,
964
//                          icadr_selsw,
965
//                icadr_selbr,
966
                icadr_selsw_l;
967
 
968
   wire         sw_or_async_stall;
969
 
970
   wire [3:0]   trap_thr;
971
 
972
   wire [3:0]   load_tpc,     // thread pc reg input select
973
                            load_bpc,     // these should be exclusive in normal mode
974
                            load_pcp4;    // but not during scan shift or reset
975
 
976
   wire         irf_ce_w,
977
                            irf_ce_m,
978
                any_ce_w,
979
                            rb_stg_w;
980
 
981
   wire [3:0]   ce_cnt0,
982
                ce_cnt0_nxt,
983
                ce_cnt1,
984
                ce_cnt1_nxt,
985
                ce_cnt_rst;
986
 
987
   wire         ce_val0_d,
988
                ce_val1_d,
989
                disable_ce_e,
990
                disable_ce_d;
991
 
992
   wire [3:0]   ntpc_vld,     // use thr_nextpc_f
993
                            ntpc_vld_nxt;
994
 
995
   wire [1:0]   sas_thrid_w;
996
 
997
   wire         rdsr_sel_pc_e,
998
                                    rdsr_sel_thr_e;
999
 
1000
   wire [1:0]   trap_tid_w2;
1001
   wire         trappc_vld_w2,
1002
                trapnpc_vld_w2;
1003
 
1004
   wire         fcl_reset,
1005
                fcl_reset_l;
1006
 
1007
   // some monitor is looking for this signal
1008
//   wire         fcl_swl_flush_wait_w=1'b0;
1009
   wire         clk;
1010
 
1011
   wire [3:0]   nextthr_bf_buf,
1012
                nextthr_final_bf;
1013
 
1014
 
1015
//
1016
// Code start here 
1017
//
1018
   assign       clk = rclk;
1019
 
1020
//----------------------------------------------------------------------
1021
// Fetch Unit Controls
1022
//----------------------------------------------------------------------
1023
 
1024
   // reset buffer
1025
   dffrl_async rstff(.din (grst_l),
1026
                     .q   (fcl_reset_l),
1027 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so(),
1028 95 fafa1971
                     .rst_l (arst_l));
1029
 
1030
   assign   fcl_reset = ~fcl_reset_l;
1031
   assign   ifu_reset_l = fcl_reset_l;
1032
 
1033
 
1034
//-----------------------------------
1035
// TLB Operations
1036
//-----------------------------------
1037
 
1038 113 albert.wat
   dff_s #(4) real_reg(.din (lsu_ifu_addr_real_l),
1039 95 fafa1971
                     .q   (itlb_addr_real_l),
1040 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1041 95 fafa1971
   assign   itlb_addr_real = ~itlb_addr_real_l;
1042
 
1043
   // ITLB on signal
1044
 
1045
//`ifdef SPARC_HPV_EN   
1046
   assign   xlate_en = (~tlu_hpstate_enb & lsu_ifu_addr_real_l |
1047
                        tlu_hpstate_enb & ~tlu_hpstate_priv) &
1048
                         ~tlu_lsu_redmode;
1049
 
1050
//`else
1051
//   assign   xlate_en = lsu_ifu_addr_real_l;
1052
//`endif
1053
 
1054 113 albert.wat
   dff_s #(4) xlate_reg(.din (xlate_en),
1055 95 fafa1971
                      .q   (xlate_en_d1),
1056 113 albert.wat
                      .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1057 95 fafa1971
 
1058
//   assign sw_itlb_on = ((nextthr_bf_buf & xlate_en_d1) == 4'b0) ?
1059
//                                   1'b0 : 1'b1;
1060
//   assign this_itlb_on = ((thr_f & xlate_en_d1) == 4'b0) ?
1061
//                                           1'b0 : 1'b1;
1062
//   assign itlb_on = switch_bf ? sw_itlb_on : this_itlb_on;
1063
   assign itlb_on = (nextthr_final_bf[0] & xlate_en_d1[0] |
1064
                     nextthr_final_bf[1] & xlate_en_d1[1] |
1065
                     nextthr_final_bf[2] & xlate_en_d1[2] |
1066
                     nextthr_final_bf[3] & xlate_en_d1[3]);
1067
 
1068
 
1069
   // flop xlate_en (done) addr_real and icache_en if timing is 
1070
   // not cutting it
1071
 
1072
   // Hypervisor signals
1073
   assign sw_itlb_real = ((nextthr_bf_buf & itlb_addr_real) == 4'b0) ?
1074
                                     1'b0 : 1'b1;
1075
   assign this_itlb_real = ((thr_f & itlb_addr_real) == 4'b0) ?
1076
                                             1'b0 : 1'b1;
1077
 
1078
//   assign fcl_itlb_cam_real_bf = switch_bf ? sw_itlb_real : this_itlb_real;
1079
 
1080
   mux3ds  creal_mx(.dout (fcl_itlb_cam_real_bf),
1081
                    .in0  (sw_itlb_real),
1082
                    .in1  (this_itlb_real),
1083
                    .in2  (tlu_fcl_dmp_real_bf),
1084
                    .sel0 (pid_sel_sw),
1085
                    .sel1 (pid_sel_curr),
1086
                    .sel2 (pid_sel_dmp));
1087
 
1088
   // Partition ID
1089
   mux4ds #(3) swpid_mux (.dout (sw_pid_bf[2:0]),
1090
                          .in0  (lsu_pid_state0[2:0]),
1091
                          .in1  (lsu_pid_state1[2:0]),
1092
                          .in2  (lsu_pid_state2[2:0]),
1093
                          .in3  (lsu_pid_state3[2:0]),
1094
                          .sel0 (nextthr_bf_buf[0]),
1095
                          .sel1 (nextthr_bf_buf[1]),
1096
                          .sel2 (nextthr_bf_buf[2]),
1097
                          .sel3 (nextthr_bf_buf[3]));
1098
 
1099
   mux4ds #(3) currpid_mux (.dout (curr_pid_bf[2:0]),
1100
                            .in0  (lsu_pid_state0[2:0]),
1101
                            .in1  (lsu_pid_state1[2:0]),
1102
                            .in2  (lsu_pid_state2[2:0]),
1103
                            .in3  (lsu_pid_state3[2:0]),
1104
                            .sel0 (thr_f[0]),
1105
                            .sel1 (thr_f[1]),
1106
                            .sel2 (thr_f[2]),
1107
                            .sel3 (thr_f[3]));
1108
 
1109
//   assign fcl_itlb_cam_pid_bf[2:0] = switch_bf ?  
1110
//                                       sw_pid_bf[2:0] : 
1111
//                                       curr_pid_bf[2:0];
1112
 
1113
//   assign pid_sel_dmp = tlu_itlb_dmp_actxt_g & ctxt_sel_dmp;
1114
   assign pid_sel_dmp = ctxt_sel_dmp;
1115
   assign pid_sel_curr = ~pid_sel_dmp & ~switch_bf;
1116
   assign pid_sel_sw = ~pid_sel_dmp & switch_bf;
1117
   mux3ds #(3) ipid_mx(.dout (fcl_itlb_cam_pid_bf[2:0]),
1118
                       .in0  (sw_pid_bf[2:0]),
1119
                       .in1  (curr_pid_bf[2:0]),
1120
                       .in2  (tlu_fcl_dmp_pid_bf[2:0]),
1121
                       .sel0 (pid_sel_sw),
1122
                       .sel1 (pid_sel_curr),
1123
                       .sel2 (pid_sel_dmp));
1124
 
1125
   // ITLB address mask
1126 113 albert.wat
   dff_s #(4) am_reg(.din (tlu_lsu_pstate_am),
1127 95 fafa1971
                   .q   (pstate_am_d1),
1128 113 albert.wat
                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1129 95 fafa1971
 
1130
   assign sw_itlb_am = ((nextthr_bf_buf & pstate_am_d1) == 4'b0) ?
1131
                                     1'b0 : 1'b1;
1132
   assign fcl_itlb_addr_mask_l = switch_bf ?
1133
                                 ~sw_itlb_am : ~fcl_fdp_mask32b_f;
1134
 
1135 113 albert.wat
   dff_s #(4) tlz_reg(.din ({lsu_ifu_t3_tlz,
1136 95 fafa1971
                           lsu_ifu_t2_tlz,
1137
                           lsu_ifu_t1_tlz,
1138
                           lsu_ifu_t0_tlz}),
1139
                    .q   (tlzero_vec_d1[3:0]),
1140 113 albert.wat
                    .clk (clk), .se (se), `SIMPLY_RISC_SCANIN, .so());
1141 95 fafa1971
 
1142
 
1143
   // TLB context select
1144
   assign fcl_fdp_tctxt_sel_prim = tlzero_vec_d1 & itlb_addr_real_l;
1145
//   assign fcl_fdp_tctxt_sel_prim[1] = lsu_ifu_t1_tlz & itlb_addr_real_l[1];
1146
//   assign fcl_fdp_tctxt_sel_prim[2] = lsu_ifu_t2_tlz & itlb_addr_real_l[2];
1147
//   assign fcl_fdp_tctxt_sel_prim[3] = lsu_ifu_t3_tlz & itlb_addr_real_l[3];
1148
 
1149
 
1150
   // Access to TLB
1151
   // ITLB may be accessed even when icache is off
1152
   assign cam_vld_bf = itlb_on & inst_access_bf;
1153
 
1154
   assign fcl_itlb_cam_vld_bf = cam_vld_bf;
1155
   assign fcl_itlb_cam_bypass_bf = ~cam_vld_bf;
1156
 
1157 113 albert.wat
   dff_s #(1) itlb_onf_ff(.din (cam_vld_bf),
1158 95 fafa1971
                                    .q   (cam_vld_f),
1159
                                    .clk (clk),
1160 113 albert.wat
                                    .se  (se), `SIMPLY_RISC_SCANIN, .so());
1161 95 fafa1971
 
1162 113 albert.wat
   dff_s #(1) itlb_ons1_ff(.din (cam_vld_f),
1163 95 fafa1971
                                     .q   (cam_vld_s1),
1164
                                     .clk (clk),
1165 113 albert.wat
                                     .se  (se), `SIMPLY_RISC_SCANIN, .so());
1166 95 fafa1971
 
1167
   // allow rd/wr/demap access to tlb
1168
   // itlb access is granted only every other cycle
1169
   // (not enough time to turn the request from mmu around)
1170
//   assign itlb_access_en = ~cam_vld_bf & ~ifq_fcl_asird_bf & 
1171
//                           ~itlb_access_done;
1172
//
1173
//   assign itlb_write_en = ~cam_vld_bf & ~ifq_fcl_asird_bf & 
1174
//                           ~itlb_write_done & 
1175
//                           (~tlu_itlb_dmp_vld_g | itlb_access_done);
1176
 
1177
// Save some timing   
1178
//   assign itlb_write_en = (~itlb_on | no_instacc_bf) & ~ifq_fcl_asird_bf &
1179
//                          ~itlb_write_done & 
1180
//                          (~tlu_itlb_dmp_vld_g | itlb_access_done);
1181
 
1182
   assign itlb_write_en = no_instacc_bf & ~ifq_fcl_asird_bf &
1183
                          ~itlb_write_done &
1184
                          (~tlu_itlb_dmp_vld_g | itlb_access_done);
1185
   assign itlb_access_en = no_instacc_bf & ~ifq_fcl_asird_bf &
1186
                           ~itlb_access_done;
1187
 
1188
   // reset tlb
1189
//   dff #(1) itlbrst_ff(.din (tlu_itlb_invalidate_all_g),
1190
//                                 .q   (tlb_invall_req_bf),
1191 113 albert.wat
//                                 .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1192 95 fafa1971
//   assign tlb_invall_bf = tlb_invall_req_bf & ~itlb_access_done;
1193
   assign tlb_invall_bf = sehold ? tlb_invall_f :
1194
                           (tlu_itlb_invalidate_all_g & itlb_access_en);
1195 113 albert.wat
   dff_s #(1) itlbrstf_ff(.din (tlb_invall_bf),
1196 95 fafa1971
                                    .q   (tlb_invall_f),
1197 113 albert.wat
                                    .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1198 95 fafa1971
 
1199
   assign fcl_itlb_wr_vld_bf = tlu_itlb_wr_vld_g & itlb_write_en;
1200
   assign fcl_itlb_dmp_vld_bf = tlu_itlb_dmp_vld_g & itlb_access_en;
1201
   assign fcl_itlb_dmp_all_bf = tlu_itlb_dmp_all_g & tlu_itlb_dmp_vld_g &
1202
                                itlb_access_en;
1203
 
1204
//   assign fcl_itlb_invall_bf = tlb_invall_bf & itlb_access_en | fcl_reset;
1205
   assign fcl_itlb_invall_f_l = ~tlb_invall_f;
1206
 
1207
   assign fcl_itlb_data_rd_vld_bf = tlu_itlb_data_rd_g & itlb_access_en &
1208
                                          ~itlb_rd_access_done_d2 &
1209
                                    ~itlb_rd_access_done_d1;
1210
 
1211
   assign fcl_itlb_tag_rd_vld_bf = tlu_itlb_tag_rd_g & itlb_access_en &
1212
                                         ~itlb_rd_access_done_d2 &
1213
                                   ~itlb_rd_access_done_d1;
1214
 
1215
   assign rst_itlb_stv_l = ((tlu_itlb_invalidate_all_g |
1216
                             tlu_itlb_dmp_vld_g |
1217
                             tlu_itlb_data_rd_g |
1218
                             tlu_itlb_tag_rd_g) & ~itlb_access_done |
1219
                            tlu_itlb_wr_vld_g & ~itlb_write_done) &
1220
                             ~fcl_reset;
1221
 
1222
   sparc_ifu_ctr5 starv_ctr(
1223
                                              // Outputs
1224
                                              .limit    (itlb_starv_alert),
1225
                                              .so       (so),
1226
                                              // Inputs
1227
                                              .clk      (clk),
1228
                                              .se       (se),
1229
                                              .si       (si),
1230
                                              .rst_ctr_l (rst_itlb_stv_l));
1231
 
1232
   assign itlb_rd_req_bf = fcl_itlb_data_rd_vld_bf | fcl_itlb_tag_rd_vld_bf;
1233
 
1234
   // tlb access request
1235
   assign itlb_access_gnt = (fcl_itlb_data_rd_vld_bf |
1236
                                               fcl_itlb_tag_rd_vld_bf  |
1237
//                             tlb_invall_bf & itlb_access_en |
1238
                             tlb_invall_bf |
1239
                             fcl_itlb_dmp_vld_bf);
1240
 
1241 113 albert.wat
   dff_s #(1) tlb_gnt1_ff(.din (itlb_access_gnt),
1242 95 fafa1971
                                  .q   (itlb_access_done),
1243 113 albert.wat
                                  .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1244 95 fafa1971
 
1245 113 albert.wat
   dff_s #(1) tlb_rd_ff(.din (itlb_rd_req_bf),
1246 95 fafa1971
                                .q   (itlb_rd_req_f),
1247 113 albert.wat
                                .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1248 95 fafa1971
 
1249 113 albert.wat
   dff_s #(1) tlb_wrt1_ff(.din (fcl_itlb_wr_vld_bf),
1250 95 fafa1971
                                    .q   (itlb_write_done),
1251 113 albert.wat
                                    .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1252 95 fafa1971
 
1253
 
1254
   // TBD:
1255
   // reads need to wait one more cycle.  Others can ack without this
1256
   // second delay.
1257
   assign itlb_rd_access_done = itlb_rd_req_f & itlb_access_done;
1258
 
1259 113 albert.wat
   dff_s #(1) tlb_rd1_ff(.din (itlb_rd_access_done),
1260 95 fafa1971
                                  .q   (itlb_rd_access_done_d1),
1261 113 albert.wat
                                  .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1262
   dff_s #(1) tlb_rd2_ff(.din (itlb_rd_access_done_d1),
1263 95 fafa1971
                                   .q   (itlb_rd_access_done_d2),
1264 113 albert.wat
                                  .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1265 95 fafa1971
   assign ifu_tlu_itlb_done = ~itlb_rd_req_f & itlb_access_done |
1266
                               itlb_write_done |
1267
                                     itlb_rd_access_done_d2;
1268
 
1269
   assign fcl_erb_itlbrd_vld_s = itlb_rd_access_done_d1;
1270
 
1271
   assign asi_tid_bf = ifq_fcl_asird_bf ? ifq_fcl_asi_tid_bf :
1272
                                                tlu_idtlb_dmp_thrid_g;
1273
 
1274 113 albert.wat
   dff_s #(2) asi_tid_reg(.din (asi_tid_bf),
1275 95 fafa1971
                                  .q   (fcl_erb_asi_tid_f),
1276 113 albert.wat
                                  .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1277 95 fafa1971
 
1278
 
1279
   // Remember if we read tag or data
1280 113 albert.wat
   dff_s #(1) tlb_rddf_ff(.din (fcl_itlb_data_rd_vld_bf),
1281 95 fafa1971
                                  .q   (itlb_data_rd_f),
1282 113 albert.wat
                                  .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1283 95 fafa1971
 
1284 113 albert.wat
   dff_s #(1) tlb_rdds_ff(.din (itlb_data_rd_f),
1285 95 fafa1971
                                  .q   (itlb_data_rd_s),
1286 113 albert.wat
                                  .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1287 95 fafa1971
 
1288
   // pick itlb ldxa data
1289
   assign fcl_erb_itlbrd_data_s =  itlb_data_rd_s;
1290
 
1291
   // Demap thread
1292
   assign fcl_fdp_dmpthr_l[0] = ~(~tlu_idtlb_dmp_thrid_g[1] & ~tlu_idtlb_dmp_thrid_g[0]);
1293
   assign fcl_fdp_dmpthr_l[1] = ~(~tlu_idtlb_dmp_thrid_g[1] & tlu_idtlb_dmp_thrid_g[0]);
1294
   assign fcl_fdp_dmpthr_l[2] = ~(tlu_idtlb_dmp_thrid_g[1] & ~tlu_idtlb_dmp_thrid_g[0]);
1295
   assign fcl_fdp_dmpthr_l[3] = ~(tlu_idtlb_dmp_thrid_g[1] & tlu_idtlb_dmp_thrid_g[0]);
1296
 
1297
   // Select appropriate context for TLB
1298
   // ctxt_sel_dmp is itlb_access_en without the asird signal
1299
   assign ctxt_sel_dmp = no_instacc_bf & ~itlb_access_done;
1300
   assign fcl_fdp_ctxt_sel_dmp_bf_l = ~ctxt_sel_dmp;
1301
   assign fcl_fdp_ctxt_sel_sw_bf_l = ctxt_sel_dmp | ~switch_bf;
1302
   assign fcl_fdp_ctxt_sel_curr_bf_l = ctxt_sel_dmp | switch_bf;
1303
 
1304
 
1305
//--------------------------
1306
// Fetch Request and Stall
1307
//--------------------------
1308
 
1309
   // Determine if we need can continue fetching next cycle
1310
//   assign fetch_bf = (~all_stallreq & ~fcl_reset & ~rst_stallreq) &
1311
//                   (switch_bf |
1312
//                    ~(part_stall_thisthr_f | fdp_fcl_swc_s2));
1313
//                    ~(stall_thisthr_f | fdp_fcl_swc_s2 | immu_fault_f));
1314
 
1315
   assign fetch_bf = (~all_stallreq & ~fcl_reset & ~rst_stallreq) &
1316
                       (switch_bf |  // replace with ntr_s?
1317
                        ~(part_stall_thisthr_f
1318
                          | fdp_fcl_swc_s2
1319
                          )
1320
                        );
1321
 
1322
   // dtu_fcl_running_s should be a part of this eqn, since it is assumed
1323
   // by the ifill completion prediction logic in the swl
1324
//   assign inst_access_bf = (~all_stallreq & ~fcl_reset & ~rst_stallreq & 
1325
//                            (switch_bf & ~usen_iso_bf |
1326
//                             ~switch_bf & ~ely_stall_thisthr_f &
1327
//                             dtu_fcl_running_s & 
1328
//                             ~ely_kill_thread_s2 &
1329
//                             //~fdp_fcl_swc_s2 & // take out for tim reasons
1330
//                             ~usep_bf));
1331
 
1332
   assign ia0_bf = (~all_stallreq & ~fcl_reset & ~rst_stallreq &
1333
                    (switch_bf |
1334
                     ~ely_stall_thisthr_f &
1335
                     dtu_fcl_running_s &
1336
                     ~ely_kill_thread_s2 &
1337
                     ~usep_bf));
1338
 
1339
   assign ia1_bf = (~all_stallreq & ~fcl_reset & ~rst_stallreq &
1340
                    (~switch_bf & ~ely_stall_thisthr_f &
1341
                     dtu_fcl_running_s &
1342
                     ~ely_kill_thread_s2 &
1343
                     ~usep_bf));
1344
 
1345
 
1346
   assign inst_access_bf = usen_iso_bf ? ia1_bf : ia0_bf;
1347
   // needs to work even if usen_iso_bf is X - not nec. 11/06/03
1348
//   dp_mux2es #(1) ia_mx(.dout (inst_access_bf),
1349
//                        .in0  (ia0_bf),
1350
//                        .in1  (ia1_bf),
1351
//                        .sel  (usen_iso_bf));
1352
 
1353
 
1354
 
1355
//   assign allow_ifq_access_icd_bf = (all_stallreq | rs
1356
//                                     ~switch_bf & 
1357
//                                     (usep_bf | stall_f) |
1358
//                                     switch_bf & usen_bf);
1359
   assign allow_ifq_access_icd_bf = ~inst_access_bf;
1360
 
1361
   // earlier version for critical stuff
1362
   assign no_instacc_bf = all_stallreq | fcl_reset | rst_stallreq |
1363
                          ~dtu_fcl_ntr_s & (ely_stall_thisthr_f | usep_bf);
1364
 
1365
   // check if icache is on
1366 113 albert.wat
   dff_s #(4) ic_en_reg(.din (lsu_ifu_icache_en),
1367 95 fafa1971
                      .q   (icache_en_d1),
1368 113 albert.wat
                      .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1369 95 fafa1971
 
1370
//   assign sw_icache_on = (nextthr_bf_buf[0] & icache_en_d1[0] |
1371
//                          nextthr_bf_buf[1] & icache_en_d1[1] |
1372
//                          nextthr_bf_buf[2] & icache_en_d1[2] |
1373
//                          nextthr_bf_buf[3] & icache_en_d1[3]);
1374
//   assign this_icache_on = (thr_f[0] & icache_en_d1[0] |
1375
//                            thr_f[1] & icache_en_d1[1] |
1376
//                            thr_f[2] & icache_en_d1[2] |
1377
//                            thr_f[3] & icache_en_d1[3]);
1378
//   assign icache_on_bf = switch_bf ? sw_icache_on : this_icache_on;
1379
 
1380
   assign icache_on_bf = (nextthr_final_bf[0] & icache_en_d1[0] |
1381
                          nextthr_final_bf[1] & icache_en_d1[1] |
1382
                          nextthr_final_bf[2] & icache_en_d1[2] |
1383
                          nextthr_final_bf[3] & icache_en_d1[3]);
1384
 
1385
   // remember if icache was turned on
1386 113 albert.wat
   dff_s #(1) icef_ff(.din (icache_on_bf),
1387 95 fafa1971
                              .q   (icache_on_f),
1388 113 albert.wat
                              .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1389
   dff_s #(1) ices_ff(.din (icache_on_f),
1390 95 fafa1971
                              .q   (icache_on_s1),
1391 113 albert.wat
                              .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1392 95 fafa1971
 
1393
   // check if cp is set
1394
   assign uncached_page_s1 = ~itlb_fcl_cp_s1 & cam_vld_s1;
1395
   assign fcl_ifq_icache_en_s_l = ~icache_on_s1 | uncached_page_s1;
1396
 
1397
   // Read from the icache only if 
1398
   //   we need to fetch AND 
1399
   //   the icache is on AND 
1400
   //   we are not using the NIR 
1401
   assign rdreq_bf = icache_on_bf & inst_access_bf;
1402
 
1403
   assign fcl_icd_rdreq_bf = rdreq_bf | ifq_fcl_rdreq_bf;
1404
 
1405
   // split off driver to icv to reduce load
1406
   assign fcl_icv_rdreq_bf = rdreq_bf | ifq_fcl_rdreq_bf;
1407
 
1408
   // Read req pipe
1409 113 albert.wat
   dffr_s #(1)  rdreq_ff(.din  (rdreq_bf),
1410 95 fafa1971
                                 .clk  (clk),
1411
                                 .rst  (fcl_reset),
1412
                                 .q    (rdreq_f),
1413 113 albert.wat
                                 .se   (se), `SIMPLY_RISC_SCANIN, .so());
1414 95 fafa1971
   // Remember if we fetched in the last cycle
1415 113 albert.wat
   dff_s #(1)  rdreqs1_ff (.din  (rdreq_f),
1416 95 fafa1971
                                   .clk  (clk),
1417
                                   .q    (rdreq_s1),
1418 113 albert.wat
                                   .se   (se), `SIMPLY_RISC_SCANIN, .so());
1419 95 fafa1971
   assign fcl_ifq_rdreq_s1 = ~stall_s1;
1420
 
1421
   // Use NIR pipe
1422
   assign usenir_bf = switch_bf ? usen_bf : usep_bf;
1423
 
1424 113 albert.wat
   dffr_s #(1)  unf_ff(.din  (usenir_bf),
1425 95 fafa1971
                                 .clk  (clk),
1426
                                 .rst  (fcl_reset),
1427
                                 .q    (usenir_f),
1428 113 albert.wat
                                 .se   (se), `SIMPLY_RISC_SCANIN, .so());
1429 95 fafa1971
   // Remember if we fetched in the last cycle
1430 113 albert.wat
   dff_s #(1)  uns1_ff (.din  (usenir_f),
1431 95 fafa1971
                                  .clk  (clk),
1432
                                  .q    (usenir_s1),
1433 113 albert.wat
                                  .se   (se), `SIMPLY_RISC_SCANIN, .so());
1434 95 fafa1971
 
1435
 
1436
   // Write signal to icache if no access from pipe
1437
   assign ic_wrreq_bf = allow_ifq_access_icd_bf & ifq_fcl_wrreq_bf;
1438
 
1439
   assign fcl_icd_wrreq_bf = ic_wrreq_bf | ifq_fcl_icd_wrreq_bf;
1440
   assign fcl_ict_wrreq_bf = ic_wrreq_bf | ifq_fcl_ictv_wrreq_bf;
1441
   assign fcl_icv_wrreq_bf = ic_wrreq_bf | ifq_fcl_ictv_wrreq_bf |
1442
                             ifq_fcl_invreq_bf;
1443
 
1444
   // synopsys translate_off
1445
   always @ (posedge clk)
1446
   begin
1447
            if (fcl_icd_rdreq_bf & fcl_icd_wrreq_bf)
1448
              begin
1449
                 // 0in <fire -message "ERROR: sparc_ifu_fcl: rd and wr req to I$ at the same time"
1450 113 albert.wat
`ifdef DEFINE_0IN
1451
`else
1452
                `ifdef MODELSIM
1453
                         $display( "CACHE_CONTENTION", "ERROR: sparc_ifu_fcl: rd and wr req to I$ at the same time");
1454
                `else
1455
                 $error("CACHE_CONTENTION", "ERROR: sparc_ifu_fcl: rd and wr req to I$ at the same time");
1456
                `endif
1457
`endif
1458 95 fafa1971
              end
1459
   end
1460
   // synopsys translate_on
1461
 
1462
 
1463
   //-------------------------
1464
   // Valid Instruction Pipe
1465
   //-------------------------
1466
   // F stage
1467
   assign inst_vld_bf = fetch_bf;
1468 113 albert.wat
   dff_s #(1) inst_vld_ff(.din (inst_vld_bf),
1469 95 fafa1971
                                  .clk (clk),
1470
                                  .q   (inst_vld_f),
1471 113 albert.wat
                                  .se  (se), `SIMPLY_RISC_SCANIN, .so());
1472 95 fafa1971
 
1473
   assign stall_f = ~inst_vld_f | kill_curr_f;
1474
   assign stall_thisthr_f = stall_f | imsto_thisthr_s1 | // intrto_thisthr_d |
1475
                                  kill_thread_s2 | rb_stg_s | ~dtu_fcl_running_s |
1476
                            iferrto_thisthr_d1;
1477
 
1478
   assign part_stall_thisthr_f = stall_f |
1479
                                 imsto_thisthr_s1 |
1480
                                 ~dtu_fcl_running_s |
1481
                                 ely_kill_thread_s2 |
1482
                                       rb_stg_s;
1483
 
1484
   assign ely_stall_thisthr_f = stall_f | rb_stg_s;
1485
 
1486
//   assign stall_s1_nxt = stall_thisthr_f | intr_vld_s | tmsto_thisthr_f;
1487
   assign stall_s1_nxt = stall_thisthr_f; //| intr_vld_s;
1488
 
1489
   // S1 stage
1490 113 albert.wat
   dff_s #(1) stalld_ff(.din (stall_s1_nxt),
1491 95 fafa1971
                                  .clk (clk),
1492
                                  .q   (stall_s1),
1493 113 albert.wat
                                  .se  (se), `SIMPLY_RISC_SCANIN, .so());
1494 95 fafa1971
 
1495
   assign inst_vld_s1 = ~stall_s1 & ~ic_miss_s1 & ~kill_curr_d;
1496
   assign val_thr_s1 = thr_s1 & {4{inst_vld_s1}}; // 4b
1497
 
1498
   // S2 stage
1499
   assign val_thr_f = thr_f & {4{~stall_f & ~rb_stg_s & dtu_fcl_running_s}};
1500
 
1501
   // Tag the S stage thr inst register as containing a valid inst or not
1502
   assign tinst_vld_nxt = (ifq_fcl_fill_thr |
1503
                           (rb_w2 & ~rb_for_iferr_e) | // set
1504
                                             val_thr_s1 & ~val_thr_f |
1505
                           //                      val_thr_s1 |
1506
                                             tinst_vld_s & ~val_thr_f) &
1507
                                              ~(clear_s_d1 |
1508
                              {4{erb_dtu_ifeterr_d1 & inst_vld_d1 &
1509
                                 ~rb_stg_e}} & thr_e);   // reset
1510
 
1511 113 albert.wat
   dffr_s #(4) tinst_reg(.din  (tinst_vld_nxt),
1512 95 fafa1971
                                 .clk  (clk),
1513
                                 .rst  (fcl_reset),
1514
                                 .q    (tinst_vld_s),
1515 113 albert.wat
                                 .se   (se), `SIMPLY_RISC_SCANIN, .so());
1516 95 fafa1971
 
1517
   // Does current thread have valid inst in s2
1518
   assign inst_vld_s2 = ((thr_f_crit & tinst_vld_s) == 4'b0000) ?
1519
                                            {1'b0} :  {1'b1};
1520
 
1521
   assign inst_vld_s = ~switch_s2 & inst_vld_s1 |
1522
                              switch_s2 & inst_vld_s2;
1523
   assign inst_vld_s_crit = ~switch_s2 & ~stall_s1 & ~kill_curr_d |
1524
                              switch_s2 & inst_vld_s2;
1525
 
1526
   assign valid_s = inst_vld_s & ~stall_f &  // f and s2 have same thread
1527
                       dtu_fcl_running_s &
1528
                             ~(ely_kill_thread_s2 | rb_stg_s);
1529
 
1530
   assign running_s2 = inst_vld_s & ~stall_thisthr_f;// f and s2 have 
1531
                                                     // same thread
1532
   // D stage
1533 113 albert.wat
   dff_s #(1) rund_ff(.din (running_s2),
1534 95 fafa1971
                              .clk (clk),
1535
                              .q   (inst_vld_d),
1536 113 albert.wat
                              .se  (se), `SIMPLY_RISC_SCANIN, .so());
1537
   dff_s #(1) eivd_ff(.din (running_s2),
1538 95 fafa1971
                                .clk (clk),
1539
                                .q   (inst_vld_d_crit),
1540 113 albert.wat
                                .se  (se), `SIMPLY_RISC_SCANIN, .so());
1541 95 fafa1971
   assign fcl_erb_inst_issue_d = inst_vld_d & ~intr_vld_d;
1542
   assign running_d = inst_vld_d & ~kill_thread_d & ~rb_stg_d &
1543
                            ~intr_vld_d;
1544
 
1545
   // E stage
1546 113 albert.wat
   dff_s #(1) rune_ff(.din (running_d),
1547 95 fafa1971
                              .clk (clk),
1548
                              .q   (inst_vld_e),
1549 113 albert.wat
                              .se  (se), `SIMPLY_RISC_SCANIN, .so());
1550 95 fafa1971
 
1551
   assign running_e = inst_vld_e & ~dtu_inst_anull_e &
1552
                            ~kill_curr_e & ~rb_stg_e &
1553
                      ~(thr_match_em & ifu_tlu_flush_m);
1554
   assign inst_vld_qual_e = inst_vld_e & ~rb_stg_e;
1555
   assign val_thr_e = thr_e_v2 & {4{inst_vld_qual_e}} & ~late_flush_w2 &
1556
                      ~(thr_w & {4{utrap_flush_w}});
1557
 
1558
 
1559
   // M stage
1560 113 albert.wat
   dff_s #(1) runm_ff(.din (running_e),
1561 95 fafa1971
                              .clk (clk),
1562
                              .q   (inst_vld_m),
1563 113 albert.wat
                              .se  (se), `SIMPLY_RISC_SCANIN, .so());
1564 95 fafa1971
   assign running_m = (inst_vld_m | intr_vld_m) & ~kill_thread_m;
1565
 
1566
   assign ifu_tlu_inst_vld_m = (inst_vld_m | intr_vld_m) & ~kill_curr_m;
1567
   // less critical
1568
   // assign ifu_lsu_inst_vld_m = ifu_tlu_inst_vld_m;
1569
 
1570
   // W stage
1571 113 albert.wat
   dff_s #(1) runw_ff(.din (running_m),
1572 95 fafa1971
                              .q   (inst_vld_w),
1573 113 albert.wat
                              .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1574 95 fafa1971
 
1575 113 albert.wat
   dff_s #(1) iw_ff(.din (running_m),
1576 95 fafa1971
                              .q   (inst_vld_w_crit),
1577 113 albert.wat
                              .clk (clk), .se  (se), `SIMPLY_RISC_SCANIN, .so());
1578 95 fafa1971
 
1579
   // synopsys translate_off
1580
//   wire         sas_m,
1581
//                          inst_done_w_for_sas;
1582
 
1583
//   assign sas_m = inst_vld_m & ~kill_thread_m & 
1584
//                      ~(exu_ifu_ecc_ce_m & inst_vld_m & ~trap_m);
1585
 
1586
//   dff #(1) sasw_ff(.din (sas_m),
1587
//                            .clk (clk),
1588
//                            .q   (inst_done_w_for_sas),
1589 113 albert.wat
//                            .se  (se), `SIMPLY_RISC_SCANIN, .so());   
1590 95 fafa1971
   // synopsys translate_on
1591
 
1592
   // need to kill branch by E stage, so qual with rb_stg_X
1593
   assign fcl_dtu_inst_vld_e = inst_vld_e & ~rb_stg_e & ~kill_curr_e;
1594
   assign fcl_dtu_intr_vld_e = intr_vld_e & ~rb_stg_e & ~kill_curr_e;
1595
   assign fcl_dtu_inst_vld_d = inst_vld_d & ~kill_curr_d &
1596
                                     ~rb_stg_d_crit & ~immu_miss_crit_d;
1597
   assign fcl_dtu_ely_inst_vld_d = inst_vld_d_crit;
1598
   assign ifu_tlu_inst_vld_w = inst_vld_w;
1599
   assign ifu_exu_inst_vld_w = inst_vld_w_crit;
1600
   assign ifu_spu_inst_vld_w = inst_vld_w;
1601
   assign ifu_exu_inst_vld_e = fcl_dtu_inst_vld_e;
1602
 
1603
   assign flush_sonly_qual_e = dtu_fcl_flush_sonly_e & inst_vld_e &
1604
//                               ~dec_fcl_kill4sta_e &
1605
                               ~rb_stg_e & ~dtu_inst_anull_e & ~kill_curr_e;
1606
 
1607
 
1608 113 albert.wat
   dff_s #(1) flshm_ff(.din (flush_sonly_qual_e),
1609 95 fafa1971
                     .q   (flush_sonly_m),
1610
                     .clk (clk),
1611 113 albert.wat
                     .se  (se), `SIMPLY_RISC_SCANIN, .so());
1612 95 fafa1971
 
1613 113 albert.wat
   dff_s #(1) imflshm_ff(.din (ifq_fcl_flush_sonly_e),
1614 95 fafa1971
                       .q   (ims_flush_sonly_m),
1615
                       .clk (clk),
1616 113 albert.wat
                       .se  (se), `SIMPLY_RISC_SCANIN, .so());
1617 95 fafa1971
   // detect collision between two different types of retractions
1618
   assign ims_flush_coll_m = ims_flush_sonly_m & ~canthr_sm &
1619
                             retract_iferr_e;
1620 113 albert.wat
   dff_s #(1) imflshw_ff(.din (ims_flush_coll_m),
1621 95 fafa1971
                       .q   (ims_flush_sonly_w),
1622
                       .clk (clk),
1623 113 albert.wat
                       .se  (se), `SIMPLY_RISC_SCANIN, .so());
1624 95 fafa1971
   assign ims_flush_coll_w = ims_flush_sonly_w & ~canthr_sw;
1625
   assign flush_sonly_qual_m = (ims_flush_sonly_m & ~canthr_sm &
1626
                                ~retract_iferr_e |
1627
                                flush_sonly_m & inst_vld_m & ~kill_local_m &
1628
                                ~kill_curr_m);
1629
   assign flush_sonly_all_m = (ims_flush_sonly_m & ~canthr_sm |
1630
                               flush_sonly_m & inst_vld_m);
1631
 
1632
//   assign flush_sonly_qual_m = flush_sonly_m & ~canthr_sm;
1633
//   assign qtrap_flush_e = dtu_fcl_qtrap_e & inst_vld_e & ~dtu_inst_anull_e & 
1634
//                        ~rb_stg_e;
1635
 
1636
//------------------------------   
1637
// Instruction Kill Logic
1638
//------------------------------
1639
 
1640
   // kill_s2 is the same as kill_f
1641
   assign kill_thread_s2 = thr_match_fw & rb_stg_w |
1642
//                               thr_match_ft & trappc_vld_w2 |
1643
                                 thr_match_fm & (flush_sonly_all_m) |
1644
                           kill_curr_f;
1645
 
1646
   assign ely_kill_thread_s2 = thr_match_fw & utrap_flush_w |
1647
//                                   thr_match_ft & trappc_vld_w2 |
1648
                                     thr_match_fm & (flush_sonly_all_m) |
1649
                               kill_curr_f;
1650
 
1651
   assign kill_thread_d = thr_match_dw & rb_stg_w |
1652
                                thr_match_dm & (flush_sonly_all_m) |
1653
                          kill_curr_d;
1654
 
1655
   // M and E still need full qualification with flush pipe   
1656
//   assign kill_thread_e = thr_match_ew & utrap_flush_w | 
1657
//                          thr_match_ew & tlu_ifu_flush_pipe_w | 
1658
//                          kill_curr_e ;
1659
   assign ely_kill_thread_m = thr_match_mw & utrap_flush_w |
1660
//                              mark4rb_m |
1661
                              kill_curr_m;
1662
   assign kill_thread_m = ely_kill_thread_m |
1663
                          thr_match_mw & tlu_ifu_flush_pipe_w;
1664
 
1665
   assign kill_local_m = thr_match_mw & (utrap_flush_w | intr_vld_w);
1666
 
1667
   assign flush_pipe_w = rb_stg_w | tlu_ifu_flush_pipe_w;
1668
//   assign part_flush_w = ifu_tlu_flush_w | tlu_ifu_flush_pipe_w;
1669
//   assign kill_nextthr_w = thr_match_nw & flush_pipe_w;
1670
   assign flush_thr_w = thr_w & {4{flush_pipe_w}};
1671 113 albert.wat
   dff_s #(1) fp_ff(.din (flush_pipe_w),
1672 95 fafa1971
                  .q   (flush_pipe_w2),
1673 113 albert.wat
                  .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1674 95 fafa1971
 
1675
//   assign clear_s_stage =  thr_e & {4{flush_sonly_qual_e}};
1676
//   assign clear_s_stage =  trap_thr & {4{trappc_vld_w2}} |
1677
//                               {4{dummy_flush_ireg}} | 
1678
//                               thr_e & {4{flush_sonly_qual_e}};
1679
                           //  | flush_thr_w 
1680
 
1681
   assign canthr_f = thr_e & {4{flush_sonly_qual_e}} |
1682
                     (rb_w2 & ~rb_for_iferr_e) | rb_froms;
1683
 
1684
//   dff #(4) cls_reg(.din (clear_s_stage),
1685
//                              .q   (clear_s_early),
1686 113 albert.wat
//                              .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1687 95 fafa1971
 
1688
   // ***NOTE***
1689
   // Don't use clear_s_d1 to generate fcl_ifq_canthr, since clear_s_d1 
1690
   // includes ifeterr!
1691
   // first term could be just flush_sonly_m & inst_vld_m & thr_m
1692
   assign clear_s_d1 = thr_m & {4{flush_sonly_all_m}} |
1693
                       late_flush_w2 |
1694
                       trap_thr & {4{trappc_vld_w2}};
1695
 
1696
   assign fcl_erb_clear_iferr = thr_m & {4{ims_flush_sonly_m |
1697
                                           flush_sonly_m}} |
1698
                                late_flush_w2 |
1699
                                trap_thr & {4{trappc_vld_w2}};
1700
 
1701
 
1702 113 albert.wat
   dff_s #(4) cm_reg(.din (canthr_f),
1703 95 fafa1971
                               .q   (canthr_s_early),
1704
                               .clk (clk),
1705 113 albert.wat
                               .se  (se), `SIMPLY_RISC_SCANIN, .so());
1706 95 fafa1971
 
1707
   assign canthr_s = canthr_s_early | late_flush_w2 |
1708
                     trap_thr & {4{trappc_vld_w2}};
1709
 
1710
//   assign fcl_ifq_canthr = clear_s_stage | rb_w2 | rb_froms | 
1711
//                               canthr_s;
1712
   assign fcl_ifq_canthr = canthr_s;
1713
 
1714
   assign canthr_sm = (canthr_s[0] & thr_m[0] |
1715
                       canthr_s[1] & thr_m[1] |
1716
                       canthr_s[2] & thr_m[2] |
1717
                       canthr_s[3] & thr_m[3]);
1718
 
1719
   assign canthr_sw = (canthr_s[0] & thr_w[0] |
1720
                       canthr_s[1] & thr_w[1] |
1721
                       canthr_s[2] & thr_w[2] |
1722
                       canthr_s[3] & thr_w[3]);
1723
 
1724
   assign canthr_sd = (canthr_s[0] & thr_d[0] |
1725
                       canthr_s[1] & thr_d[1] |
1726
                       canthr_s[2] & thr_d[2] |
1727
                       canthr_s[3] & thr_d[3]) |
1728
                        thr_match_dw & utrap_flush_w;
1729
 
1730 113 albert.wat
   dff_s #(4) fpw2_reg(.din (flush_thr_w),
1731 95 fafa1971
                     .q   (late_flush_w2),
1732 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1733 95 fafa1971
 
1734
//   assign late_flush_w2 = thr_w2 & {4{flush_pipe_w2}};
1735
 
1736
   assign kill_curr_f = (thr_f_crit[0] & late_flush_w2[0] |
1737
                         thr_f_crit[1] & late_flush_w2[1] |
1738
                         thr_f_crit[2] & late_flush_w2[2] |
1739
                         thr_f_crit[3] & late_flush_w2[3]);
1740
   assign kill_curr_d = (thr_d[0] & late_flush_w2[0] |
1741
                         thr_d[1] & late_flush_w2[1] |
1742
                         thr_d[2] & late_flush_w2[2] |
1743
                         thr_d[3] & late_flush_w2[3]);
1744
   assign kill_curr_e = (thr_e_v2[0] & late_flush_w2[0] |
1745
                         thr_e_v2[1] & late_flush_w2[1] |
1746
                         thr_e_v2[2] & late_flush_w2[2] |
1747
                         thr_e_v2[3] & late_flush_w2[3]) |
1748
                          thr_match_ew & utrap_flush_w;
1749
 
1750
//   assign kill_curr_m = (thr_m[0] & late_flush_w2[0] |
1751
//                         thr_m[1] & late_flush_w2[1] |
1752
//                         thr_m[2] & late_flush_w2[2] |
1753
//                         thr_m[3] & late_flush_w2[3]);
1754
   assign kill_curr_m = same_thr_mw2 & flush_pipe_w2;
1755
 
1756
   //------------------------------
1757
   // track I$ misses
1758
   //------------------------------
1759
 
1760
   // force a miss if a fetch and icache is off
1761
   // forcemiss triggers a fill vld_grequest to L2, so set to zero by default
1762
   assign forcemiss_f = inst_vld_f & ~icache_on_f;
1763 113 albert.wat
   dffr_s #(1)  miss_ff(.din (forcemiss_f),
1764 95 fafa1971
                                  .clk (clk),
1765
                                  .rst (fcl_reset),
1766
                                  .q   (forcemiss_s1),
1767 113 albert.wat
                                  .se  (se), `SIMPLY_RISC_SCANIN, .so());
1768 95 fafa1971
 
1769
   //ooooooooooooooooooooooooooooooooooooooooooooooooooooooo
1770
   // removed imiss_s_l from this signal for timing fix  
1771
   // Perf Hit: 0.2% TPCC, 0.4% JBB
1772
//   assign ic_miss_sw_s1 = (~itlb_fcl_imiss_s_l & rdreq_s1 |
1773
//                             tlb_cam_miss_s1 | 
1774
//                             forcemiss_s1);
1775
//   assign ic_miss_sw_s1 =   tlb_cam_miss_s1 | 
1776
//                            forcemiss_s1;
1777
   //ooooooooooooooooooooooooooooooooooooooooooooooooooooooo
1778
 
1779
   assign ic_miss_s1 =  (~itlb_fcl_imiss_s_l & rdreq_s1 |
1780
                                           forcemiss_s1) &
1781
                        ~stall_s1 & ~tlbmiss_s1_crit & ~pc_oor_s1 &
1782
                        ~rb_stg_d_crit & ~canthr_sd;
1783
 
1784
   assign icmiss_for_perf =  (~itlb_fcl_imiss_s_l & rdreq_s1) &
1785
                        ~stall_s1 & ~tlbmiss_s1_crit & ~pc_oor_s1 &
1786
                        ~rb_stg_d & ~canthr_sd;
1787
 
1788
//   assign fcl_ifq_icmiss_s1 = ic_miss_s1 & ~ely_kill_thread_d;  // use buffer
1789
   assign fcl_ifq_icmiss_s1 = ic_miss_s1;  // use buffer   
1790
 
1791
   // for perf counters (d1=e)
1792 113 albert.wat
   dff_s #(1) icmd1_ff(.din (icmiss_for_perf),
1793 95 fafa1971
                     .q   (ifu_tlu_icmiss_e),
1794 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1795 95 fafa1971
 
1796
   // I$ miss is always to thr_s1.  Below we check to see if this is
1797
   // the same as thr_f (=thr_s2) which is the "current thread"
1798
//   assign imsto_thisthr_s1 = thr_match_fd & ic_miss_s1;
1799
//   assign imsto_nextthr_s1 = thr_match_nd & (ic_miss_s1 | tlbmiss_s1);
1800
 
1801
   assign imsto_thisthr_s1 = thr_match_fd & ic_miss_s1;
1802
//   assign imsto_nextthr_s1 = thr_match_nd & (ic_miss_sw_s1);
1803
//   assign intrto_thisthr_d = thr_match_fd & fcl_dtu_sync_intr_d;
1804
 
1805
   assign iferrto_thisthr_d1 = thr_match_fe & erb_dtu_ifeterr_d1 &
1806
                               inst_vld_d1;
1807
 
1808
 
1809
//------------------------------
1810
// track itlb misses
1811
//------------------------------
1812
 
1813
   // default to hit when camming is turned off
1814
   assign tlb_cam_miss_f = ~itlb_fcl_tlbmiss_f_l & cam_vld_f;
1815 113 albert.wat
   dff_s #(1) tlbmsf_ff(.din (tlb_cam_miss_f),
1816 95 fafa1971
                                  .clk (clk),
1817
                                  .q   (tlb_cam_miss_s1),
1818 113 albert.wat
                                  .se  (se), `SIMPLY_RISC_SCANIN, .so());
1819 95 fafa1971
 
1820
   // tlb miss logic
1821
   // va hole has higher priority than immu miss
1822
   assign tlbmiss_s2 = (({4{tlbmiss_s1 & ~pc_oor_s1 & ~rb_stg_d}} & thr_s1) |
1823
                                          ({4{erb_fcl_itlb_ce_d1 & inst_vld_d1 &
1824
                            ~rb_stg_e}} & thr_e &
1825
                                           (~thr_d | {4{~inst_vld_d | ~thr_match_de}})) |
1826
                                          ({4{immu_miss_e}} & rb_frome) |
1827
                                          ({4{immu_miss_d}} & rb_fromd & ~rb_frome) |  // set
1828
                                          tlbmiss_d & (~thr_d | {4{~inst_vld_d}}) & ~rb_w2) &
1829
                                         ~(clear_s_d1); // reset
1830
 
1831
//   assign tlbmiss_s2 = (({4{tlbmiss_s1 & ~pc_oor_s1 & ~rb_stg_d}} & thr_s1) |
1832
//                      ({4{erb_fcl_itlb_ce_d1 & inst_vld_qual_d1}} & thr_e |
1833
//                       tlbmiss_d & (~thr_e | {4{~inst_vld_qual_e}}) & 
1834
//                       ~rb_w2) & ~(clear_s_stage); // reset
1835
 
1836 113 albert.wat
   dffr_s #(4) tlbmiss_reg(.din (tlbmiss_s2),
1837 95 fafa1971
                                     .q   (tlbmiss_d),
1838
                                     .clk (clk),
1839
                                     .rst (fcl_reset),
1840 113 albert.wat
                                     .se  (se), `SIMPLY_RISC_SCANIN, .so());
1841 95 fafa1971
 
1842
   assign immu_fault_f = (thr_f_crit[0] & (tlbmiss_d[0] | inst_acc_vec_d[0]) |
1843
                                            thr_f_crit[1] & (tlbmiss_d[1] | inst_acc_vec_d[1]) |
1844
                                            thr_f_crit[2] & (tlbmiss_d[2] | inst_acc_vec_d[2]) |
1845
                                            thr_f_crit[3] & (tlbmiss_d[3] | inst_acc_vec_d[3])) &
1846
                           switch_s2|
1847
                                             // D stage miss
1848
                                             (tlbmiss_s1 | pc_oor_s1) & thr_match_fs1;
1849
                                 // S stage miss
1850
 
1851
   assign immu_miss_crit_d = (thr_d[0] & tlbmiss_d[0] |
1852
                                                thr_d[1] & tlbmiss_d[1] |
1853
                                                thr_d[2] & tlbmiss_d[2] |
1854
                                                thr_d[3] & tlbmiss_d[3]);
1855
 
1856
   // TBD: move this to the E stage, post RB
1857
   assign immu_miss_d = immu_miss_crit_d & inst_vld_d |
1858
                                          thr_match_de & erb_fcl_itlb_ce_d1 & inst_vld_d1;
1859
 
1860
   // don't need to do this, once everyone switches to immu_miss_m
1861
   assign immu_miss_qual_d = immu_miss_d & ~kill_thread_d &
1862
                                    ~(immu_miss_e & thr_match_de &
1863
                                inst_vld_e & ~dtu_inst_anull_e & ~rb_stg_e &
1864
                                ~kill_curr_e);
1865
 
1866 113 albert.wat
   dff_s immu_misse_ff(.din (immu_miss_qual_d),
1867 95 fafa1971
                                 .clk (clk),
1868
                                 .q   (immu_miss_e),
1869 113 albert.wat
                                 .se  (se), `SIMPLY_RISC_SCANIN, .so());
1870 95 fafa1971
 
1871
 
1872
   // flop this and send in M
1873
//   assign ifu_tlu_immu_miss_e = immu_miss_e & ~addr_real_e & 
1874
//                                inst_vld_e & ~dtu_inst_anull_e & ~rb_stg_e;
1875
//   assign ifu_tlu_immu_miss_e = 1'b0;
1876
 
1877
//   assign immu_miss_qual_e = immu_miss_e & //~addr_real_e & 
1878
// //                             ~(immu_miss_m & thr_match_em) &
1879
//                             inst_vld_e & ~dtu_inst_anull_e & ~rb_stg_e;
1880
 
1881
//   dff #(1) immu_msm_ff(.din (immu_miss_qual_e),
1882 113 albert.wat
   dff_s #(1) immu_msm_ff(.din (immu_miss_e),
1883 95 fafa1971
                        .q   (immu_miss_m),
1884 113 albert.wat
                        .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1885 95 fafa1971
 
1886
   assign ifu_tlu_immu_miss_m = immu_miss_m & inst_vld_m & ~kill_curr_m;
1887
 
1888
   assign addr_real_e = (itlb_addr_real[0] & thr_e[0] |
1889
                         itlb_addr_real[1] & thr_e[1] |
1890
                         itlb_addr_real[2] & thr_e[2] |
1891
                         itlb_addr_real[3] & thr_e[3]);
1892
 
1893
   // store tlbmiss state for NIR
1894
   assign nir_tlbmiss_next = ({4{tlb_cam_miss_s1 & ~stall_s1}} & thr_s1 |
1895
                                                nir_tlbmiss_vec & (~thr_s1 | {4{stall_s1}}));
1896
 
1897 113 albert.wat
   dffr_s #(4) nirtlbm_reg(.din (nir_tlbmiss_next),
1898 95 fafa1971
                                   .clk (clk),
1899
                                   .q   (nir_tlbmiss_vec),
1900
                                   .rst (fcl_reset),
1901 113 albert.wat
                                   .se  (se), `SIMPLY_RISC_SCANIN, .so());
1902 95 fafa1971
 
1903
   assign nir_tlbmiss_s1 = (nir_tlbmiss_vec[0] & thr_s1[0] |
1904
                                              nir_tlbmiss_vec[1] & thr_s1[1] |
1905
                                              nir_tlbmiss_vec[2] & thr_s1[2] |
1906
                                              nir_tlbmiss_vec[3] & thr_s1[3]);
1907
 
1908
   assign tlbmiss_s1_crit = ~usenir_s1 ? tlb_cam_miss_s1 :
1909
                                               nir_tlbmiss_s1;
1910
 
1911
   assign tlbmiss_s1 = tlbmiss_s1_crit & ~stall_s1;
1912
 
1913
//---------------------------------
1914
//  Privilege Mode and VA Hole
1915
//---------------------------------
1916
   assign addr_mask_32b_m = (thr_m[0] & pstate_am_d1[0] |
1917
                                               thr_m[1] & pstate_am_d1[1] |
1918
                                               thr_m[2] & pstate_am_d1[2] |
1919
                                               thr_m[3] & pstate_am_d1[3]);
1920
 
1921
   assign fcl_fdp_mask32b_f = (thr_f[0] & pstate_am_d1[0] |
1922
                                                 thr_f[1] & pstate_am_d1[1] |
1923
                                                 thr_f[2] & pstate_am_d1[2] |
1924
                                                 thr_f[3] & pstate_am_d1[3]);
1925
 
1926 113 albert.wat
   dff_s #(1) amd_ff(.din (fcl_fdp_mask32b_f),
1927 95 fafa1971
                               .q   (fcl_fdp_addr_mask_d),
1928 113 albert.wat
                               .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1929 95 fafa1971
 
1930
   // keep track of whether pc is outside va hole
1931
   assign set_oor_m = exu_ifu_va_oor_m & brtaken_m & ~addr_mask_32b_m;
1932
   assign fcl_fdp_pcoor_vec_f = fdp_fcl_pc_oor_vec_f | {4{set_oor_m}} & thr_m;
1933
 
1934
   assign fcl_fdp_pcoor_f =  (thr_f[0] & fcl_fdp_pcoor_vec_f[0] |
1935
                                                thr_f[1] & fcl_fdp_pcoor_vec_f[1] |
1936
                                                thr_f[2] & fcl_fdp_pcoor_vec_f[2] |
1937
                                                thr_f[3] & fcl_fdp_pcoor_vec_f[3]);
1938
 
1939
   assign pc_oor_f = fcl_fdp_pcoor_f  & ~part_stall_thisthr_f;
1940 113 albert.wat
   dff_s oors1_ff(.din (pc_oor_f),
1941 95 fafa1971
                            .q   (pc_oor_s1),
1942 113 albert.wat
                            .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1943 95 fafa1971
 
1944
   // track privilege mode of current page
1945
   assign priv_mode_f = (thr_f[0] & tlu_lsu_pstate_priv[0] |
1946
                                           thr_f[1] & tlu_lsu_pstate_priv[1] |
1947
                                           thr_f[2] & tlu_lsu_pstate_priv[2] |
1948
                                           thr_f[3] & tlu_lsu_pstate_priv[3]);
1949
 
1950 113 albert.wat
   dff_s #(1) priv_ff(.din (priv_mode_f),
1951 95 fafa1971
                    .q   (priv_mode_s1),
1952 113 albert.wat
                    .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1953 95 fafa1971
 
1954
   // s1 and d are the same thread
1955
   assign fcl_dtu_privmode_d = priv_mode_s1;
1956
 
1957
   // hyper privilege
1958
   assign hpriv_mode_f = (thr_f[0] & tlu_hpstate_priv[0] |
1959
                                            thr_f[1] & tlu_hpstate_priv[1] |
1960
                                            thr_f[2] & tlu_hpstate_priv[2] |
1961
                                            thr_f[3] & tlu_hpstate_priv[3]);
1962
 
1963
   assign hpriv_mode_w = (thr_w[0] & tlu_hpstate_priv[0] |
1964
                                            thr_w[1] & tlu_hpstate_priv[1] |
1965
                                            thr_w[2] & tlu_hpstate_priv[2] |
1966
                                            thr_w[3] & tlu_hpstate_priv[3]);
1967
 
1968 113 albert.wat
   dff_s #(1) hprivd_ff(.din (hpriv_mode_f),
1969 95 fafa1971
                     .q   (hpriv_mode_s1),
1970 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1971 95 fafa1971
 
1972
   assign fcl_dtu_hprivmode_d = hpriv_mode_s1;
1973
 
1974 113 albert.wat
   dff_s #(1) hprivw2_ff(.din (hpriv_mode_w),
1975 95 fafa1971
                     .q   (hpriv_mode_w2),
1976 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
1977 95 fafa1971
   assign fcl_dtu_hprivmode_w2 = hpriv_mode_w2;
1978
 
1979
   // determine if priv page has been accessed in non priv mode
1980
   // or if we have fallen into the VA hole
1981
   assign inst_acc_exc_s1 = (priv_inst_s1 & ~(priv_mode_s1 | hpriv_mode_s1) &
1982
                                               ~tlbmiss_s1_crit & cam_vld_s1 |
1983
                                               pc_oor_s1) & ~stall_s1 & ~rb_stg_d;
1984
   assign pc_oor_s2 = (thr_f[0] & inst_acc_vec_d[0] |
1985
                       thr_f[1] & inst_acc_vec_d[1] |
1986
                       thr_f[2] & inst_acc_vec_d[2] |
1987
                       thr_f[3] & inst_acc_vec_d[3]);
1988
   assign pc_oor_s = (tm_fd_l) ? pc_oor_s2 : pc_oor_s1;
1989
 
1990
   assign inst_acc_vec_s2 = (({4{inst_acc_exc_s1}} & thr_s1) |
1991
                                               ({4{inst_acc_exc_e}} & rb_frome) |
1992
                                               ({4{inst_acc_exc_d}} & rb_fromd & ~rb_frome) |
1993
                                   inst_acc_vec_d & (~thr_d | {4{~inst_vld_d}}) &
1994
                                               ~rb_w2) &
1995
                                                ~(clear_s_d1);
1996
 
1997 113 albert.wat
   dffr_s #(4) instaccd_reg(.din (inst_acc_vec_s2),
1998 95 fafa1971
                                          .q   (inst_acc_vec_d),
1999
                                          .rst (fcl_reset),
2000 113 albert.wat
                                          .clk (clk), .se (se), `SIMPLY_RISC_SCANIN, .so());
2001 95 fafa1971
 
2002
   assign inst_acc_exc_d = (thr_d[0] & inst_acc_vec_d[0] |
2003
                                              thr_d[1] & inst_acc_vec_d[1] |
2004
                                              thr_d[2] & inst_acc_vec_d[2] |
2005
                                              thr_d[3] & inst_acc_vec_d[3]);
2006
 
2007 113 albert.wat
   dff_s #(1) instacce_ff(.din (inst_acc_exc_d),
2008 95 fafa1971
                                  .q   (inst_acc_exc_e),
2009 113 albert.wat
                                  .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2010 95 fafa1971
 
2011
   // TLU needs to know if this is a priv violtn
2012
   assign priv_violtn_e = inst_acc_exc_e & ~fdp_fcl_pc_oor_e;
2013 113 albert.wat
   dff_s #(1) privm_ff(.din (priv_violtn_e),
2014 95 fafa1971
                               .q   (priv_violtn_m),
2015 113 albert.wat
                               .clk (clk),  .se  (se), `SIMPLY_RISC_SCANIN, .so());
2016 95 fafa1971
 
2017
   assign ifu_tlu_priv_violtn_m = priv_violtn_m & inst_vld_m & ~kill_curr_m;
2018
 
2019
   // NIR privilege bit
2020
   assign next_nir_privvec = {4{itlb_fcl_priv_s1 & ~stall_s1 &
2021
                                cam_vld_s1}} & thr_s1 |
2022
                                   nir_privvec & (~thr_s1 | {4{stall_s1}});
2023
 
2024 113 albert.wat
   dffr_s #(4) nir_priv_reg(.din (next_nir_privvec),
2025 95 fafa1971
                                          .q   (nir_privvec),
2026
                                          .rst (fcl_reset),
2027 113 albert.wat
                                          .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2028 95 fafa1971
 
2029
   assign nir_priv_s1 = (nir_privvec[0] & thr_s1[0] |
2030
                                           nir_privvec[1] & thr_s1[1] |
2031
                                           nir_privvec[2] & thr_s1[2] |
2032
                                           nir_privvec[3] & thr_s1[3]);
2033
 
2034
   assign priv_inst_s1 = ~usenir_s1 ? (itlb_fcl_priv_s1 & cam_vld_s1) :
2035
                                        nir_priv_s1;
2036
 
2037
//-------------------------
2038
// Errors
2039
//-------------------------
2040
 
2041
   // decide when the errors are valid
2042
   assign running_s1 = ~stall_s1 & ~kill_thread_d & ~rb_stg_d & ~pc_oor_s1 &
2043
                             ~tlb_cam_miss_s1 & ~retract_inst_d;
2044
//   assign ely_running_s1 = ~stall_s1 & ~rb_stg_d & ~pc_oor_s1 & 
2045
//                           ~tlb_cam_miss_s1 & ~retract_inst_d & ~kill_curr_d;
2046
   assign ely_running_s1 = ~stall_s1 & ~rb_stg_d_crit & ~pc_oor_s1 &
2047
                           ~tlb_cam_miss_s1 & ~kill_curr_d;
2048
   assign fcl_erb_ievld_s1 = ely_running_s1 & rdreq_s1 & itlb_fcl_imiss_s_l;
2049
   assign fcl_erb_tevld_s1 = ely_running_s1 & rdreq_s1;
2050
 
2051
   assign fcl_erb_immuevld_s1 = ely_running_s1 & cam_vld_s1;
2052
 
2053
//   assign fcl_erb_ttevld_s1 = asird_s & rdtag_s;
2054
//   assign fcl_erb_tdevld_s1 = asird_s & ~rdtag_s;
2055
 
2056 113 albert.wat
   dff_s #(1) d1vld_ff(.din (running_s1),
2057 95 fafa1971
                                 .q   (inst_vld_d1),
2058 113 albert.wat
                                 .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2059 95 fafa1971
//   assign inst_vld_qual_d1 = inst_vld_d1 & ~kill_thread_e & 
2060
//                                 ~flush_sonly_qual_e & ~rb_stg_e;
2061
   assign fcl_erb_inst_vld_d1 = inst_vld_d1;
2062
 
2063
 
2064
   // ifetch unc. error
2065
   assign ifet_ue_vec_d1 = (erb_fcl_ifet_uevec_d1 |
2066
                                  ifet_ue_vec_e & ~val_thr_e) &   // reset
2067
                                               ~(clear_s_d1);                 // wins
2068
 
2069 113 albert.wat
   dffr_s #(4) ifuerr_reg(.din (ifet_ue_vec_d1),
2070 95 fafa1971
                                  .q   (ifet_ue_vec_e),
2071
                                  .rst (fcl_reset),
2072 113 albert.wat
                                  .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2073 95 fafa1971
 
2074
   assign ifet_ue_e = (ifet_ue_vec_e[0] & thr_e[0] |
2075
                                   ifet_ue_vec_e[1] & thr_e[1] |
2076
                                   ifet_ue_vec_e[2] & thr_e[2] |
2077
                                   ifet_ue_vec_e[3] & thr_e[3]);
2078
 
2079
 
2080
//----------------------
2081
// Other I side traps
2082
//----------------------
2083
   // Determine if we are in Trap Level 0
2084
   assign tlzero_s2 = (thr_f[0] & tlzero_vec_d1[0] |
2085
                                   thr_f[1] & tlzero_vec_d1[1] |
2086
                                   thr_f[2] & tlzero_vec_d1[2] |
2087
                                   thr_f[3] & tlzero_vec_d1[3]);
2088 113 albert.wat
   dff_s #(1) tlzd_ff(.din (tlzero_s2),
2089 95 fafa1971
                              .q   (fcl_dtu_tlzero_d),
2090 113 albert.wat
                              .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2091 95 fafa1971
 
2092
   // Collect all IFU traps
2093
   assign trap_e = (immu_miss_e | inst_acc_exc_e | dtu_fcl_illinst_e |
2094
                                dtu_fcl_fpdis_e | dtu_fcl_privop_e | ifet_ue_e |
2095
                                dtu_fcl_imask_hit_e | dtu_fcl_sir_inst_e) &
2096
                     inst_vld_e;
2097
 
2098 113 albert.wat
   dff_s trapm_ff(.din (trap_e),
2099 95 fafa1971
                            .q   (trap_m),
2100
                            .clk (clk),
2101 113 albert.wat
                            .se  (se), `SIMPLY_RISC_SCANIN, .so());
2102 95 fafa1971
 
2103
   assign no_iftrap_m = ~ifu_tlu_ttype_vld_m;
2104 113 albert.wat
   dff_s trapw_ff(.din (no_iftrap_m),
2105 95 fafa1971
                            .q   (no_iftrap_w),
2106
                            .clk (clk),
2107 113 albert.wat
                            .se  (se), `SIMPLY_RISC_SCANIN, .so());
2108 95 fafa1971
 
2109
   // south is very critical
2110
   assign ifu_tlu_ttype_vld_m = (trap_m & inst_vld_m |
2111
                                 disr_trap_m) & ~kill_curr_m & ~kill_local_m;
2112
   // less critical going east
2113
   assign ifu_exu_ttype_vld_m = trap_m & inst_vld_m;
2114
 
2115
   // less critical going southwest
2116
   assign ifu_mmu_trap_m = trap_m;
2117
 
2118
   // less critical going south   
2119
   assign ifu_tlu_trap_m = trap_m;
2120
 
2121
   // trap type priority encode
2122
   // Decreasing priority is
2123
   //   pc out of range           i_acc_exc
2124
   //   immu parity error         i_acc_err
2125
   //   immu miss                 i_acc_mmu_ms
2126
   //   icache/tag parity error   i_acc_err
2127
   //   privilege page            i_acc_exc
2128
   //   privilege opcode          priv_opc
2129
   //   illegal non-fp inst       ill_inst
2130
   //   soft reset                sir
2131
   //   fp disabled               fp_disabled
2132
   //   illegal fp instruction    ill_inst
2133
 
2134
   // Clean this up!!
2135
   assign ttype_sel_spuma_e = spuint1_qual_e;
2136
   assign ttype_sel_spuenc_e = spuint0_qual_e;
2137
   assign ttype_sel_corr_err_e = ceint_qual_e;
2138
   assign ttype_sel_unc_err_e = ueint_qual_e;
2139
   assign ttype_sel_res_err_e = rerr_qual_e;
2140
   assign ttype_sel_hstk_cmp_e = hintp_qual_e;
2141
 
2142
   assign ttype_sel_pcoor_e = fdp_fcl_pc_oor_e & inst_acc_exc_e;
2143
   assign ttype_sel_icache_err_e = ifet_ue_e;
2144
   assign ttype_sel_immu_miss_e = ~fdp_fcl_pc_oor_e & immu_miss_e &
2145
                                  ~addr_real_e;
2146
   assign ttype_sel_real_trans_e = ~fdp_fcl_pc_oor_e & immu_miss_e &
2147
                                   addr_real_e;
2148
   assign ttype_sel_priv_viol_e = ~fdp_fcl_pc_oor_e & ~immu_miss_e &
2149
                                   inst_acc_exc_e;
2150
   assign ttype_sel_ibe_e = ~fdp_fcl_pc_oor_e & ~immu_miss_e &
2151
                                ~inst_acc_exc_e & dtu_fcl_imask_hit_e;
2152
   assign ttype_sel_privop_e = ~fdp_fcl_pc_oor_e & ~immu_miss_e &
2153
                               ~inst_acc_exc_e & dtu_fcl_privop_e;
2154
   assign ttype_sel_illinst_e = ~fdp_fcl_pc_oor_e & ~immu_miss_e &
2155
                                ~inst_acc_exc_e & dtu_fcl_illinst_e;
2156
   assign ttype_sel_sir_e = ~fdp_fcl_pc_oor_e & ~immu_miss_e &
2157
                            ~inst_acc_exc_e & ~dtu_fcl_illinst_e &
2158
                             dtu_fcl_sir_inst_e;
2159
 
2160
   assign ttype_sel_fpdis_e = ~fdp_fcl_pc_oor_e & ~immu_miss_e &
2161
                              ~inst_acc_exc_e & ~dtu_fcl_illinst_e &
2162
                               dtu_fcl_fpdis_e;
2163
 
2164
   // mux in the trap type
2165 113 albert.wat
   assign ttype_e[8:0] = ttype_sel_unc_err_e    ? `DATA_ERR  :
2166
                   ttype_sel_hstk_cmp_e   ? `HSTICK_CMP    :
2167
                         ttype_sel_spuma_e      ? `SPU_MAINT     :
2168
                         ttype_sel_spuenc_e     ? `SPU_ENCINT    :
2169
                         ttype_sel_corr_err_e   ? `CORR_ECC_ERR  :
2170
                   ttype_sel_res_err_e    ? `RESUMABLE_ERR :
2171 95 fafa1971
 
2172 113 albert.wat
                         ttype_sel_pcoor_e      ? `INST_ACC_EXC  :
2173
                         ttype_sel_immu_miss_e  ? `FAST_MMU_MS   :
2174
                         ttype_sel_real_trans_e ? `REAL_TRANS_MS :
2175
                         ttype_sel_icache_err_e ? `INST_ACC_ERR  :
2176
                         ttype_sel_priv_viol_e  ? `INST_ACC_EXC  :
2177
                         ttype_sel_ibe_e        ? `INST_BRK_PT   :
2178
                         ttype_sel_privop_e     ? `PRIV_OPC :
2179
                         ttype_sel_illinst_e    ? `ILL_INST :
2180
                         ttype_sel_sir_e        ? `SIR      :
2181
                         ttype_sel_fpdis_e      ? `FP_DISABLED :
2182 95 fafa1971
                                                   9'h1ff;
2183
 
2184 113 albert.wat
   dff_s #(9) ttype_reg(.din (ttype_e[8:0]),
2185 95 fafa1971
                                .q   (ifu_tlu_ttype_m[8:0]),
2186 113 albert.wat
                                .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2187 95 fafa1971
 
2188
//------------------------------
2189
// Interrupts and Resets
2190
//------------------------------
2191
   // Process resets to see if they are sync or async
2192
   assign intr_in_pipe = ({4{intr_vld_d}} & thr_d |
2193
                          {4{intr_vld_e}} & thr_e |
2194
                          {4{intr_vld_m}} & thr_m |
2195
                          {4{intr_vld_w}} & thr_w);
2196
 
2197
//   assign async_rst_i2 = tlu_ifu_rstthr_i2  & {4{tlu_ifu_rstint_i2}} &
2198
   assign async_rst_i3 = (rstint_i3 | nuke_thr_i3 | resumint_i3) &
2199
                           ~dtu_fcl_thr_active & ~intr_in_pipe;
2200
 
2201 113 albert.wat
   dff_s #(4) asyrst4_reg(.din (async_rst_i3),
2202 95 fafa1971
                        .q   (async_rst_i4),
2203 113 albert.wat
                        .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2204 95 fafa1971
 
2205
   // stall pipe before switching in rst thread
2206
   assign rst_stallreq_d0 = (|async_rst_i4[3:0]);
2207
   assign rst_stallreq = rst_stallreq_d0 | rst_stallreq_d1 | rst_stallreq_d2;
2208
 
2209 113 albert.wat
   dff_s #(2) stlreq_reg(.din ({lsu_ifu_stallreq,
2210 95 fafa1971
                              ffu_ifu_stallreq}),
2211
                       .q   ({lsu_stallreq_d1,
2212
                              ffu_stallreq_d1}),
2213 113 albert.wat
                       .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2214 95 fafa1971
 
2215 103 fafa1971
   assign all_stallreq = ifq_fcl_stallreq | lsu_stallreq_d1 |
2216 95 fafa1971
                         ffu_stallreq_d1 | itlb_starv_alert;
2217
 
2218
   // leave out stall from ifq which goes directly to swl
2219
   assign fcl_dtu_stall_bf = lsu_stallreq_d1 | ffu_stallreq_d1 |
2220
                             itlb_starv_alert | rst_stallreq;
2221
 
2222
   // priority encode rst interrupts
2223
   // this could lead to obvious starvation of thr3, the assumption is that
2224
   // idle/resume/reset interrupts do not occur very frequently
2225
   assign rstint_penc[0] = async_rst_i4[0];
2226
   assign rstint_penc[1] = ~async_rst_i4[0] & async_rst_i4[1];
2227
   assign rstint_penc[2] = ~async_rst_i4[0] & ~async_rst_i4[1]  &
2228
                                  async_rst_i4[2];
2229
   assign rstint_penc[3] = ~async_rst_i4[0] & ~async_rst_i4[1]  &
2230
                                 ~async_rst_i4[2];
2231
 
2232
   // BF - switch in rst thread
2233 113 albert.wat
   dff_s #(1) asyncr1_ff(.din (rst_stallreq_d0),
2234 95 fafa1971
                                   .q   (rst_stallreq_d1),
2235 113 albert.wat
                                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2236 95 fafa1971
   assign arst_vld_f_l = ~arst_vld_f;
2237
   assign arst_vld_s_l = ~arst_vld_s;
2238
   bw_u1_nand3_4x UZsize_rstsw_n3(.z (rst_sw_bf_l),
2239
                                  .a (arst_vld_f_l),
2240
                                  .b (arst_vld_s_l),
2241
                                  .c (rst_stallreq_d1));
2242
   assign rst_sw_bf = ~rst_sw_bf_l;
2243
 
2244
   // double check if asyn intrs are still valid
2245
   assign sw_for_real_rst_bf = rst_sw_bf & rst_stallreq_d0;
2246
 
2247
   // F
2248 113 albert.wat
   dff_s #(1) asyncr2_ff(.din (sw_for_real_rst_bf),
2249 95 fafa1971
                                   .q   (rst_stallreq_d2),
2250 113 albert.wat
                                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2251 95 fafa1971
//   assign arst_vld_f = rst_stallreq_d2 & any_rstnuke_f;
2252
   assign arst_vld_f = rst_stallreq_d2;
2253
 
2254
   // hold thread till reset of curr thread is processed
2255
//   assign rst_thr_bf = arst_vld_f ? thr_f : rstint_penc;
2256
 
2257
   // S issue to pipe
2258 113 albert.wat
   dff_s #(1) rstvlds_ff(.din (arst_vld_f),
2259 95 fafa1971
                                   .q   (arst_vld_s),
2260 113 albert.wat
                                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2261 95 fafa1971
   assign async_intr_vld_s = arst_vld_s & ~kill_intr_f; // & any_rstnuke_f 
2262
 
2263
 
2264
   //
2265
   // thread wise interrupts
2266
   //
2267
   assign rstint_i2 = {4{tlu_ifu_rstint_i2}} & tlu_ifu_rstthr_i2;
2268
   assign resumint_i2 = {4{tlu_ifu_resumint_i2}} & tlu_ifu_rstthr_i2;
2269
   assign nuke_thr_i2 =  {4{tlu_ifu_nukeint_i2}} & tlu_ifu_rstthr_i2;
2270
 
2271
   assign next_rst_i2 = rstint_i2 |
2272
                              rstint_i3 & (~(thr_w & {4{fcl_dtu_rst_thr_w}}));
2273
   assign next_resum_i2 = resumint_i2 |
2274
                                resumint_i3 & (~(thr_w & {4{fcl_dtu_resum_thr_w}}))
2275
                          & ~rstint_i2;
2276
 
2277
   assign next_nuke_i2  = (nuke_thr_i2 | nuke_thr_i3) &
2278
                            (~(thr_w & {4{fcl_dtu_nuke_thr_w}})) &
2279
                               ~(rstint_i2 | resumint_i2);
2280
 
2281
   assign next_sftint_i2 = tlu_ifu_sftint_vld;
2282
   assign next_hwint_i3 = tlu_ifu_hwint_i3;
2283
   assign next_hintp_i2 = tlu_ifu_hintp_vld;
2284
   assign next_rerr_i2 = tlu_ifu_rerr_vld;
2285
 
2286
   assign next_ceint_i2 = erb_fcl_ce_trapvec |
2287
                                ceint_i3 & (~(thr_w & {4{ceint_qual_w}}));
2288
 
2289
   assign next_ueint_i2 = erb_fcl_ue_trapvec |
2290
                                ueint_i3 & (~(thr_w & {4{ueint_qual_w}}));
2291
 
2292
   // From Farnad: tid is ready several cycles before everything else
2293
   // I will assume 1 cycle before in the ifu
2294 113 albert.wat
   dff_s #(2) sptid_reg(.din (spu_ifu_ttype_tid_w2),
2295 95 fafa1971
                      .q   (spu_tid_w2),
2296 113 albert.wat
                      .clk (clk), .se(se), .so(), `SIMPLY_RISC_SCANIN);
2297 95 fafa1971
 
2298
   assign spu_thr[0] = ~spu_tid_w2[1] & ~spu_tid_w2[0];
2299
   assign spu_thr[1] = ~spu_tid_w2[1] &  spu_tid_w2[0];
2300
   assign spu_thr[2] =  spu_tid_w2[1] & ~spu_tid_w2[0];
2301
   assign spu_thr[3] =  spu_tid_w2[1] &  spu_tid_w2[0];
2302
 
2303
   assign next_spuint1_i2 = {4{spu_ifu_ttype_vld_w2 & spu_ifu_ttype_w2}} &
2304
                                  spu_thr & ~erb_fcl_spu_uetrap |
2305
                                  spuint1_i3 & ~({4{spuint1_w}} & thr_w);
2306
 
2307
   assign next_spuint0_i2 = {4{spu_ifu_ttype_vld_w2 & ~spu_ifu_ttype_w2}} &
2308
                                  spu_thr & ~erb_fcl_spu_uetrap |
2309
                                  spuint0_i3 & ~({4{spuint0_w}} & thr_w);
2310
 
2311
 
2312 113 albert.wat
   dffr_s #(4) rst_reg(.din  (next_rst_i2),
2313 95 fafa1971
                                 .q    (rstint_i3),
2314
                                 .clk  (clk),
2315
                                 .rst  (fcl_reset),
2316 113 albert.wat
                                 .se   (se), `SIMPLY_RISC_SCANIN, .so());
2317 95 fafa1971
 
2318 113 albert.wat
   dffr_s #(4) resum_reg(.din  (next_resum_i2),
2319 95 fafa1971
                                   .q    (resumint_i3),
2320
                                   .clk  (clk),
2321
                                   .rst  (fcl_reset),
2322 113 albert.wat
                                   .se   (se), `SIMPLY_RISC_SCANIN, .so());
2323 95 fafa1971
 
2324 113 albert.wat
   dffr_s #(4) nuke_reg(.din  (next_nuke_i2),
2325 95 fafa1971
                                  .q    (nuke_thr_i3),
2326
                                  .rst  (fcl_reset),
2327
                                  .clk  (clk),
2328 113 albert.wat
                                  .se   (se), `SIMPLY_RISC_SCANIN, .so());
2329 95 fafa1971
 
2330 113 albert.wat
   dffr_s #(4) sfti_reg(.din  (next_sftint_i2),
2331 95 fafa1971
                                  .q    (sftint_i3),
2332
                                  .rst  (fcl_reset),
2333 113 albert.wat
                                  .clk  (clk), .se   (se), `SIMPLY_RISC_SCANIN, .so());
2334
   dffr_s #(4) hstki_reg(.din  (next_hintp_i2),
2335 95 fafa1971
                                  .q    (hintp_i3),
2336
                                  .rst  (fcl_reset),
2337 113 albert.wat
                                  .clk  (clk), .se   (se), `SIMPLY_RISC_SCANIN, .so());
2338
   dffr_s #(4) reri_reg(.din  (next_rerr_i2),
2339 95 fafa1971
                                  .q    (rerr_i3),
2340
                                  .rst  (fcl_reset),
2341 113 albert.wat
                                  .clk  (clk), .se   (se), `SIMPLY_RISC_SCANIN, .so());
2342
   dffr_s #(4) hwi_reg(.din  (next_hwint_i3),
2343 95 fafa1971
                                 .q    (hwint_i4),
2344
                                 .rst  (fcl_reset),
2345 113 albert.wat
                                 .clk  (clk), .se   (se), `SIMPLY_RISC_SCANIN, .so());
2346 95 fafa1971
 
2347 113 albert.wat
   dffr_s #(4) spui0_reg(.din  (next_spuint0_i2),
2348 95 fafa1971
                                   .q    (spuint0_i3),
2349
                                   .rst  (fcl_reset),
2350 113 albert.wat
                                   .clk  (clk), .se   (se), `SIMPLY_RISC_SCANIN, .so());
2351 95 fafa1971
 
2352 113 albert.wat
   dffr_s #(4) spui1_reg(.din  (next_spuint1_i2),
2353 95 fafa1971
                                   .q    (spuint1_i3),
2354
                                   .rst  (fcl_reset),
2355 113 albert.wat
                                   .clk  (clk), .se   (se), `SIMPLY_RISC_SCANIN, .so());
2356 95 fafa1971
 
2357 113 albert.wat
   dffr_s #(4) cei_reg(.din  (next_ceint_i2),
2358 95 fafa1971
                                 .q    (ceint_i3),
2359
                                 .rst  (fcl_reset),
2360 113 albert.wat
                                 .clk  (clk), .se   (se), `SIMPLY_RISC_SCANIN, .so());
2361 95 fafa1971
 
2362 113 albert.wat
   dffr_s #(4) uei_reg(.din  (next_ueint_i2),
2363 95 fafa1971
                                 .q    (ueint_i3),
2364
                                 .rst  (fcl_reset),
2365 113 albert.wat
                                 .clk  (clk), .se   (se), `SIMPLY_RISC_SCANIN, .so());
2366 95 fafa1971
 
2367
   assign supv_int_en = (~tlu_hpstate_priv | ~tlu_hpstate_enb) &
2368
                         tlu_ifu_pstate_ie & dtu_fcl_thr_active;
2369
   assign hypv_int_en = ~tlu_hpstate_priv & tlu_hpstate_enb |
2370
                        tlu_ifu_pstate_ie & dtu_fcl_thr_active;
2371
 
2372 113 albert.wat
   dff_s #(4) spvie_ff(.din (supv_int_en),
2373 95 fafa1971
                     .q   (supv_int_en_d1),
2374 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2375
   dff_s #(4) hpvie_ff(.din (hypv_int_en),
2376 95 fafa1971
                     .q   (hypv_int_en_d1),
2377 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2378 95 fafa1971
 
2379
   // force an interrupt by putting nop on pipe
2380
   // use this signal instead of hw_int_s to help with crit path
2381
   assign supv_masked_intr_s = (sftint_i3        |
2382
                                                  rerr_i3);
2383
   assign hypv_masked_intr_s = (hwint_i4         |
2384
                                                  hintp_i3         |
2385
                                                  ceint_i3         |
2386
                                                  ueint_i3         |
2387
                                                  spuint0_i3       |
2388
                                                  spuint1_i3);
2389
 
2390
   assign fcl_swl_int_activate_i3 = hypv_masked_intr_s |
2391
                                    supv_masked_intr_s;
2392
 
2393
    // keep track of rolled back interrupts
2394
   assign intr_pending_nxt =  (({4{intr_vld_e}} & rb_frome) |
2395
                               ({4{intr_vld_d}} & rb_fromd & ~rb_frome) |
2396
                                intr_pending_s) & ~clear_s_d1;
2397
 
2398 113 albert.wat
   dffr_s #(4) ipend_reg(.din (intr_pending_nxt),
2399 95 fafa1971
                       .q   (intr_pending_s),
2400
                       .rst (fcl_reset),
2401 113 albert.wat
                       .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2402 95 fafa1971
 
2403
   assign any_intr_vec_f = (supv_masked_intr_s & supv_int_en_d1 |
2404
                            hypv_masked_intr_s & hypv_int_en_d1 |
2405
                            intr_pending_s    |
2406
                                              rstint_i3         |
2407
                            resumint_i3       |
2408
                                              nuke_thr_i3);
2409
 
2410 113 albert.wat
   dff_s #(4) anyints_reg(.din (any_intr_vec_f),
2411 95 fafa1971
                        .q   (any_intr_vec_s),
2412 113 albert.wat
                        .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2413 95 fafa1971
 
2414
   assign force_intr_s = (thr_f_crit[0] & any_intr_vec_s[0] |
2415
                          thr_f_crit[1] & any_intr_vec_s[1] |
2416
                          thr_f_crit[2] & any_intr_vec_s[2] |
2417
                          thr_f_crit[3] & any_intr_vec_s[3]) &
2418
                                 ~kill_intr_f;
2419
 
2420
   // interrupt and reset signal pipe
2421
   // VA hole trap has higher priority than interrupt
2422
   //   - since the VA hole marker is lost once the intr is taken
2423
   assign intr_vld_s = force_intr_s & (valid_s & ~pc_oor_s |
2424
                                       async_intr_vld_s);
2425
 
2426
   assign intr_vld_qual_s = intr_vld_s & ~iferrto_thisthr_d1;
2427 113 albert.wat
   dff_s #(1) any_intrd_ff(.din (intr_vld_qual_s),
2428 95 fafa1971
                                     .q   (intr_vld_d),
2429
                                     .clk (clk),
2430 113 albert.wat
                                     .se  (se), .so(), `SIMPLY_RISC_SCANIN);
2431 95 fafa1971
   assign fcl_dec_intr_vld_d = intr_vld_d;
2432
   assign intr_vld_qual_d = intr_vld_d & ~kill_intr_d & ~kill_thread_d &
2433
                                   ~rb_stg_d;
2434
 
2435 113 albert.wat
   dff_s #(1) intr_vlde_ff(.din (intr_vld_qual_d),
2436 95 fafa1971
                                   .q   (intr_vld_e),
2437 113 albert.wat
                                   .clk (clk), .se  (se), .so(), `SIMPLY_RISC_SCANIN);
2438 95 fafa1971
 
2439
   assign intr_vld_qual_e = intr_vld_e & ~kill_curr_e & ~rb_stg_e &
2440
                            ~kill_intr_e & ~dtu_inst_anull_e &
2441
                      ~(thr_match_em & ifu_tlu_flush_m);
2442
 
2443 113 albert.wat
   dff_s #(1) intr_vldm_ff(.din (intr_vld_qual_e),
2444 95 fafa1971
                                   .q   (intr_vld_m),
2445 113 albert.wat
                                   .clk (clk), .se  (se), .so(), `SIMPLY_RISC_SCANIN);
2446 95 fafa1971
 
2447
   assign intr_vld_qual_m = intr_vld_m & ~kill_thread_m & ~mark4rb_m;
2448
 
2449 113 albert.wat
   dff_s #(1) intr_vldw_ff(.din (intr_vld_qual_m),
2450 95 fafa1971
                                   .q   (intr_vld_w),
2451 113 albert.wat
                                   .clk (clk), .se  (se), .so(), `SIMPLY_RISC_SCANIN);
2452 95 fafa1971
 
2453
   // Reset and Idle are prioritized in M.  All others in E
2454
   // reset interrupt
2455
   assign rstint_m = (rstint_i3[0] & thr_m[0] |
2456
                                        rstint_i3[1] & thr_m[1] |
2457
                                        rstint_i3[2] & thr_m[2] |
2458
                                        rstint_i3[3] & thr_m[3]);
2459
 
2460
   assign ifu_tlu_rstint_m = rstint_m & intr_vld_m & ~kill_local_m &
2461
                             ~kill_curr_m;
2462
//   assign rstint_qual_m = rstint_m & ~ely_kill_thread_m & intr_vld_m;
2463 113 albert.wat
   dff_s #(1) rstw_ff(.din (rstint_m),
2464 95 fafa1971
                    .q   (rst_thr_w),
2465 113 albert.wat
                    .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2466 95 fafa1971
   assign fcl_dtu_rst_thr_w = rst_thr_w & intr_vld_w;
2467
 
2468
   // resume interrupt
2469
   assign resumint_m = (resumint_i3[0] & thr_m[0] |
2470
                                          resumint_i3[1] & thr_m[1] |
2471
                                          resumint_i3[2] & thr_m[2] |
2472
                                          resumint_i3[3] & thr_m[3]);
2473
   assign resumint_qual_m = resumint_m & ~rstint_m;
2474
 
2475 113 albert.wat
   dff_s #(1) resumw_ff(.din (resumint_qual_m),
2476 95 fafa1971
                      .q   (resum_thr_w),
2477 113 albert.wat
                      .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2478 95 fafa1971
   assign fcl_dtu_resum_thr_w = resum_thr_w & intr_vld_w;
2479
 
2480
   // idle interrupt
2481
   assign nuke_thr_m = (nuke_thr_i3[0] & thr_m[0] |
2482
                                                nuke_thr_i3[1] & thr_m[1] |
2483
                                                nuke_thr_i3[2] & thr_m[2] |
2484
                                                nuke_thr_i3[3] & thr_m[3]);
2485
 
2486
   assign nuke_thr_qual_m = nuke_thr_m & ~rstint_m & ~resumint_m;
2487
 
2488 113 albert.wat
   dff_s #(1) nukw_ff(.din (nuke_thr_qual_m),
2489 95 fafa1971
                    .q   (nuke_thr_w),
2490
                    .clk (clk),
2491 113 albert.wat
                    .se  (se), `SIMPLY_RISC_SCANIN, .so());
2492 95 fafa1971
   assign fcl_dtu_nuke_thr_w = nuke_thr_w & intr_vld_w;
2493
 
2494
   // uncorrected ecc
2495
   assign ueint_e = (ueint_i3[0] & thr_e[0] & hypv_int_en_d1[0] |
2496
                                 ueint_i3[1] & thr_e[1] & hypv_int_en_d1[1] |
2497
                                 ueint_i3[2] & thr_e[2] & hypv_int_en_d1[2] |
2498
                                 ueint_i3[3] & thr_e[3] & hypv_int_en_d1[3]);
2499
   assign ueint_qual_e = ueint_e & intr_vld_e;
2500
 
2501 113 albert.wat
   dff_s #(1) uem_ff (.din (ueint_qual_e),
2502 95 fafa1971
                    .q   (ueint_m),
2503 113 albert.wat
                    .clk (clk), .se (se), `SIMPLY_RISC_SCANIN, .so());
2504 95 fafa1971
 
2505
//   assign ueint_m = (ueint_i3[0] & thr_m[0] |
2506
//                               ueint_i3[1] & thr_m[1] |
2507
//                               ueint_i3[2] & thr_m[2] |
2508
//                               ueint_i3[3] & thr_m[3]);
2509
 
2510
   assign ueint_trap_m = ueint_m & intr_vld_m &
2511
                         ~(rstint_m | resumint_m | nuke_thr_m);
2512
 
2513
//   assign ueint_qual_m = ueint_trap_m & ~ely_kill_thread_m;
2514 113 albert.wat
   dff_s #(1) ueintw_ff(.din (ueint_trap_m),
2515 95 fafa1971
                      .q   (ueint_trap_w),
2516 113 albert.wat
                      .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2517 95 fafa1971
   assign ueint_qual_w = ueint_trap_w & intr_vld_w;
2518
 
2519
   // hstk match interrupt
2520
   assign hintp_e = (hintp_i3[0] & thr_e[0] & hypv_int_en_d1[0] |
2521
                                       hintp_i3[1] & thr_e[1] & hypv_int_en_d1[1] |
2522
                                       hintp_i3[2] & thr_e[2] & hypv_int_en_d1[2] |
2523
                                       hintp_i3[3] & thr_e[3] & hypv_int_en_d1[3]);
2524
   assign hintp_qual_e = hintp_e & intr_vld_e & ~ueint_e;
2525
 
2526 113 albert.wat
   dff_s #(1) hintpm_ff (.din (hintp_qual_e),
2527 95 fafa1971
                       .q   (hintp_m),
2528 113 albert.wat
                       .clk (clk), .se (se), `SIMPLY_RISC_SCANIN, .so());
2529 95 fafa1971
 
2530
//   assign ifu_tlu_hintp_m = hintp_m & ~kill_local_m & intr_vld_m & 
2531
//                          ~(rstint_m | nuke_thr_m | ueint_m);
2532
 
2533
   // hw int
2534
   assign hwint_e = (hwint_i4[0] & thr_e[0] & hypv_int_en_d1[0] |
2535
                                       hwint_i4[1] & thr_e[1] & hypv_int_en_d1[1] |
2536
                                       hwint_i4[2] & thr_e[2] & hypv_int_en_d1[2] |
2537
                                       hwint_i4[3] & thr_e[3] & hypv_int_en_d1[3]);
2538 113 albert.wat
   dff_s #(1) hwe_ff(.din (hwint_e),
2539 95 fafa1971
                   .q   (hwint_m),
2540 113 albert.wat
                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2541 95 fafa1971
 
2542
   assign ifu_tlu_hwint_m = hwint_m & intr_vld_m & ~kill_local_m &
2543
                     ~kill_curr_m &
2544
                           ~(rstint_m | resumint_m | nuke_thr_m | ueint_m | hintp_m);
2545
 
2546
 
2547
   // spu interrupt
2548
   assign spuint1_e = (spuint1_i3[0] & thr_e[0] & hypv_int_en_d1[0] |
2549
                                   spuint1_i3[1] & thr_e[1] & hypv_int_en_d1[1] |
2550
                                   spuint1_i3[2] & thr_e[2] & hypv_int_en_d1[2] |
2551
                                   spuint1_i3[3] & thr_e[3] & hypv_int_en_d1[3]);
2552
   assign spuint1_qual_e = spuint1_e & intr_vld_e & ~ueint_e & ~hintp_e;
2553
 
2554
//   assign spuint1_m = (spuint1_i3[0] & thr_m[0] |
2555
//                                 spuint1_i3[1] & thr_m[1] |
2556
//                                 spuint1_i3[2] & thr_m[2] |
2557
//                                 spuint1_i3[3] & thr_m[3]);
2558
 
2559 113 albert.wat
   dff_s #(1) spu1m_ff(.din (spuint1_qual_e),
2560 95 fafa1971
                     .q   (spuint1_m),
2561 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2562 95 fafa1971
 
2563
   assign spuint1_trap_m = spuint1_m & intr_vld_m &
2564
                            ~(rstint_m | resumint_m | nuke_thr_m | hwint_m);
2565
 
2566
//   assign spuint1_qual_m = spuint1_trap_m & ~ely_kill_thread_m;
2567
 
2568 113 albert.wat
   dff_s #(1) spiw1_ff(.din (spuint1_trap_m),
2569 95 fafa1971
                                 .q   (spuint1_trap_w),
2570 113 albert.wat
                                 .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2571 95 fafa1971
   assign spuint1_w = spuint1_trap_w & intr_vld_w;
2572
 
2573
   assign spuint0_e = (spuint0_i3[0] & thr_e[0] & hypv_int_en_d1[0] |
2574
                                   spuint0_i3[1] & thr_e[1] & hypv_int_en_d1[1] |
2575
                                   spuint0_i3[2] & thr_e[2] & hypv_int_en_d1[2] |
2576
                                   spuint0_i3[3] & thr_e[3] & hypv_int_en_d1[3]);
2577
 
2578
   assign spuint0_qual_e = spuint0_e & intr_vld_e & ~ueint_e &
2579
                                             ~spuint1_e & ~hintp_e;
2580
 
2581
//   assign spuint0_m = (spuint0_i3[0] & thr_m[0] |
2582
//                                 spuint0_i3[1] & thr_m[1] |
2583
//                                 spuint0_i3[2] & thr_m[2] |
2584
//                                 spuint0_i3[3] & thr_m[3]);
2585 113 albert.wat
   dff_s #(1) spu0m_ff(.din (spuint0_qual_e),
2586 95 fafa1971
                     .q   (spuint0_m),
2587 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2588 95 fafa1971
 
2589
   assign spuint0_trap_m = spuint0_m & intr_vld_m &
2590
                        ~(rstint_m | nuke_thr_m | resumint_m |
2591
                                    hwint_m);
2592
 
2593
//   assign spuint0_qual_m = spuint0_trap_m & ~kill_thread_m;
2594
 
2595 113 albert.wat
   dff_s #(1) spiw0_ff(.din (spuint0_trap_m),
2596 95 fafa1971
                                 .q   (spuint0_trap_w),
2597 113 albert.wat
                                 .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2598 95 fafa1971
   assign spuint0_w = spuint0_trap_w & intr_vld_w;
2599
 
2600
//   assign ifu_spu_trap_ack = {spuint1_w, spuint0_w};
2601
   assign ifu_spu_trap_ack = spuint1_w;
2602
 
2603
 
2604
   // software interrupts
2605
   assign sftint_e = (sftint_i3[0] & thr_e[0] & supv_int_en_d1[0] |
2606
                                        sftint_i3[1] & thr_e[1] & supv_int_en_d1[1] |
2607
                                        sftint_i3[2] & thr_e[2] & supv_int_en_d1[2] |
2608
                                        sftint_i3[3] & thr_e[3] & supv_int_en_d1[3]);
2609
 
2610
   assign sftint_qual_e = sftint_e & ~spuint0_e & intr_vld_e &
2611
                          ~ueint_e & ~spuint1_e & ~hintp_e;
2612
 
2613 113 albert.wat
   dff_s #(1) swm_ff(.din (sftint_qual_e),
2614 95 fafa1971
                   .q   (sftint_m),
2615 113 albert.wat
                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2616 95 fafa1971
 
2617
   // if nothing else, signal sftint!
2618
//   assign ifu_tlu_sftint_m = (sftint_m & 
2619
//                                  ~(rstint_m | nuke_thr_m | hintp_m | resumint_m |
2620
//                                                      hwint_m | spuint1_m | spuint0_m | ueint_m) |
2621
//                              ~(ceint_m | rerr_m)) & 
2622
//                               ~kill_local_m & intr_vld_m;
2623
 
2624
   assign ifu_tlu_sftint_m = (sftint_m &
2625
                                    ~(rstint_m | nuke_thr_m | hintp_m | resumint_m |
2626
                                                        hwint_m | spuint1_m | spuint0_m | ueint_m)) &
2627
                               ~kill_local_m & ~kill_curr_m & intr_vld_m;
2628
 
2629
 
2630
   // corrected ecc interrupt
2631
   assign ceint_e = (ceint_i3[0] & thr_e[0] & hypv_int_en_d1[0] |
2632
                                 ceint_i3[1] & thr_e[1] & hypv_int_en_d1[1] |
2633
                                 ceint_i3[2] & thr_e[2] & hypv_int_en_d1[2] |
2634
                                 ceint_i3[3] & thr_e[3] & hypv_int_en_d1[3]);
2635
   assign ceint_qual_e = ceint_e & intr_vld_e & ~ueint_e &
2636
                          ~spuint1_e & ~spuint0_e & ~hintp_e;
2637
 
2638
//   assign ceint_m = (ceint_i3[0] & thr_m[0] |
2639
//                               ceint_i3[1] & thr_m[1] |
2640
//                               ceint_i3[2] & thr_m[2] |
2641
//                               ceint_i3[3] & thr_m[3]);
2642 113 albert.wat
   dff_s #(1) cem_ff(.din (ceint_qual_e),
2643 95 fafa1971
                   .q   (ceint_m),
2644 113 albert.wat
                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2645 95 fafa1971
 
2646
   assign ceint_trap_m = ceint_m & intr_vld_m &
2647
                         ~(rstint_m | nuke_thr_m | resumint_m |
2648
                                 sftint_m | hwint_m);
2649
 
2650
//   assign ceint_qual_m = ceint_trap_m & ~ely_kill_thread_m;
2651 113 albert.wat
   dff_s #(1) ceintw_ff(.din (ceint_trap_m),
2652 95 fafa1971
                      .q   (ceint_trap_w),
2653 113 albert.wat
                      .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2654 95 fafa1971
   assign ceint_qual_w = ceint_trap_w & intr_vld_w;
2655
 
2656
   // resumable error interrupt
2657
   assign rerr_e = (rerr_i3[0] & thr_e[0] & supv_int_en_d1[0] |
2658
                                 rerr_i3[1] & thr_e[1] & supv_int_en_d1[1] |
2659
                                 rerr_i3[2] & thr_e[2] & supv_int_en_d1[2] |
2660
                                 rerr_i3[3] & thr_e[3] & supv_int_en_d1[3]);
2661
   assign rerr_qual_e = rerr_e & intr_vld_e & ~ueint_e & ~ceint_e &
2662
                        ~spuint1_e & ~spuint0_e & ~hintp_e;
2663
 
2664 113 albert.wat
   dff_s #(1) rem_ff(.din (rerr_qual_e),
2665 95 fafa1971
                   .q   (rerr_m),
2666 113 albert.wat
                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2667 95 fafa1971
 
2668
//   assign rerr_m = (rerr_i3[0] & thr_m[0] |
2669
//                                    rerr_i3[1] & thr_m[1] |
2670
//                                    rerr_i3[2] & thr_m[2] |
2671
//                                    rerr_i3[3] & thr_m[3]);
2672
 
2673
//   assign ifu_tlu_rerr_m = rerr_m & ~kill_local_m & intr_vld_m & 
2674
//                          ~(rstint_m | nuke_thr_m | ueint_m | ceint_m);
2675
 
2676
   assign disr_trap_m = (ueint_m | hintp_m | spuint0_m | spuint1_m |
2677
                         ceint_m | rerr_m) & ~rstint_m & ~nuke_thr_m &
2678
                          ~resumint_m & intr_vld_m;
2679
 
2680
   // check if a scheduled interrupt evaporated...
2681
   assign any_intr_m = (ueint_m | ceint_m | spuint0_m | spuint1_m |
2682
                        hintp_m | rerr_m | sftint_m | hwint_m |
2683
                        rstint_m | nuke_thr_m | resumint_m);
2684
 
2685
   // ..and rollback if that is the case
2686
   assign rb_intr_m = ~any_intr_m & intr_vld_m;
2687 113 albert.wat
   dff_s #(1) rbint_ff(.din (rb_intr_m),
2688 95 fafa1971
                     .q   (rb_intr_w),
2689 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2690 95 fafa1971
 
2691
   // use synchronous interrupt signal to switch out thread in swl
2692
//   assign fcl_dtu_sync_intr_d = (intr_vld_d | immu_miss_crit_d) & ~rb_stg_d;
2693
   assign fcl_dtu_sync_intr_d = (intr_vld_d) & ~rb_stg_d_crit;
2694
 
2695
   // kill the next three interrupts.  After that you are on your own.
2696
//   assign kill_intr_m = ((thr_m & thr_w) == 4'b0) ?
2697
//                                          1'b0 : (intr_vld_w);
2698
   assign kill_intr_e = ((thr_e & thr_w) == 4'b0) ?
2699
                                            1'b0 : (intr_vld_w);
2700
   assign kill_intr_d = ((thr_d & thr_w) == 4'b0) ?
2701
                                            1'b0 : (intr_vld_w);
2702
   assign kill_intr_f = ((thr_f & thr_w) == 4'b0) ?
2703
                                            1'b0 : (intr_vld_w);
2704
 
2705
//--------------------------------
2706
// check if we are in a delay slot
2707
//--------------------------------
2708
   // remember if the current instruction is a delay slot
2709
   assign delay_slot_vec_nxt = ({4{dtu_fcl_br_inst_d & inst_vld_d &
2710
                                   ~rb_stg_d}} & thr_d | // set
2711
                                delay_slot_vec &
2712
                                ~(thr_d & {4{inst_vld_d &
2713
                                             ~rb_stg_d &
2714
                                             ~intr_vld_d}})) &
2715
                                 ~(trap_thr & {4{trappc_vld_w2}});
2716
                                // & ~late_flush_w2;
2717
   // Need to be a little pessimitic: can't clear the delay slot vec
2718
   // after a utrap, since we may still be in the delay slot when we
2719
   // re-execute
2720
 
2721 113 albert.wat
   dffr_s #(4) ds_reg(.din (delay_slot_vec_nxt),
2722 95 fafa1971
                    .q   (delay_slot_vec),
2723
                    .rst (fcl_reset),
2724 113 albert.wat
                    .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
2725 95 fafa1971
   assign fcl_dec_dslot_s = (delay_slot_vec[0] & thr_f[0] |
2726
                             delay_slot_vec[1] & thr_f[1] |
2727
                             delay_slot_vec[2] & thr_f[2] |
2728
                             delay_slot_vec[3] & thr_f[3]);
2729
 
2730
 
2731
//------------------------------
2732
// NIR control
2733
//------------------------------
2734
   // use nir if va[2] of previous fetch is a zero (i.e lower word)
2735 113 albert.wat
   dff_s #(1) va2_ff(.din (fdp_fcl_va2_bf),
2736 95 fafa1971
                               .clk (clk),
2737
                               .q   (va2_f),
2738 113 albert.wat
                               .se  (se), `SIMPLY_RISC_SCANIN, .so());
2739 95 fafa1971
 
2740
   assign usep_bf = rdreq_f & ~va2_f & ~ntpc_thisthr & ~stall_f;
2741
   assign set_usen_bf = usep_bf & ~ely_stall_thisthr_f & dtu_fcl_running_s;
2742
 
2743
   // need to kill usen if trap or interrupt or flush
2744
   assign thr_usen_nxt = ({4{set_usen_bf}} &  thr_f  |    // set usen
2745
                                            thr_usen_bf  & ~val_thr_f) &    // keep old value
2746
                                             ~((thr_d & {4{dtu_fcl_br_inst_d}})  |
2747
                                         (thr_s1 & {4{ic_miss_s1}})  |
2748
                             (thr_e & {4{erb_dtu_ifeterr_d1 & inst_vld_d1}}) |
2749
                                               (clear_s_d1) |
2750
                                               (ntpc_vld)  |
2751
                                               (rb_w2 | rb_froms));     // reset usen (wins)
2752
                         // & ~dtu_fcl_flush_nir
2753
 
2754 113 albert.wat
   dffr_s #(4) thr_usen_reg(.din  (thr_usen_nxt),
2755 95 fafa1971
                                          .clk  (clk),
2756
                                          .q    (thr_usen_bf),
2757
                                          .rst  (fcl_reset),
2758 113 albert.wat
                                          .se   (se), `SIMPLY_RISC_SCANIN, .so());
2759 95 fafa1971
 
2760
   /*
2761
   // Use hand instantiated mux
2762
   bw_u1_ao2222_4x UZsize_usn_mx(.z   (usen_iso_bf)
2763
                                            .a2  (thr_usen_bf[0]),
2764
                                            .b2  (thr_usen_bf[1]),
2765
                                            .c2  (thr_usen_bf[2]),
2766
                                            .d2  (thr_usen_bf[3]),
2767
                                            .a1  (nextthr_bf_buf[0]),
2768
                                            .b1  (nextthr_bf_buf[1]),
2769
                                            .c1  (nextthr_bf_buf[2]),
2770
                                            .d1  (nextthr_bf_buf[3]));
2771
 
2772
    // isolate from critical path
2773
    bw_u1_buf_5x  UZsize_usn_iso(.z(usen_bf), .a(usen_iso_bf));
2774
    */
2775
 
2776
   assign usen_iso_bf = (thr_usen_bf[0] & nextthr_bf_buf[0] |
2777
                         thr_usen_bf[1] & nextthr_bf_buf[1] |
2778
                         thr_usen_bf[2] & nextthr_bf_buf[2] |
2779
                         thr_usen_bf[3] & nextthr_bf_buf[3]);
2780
   assign usen_bf = usen_iso_bf;
2781
 
2782
 
2783
 
2784
//------------------------------
2785
// Switch Control
2786
//------------------------------   
2787
   // Switch IF
2788
   //   1. Another thread is ready OR
2789
   //   2. We hit a switch condition or Imiss and another thread is
2790
   //      speculatively ready
2791
   //   3. No thread is running and another thread is speculatively ready
2792
   //   4. The DTU calls for a thread switch and another thread is ready
2793
   //   (NOTE: if we hit a switch condition or Imiss and no thread is
2794
   //    speculatively or otherwise ready we stall the pipe).
2795
   //
2796
   //   New plan:  switch if another thread is ready or spec ready.
2797
   //
2798
 
2799
//   assign switch_bf = dtu_fcl_ntr_s;
2800
   bw_u1_buf_20x UZsize_swbuf(.a (dtu_fcl_ntr_s),
2801
                              .z (switch_bf));
2802
 
2803
//   assign switch_bf = dtu_fcl_ntr_s & ~imsto_nextthr_s1;
2804
//   assign switch_bf = dtu_fcl_ntr_s & ~(imsto_nextthr_s1 | kill_nextthr_w | 
2805
//                                        intrto_nextthr_d);   
2806
 
2807
//   assign fcl_dtu_switch_s = switch_bf & ~all_stallreq & ~rst_stallreq;
2808
//   assign fcl_dtu_switch_s = switch_bf & ~kill_nextthr_w;
2809
 
2810
   // TBD: No need to send this anymore, since switch_bf = ntr_s
2811
//   assign fcl_dtu_switch_s = switch_bf;  // sw out curr and sw in next
2812
 
2813
   assign fcl_swl_swout_f = stall_f;     // sw out curr but don't sw in next
2814
   // Note: need fcl_swl_swout_f and dtu_fcl_running_s to sync swl and
2815
   // fcl at all times.  
2816
 
2817
   assign switch_qual_bf = switch_bf & ~rst_stallreq;
2818 113 albert.wat
   dff_s #(1) sw_ff (.din  (switch_qual_bf),
2819 95 fafa1971
                               .clk  (clk),
2820
                               .q    (switch_s2),
2821 113 albert.wat
                               .se   (se), `SIMPLY_RISC_SCANIN, .so());
2822 95 fafa1971
 
2823 113 albert.wat
   dff_s #(1) tmfn_ff (.din  (switch_bf),
2824 95 fafa1971
                                 .clk  (clk),
2825
                                 .q    (tm_fd_l),
2826 113 albert.wat
                                 .se   (se), `SIMPLY_RISC_SCANIN, .so());
2827 95 fafa1971
 
2828
   // need to qual with immu_fault to avoid X's
2829
//   assign fcl_dtu_swc_s = fdp_fcl_swc_s2 & inst_vld_s_crit & 
2830
//                          ~immu_fault_f & ~part_stall_thisthr_f;
2831
//   assign fcl_dtu_swc_s = fdp_fcl_swc_s2 & inst_vld_s_crit & 
2832
//                          ~immu_fault_f & ~imsto_thisthr_s1 & ~rb_stg_s;
2833
   assign fcl_swl_swcvld_s = inst_vld_s_crit & ~immu_fault_f &
2834
                             ~imsto_thisthr_s1 & ~rb_stg_s;
2835
 
2836
 
2837
//------------------------------   
2838
// Thread pipe
2839
//------------------------------
2840
 
2841
//`ifdef VERPLEX
2842
//   $constraint nthr_1h4 ($one_hot(dtu_fcl_nextthr_bf[3:0]));
2843
//   $constraint thrf_1h4 ($one_hot(thr_f[3:0]));
2844
//`endif
2845
 
2846
   // Keep track the thread in each pipe stage
2847
   assign rstt = (~fcl_reset & (rst_stallreq_d1 & ~arst_vld_f)) | rst_tri_en;
2848
   assign swt =  (~rst_stallreq_d1 & ~arst_vld_f & switch_bf | fcl_reset) &
2849
                   ~rst_tri_en;
2850
   assign samet = (~rst_stallreq_d1 & ~switch_bf | arst_vld_f) &
2851
                    ~fcl_reset & ~rst_tri_en;
2852
 
2853
   mux3ds #(4)  nxttthr_mux(.dout  (thr_bf[3:0]),
2854
                                              .in0   (thr_f[3:0]),
2855
                                              .in1   (nextthr_bf_buf[3:0]),
2856
                                              .in2   (rstint_penc[3:0]),
2857
                                              .sel0  (samet),
2858
                                              .sel1  (swt),
2859
                                              .sel2  (rstt));
2860
 
2861
   assign thr_match_nw = (thr_w[0] & nextthr_bf_buf[0] |
2862
                                            thr_w[1] & nextthr_bf_buf[1] |
2863
                                            thr_w[2] & nextthr_bf_buf[2] |
2864
                                            thr_w[3] & nextthr_bf_buf[3]);
2865
 
2866
   assign thr_match_nd = (thr_d[0] & nextthr_bf_buf[0] |
2867
                                            thr_d[1] & nextthr_bf_buf[1] |
2868
                                            thr_d[2] & nextthr_bf_buf[2] |
2869
                                            thr_d[3] & nextthr_bf_buf[3]);
2870
 
2871
//   assign thr_match_ne = (thr_e[0] & dtu_fcl_nextthr_bf[0] | 
2872
//                                          thr_e[1] & dtu_fcl_nextthr_bf[1] | 
2873
//                                          thr_e[2] & dtu_fcl_nextthr_bf[2] | 
2874
//                                          thr_e[3] & dtu_fcl_nextthr_bf[3]);
2875
   // qualify inst_vld_e in fcl itself
2876
 
2877
//   bw_u1_ao2222_4x UZsize_tmne(.z  (thr_match_ne),
2878
//                               .a1 (val_thr_e[0]),
2879
//                               .b1 (val_thr_e[1]),
2880
//                               .c1 (val_thr_e[2]),
2881
//                               .d1 (val_thr_e[3]),
2882
//                               .a2 (dtu_fcl_nextthr_bf[0]),
2883
//                               .b2 (dtu_fcl_nextthr_bf[1]),
2884
//                               .c2 (dtu_fcl_nextthr_bf[2]),
2885
//                               .d2 (dtu_fcl_nextthr_bf[3]));
2886
 
2887
   wire   tmne_10,
2888
          tmne_32;
2889
   bw_u1_aoi22_2x UZsize_tmne10(.z (tmne_10),
2890
                                .a1 (dtu_fcl_nextthr_bf[0]),
2891
                                .b1 (dtu_fcl_nextthr_bf[1]),
2892
                                .a2 (val_thr_e[0]),
2893
                                .b2 (val_thr_e[1]));
2894
   bw_u1_aoi22_2x UZsize_tmne32(.z (tmne_32),
2895
                                .a1 (dtu_fcl_nextthr_bf[2]),
2896
                                .b1 (dtu_fcl_nextthr_bf[3]),
2897
                                .a2 (val_thr_e[2]),
2898
                                .b2 (val_thr_e[3]));
2899
   bw_u1_nand2_4x UZsize_tmne30(.z (thr_match_ne),
2900
                                .a (tmne_10),
2901
                                .b (tmne_32));
2902
 
2903
 
2904 113 albert.wat
   dff_s #(4) thrf_reg(.din   (thr_bf),     // thr_f may be 4'b0000 but it has 
2905 95 fafa1971
                                 .clk   (clk),        // to reset to 4'b0001
2906
                                 .q     (thr_f_flop),
2907 113 albert.wat
                                 .se    (se),  `SIMPLY_RISC_SCANIN, .so());
2908 95 fafa1971
 
2909
   bw_u1_buf_10x UZsize_tfcrit0(.a (thr_f_flop[0]), .z(thr_f_crit[0]));
2910
   bw_u1_buf_10x UZsize_tfcrit1(.a (thr_f_flop[1]), .z(thr_f_crit[1]));
2911
   bw_u1_buf_10x UZsize_tfcrit2(.a (thr_f_flop[2]), .z(thr_f_crit[2]));
2912
   bw_u1_buf_10x UZsize_tfcrit3(.a (thr_f_flop[3]), .z(thr_f_crit[3]));
2913
 
2914
   bw_u1_buf_10x UZsize_tfncr0(.a (thr_f_flop[0]), .z(thr_f[0]));
2915
   bw_u1_buf_10x UZsize_tfncr1(.a (thr_f_flop[1]), .z(thr_f[1]));
2916
   bw_u1_buf_10x UZsize_tfncr2(.a (thr_f_flop[2]), .z(thr_f[2]));
2917
   bw_u1_buf_10x UZsize_tfncr3(.a (thr_f_flop[3]), .z(thr_f[3]));
2918
 
2919
   assign     ifu_exu_tid_s2[1] = thr_f[3] | thr_f[2];
2920
   assign     ifu_exu_tid_s2[0] = thr_f[3] | thr_f[1];
2921
   assign     ifu_lsu_thrid_s = ifu_exu_tid_s2;
2922
   assign     fcl_dtu_thr_f = thr_f;
2923
 
2924
//   assign thr_s1_next = inst_vld_f ? thr_f : thr_s1;
2925
   assign     thr_s1_next[0] = thr_f[0];
2926
   assign     thr_s1_next[1] = ~thr_f[0] & thr_f[1];
2927
   assign     thr_s1_next[2] = ~thr_f[0] & ~thr_f[1] & thr_f[2];
2928
   assign     thr_s1_next[3] = ~thr_f[0] & ~thr_f[1] & ~thr_f[2];
2929
 
2930
//`ifdef VERPLEX
2931
//   $constraint thr_s1_1h4 ($one_hot(thr_s1_next[3:0]));
2932
//`endif
2933
 
2934 113 albert.wat
   dff_s #(4) thrs1_reg(.din   (thr_s1_next),
2935 95 fafa1971
                    .clk   (clk),
2936
                    .q     (thr_s1),
2937 113 albert.wat
                    .se    (se), `SIMPLY_RISC_SCANIN, .so());
2938 95 fafa1971
 
2939 113 albert.wat
   dff_s #(4) thrd_reg(.din    (thr_s1_next),
2940 95 fafa1971
                     .clk   (clk),
2941
                     .q     (thr_d),
2942 113 albert.wat
                     .se    (se), `SIMPLY_RISC_SCANIN, .so());
2943 95 fafa1971
 
2944
   assign fcl_ifq_thr_s1[0] = thr_s1[3] | thr_s1[1];
2945
   assign fcl_ifq_thr_s1[1] = thr_s1[3] | thr_s1[2];
2946
 
2947
   assign ifu_tlu_thrid_d[1] = thr_d[3] | thr_d[2];
2948
   assign ifu_tlu_thrid_d[0] = thr_d[3] | thr_d[1];
2949
 
2950
   assign thr_match_fs1 = (thr_d[0] & thr_f_crit[0] |
2951
                                             thr_d[1] & thr_f_crit[1] |
2952
                                             thr_d[2] & thr_f_crit[2] |
2953
                                             thr_d[3] & thr_f_crit[3]);
2954
   assign thr_match_fd = thr_match_fs1;
2955
   assign thr_match_fe = (thr_e[0] & thr_f[0] |
2956
                                            thr_e[1] & thr_f[1] |
2957
                                            thr_e[2] & thr_f[2] |
2958
                                            thr_e[3] & thr_f[3]);
2959
   assign thr_match_fm = (thr_m[0] & thr_f[0] |
2960
                                            thr_m[1] & thr_f[1] |
2961
                                            thr_m[2] & thr_f[2] |
2962
                                            thr_m[3] & thr_f[3]);
2963
//   assign thr_match_ft = (trap_thr[0] & thr_f[0] | 
2964
//                        trap_thr[1] & thr_f[1] | 
2965
//                        trap_thr[2] & thr_f[2] | 
2966
//                        trap_thr[3] & thr_f[3]);
2967
 
2968 113 albert.wat
   dffr_s #(4) thre_reg(.din   (thr_d),
2969 95 fafa1971
                    .clk   (clk),
2970
                    .rst   (fcl_reset),
2971
                    .q     (thr_e),
2972 113 albert.wat
                    .se    (se), `SIMPLY_RISC_SCANIN, .so());
2973 95 fafa1971
 
2974 113 albert.wat
   dffr_s #(4) thre2_reg(.din   (thr_d),
2975 95 fafa1971
                    .clk   (clk),
2976
                    .rst   (fcl_reset),
2977
                    .q     (thr_e_v2),
2978 113 albert.wat
                    .se    (se), `SIMPLY_RISC_SCANIN, .so());
2979 95 fafa1971
 
2980
   assign     ifu_tlu_thrid_e[1] = thr_e[3] | thr_e[2];
2981
   assign     ifu_tlu_thrid_e[0] = thr_e[3] | thr_e[1];
2982
 
2983
   assign thr_match_de = (thr_d[0] & thr_e[0] |
2984
                                            thr_d[1] & thr_e[1] |
2985
                                            thr_d[2] & thr_e[2] |
2986
                                            thr_d[3] & thr_e[3]);
2987
 
2988
   assign thr_match_dm = (thr_d[0] & thr_m[0] |
2989
                                            thr_d[1] & thr_m[1] |
2990
                                            thr_d[2] & thr_m[2] |
2991
                                            thr_d[3] & thr_m[3]);
2992
 
2993 113 albert.wat
   dff_s #(4) thrm_reg(.din   (thr_e),
2994 95 fafa1971
                   .clk   (clk),
2995
                   .q     (thr_m),
2996 113 albert.wat
                   .se    (se), `SIMPLY_RISC_SCANIN, .so());
2997 95 fafa1971
 
2998 113 albert.wat
   dff_s #(4) thrw_reg(.din   (thr_m),
2999 95 fafa1971
                   .clk   (clk),
3000
                   .q     (thr_w),
3001 113 albert.wat
                   .se    (se), `SIMPLY_RISC_SCANIN, .so());
3002 95 fafa1971
 
3003
   assign sas_thrid_w[1] = thr_w[3] | thr_w[2];
3004
   assign sas_thrid_w[0] = thr_w[3] | thr_w[1];
3005
 
3006
   assign thr_match_fw = (thr_f[0] & thr_w[0] |
3007
                                            thr_f[1] & thr_w[1] |
3008
                                            thr_f[2] & thr_w[2] |
3009
                                            thr_f[3] & thr_w[3]);
3010
 
3011
   assign thr_match_fw2 = (thr_f[0] & thr_w2[0] |
3012
                                             thr_f[1] & thr_w2[1] |
3013
                                             thr_f[2] & thr_w2[2] |
3014
                                             thr_f[3] & thr_w2[3]);
3015
 
3016
   assign thr_match_dw = (thr_d[0] & thr_w[0] |
3017
                                            thr_d[1] & thr_w[1] |
3018
                                            thr_d[2] & thr_w[2] |
3019
                                            thr_d[3] & thr_w[3]);
3020
 
3021
   assign thr_match_dw2 = (thr_d[0] & thr_w2[0] |
3022
                                             thr_d[1] & thr_w2[1] |
3023
                                             thr_d[2] & thr_w2[2] |
3024
                                             thr_d[3] & thr_w2[3]);
3025
 
3026
   assign thr_match_em = (thr_e[0] & thr_m[0] |
3027
                                            thr_e[1] & thr_m[1] |
3028
                                            thr_e[2] & thr_m[2] |
3029
                                            thr_e[3] & thr_m[3]);
3030
 
3031
   assign thr_match_ew = (thr_e_v2[0] & thr_w[0] |
3032
                                            thr_e_v2[1] & thr_w[1] |
3033
                                            thr_e_v2[2] & thr_w[2] |
3034
                                            thr_e_v2[3] & thr_w[3]);
3035
 
3036 113 albert.wat
   dff_s #(1) stmw2_ff(.din (thr_match_ew),
3037 95 fafa1971
                     .q   (same_thr_mw2),
3038 113 albert.wat
                     .clk (clk), .se (se), `SIMPLY_RISC_SCANIN, .so());
3039 95 fafa1971
 
3040
   assign thr_match_ew2 = (thr_e[0] & thr_w2[0] |
3041
                                             thr_e[1] & thr_w2[1] |
3042
                                             thr_e[2] & thr_w2[2] |
3043
                                             thr_e[3] & thr_w2[3]);
3044
 
3045
   assign thr_match_mw = (thr_m[0] & thr_w[0] |
3046
                                            thr_m[1] & thr_w[1] |
3047
                                            thr_m[2] & thr_w[2] |
3048
                                            thr_m[3] & thr_w[3]);
3049
 
3050 113 albert.wat
   dff_s #(4) thrw2_reg(.din   (thr_w),
3051 95 fafa1971
                    .clk   (clk),
3052
                    .q     (thr_w2),
3053 113 albert.wat
                    .se    (se), `SIMPLY_RISC_SCANIN, .so());
3054 95 fafa1971
 
3055
 
3056
//-------------------------
3057
// Rollback
3058
//-------------------------
3059
 
3060
   // 04/05/02
3061
   // Looks like we made a mistake with rollback.  Should never
3062
   // rollback to S.  In the event of a dmiss or mul contention, just
3063
   // kill all the instructions and rollback to F.  This adds one
3064
   // cycle to the dmiss penalty and to the mul latency if we have to
3065
   // wait, both not a very high price to pay.  This would have saved
3066
   // lots of hours of design and verif time.
3067
   //    
3068
   assign rb2_inst_d = thr_match_dw & inst_vld_d & dtu_fcl_rollback_g;
3069
   assign rb1_inst_s = thr_match_fw & inst_vld_s & dtu_fcl_rollback_g;
3070
   assign rb0_inst_bf = thr_match_nw & switch_bf & dtu_fcl_rollback_g;
3071
 
3072
//   assign rt1_inst_s = thr_match_fd & inst_vld_s & retract_inst_d;
3073
//   assign rt0_inst_bf = thr_match_nd & dtu_fcl_ntr_s & retract_inst_d;
3074
 
3075
//   assign retract_iferr_d = thr_match_de & erb_dtu_ifeterr_d1 & inst_vld_d1 &
3076
//                            ~kill_curr_e & fcl_dtu_inst_vld_d;
3077
   assign retract_iferr_d1 = erb_dtu_ifeterr_d1 & inst_vld_d1;
3078
 
3079
   assign retract_inst_d = retract_iferr_d1 & thr_match_de &
3080
                           fcl_dtu_inst_vld_d |
3081
                           mark4rb_d |
3082
                           dtu_fcl_retract_d;
3083
 
3084
   assign rt1_inst_s = thr_match_fd & inst_vld_s & dtu_fcl_retract_d |
3085
                       mark4rb_s;
3086
//                     | thr_match_fe & inst_vld_s & retract_iferr_d1;
3087
 
3088
   // TBD:  This is not necessary since the thread will switch out and
3089
   // stall whatever makes its way to the S stage.
3090
   // NOTE: rb0_inst *is needed* however.
3091
   assign rt0_inst_bf = thr_match_nd & switch_bf & dtu_fcl_retract_d;
3092
//                      | thr_match_ne & dtu_fcl_ntr_s & retract_iferr_d1;
3093
 
3094
   assign retract_iferr_qual_d1 = retract_iferr_d1 & thr_match_de &
3095
                                  fcl_dtu_inst_vld_d &
3096
                                  ~(dtu_fcl_rollback_g & thr_match_ew);
3097
 
3098 113 albert.wat
   dff_s rbe_ff(.din (rb2_inst_d),
3099 95 fafa1971
              .q   (rb2_inst_e),
3100
              .clk (clk),
3101 113 albert.wat
              .se  (se), `SIMPLY_RISC_SCANIN, .so());
3102 95 fafa1971
 
3103 113 albert.wat
   dff_s rte_ff(.din (retract_inst_d),
3104 95 fafa1971
              .q   (rt2_inst_e),
3105
              .clk (clk),
3106 113 albert.wat
              .se  (se), `SIMPLY_RISC_SCANIN, .so());
3107 95 fafa1971
 
3108 113 albert.wat
   dff_s rbd_ff(.din (rb1_inst_s),
3109 95 fafa1971
              .q   (rb1_inst_d),
3110
              .clk (clk),
3111 113 albert.wat
              .se  (se), `SIMPLY_RISC_SCANIN, .so());
3112 95 fafa1971
 
3113 113 albert.wat
   dff_s rtd_ff(.din (rt1_inst_s),
3114 95 fafa1971
              .q   (rt1_inst_d),
3115
              .clk (clk),
3116 113 albert.wat
              .se  (se), `SIMPLY_RISC_SCANIN, .so());
3117 95 fafa1971
 
3118 113 albert.wat
   dff_s rbs_ff(.din (rb0_inst_bf),
3119 95 fafa1971
              .q   (rb0_inst_s),
3120
              .clk (clk),
3121 113 albert.wat
              .se  (se), `SIMPLY_RISC_SCANIN, .so());
3122 95 fafa1971
 
3123
   // TBD: is this necessary?
3124 113 albert.wat
   dff_s rts_ff(.din (rt0_inst_bf),
3125 95 fafa1971
              .q   (rt0_inst_s),
3126
              .clk (clk),
3127 113 albert.wat
              .se  (se), `SIMPLY_RISC_SCANIN, .so());
3128 95 fafa1971
 
3129 113 albert.wat
   dff_s rtiferr_ff(.din (retract_iferr_qual_d1),
3130 95 fafa1971
                  .q   (retract_iferr_e),
3131
                  .clk (clk),
3132 113 albert.wat
                  .se  (se), `SIMPLY_RISC_SCANIN, .so());
3133 95 fafa1971
 
3134
   assign rb_stg_s = (rb0_inst_s | rt0_inst_s) & tm_fd_l |
3135
                           (rb1_inst_d | rt1_inst_d) & ~tm_fd_l;
3136
   assign rb_stg_d_crit = rb1_inst_d | rt1_inst_d;
3137
   assign rb_stg_e = rb2_inst_e | rt2_inst_e;
3138
 
3139
   bw_u1_buf_5x UZsize_rbd_buf(.a (rb_stg_d_crit),
3140
                               .z (rb_stg_d));
3141
 
3142
   // determine rollback amount
3143
   assign rb_frome = {4{(rb2_inst_e | rt2_inst_e) &
3144
                        (inst_vld_e | intr_vld_e)}} & thr_e;
3145
   assign rb_fromd = {4{(rb1_inst_d | rt1_inst_d) &
3146
                        (inst_vld_d | intr_vld_d)}} & thr_d;
3147
   assign rb_froms = {4{rb_stg_s & inst_vld_s_crit}} & thr_f;
3148
   assign rb_w2 = rb_frome | rb_fromd;
3149
   assign rb_for_iferr_e = {4{retract_iferr_e}} & thr_e;
3150
 
3151
//------------------------------   
3152
// Branch Control
3153
//------------------------------
3154
   // final portion of branch evaluation
3155
   wire brtaken_e_l;
3156
   bw_u1_buf_20x UZsize_bcbf(.z(fcl_dcl_regz_e),
3157
                             .a(exu_ifu_regz_e));
3158
 
3159
   bw_u1_muxi21_6x UZsize_bcmux(.z(brtaken_e_l),
3160
                                .d0(dcl_fcl_bcregz0_e),
3161
                                .d1(dcl_fcl_bcregz1_e),
3162
                                .s(exu_ifu_regz_e));
3163
 
3164
   bw_u1_inv_15x UZsize_bcinv(.z(brtaken_e),
3165
                              .a(brtaken_e_l));
3166
 
3167
   // Branch is taken in the E stage to thr_e.  Below we check to see
3168
   // if this is the same as the next thread we will switch to
3169
 
3170
   // isolate non critical section
3171
   bw_u1_buf_5x UZsize_btbuf(.z (brtaken_unq_e),
3172
                             .a (brtaken_e));
3173
   assign brtaken_buf_e = brtaken_unq_e & inst_vld_qual_e & ~kill_curr_e;
3174
 
3175
//   assign thr_match_ne_norst = thr_match_ne & ~rst_sw_bf;
3176
//   assign brto_nxtthr_bf  = thr_match_ne & brtaken_e;
3177
   bw_u1_nand2_4x UZsize_btkn_ntl(.a (brtaken_e),
3178
                                  .b (thr_match_ne),
3179
                                  .z (brto_nxtthr_bf_l));
3180
 
3181
//   bw_u1_inv_8x UZsize_btkn_bf(.a (brto_nxtthr_bf_l),
3182
//                               .z (brto_nxtthr_bf));
3183
 
3184 113 albert.wat
   dff_s #(1) br_ff(.din (brtaken_buf_e),
3185 95 fafa1971
                              .q   (brtaken_m),
3186
                              .clk (clk),
3187 113 albert.wat
                              .se  (se), `SIMPLY_RISC_SCANIN, .so());
3188 95 fafa1971
 
3189
 
3190
//----------------------------------------------------------------------
3191
// PC related control
3192
//----------------------------------------------------------------------
3193
 
3194
   // Choose next IC address
3195
   // IC address is chosen from
3196
   //    1. Next PC assuming no switch 
3197
   //    2. Branch PC if E stage branch is to next thread
3198
   //    3. Saved F stage Thread PC if we switch threads
3199
 
3200
   assign fcl_icd_index_sel_ifq_bf = allow_ifq_access_icd_bf;
3201
   assign fcl_ifq_grant_bf = allow_ifq_access_icd_bf;
3202
 
3203
   // Select branch PC
3204
//   assign fcl_fdp_icaddr_sel_br_bf_l = ~(~all_stallreq &
3205
//                                                                     brto_nxtthr_bf    &
3206
//                                                                     switch_bf);
3207
//
3208
//   // Select the switch PC from thread PC register
3209
//   assign fcl_fdp_icaddr_sel_swpc_bf_l = ~(~all_stallreq &
3210
//                                                                       ~usen_bf &
3211
//                                                                       ~brto_nxtthr_bf &
3212
//                                                                       switch_bf);
3213
//
3214
//   // Select current thread's next PC or IC write addr (PC/PC+4/I$ wraddr)
3215
//   assign fcl_fdp_icaddr_sel_curr_bf_l = ~(~all_stallreq &
3216
//                                                                       ~(stall_f | usep_bf) & 
3217
//                                                                       ~switch_bf);
3218
//   
3219
//   assign fcl_fdp_icaddr_sel_ifq_bf_l = ~(all_stallreq |
3220
//                                                                      (stall_f | usep_bf) & ~switch_bf |
3221
//                                                                      ~brto_nxtthr_bf & usen_bf &
3222
//                                                                      (switch_bf | stall_f | usep_bf));
3223
 
3224
 
3225
 
3226
//   assign sw_or_async_stall = (switch_bf & ~rst_stallreq | rst_sw_bf);
3227
   wire   sw_or_async_stall_l;
3228
   assign rst_stallreq_l = ~rst_stallreq;
3229
   bw_u1_aoi21_4x UZsize_swstl_aoi(.z  (sw_or_async_stall_l),
3230
                                   .a  (rst_sw_bf),
3231
                                   .b1 (switch_bf),
3232
                                   .b2 (rst_stallreq_l));
3233
   assign sw_or_async_stall = ~sw_or_async_stall_l;
3234
 
3235
//   assign icadr_selbr = sw_or_async_stall & brto_nxtthr_bf;
3236
   assign sw_match_ne_norst = sw_or_async_stall & thr_match_ne;
3237
   bw_u1_nand2_10x UZfix_icad_br(.a (brtaken_e),
3238
                                 .b (sw_match_ne_norst),
3239
                                 .z (icadr_selbr_l));
3240
 
3241
//   assign icadr_selsw = sw_or_async_stall & ~brto_nxtthr_bf;
3242
   bw_u1_nand2_15x UZfix_icad_sw(.a (brto_nxtthr_bf_l),
3243
                                 .b (sw_or_async_stall),
3244
                                 .z (icadr_selsw_l));
3245
 
3246
 
3247
   // select next PC
3248
   assign fcl_fdp_pcbf_sel_br_bf_l = icadr_selbr_l;
3249
   assign fcl_fdp_pcbf_sel_swpc_bf_l = icadr_selsw_l ;
3250
   assign fcl_fdp_pcbf_sel_nosw_bf_l = ~sw_or_async_stall_l;
3251
 
3252
   // Select PC to switch to in the event of a switch
3253
   // No need to protect during scan
3254
   // NOTE: SWL guarantees nextthr_bf is one hot
3255
//   assign fcl_fdp_next_thr_bf_l = rst_stallreq_d1 ? ~rstint_penc :
3256
//                                                    ~dtu_fcl_nextthr_bf;
3257
 
3258
   wire [3:0] next_thr_bf_l;
3259
   wire       nt_sel_rst;
3260
   assign     nt_sel_rst = rst_stallreq_d1 | rst_tri_en;
3261
 
3262
   bw_u1_muxi21_2x UZfix_nthr_mx0(.z (next_thr_bf_l[0]),
3263
                                  .d0 (dtu_fcl_nextthr_bf[0]),
3264
                                  .d1 (rstint_penc[0]),
3265
                                  .s  (nt_sel_rst));
3266
   bw_u1_muxi21_2x UZfix_nthr_mx1(.z (next_thr_bf_l[1]),
3267
                                  .d0 (dtu_fcl_nextthr_bf[1]),
3268
                                  .d1 (rstint_penc[1]),
3269
                                  .s  (nt_sel_rst));
3270
   bw_u1_muxi21_2x UZfix_nthr_mx2(.z (next_thr_bf_l[2]),
3271
                                  .d0 (dtu_fcl_nextthr_bf[2]),
3272
                                  .d1 (rstint_penc[2]),
3273
                                  .s  (nt_sel_rst));
3274
   bw_u1_muxi21_2x UZfix_nthr_mx3(.z (next_thr_bf_l[3]),
3275
                                  .d0 (dtu_fcl_nextthr_bf[3]),
3276
                                  .d1 (rstint_penc[3]),
3277
                                  .s  (nt_sel_rst));
3278
   assign     fcl_fdp_next_thr_bf_l = next_thr_bf_l;
3279
 
3280
 
3281
//   assign nextthr_bf_buf = dtu_fcl_nextthr_bf;
3282
   bw_u1_buf_20x UZsize_ntbf0(.a (dtu_fcl_nextthr_bf[0]),
3283
                              .z (nextthr_bf_buf[0]));
3284
   bw_u1_buf_20x UZsize_ntbf1(.a (dtu_fcl_nextthr_bf[1]),
3285
                              .z (nextthr_bf_buf[1]));
3286
   bw_u1_buf_20x UZsize_ntbf2(.a (dtu_fcl_nextthr_bf[2]),
3287
                              .z (nextthr_bf_buf[2]));
3288
   bw_u1_buf_20x UZsize_ntbf3(.a (dtu_fcl_nextthr_bf[3]),
3289
                              .z (nextthr_bf_buf[3]));
3290
   // use 6x
3291
   assign fcl_fdp_next_ctxt_bf_l[2:0] = ~nextthr_bf_buf[2:0] | {3{rst_tri_en}};
3292
   assign fcl_fdp_next_ctxt_bf_l[3] = ~nextthr_bf_buf[3] & ~rst_tri_en;
3293
 
3294
//   assign nextthr_final_bf = switch_bf ? dtu_fcl_nextthr_bf : thr_f;
3295
   wire [3:0] nextthr_final_bf_l;
3296
   bw_u1_muxi21_2x UZfix_ntfmux0(.z  (nextthr_final_bf_l[0]),
3297
                                .d0 (thr_f[0]),
3298
                                .d1 (dtu_fcl_nextthr_bf[0]),
3299
                                .s  (switch_bf));
3300
   bw_u1_inv_8x UZsize_ntfin_buf0(.z (nextthr_final_bf[0]),
3301
                                 .a (nextthr_final_bf_l[0]));
3302
 
3303
   bw_u1_muxi21_2x UZfix_ntfmux1(.z  (nextthr_final_bf_l[1]),
3304
                                .d0 (thr_f[1]),
3305
                                .d1 (dtu_fcl_nextthr_bf[1]),
3306
                                .s  (switch_bf));
3307
   bw_u1_inv_8x UZsize_ntfin_buf1(.z (nextthr_final_bf[1]),
3308
                                 .a (nextthr_final_bf_l[1]));
3309
 
3310
   bw_u1_muxi21_2x UZfix_ntfmux2(.z  (nextthr_final_bf_l[2]),
3311
                                .d0 (thr_f[2]),
3312
                                .d1 (dtu_fcl_nextthr_bf[2]),
3313
                                .s  (switch_bf));
3314
   bw_u1_inv_8x UZsize_ntfin_buf2(.z (nextthr_final_bf[2]),
3315
                                 .a (nextthr_final_bf_l[2]));
3316
 
3317
   bw_u1_muxi21_2x UZfix_ntfmux3(.z  (nextthr_final_bf_l[3]),
3318
                                .d0 (thr_f[3]),
3319
                                .d1 (dtu_fcl_nextthr_bf[3]),
3320
                                .s  (switch_bf));
3321
   bw_u1_inv_8x UZsize_ntfin_buf3(.z (nextthr_final_bf[3]),
3322
                                 .a (nextthr_final_bf_l[3]));
3323
 
3324
 
3325
   // decode trap thread
3326 113 albert.wat
   dff_s #(2) ld_trp_reg(.din ({tlu_ifu_trappc_vld_w1,
3327 95 fafa1971
                              tlu_ifu_trapnpc_vld_w1}),
3328
                       .q   ({trappc_vld_w2,
3329
                              trapnpc_vld_w2}),
3330 113 albert.wat
                       .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
3331 95 fafa1971
 
3332 113 albert.wat
   dff_s #(2) trp_tid_reg(.din (tlu_ifu_trap_tid_w1[1:0]),
3333 95 fafa1971
                        .q   (trap_tid_w2[1:0]),
3334 113 albert.wat
                        .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
3335 95 fafa1971
 
3336
   assign trap_thr[0] = ~trap_tid_w2[1] & ~trap_tid_w2[0];
3337
   assign trap_thr[1] = ~trap_tid_w2[1] &  trap_tid_w2[0];
3338
   assign trap_thr[2] =  trap_tid_w2[1] & ~trap_tid_w2[0];
3339
   assign trap_thr[3] =  trap_tid_w2[1] &  trap_tid_w2[0];
3340
 
3341
   assign load_tpc[3:0] = {4{trappc_vld_w2}} & trap_thr |
3342
                           rb_w2 |
3343
                           {4{rb_stg_w | ims_flush_coll_w}} & thr_w |
3344
//                     {4{dec_fcl_kill4sta_e}} & thr_e |
3345
                           {4{flush_sonly_qual_m}} & thr_m;
3346
 
3347
   assign load_bpc[3:0] = {4{brtaken_buf_e}} & thr_e;
3348
   assign load_pcp4[3:0] = {4{~part_stall_thisthr_f &
3349
                              ~iferrto_thisthr_d1 |
3350
                              arst_vld_f |
3351
                              async_intr_vld_s}}     & thr_f;
3352
 
3353
   always @ (/*AUTOSENSE*/load_bpc or load_pcp4 or load_tpc)
3354
     begin
3355
//            if (fcl_reset)
3356
//              begin // RESET PC is loaded to T0
3357
//                 fcl_fdp_tpcbf_sel_old_bf_l = 4'b0001;
3358
//                 fcl_fdp_tpcbf_sel_pcp4_bf_l = 4'b1110;
3359
//                 fcl_fdp_tpcbf_sel_trap_bf_l = 4'b1111;
3360
//                 fcl_fdp_tpcbf_sel_brpc_bf_l = 4'b1111;
3361
//              end // if (reset)
3362
//            else 
3363
//              begin
3364
              fcl_fdp_tpcbf_sel_old_bf_l = (load_bpc | load_tpc | load_pcp4);
3365
              fcl_fdp_tpcbf_sel_brpc_bf_l = ~load_bpc | load_tpc | load_pcp4;
3366
              fcl_fdp_tpcbf_sel_pcp4_bf_l = ~load_pcp4 | load_tpc;
3367
              fcl_fdp_tpcbf_sel_trap_bf_l = ~load_tpc;
3368
     end // always @ (...
3369
 
3370
   // Track correctible errors
3371
   assign irf_ce_m = exu_ifu_ecc_ce_m & ~trap_m & inst_vld_m & ~kill_curr_m;
3372 113 albert.wat
   dff_s #(1) irfcew_ff(.din (irf_ce_m),
3373 95 fafa1971
                                .q   (irf_ce_w),
3374 113 albert.wat
                                .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
3375 95 fafa1971
 
3376
   // track if ldhit was actually a miss
3377
   // D and S stage are rolled back through the normal D stage retract
3378
   // process.  
3379
   assign mark4rb_d = lsu_ifu_dc_parity_error_w2 & thr_match_dw2 &
3380
                      (inst_vld_d | intr_vld_d);
3381
   assign mark4rb_s = lsu_ifu_dc_parity_error_w2 & thr_match_fw2 &
3382
                      (inst_vld_s | intr_vld_s);
3383
 
3384
   assign mark4rb_e = lsu_ifu_dc_parity_error_w2 & thr_match_ew2 &
3385
                      (inst_vld_e | intr_vld_e) &
3386
                        ~dtu_inst_anull_e & ~kill_curr_e;
3387
 
3388 113 albert.wat
   dff_s #(2) markrb_reg(.din ({mark4rb_m,
3389 95 fafa1971
                              mark4rb_e}),
3390
                       .q   ({mark4rb_w,
3391
                              mark4rb_m}),
3392
                       .clk (clk),
3393 113 albert.wat
                       .se  (se), `SIMPLY_RISC_SCANIN, .so());
3394 95 fafa1971
 
3395
   // Rollback from W on irf/frf ce and on a dcache parity error
3396
   assign rb_stg_w = irf_ce_w & inst_vld_w & no_iftrap_w |
3397
                           ffu_ifu_fst_ce_w & inst_vld_w & no_iftrap_w |
3398
                     rb_intr_w & intr_vld_w |
3399
                     mark4rb_w |
3400
                     fcl_dtu_resum_thr_w |
3401
                                 fcl_dtu_nuke_thr_w;
3402
 
3403
   // flush after hardware micro trap
3404
//   assign ifu_tlu_flush_w = irf_ce_w | fcl_dtu_nuke_thr_w | mark4rb_w |
3405
//                            fcl_dtu_resum_thr_w;
3406
   // very critical
3407
   assign ifu_tlu_flush_m = (exu_ifu_ecc_ce_m & inst_vld_m & ~trap_m |
3408
                             (resumint_m | nuke_thr_m) &
3409
                             intr_vld_m & ~rstint_m |
3410
                             rb_intr_m |
3411
                             mark4rb_m);
3412
   assign utrap_flush_m =  ifu_tlu_flush_m & ~kill_local_m;
3413 113 albert.wat
   dff_s #(1) flw_ff(.din (utrap_flush_m),
3414 95 fafa1971
                   .q   (utrap_flush_w),
3415 113 albert.wat
                   .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
3416 95 fafa1971
   assign ifu_tlu_flush_w = utrap_flush_w;
3417
   assign fcl_swl_flush_w =  (irf_ce_w & inst_vld_w & no_iftrap_w |
3418
                              rb_intr_w & intr_vld_w |
3419
                              mark4rb_w |
3420
                              fcl_dtu_resum_thr_w |
3421
                                          fcl_dtu_nuke_thr_w);
3422
 
3423
   // tells swl to flush and then wake up
3424
   assign fcl_swl_flush_wake_w = fcl_swl_flush_w & ~mark4rb_w;
3425
 
3426
   // if the same instruction keeps hitting ce's disable ce detection
3427
   // count how many ce's occur to a given thread
3428
   assign any_ce_w = ffu_ifu_fst_ce_w | irf_ce_w;
3429
 
3430
   assign ce_cnt1_nxt = (({4{any_ce_w & inst_vld_w}} & thr_w &
3431
                          ce_cnt0) ^ ce_cnt1) & ~ce_cnt_rst;
3432
   assign ce_cnt0_nxt = (({4{any_ce_w & inst_vld_w}} & thr_w) ^
3433
                         ce_cnt0) & ~ce_cnt_rst;
3434
 
3435
   assign ce_cnt_rst = thr_w & {4{inst_vld_w & ~any_ce_w}} | {4{fcl_reset}};
3436
 
3437 113 albert.wat
   dff_s #(8) cecnt_reg(.din ({ce_cnt1_nxt, ce_cnt0_nxt}),
3438 95 fafa1971
                      .q   ({ce_cnt1, ce_cnt0}),
3439
                      .clk (clk),
3440 113 albert.wat
                      .se(se), `SIMPLY_RISC_SCANIN, .so());
3441 95 fafa1971
 
3442
   // find the count for the current d stage thread
3443
   assign ce_val1_d = (thr_d[0] & ce_cnt1[0] |
3444
                       thr_d[1] & ce_cnt1[1] |
3445
                       thr_d[2] & ce_cnt1[2] |
3446
                       thr_d[3] & ce_cnt1[3]);
3447
 
3448
   assign ce_val0_d = (thr_d[0] & ce_cnt0[0] |
3449
                       thr_d[1] & ce_cnt0[1] |
3450
                       thr_d[2] & ce_cnt0[2] |
3451
                       thr_d[3] & ce_cnt0[3]);
3452
 
3453
   // if count hits 3 disable ce's
3454
   assign disable_ce_d = ce_val1_d & ce_val0_d;
3455
 
3456 113 albert.wat
   dff_s #(1) disce_ff(.din (disable_ce_d),
3457 95 fafa1971
                     .q   (disable_ce_e),
3458 113 albert.wat
                     .clk (clk), .se(se), `SIMPLY_RISC_SCANIN, .so());
3459 95 fafa1971
   assign ifu_exu_disable_ce_e = disable_ce_e;
3460
 
3461
   // select error/trap/utrap rollback PC
3462
   assign fcl_fdp_trrbpc_sel_trap_bf_l =
3463
                                ~({4{trappc_vld_w2}} & trap_thr);
3464
 
3465
   assign fcl_fdp_trrbpc_sel_err_bf_l =
3466
                  ({4{trappc_vld_w2}} & trap_thr) |
3467
                         ~({4{rb_stg_w}} & thr_w);
3468
 
3469
   assign fcl_fdp_trrbpc_sel_rb_bf_l =
3470
                  ({4{trappc_vld_w2}} & trap_thr) |
3471
                               ({4{rb_stg_w}} & thr_w) |
3472
                        ~(rb_frome & rb_fromd);
3473
 
3474
   assign fcl_fdp_trrbpc_sel_pcs_bf_l =
3475
                 ({4{trappc_vld_w2}} & trap_thr) |
3476
                               ({4{rb_stg_w}} & thr_w) |
3477
                         (rb_frome & rb_fromd);
3478
 
3479
   // select next S stage Thr PC
3480
   assign fcl_fdp_nextpcs_sel_pce_f_l = ~rb_frome;
3481
   assign fcl_fdp_nextpcs_sel_pcd_f_l = rb_frome | ~rb_fromd;
3482
   assign fcl_fdp_nextpcs_sel_pcf_f_l = rb_frome | rb_fromd |
3483
                                        ~(thr_f & {4{~part_stall_thisthr_f &
3484
                                               ~iferrto_thisthr_d1 |
3485
                                               arst_vld_f |
3486
                                               async_intr_vld_s}});
3487
   assign fcl_fdp_nextpcs_sel_pcs_f_l = rb_frome | rb_fromd |
3488
                                        (thr_f & {4{~part_stall_thisthr_f &
3489
                                              ~iferrto_thisthr_d1 |
3490
                                              arst_vld_f |
3491
                                              async_intr_vld_s}});
3492
 
3493
   // next S2 stage pc and npc select
3494
   assign thr_f_dec[3:1] = thr_f_crit[3:1] & {3{~rst_tri_en}};
3495
   assign thr_f_dec[0] = thr_f_crit[0] | rst_tri_en;
3496
   assign fcl_fdp_thr_s2_l = ~thr_f_dec;     // thr_f = thr_s2
3497
 
3498
 
3499
   // Select NextPC from
3500
   //    1. Trap NextPC (if the tnpc is valid)
3501
   //    2. reset PC
3502
   //    3. incremented PC (PC+4)
3503
   //    4. old PC (in the event of a stall)
3504
 
3505
   // Load the trap PC to the BF stage NPC.  (The BF stage NPC is used
3506
   // only for storing the next PC from the TLU
3507
   assign fcl_fdp_thrtnpc_sel_tnpc_l = ~({4{trapnpc_vld_w2}} & trap_thr);
3508
 
3509
   assign fcl_fdp_thrtnpc_sel_npcw_l = ({4{trapnpc_vld_w2}} & trap_thr) |
3510
                                               ~({4{rb_stg_w}} & thr_w);
3511
 
3512
   assign fcl_fdp_thrtnpc_sel_pcf_l = ({4{trapnpc_vld_w2}} & trap_thr) |
3513
                                              ({4{rb_stg_w}} & thr_w) |
3514
                                                (~({4{ims_flush_coll_w}} & thr_w) &
3515
                                           ~({4{flush_sonly_qual_m}} & thr_m));
3516
                                       //   {4{dec_fcl_kill4sta_e}} & thr_e);
3517
 
3518
   assign fcl_fdp_thrtnpc_sel_old_l = ({4{trapnpc_vld_w2}} & trap_thr) |
3519
                                              ({4{rb_stg_w}} & thr_w) |
3520
                                              ({4{ims_flush_coll_w}} & thr_w) |
3521
                                        ({4{flush_sonly_qual_m}} & thr_m);
3522
                                         // {4{dec_fcl_kill4sta_e}} & thr_e);
3523
 
3524
   assign ntpc_vld_nxt = fcl_fdp_thrtnpc_sel_old_l |
3525
                               ntpc_vld & ({4{(part_stall_thisthr_f |
3526
                                         iferrto_thisthr_d1) &
3527
                                        ~arst_vld_f &
3528
                                        ~async_intr_vld_s}} | ~thr_f) &
3529
                                  ~({4{trappc_vld_w2}} & trap_thr);
3530
 
3531 113 albert.wat
   dffr_s #(4) ntpcv_reg(.din  (ntpc_vld_nxt),
3532 95 fafa1971
                     .clk  (clk),
3533
                     .q    (ntpc_vld),
3534
                     .rst  (fcl_reset),
3535 113 albert.wat
                     .se   (se), `SIMPLY_RISC_SCANIN, .so());
3536 95 fafa1971
 
3537
   assign ntpc_thisthr = (thr_f[0] & ntpc_vld[0] |
3538
                                            thr_f[1] & ntpc_vld[1] |
3539
                                            thr_f[2] & ntpc_vld[2] |
3540
                                            thr_f[3] & ntpc_vld[3]);
3541
 
3542
//   assign fcl_fdp_noswpc_sel_rst_l_bf = 1'b1; 
3543
   assign fcl_fdp_noswpc_sel_tnpc_l_bf = ~ntpc_thisthr;
3544
   assign fcl_fdp_noswpc_sel_old_l_bf = ntpc_thisthr | inst_vld_f | arst_vld_f;
3545
   assign fcl_fdp_noswpc_sel_inc_l_bf = ntpc_thisthr | ~inst_vld_f & ~arst_vld_f;
3546
 
3547
 
3548
   // Don't need noswpc_sel_old anymore (this is always 1)
3549
//   always @(/*AUTOSENSE*/ntpc_vld or reset or thr_f)
3550
//     begin
3551
//            if (reset)
3552
//              begin
3553
//                 fcl_fdp_noswpc_sel_tnpc_l_bf = 1'b1;
3554
//                 fcl_fdp_noswpc_sel_rst_l_bf = 1'b0;  
3555
//                 fcl_fdp_noswpc_sel_inc_l_bf = 1'b1;
3556
//                 fcl_fdp_noswpc_sel_old_l_bf = 1'b1;
3557
//              end
3558
//            else if ((ntpc_vld & thr_f) != 4'b0000)
3559
//              begin
3560
//                 fcl_fdp_noswpc_sel_tnpc_l_bf = 1'b0;
3561
//                 fcl_fdp_noswpc_sel_rst_l_bf = 1'b1;  
3562
//                 fcl_fdp_noswpc_sel_inc_l_bf = 1'b1;
3563
//                 fcl_fdp_noswpc_sel_old_l_bf = 1'b1;  
3564
//              end // if ((ntpc_vld & thr_f) != 4'b0000)
3565
////    else if (ely_stall_thisthr_f)
3566
////      begin
3567
////         fcl_fdp_noswpc_sel_tnpc_l_bf = 1'b1;
3568
////         fcl_fdp_noswpc_sel_rst_l_bf = 1'b1;        
3569
////         fcl_fdp_noswpc_sel_inc_l_bf = 1'b1;
3570
////         fcl_fdp_noswpc_sel_old_l_bf = 1'b0;             
3571
////      end // if (ely_stall_thisthr_f)
3572
//            else 
3573
//              begin
3574
//                 fcl_fdp_noswpc_sel_tnpc_l_bf = 1'b1;
3575
//                 fcl_fdp_noswpc_sel_rst_l_bf = 1'b1;  
3576
//                 fcl_fdp_noswpc_sel_inc_l_bf = 1'b0;
3577
//                 fcl_fdp_noswpc_sel_old_l_bf = 1'b1;  
3578
//              end // else: 
3579
//            
3580
//     end // always @ (...
3581
 
3582
   // NOTE: direct branch vs indirect branch select goes from dtu to fdp
3583
 
3584
//----------------------------------------------------------------------
3585
// Instruction Register Related Control
3586
//----------------------------------------------------------------------
3587
 
3588
   // use NIR if no read previously
3589
   assign fcl_fdp_usenir_sel_nir_s1 = usenir_s1;
3590
 
3591
 
3592
   assign  fcl_fdp_inst_sel_nop_s_l = ~(ely_stall_thisthr_f |
3593
                                        ~inst_vld_s_crit |
3594
                                        force_intr_s |
3595
                                        immu_fault_f);
3596
 
3597
   assign  fcl_fdp_inst_sel_switch_s_l = ~switch_s2 |
3598
                                        (ely_stall_thisthr_f |
3599
                                         ~inst_vld_s_crit |
3600
                                         force_intr_s |
3601
                                         immu_fault_f);
3602
 
3603
   assign  fcl_fdp_inst_sel_nir_s_l = ~usenir_s1 |
3604
                                        (switch_s2 |
3605
                                         ely_stall_thisthr_f |
3606
                                         ~inst_vld_s_crit |
3607
                                         force_intr_s |
3608
                                         immu_fault_f);
3609
 
3610
   assign  fcl_fdp_inst_sel_curr_s_l = (usenir_s1 |
3611
                                        switch_s2 |
3612
                                        ely_stall_thisthr_f |
3613
                                        ~inst_vld_s_crit |
3614
                                        force_intr_s |
3615
                                        immu_fault_f);
3616
 
3617
 
3618
   // Instruction Output Mux
3619
//   always @ (/*AUTOSENSE*/ely_stall_thisthr_f or force_intr_s
3620
//             or immu_fault_f or inst_vld_s_crit or switch_s2
3621
//             or usenir_s1)
3622
//     begin
3623
//            if (ely_stall_thisthr_f | ~inst_vld_s_crit | force_intr_s | 
3624
//            immu_fault_f) 
3625
//              begin // stalled or imiss
3626
//                 fcl_fdp_inst_sel_nop_s_l = 1'b0;
3627
//                 fcl_fdp_inst_sel_switch_s_l = 1'b1;
3628
//                 fcl_fdp_inst_sel_nir_s_l = 1'b1;
3629
//                 fcl_fdp_inst_sel_curr_s_l = 1'b1;
3630
//              end
3631
//            else if (switch_s2) 
3632
//              begin
3633
//                 fcl_fdp_inst_sel_nop_s_l = 1'b1;
3634
//                 fcl_fdp_inst_sel_switch_s_l = 1'b0;
3635
//                 fcl_fdp_inst_sel_nir_s_l = 1'b1;
3636
//                 fcl_fdp_inst_sel_curr_s_l = 1'b1;
3637
//              end
3638
//            else if (usenir_s1) 
3639
//              begin
3640
//                 fcl_fdp_inst_sel_nop_s_l = 1'b1;
3641
//                 fcl_fdp_inst_sel_switch_s_l = 1'b1;
3642
//                 fcl_fdp_inst_sel_nir_s_l = 1'b0;
3643
//                 fcl_fdp_inst_sel_curr_s_l = 1'b1;
3644
//              end
3645
//            else
3646
//              begin
3647
//                 fcl_fdp_inst_sel_nop_s_l = 1'b1;
3648
//                 fcl_fdp_inst_sel_switch_s_l = 1'b1;
3649
//                 fcl_fdp_inst_sel_nir_s_l = 1'b1;
3650
//                 fcl_fdp_inst_sel_curr_s_l = 1'b0;
3651
//              end // else: !if(switch_s2 | stall_s1)
3652
//     end // always @ (...
3653
 
3654
   // thread IR input muxes
3655
   assign fcl_fdp_tinst_sel_rb_s_l   = ~rb_w2;
3656
   assign fcl_fdp_tinst_sel_ifq_s_l  = rb_w2 | ~ifq_fcl_fill_thr;
3657
   assign fcl_fdp_tinst_sel_curr_s_l = ~val_thr_s1 | rb_w2 | ifq_fcl_fill_thr;
3658
   assign fcl_fdp_tinst_sel_old_s_l  = val_thr_s1 | rb_w2 | ifq_fcl_fill_thr;
3659
 
3660
   // Select rollback instruction
3661
   assign fcl_fdp_rbinst_sel_inste_s = {4{rb2_inst_e | rt2_inst_e}} &
3662
                                       thr_e;
3663
 
3664
   // thread NIR input muxes  (2:1 no need to protect)
3665
   assign fcl_fdp_thr_s1_l = ~thr_s1 | {4{stall_s1}};
3666
 
3667
   // select appropriate NIR
3668
   assign dec_thr_s1_l[0] = ~(thr_s1[0] | rst_tri_en);
3669
   assign dec_thr_s1_l[3:1] = ~(thr_s1[3:1] & {3{~rst_tri_en}});
3670
 
3671
   assign fcl_fdp_nirthr_s1_l = dec_thr_s1_l;
3672
 
3673
 
3674
//--------------------
3675
// rdsr data to exu
3676
//--------------------   
3677
 
3678 113 albert.wat
   dff_s #(1) pcrsr_ff(.din  (dec_fcl_rdsr_sel_pc_d),
3679 95 fafa1971
                               .clk  (clk),
3680
                               .q    (rdsr_sel_pc_e),
3681 113 albert.wat
                               .se   (se), `SIMPLY_RISC_SCANIN, .so());
3682
   dff_s #(1) thrrsr_ff(.din  (dec_fcl_rdsr_sel_thr_d),
3683 95 fafa1971
                                .clk  (clk),
3684
                                .q    (rdsr_sel_thr_e),
3685 113 albert.wat
                                .se   (se), `SIMPLY_RISC_SCANIN, .so());
3686 95 fafa1971
   // make sure they are exclusive
3687
   assign fcl_fdp_rdsr_sel_pc_e_l = ~rdsr_sel_pc_e;
3688
   assign fcl_fdp_rdsr_sel_thr_e_l = ~(~rdsr_sel_pc_e & rdsr_sel_thr_e);
3689
   assign fcl_fdp_rdsr_sel_ver_e_l = ~(~rdsr_sel_pc_e & ~rdsr_sel_thr_e);
3690
 
3691
//--------------------------------------------------------------
3692
// Reg file control
3693
//--------------------------------------------------------------
3694
 
3695
// Some decode is done here since these signals are in the crit path
3696
 
3697
   // Regfile enables are only power saving features.  So they don't
3698
   // have to be exact, as long as they are on, a super set of when
3699
   // they need to be on.
3700
 
3701
   // Enable rs3 if store or atomic or mov
3702
   assign ifu_exu_ren3_s =  inst_vld_f & fdp_fcl_op_s[1] & fdp_fcl_op3_s[2] &
3703
                            (fdp_fcl_op_s[0] | fdp_fcl_op3_s[5]);
3704
 
3705
   // enable rs2 if i=0 and !branch or CAS
3706
   // cas not fully decoded;  i=inst[13];
3707
   assign ifu_exu_ren2_s = inst_vld_f & fdp_fcl_op_s[1] &
3708
                            (~fdp_fcl_ibit_s |
3709
                             fdp_fcl_op_s[0] & fdp_fcl_op3_s[5]);
3710
 
3711
   // rs1 is read if this is not (a branch on cc or no-op/sethi)
3712
   assign ifu_exu_ren1_s = inst_vld_f & (fdp_fcl_op_s[1] |     // not br/call
3713
                           fdp_fcl_op3_s[4] & fdp_fcl_op3_s[3]);  // BPR
3714
 
3715
   //-------------------------------------
3716
   // Generate oddwin signal for rs and rd
3717
   //-------------------------------------
3718
   assign fcl_fdp_oddwin_s = (exu_ifu_oddwin_s[0] & thr_f[0] |
3719
                              exu_ifu_oddwin_s[1] & thr_f[1] |
3720
                              exu_ifu_oddwin_s[2] & thr_f[2] |
3721
                              exu_ifu_oddwin_s[3] & thr_f[3]);
3722
 
3723 113 albert.wat
   dff_s #(1) oddwin_ff(.din (fcl_fdp_oddwin_s),
3724 95 fafa1971
                                  .clk (clk),
3725
                                  .q   (fcl_imd_oddwin_d),
3726 113 albert.wat
                                  .se  (se), `SIMPLY_RISC_SCANIN, .so());
3727 95 fafa1971
 
3728
 
3729
   sink #(2) s0(.in (sas_thrid_w));
3730
endmodule // sparc_ifu_fcl

powered by: WebSVN 2.1.0

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