1 |
3 |
dgisselq |
///////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: zipcpu.v
|
4 |
|
|
//
|
5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
6 |
|
|
//
|
7 |
|
|
// Purpose: This is the top level module holding the core of the Zip CPU
|
8 |
|
|
// together. The Zip CPU is designed to be as simple as possible.
|
9 |
|
|
// (actual implementation aside ...) The instruction set is about as
|
10 |
|
|
// RISC as you can get, there are only 16 instruction types supported.
|
11 |
|
|
// Please see the accompanying spec.pdf file for a description of these
|
12 |
|
|
// instructions.
|
13 |
|
|
//
|
14 |
|
|
// All instructions are 32-bits wide. All bus accesses, both address and
|
15 |
|
|
// data, are 32-bits over a wishbone bus.
|
16 |
|
|
//
|
17 |
|
|
// The Zip CPU is fully pipelined with the following pipeline stages:
|
18 |
|
|
//
|
19 |
|
|
// 1. Prefetch, returns the instruction from memory.
|
20 |
|
|
//
|
21 |
|
|
// 2. Instruction Decode
|
22 |
|
|
//
|
23 |
|
|
// 3. Read Operands
|
24 |
|
|
//
|
25 |
|
|
// 4. Apply Instruction
|
26 |
|
|
//
|
27 |
|
|
// 4. Write-back Results
|
28 |
|
|
//
|
29 |
|
|
// Further information about the inner workings of this CPU may be
|
30 |
|
|
// found in the spec.pdf file. (The documentation within this file
|
31 |
|
|
// had become out of date and out of sync with the spec.pdf, so look
|
32 |
|
|
// to the spec.pdf for accurate and up to date information.)
|
33 |
|
|
//
|
34 |
|
|
//
|
35 |
|
|
// In general, the pipelining is controlled by three pieces of logic
|
36 |
|
|
// per stage: _ce, _stall, and _valid. _valid means that the stage
|
37 |
|
|
// holds a valid instruction. _ce means that the instruction from the
|
38 |
|
|
// previous stage is to move into this one, and _stall means that the
|
39 |
|
|
// instruction from the previous stage may not move into this one.
|
40 |
|
|
// The difference between these control signals allows individual stages
|
41 |
|
|
// to propagate instructions independently. In general, the logic works
|
42 |
|
|
// as:
|
43 |
|
|
//
|
44 |
|
|
//
|
45 |
|
|
// assign (n)_ce = (n-1)_valid && (~(n)_stall)
|
46 |
|
|
//
|
47 |
|
|
//
|
48 |
|
|
// always @(posedge i_clk)
|
49 |
|
|
// if ((i_rst)||(clear_pipeline))
|
50 |
|
|
// (n)_valid = 0
|
51 |
|
|
// else if (n)_ce
|
52 |
|
|
// (n)_valid = 1
|
53 |
|
|
// else if (n+1)_ce
|
54 |
|
|
// (n)_valid = 0
|
55 |
|
|
//
|
56 |
|
|
// assign (n)_stall = ( (n-1)_valid && ( pipeline hazard detection ) )
|
57 |
|
|
// || ( (n)_valid && (n+1)_stall );
|
58 |
|
|
//
|
59 |
|
|
// and ...
|
60 |
|
|
//
|
61 |
|
|
// always @(posedge i_clk)
|
62 |
|
|
// if (n)_ce
|
63 |
|
|
// (n)_variable = ... whatever logic for this stage
|
64 |
|
|
//
|
65 |
|
|
// Note that a stage can stall even if no instruction is loaded into
|
66 |
|
|
// it.
|
67 |
|
|
//
|
68 |
|
|
//
|
69 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
70 |
|
|
// Gisselquist Technology, LLC
|
71 |
|
|
//
|
72 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
73 |
|
|
//
|
74 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
75 |
|
|
//
|
76 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
77 |
|
|
// modify it under the terms of the GNU General Public License as published
|
78 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
79 |
|
|
// your option) any later version.
|
80 |
|
|
//
|
81 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
82 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
83 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
84 |
|
|
// for more details.
|
85 |
|
|
//
|
86 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
87 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
88 |
|
|
//
|
89 |
|
|
//
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
//
|
92 |
|
|
// We can either pipeline our fetches, or issue one fetch at a time. Pipelined
|
93 |
|
|
// fetches are more complicated and therefore use more FPGA resources, while
|
94 |
|
|
// single fetches will cause the CPU to stall for about 5 stalls each
|
95 |
|
|
// instruction cycle, effectively reducing the instruction count per clock to
|
96 |
|
|
// about 0.2. However, the area cost may be worth it. Consider:
|
97 |
|
|
//
|
98 |
|
|
// Slice LUTs ZipSystem ZipCPU
|
99 |
|
|
// Single Fetching 2521 1734
|
100 |
|
|
// Pipelined fetching 2796 2046
|
101 |
|
|
//
|
102 |
|
|
//
|
103 |
|
|
//
|
104 |
|
|
`define CPU_CC_REG 4'he
|
105 |
|
|
`define CPU_PC_REG 4'hf
|
106 |
|
|
`define CPU_CLRCACHE_BIT 14 // Floating point error flag, set on error
|
107 |
|
|
`define CPU_PHASE_BIT 13 // Floating point error flag, set on error
|
108 |
|
|
`define CPU_FPUERR_BIT 12 // Floating point error flag, set on error
|
109 |
|
|
`define CPU_DIVERR_BIT 11 // Divide error flag, set on divide by zero
|
110 |
|
|
`define CPU_BUSERR_BIT 10 // Bus error flag, set on error
|
111 |
|
|
`define CPU_TRAP_BIT 9 // User TRAP has taken place
|
112 |
|
|
`define CPU_ILL_BIT 8 // Illegal instruction
|
113 |
|
|
`define CPU_BREAK_BIT 7
|
114 |
|
|
`define CPU_STEP_BIT 6 // Will step one or two (VLIW) instructions
|
115 |
|
|
`define CPU_GIE_BIT 5
|
116 |
|
|
`define CPU_SLEEP_BIT 4
|
117 |
|
|
// Compile time defines
|
118 |
|
|
//
|
119 |
|
|
`include "cpudefs.v"
|
120 |
|
|
//
|
121 |
|
|
//
|
122 |
|
|
module zipcpuhs(i_clk, i_rst, i_interrupt,
|
123 |
|
|
// Debug interface
|
124 |
|
|
i_halt, i_clear_pf_cache, i_dbg_reg, i_dbg_we, i_dbg_data,
|
125 |
|
|
o_dbg_stall, o_dbg_reg, o_dbg_cc,
|
126 |
|
|
o_break,
|
127 |
|
|
// CPU interface to the wishbone bus
|
128 |
|
|
o_wb_gbl_cyc, o_wb_gbl_stb,
|
129 |
|
|
o_wb_lcl_cyc, o_wb_lcl_stb,
|
130 |
|
|
o_wb_we, o_wb_addr, o_wb_data,
|
131 |
|
|
i_wb_ack, i_wb_stall, i_wb_data,
|
132 |
|
|
i_wb_err,
|
133 |
|
|
// Accounting/CPU usage interface
|
134 |
|
|
o_op_stall, o_pf_stall, o_i_count
|
135 |
|
|
`ifdef DEBUG_SCOPE
|
136 |
|
|
, o_debug
|
137 |
|
|
`endif
|
138 |
|
|
);
|
139 |
|
|
parameter RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=24,
|
140 |
|
|
LGICACHE=6;
|
141 |
|
|
`ifdef OPT_MULTIPLY
|
142 |
|
|
parameter IMPLEMENT_MPY = `OPT_MULTIPLY;
|
143 |
|
|
`else
|
144 |
|
|
parameter IMPLEMENT_MPY = 0;
|
145 |
|
|
`endif
|
146 |
|
|
`ifdef OPT_DIVIDE
|
147 |
|
|
parameter IMPLEMENT_DIVIDE = 1;
|
148 |
|
|
`else
|
149 |
|
|
parameter IMPLEMENT_DIVIDE = 0;
|
150 |
|
|
`endif
|
151 |
|
|
`ifdef OPT_IMPLEMENT_FPU
|
152 |
|
|
parameter IMPLEMENT_FPU = 1,
|
153 |
|
|
`else
|
154 |
|
|
parameter IMPLEMENT_FPU = 0,
|
155 |
|
|
`endif
|
156 |
|
|
IMPLEMENT_LOCK=1;
|
157 |
|
|
`ifdef OPT_EARLY_BRANCHING
|
158 |
|
|
parameter EARLY_BRANCHING = 1;
|
159 |
|
|
`else
|
160 |
|
|
parameter EARLY_BRANCHING = 0;
|
161 |
|
|
`endif
|
162 |
|
|
parameter AW=ADDRESS_WIDTH;
|
163 |
|
|
input i_clk, i_rst, i_interrupt;
|
164 |
|
|
// Debug interface -- inputs
|
165 |
|
|
input i_halt, i_clear_pf_cache;
|
166 |
|
|
input [4:0] i_dbg_reg;
|
167 |
|
|
input i_dbg_we;
|
168 |
|
|
input [31:0] i_dbg_data;
|
169 |
|
|
// Debug interface -- outputs
|
170 |
|
|
output wire o_dbg_stall;
|
171 |
|
|
output reg [31:0] o_dbg_reg;
|
172 |
|
|
output reg [3:0] o_dbg_cc;
|
173 |
|
|
output wire o_break;
|
174 |
|
|
// Wishbone interface -- outputs
|
175 |
|
|
output wire o_wb_gbl_cyc, o_wb_gbl_stb;
|
176 |
|
|
output wire o_wb_lcl_cyc, o_wb_lcl_stb, o_wb_we;
|
177 |
|
|
output wire [(AW-1):0] o_wb_addr;
|
178 |
|
|
output wire [31:0] o_wb_data;
|
179 |
|
|
// Wishbone interface -- inputs
|
180 |
|
|
input i_wb_ack, i_wb_stall;
|
181 |
|
|
input [31:0] i_wb_data;
|
182 |
|
|
input i_wb_err;
|
183 |
|
|
// Accounting outputs ... to help us count stalls and usage
|
184 |
|
|
output wire o_op_stall;
|
185 |
|
|
output wire o_pf_stall;
|
186 |
|
|
output wire o_i_count;
|
187 |
|
|
//
|
188 |
|
|
`ifdef DEBUG_SCOPE
|
189 |
|
|
output reg [31:0] o_debug;
|
190 |
|
|
`endif
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
// Registers
|
194 |
|
|
//
|
195 |
|
|
// The distributed RAM style comment is necessary on the
|
196 |
|
|
// SPARTAN6 with XST to prevent XST from oversimplifying the register
|
197 |
|
|
// set and in the process ruining everything else. It basically
|
198 |
|
|
// optimizes logic away, to where it no longer works. The logic
|
199 |
|
|
// as described herein will work, this just makes sure XST implements
|
200 |
|
|
// that logic.
|
201 |
|
|
//
|
202 |
|
|
(* ram_style = "distributed" *)
|
203 |
|
|
reg [31:0] regset [0:31];
|
204 |
|
|
|
205 |
|
|
// Condition codes
|
206 |
|
|
// (BUS, TRAP,ILL,BREAKEN,STEP,GIE,SLEEP ), V, N, C, Z
|
207 |
|
|
reg [3:0] flags, iflags;
|
208 |
|
|
wire [14:0] w_uflags, w_iflags;
|
209 |
|
|
reg trap, break_en, step, gie, sleep, r_halted,
|
210 |
|
|
break_pending;
|
211 |
|
|
wire w_clear_icache;
|
212 |
|
|
`ifdef OPT_ILLEGAL_INSTRUCTION
|
213 |
|
|
reg ill_err_u, ill_err_i;
|
214 |
|
|
`else
|
215 |
|
|
wire ill_err_u, ill_err_i;
|
216 |
|
|
`endif
|
217 |
|
|
reg ubreak;
|
218 |
|
|
reg ibus_err_flag, ubus_err_flag;
|
219 |
|
|
wire idiv_err_flag, udiv_err_flag;
|
220 |
|
|
wire ifpu_err_flag, ufpu_err_flag;
|
221 |
|
|
wire ihalt_phase, uhalt_phase;
|
222 |
|
|
|
223 |
|
|
// The master chip enable
|
224 |
|
|
wire master_ce;
|
225 |
|
|
|
226 |
|
|
//
|
227 |
|
|
//
|
228 |
|
|
// PIPELINE STAGE #1 :: Prefetch
|
229 |
|
|
// Variable declarations
|
230 |
|
|
//
|
231 |
|
|
reg [(AW-1):0] pf_pc;
|
232 |
|
|
reg new_pc;
|
233 |
|
|
wire clear_pipeline;
|
234 |
|
|
assign clear_pipeline = new_pc;
|
235 |
|
|
|
236 |
|
|
wire dcd_stalled;
|
237 |
|
|
wire pf_cyc, pf_stb, pf_we, pf_busy, pf_ack, pf_stall, pf_err;
|
238 |
|
|
wire [(AW-1):0] pf_addr;
|
239 |
|
|
wire [31:0] pf_data;
|
240 |
|
|
wire [31:0] instruction;
|
241 |
|
|
wire [(AW-1):0] instruction_pc;
|
242 |
|
|
wire pf_valid, instruction_gie, pf_illegal;
|
243 |
|
|
|
244 |
|
|
//
|
245 |
|
|
//
|
246 |
|
|
// PIPELINE STAGE #2 :: Instruction Decode
|
247 |
|
|
// Variable declarations
|
248 |
|
|
//
|
249 |
|
|
//
|
250 |
|
|
wire op_stall, dcd_ce, dcd_phase;
|
251 |
|
|
wire [3:0] dcdOp;
|
252 |
|
|
wire [4:0] dcd_iA, dcd_iB, dcd_iR;
|
253 |
|
|
wire dcdA_cc, dcdB_cc, dcdA_pc, dcdB_pc, dcdR_cc, dcdR_pc;
|
254 |
|
|
wire [3:0] dcdF;
|
255 |
|
|
wire dcd_wR, dcd_rA, dcd_rB,
|
256 |
|
|
dcdALU, dcdM, dcdDV, dcdFP,
|
257 |
|
|
dcdF_wr, dcd_gie, dcd_break, dcd_lock,
|
258 |
|
|
dcd_pipe, dcd_ljmp;
|
259 |
|
|
reg [1:0] r_dcdvalid;
|
260 |
|
|
wire dcd_valid;
|
261 |
|
|
wire [(AW-1):0] dcd_pc;
|
262 |
|
|
wire [31:0] dcd_I;
|
263 |
|
|
wire dcd_zI; // true if dcdI == 0
|
264 |
|
|
wire dcdA_stall, dcdB_stall, dcdF_stall;
|
265 |
|
|
|
266 |
|
|
wire dcd_illegal;
|
267 |
|
|
wire dcd_early_branch;
|
268 |
|
|
wire [(AW-1):0] dcd_branch_pc;
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
//
|
272 |
|
|
//
|
273 |
|
|
// PIPELINE STAGE #3a :: Read Operands
|
274 |
|
|
// Variable declarations
|
275 |
|
|
//
|
276 |
|
|
//
|
277 |
|
|
//
|
278 |
|
|
// Now, let's read our operands
|
279 |
|
|
reg opa_valid, opa_DV, opa_FP, opa_ALU, opa_M,
|
280 |
|
|
opa_rA, opa_rB;
|
281 |
|
|
reg [4:0] alu_reg;
|
282 |
|
|
reg [3:0] opa_opn;
|
283 |
|
|
reg [4:0] opa_R, opa_iA;
|
284 |
|
|
reg [31:0] r_opa_B;
|
285 |
|
|
reg [(AW-1):0] opa_pc;
|
286 |
|
|
wire [31:0] opA_nowait, opa_Bnowait, opa_A, opa_B, opa_I;
|
287 |
|
|
reg opa_wR, opa_ccR, opa_wF, opa_gie;
|
288 |
|
|
wire [13:0] opa_Fl;
|
289 |
|
|
reg [5:0] r_opa_F;
|
290 |
|
|
wire [7:0] opa_F;
|
291 |
|
|
wire opa_ce, opa_phase, opa_pipe;
|
292 |
|
|
// Some pipeline control wires
|
293 |
|
|
reg opa_A_alu, opa_A_mem;
|
294 |
|
|
reg opa_B_alu, opa_B_mem;
|
295 |
|
|
`ifdef OPT_ILLEGAL_INSTRUCTION
|
296 |
|
|
reg opa_illegal;
|
297 |
|
|
`else
|
298 |
|
|
wire opa_illegal;
|
299 |
|
|
assign opa_illegal = 1'b0;
|
300 |
|
|
`endif
|
301 |
|
|
reg opa_break;
|
302 |
|
|
reg opa_lock;
|
303 |
|
|
|
304 |
|
|
//
|
305 |
|
|
//
|
306 |
|
|
// PIPELINE STAGE #3b :: Read Operands
|
307 |
|
|
// Variable declarations
|
308 |
|
|
//
|
309 |
|
|
//
|
310 |
|
|
//
|
311 |
|
|
// Now, let's read our operands
|
312 |
|
|
reg [3:0] opb_opn;
|
313 |
|
|
reg opb_valid, opb_valid_mem, opb_valid_alu;
|
314 |
|
|
reg opb_valid_div, opb_valid_fpu;
|
315 |
|
|
reg [4:0] opb_R;
|
316 |
|
|
reg [31:0] r_opb_A, r_opb_B;
|
317 |
|
|
reg [(AW-1):0] opb_pc;
|
318 |
|
|
wire [31:0] opb_A_nowait, opb_B_nowait, opb_A, opb_B;
|
319 |
|
|
reg opb_wR, opb_ccR, opb_wF, opb_gie;
|
320 |
|
|
wire [13:0] opb_Fl;
|
321 |
|
|
reg [5:0] r_opb_F;
|
322 |
|
|
wire [7:0] opb_F;
|
323 |
|
|
wire opb_ce, opb_phase, opb_pipe;
|
324 |
|
|
// Some pipeline control wires
|
325 |
|
|
reg opb_A_alu, opb_A_mem;
|
326 |
|
|
reg opb_B_alu, opb_B_mem;
|
327 |
|
|
`ifdef OPT_ILLEGAL_INSTRUCTION
|
328 |
|
|
reg opb_illegal;
|
329 |
|
|
`else
|
330 |
|
|
wire opb_illegal;
|
331 |
|
|
assign opb_illegal = 1'b0;
|
332 |
|
|
`endif
|
333 |
|
|
reg opb_break;
|
334 |
|
|
reg opb_lock;
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
//
|
338 |
|
|
//
|
339 |
|
|
// PIPELINE STAGE #4 :: ALU / Memory / Divide
|
340 |
|
|
// Variable declarations
|
341 |
|
|
//
|
342 |
|
|
//
|
343 |
|
|
reg [(AW-1):0] alu_pc;
|
344 |
|
|
reg r_alu_pc_valid, mem_pc_valid;
|
345 |
|
|
wire alu_pc_valid;
|
346 |
|
|
wire alu_phase;
|
347 |
|
|
wire alu_ce, alu_stall;
|
348 |
|
|
wire [31:0] alu_result;
|
349 |
|
|
wire [3:0] alu_flags;
|
350 |
|
|
wire alu_valid, alu_busy;
|
351 |
|
|
wire set_cond;
|
352 |
|
|
reg alu_wr, alF_wr, alu_gie;
|
353 |
|
|
wire alu_illegal_op;
|
354 |
|
|
wire alu_illegal;
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
wire mem_ce, mem_stalled;
|
359 |
|
|
wire mem_pipe_stalled;
|
360 |
|
|
wire mem_valid, mem_ack, mem_stall, mem_err, bus_err,
|
361 |
|
|
mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl, mem_we;
|
362 |
|
|
wire [4:0] mem_wreg;
|
363 |
|
|
|
364 |
|
|
wire mem_busy, mem_rdbusy;
|
365 |
|
|
wire [(AW-1):0] mem_addr;
|
366 |
|
|
wire [31:0] mem_data, mem_result;
|
367 |
|
|
|
368 |
|
|
wire div_ce, div_error, div_busy, div_valid;
|
369 |
|
|
wire [31:0] div_result;
|
370 |
|
|
wire [3:0] div_flags;
|
371 |
|
|
|
372 |
|
|
assign div_ce = (master_ce)&&(~clear_pipeline)&&(opb_valid_div)
|
373 |
|
|
&&(~stage_busy)&&(set_cond);
|
374 |
|
|
|
375 |
|
|
wire fpu_ce, fpu_error, fpu_busy, fpu_valid;
|
376 |
|
|
wire [31:0] fpu_result;
|
377 |
|
|
wire [3:0] fpu_flags;
|
378 |
|
|
|
379 |
|
|
assign fpu_ce = (master_ce)&&(~clear_pipeline)&&(opb_valid_fpu)
|
380 |
|
|
&&(~stage_busy)&&(set_cond);
|
381 |
|
|
|
382 |
|
|
//
|
383 |
|
|
//
|
384 |
|
|
// PIPELINE STAGE #5 :: Write-back
|
385 |
|
|
// Variable declarations
|
386 |
|
|
//
|
387 |
|
|
wire wr_reg_ce, wr_flags_ce, wr_write_pc, wr_write_cc;
|
388 |
|
|
wire [4:0] wr_reg_id;
|
389 |
|
|
wire [31:0] wr_gpreg_vl, wr_spreg_vl;
|
390 |
|
|
wire w_switch_to_interrupt, w_release_from_interrupt;
|
391 |
|
|
reg [(AW-1):0] upc, ipc;
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
//
|
396 |
|
|
// MASTER: clock enable.
|
397 |
|
|
//
|
398 |
|
|
assign master_ce = (~i_halt)&&(~o_break)&&(~sleep);
|
399 |
|
|
|
400 |
|
|
|
401 |
|
|
//
|
402 |
|
|
// PIPELINE STAGE #1 :: Prefetch
|
403 |
|
|
// Calculate stall conditions
|
404 |
|
|
//
|
405 |
|
|
// These are calculated externally, within the prefetch module.
|
406 |
|
|
//
|
407 |
|
|
|
408 |
|
|
//
|
409 |
|
|
// PIPELINE STAGE #2 :: Instruction Decode
|
410 |
|
|
// Calculate stall conditions
|
411 |
|
|
assign dcd_ce = ((~dcd_valid)||(~dcd_stalled))&&(~clear_pipeline);
|
412 |
|
|
|
413 |
|
|
assign dcd_stalled = (dcd_valid)&&(op_stall);
|
414 |
|
|
//
|
415 |
|
|
// PIPELINE STAGE #3 :: Read Operands
|
416 |
|
|
// Calculate stall conditions
|
417 |
|
|
wire op_lock_stall;
|
418 |
|
|
assign op_stall = (opvalid)&&( // Only stall if we're loaded w/validins
|
419 |
|
|
// Stall if we're stopped, and not allowed to execute
|
420 |
|
|
// an instruction
|
421 |
|
|
// (~master_ce) // Already captured in alu_stall
|
422 |
|
|
//
|
423 |
|
|
// Stall if going into the ALU and the ALU is stalled
|
424 |
|
|
// i.e. if the memory is busy, or we are single
|
425 |
|
|
// stepping. This also includes our stalls for
|
426 |
|
|
// op_break and op_lock, so we don't need to
|
427 |
|
|
// include those as well here.
|
428 |
|
|
// This also includes whether or not the divide or
|
429 |
|
|
// floating point units are busy.
|
430 |
|
|
(alu_stall)
|
431 |
|
|
//
|
432 |
|
|
// Stall if we are going into memory with an operation
|
433 |
|
|
// that cannot be pipelined, and the memory is
|
434 |
|
|
// already busy
|
435 |
|
|
||(mem_stalled) // &&(opvalid_mem) part of mem_stalled
|
436 |
|
|
)
|
437 |
|
|
||(dcd_valid)&&(
|
438 |
|
|
// Stall if we need to wait for an operand A
|
439 |
|
|
// to be ready to read
|
440 |
|
|
(dcdA_stall)
|
441 |
|
|
// Likewise for B, also includes logic
|
442 |
|
|
// regarding immediate offset (register must
|
443 |
|
|
// be in register file if we need to add to
|
444 |
|
|
// an immediate)
|
445 |
|
|
||(dcdB_stall)
|
446 |
|
|
// Or if we need to wait on flags to work on the
|
447 |
|
|
// CC register
|
448 |
|
|
||(dcdF_stall)
|
449 |
|
|
);
|
450 |
|
|
assign opa_ce = ((dcd_valid)||(dcd_illegal))&&(~opa_stall);
|
451 |
|
|
|
452 |
|
|
//
|
453 |
|
|
// PIPELINE STAGE #4 :: ALU / Memory
|
454 |
|
|
// Calculate stall conditions
|
455 |
|
|
//
|
456 |
|
|
// 1. Basic stall is if the previous stage is valid and the next is
|
457 |
|
|
// busy.
|
458 |
|
|
// 2. Also stall if the prior stage is valid and the master clock enable
|
459 |
|
|
// is de-selected
|
460 |
|
|
// 3. Stall if someone on the other end is writing the CC register,
|
461 |
|
|
// since we don't know if it'll put us to sleep or not.
|
462 |
|
|
// 4. Last case: Stall if we would otherwise move a break instruction
|
463 |
|
|
// through the ALU. Break instructions are not allowed through
|
464 |
|
|
// the ALU.
|
465 |
|
|
assign alu_stall = (((~master_ce)||(mem_rdbusy)||(alu_busy))&&(opvalid_alu)) //Case 1&2
|
466 |
|
|
// Old case #3--this isn't an ALU stall though ...
|
467 |
|
|
||((opvalid_alu)&&(wr_reg_ce)&&(wr_reg_id[4] == op_gie)
|
468 |
|
|
&&(wr_write_cc)) // Case 3
|
469 |
|
|
||((opvalid)&&(op_lock)&&(op_lock_stall))
|
470 |
|
|
||((opvalid)&&(op_break))
|
471 |
|
|
||(div_busy)||(fpu_busy);
|
472 |
|
|
assign alu_ce = (master_ce)&&(stage_ce)&&(opvalid_alu)&&(~clear_pipeline);
|
473 |
|
|
assign stage_ce = (~div_busy)&&(~alu_busy)&&(~mem_rdbusy)&&(~fpu_busy);
|
474 |
|
|
//
|
475 |
|
|
|
476 |
|
|
//
|
477 |
|
|
// Note: if you change the conditions for mem_ce, you must also change
|
478 |
|
|
// alu_pc_valid.
|
479 |
|
|
//
|
480 |
|
|
assign mem_ce = (master_ce)&&(opvalid_mem)&&(~mem_stalled)
|
481 |
|
|
&&(~clear_pipeline);
|
482 |
|
|
assign mem_stalled = (~master_ce)||(alu_busy)||((opvalid_mem)&&(
|
483 |
|
|
(mem_pipe_stalled)
|
484 |
|
|
||((~op_pipe)&&(mem_busy))
|
485 |
|
|
||(div_busy)
|
486 |
|
|
||(fpu_busy)
|
487 |
|
|
// Stall waiting for flags to be valid
|
488 |
|
|
// Or waiting for a write to the PC register
|
489 |
|
|
// Or CC register, since that can change the
|
490 |
|
|
// PC as well
|
491 |
|
|
||((wr_reg_ce)&&(wr_reg_id[4] == op_gie)
|
492 |
|
|
&&((wr_write_pc)||(wr_write_cc)))));
|
493 |
|
|
|
494 |
|
|
|
495 |
|
|
//
|
496 |
|
|
//
|
497 |
|
|
// PIPELINE STAGE #1 :: Prefetch
|
498 |
|
|
//
|
499 |
|
|
//
|
500 |
|
|
fastcache #(LGICACHE, ADDRESS_WIDTH)
|
501 |
|
|
pf(i_clk, i_rst, (new_pc)||((dcd_early_branch)&&(~clear_pipeline)),
|
502 |
|
|
i_clear_pf_cache,
|
503 |
|
|
// dcd_pc,
|
504 |
|
|
~dcd_stalled,
|
505 |
|
|
((dcd_early_branch)&&(~clear_pipeline))
|
506 |
|
|
? dcd_branch_pc:pf_pc,
|
507 |
|
|
instruction, instruction_pc, pf_valid,
|
508 |
|
|
pf_cyc, pf_stb, pf_we, pf_addr, pf_data,
|
509 |
|
|
pf_ack, pf_stall, pf_err, i_wb_data,
|
510 |
|
|
pf_illegal);
|
511 |
|
|
assign instruction_gie = gie;
|
512 |
|
|
|
513 |
|
|
//
|
514 |
|
|
// The ifastdec decoder takes two clocks to decode an instruction.
|
515 |
|
|
// Therefore, to determine if a decoded instruction is valid, we
|
516 |
|
|
// need to wait two clocks from pf_valid. Hence, we dump this into
|
517 |
|
|
// a pipeline below.
|
518 |
|
|
//
|
519 |
|
|
initial r_dcdvalid = 2'b00;
|
520 |
|
|
always @(posedge i_clk)
|
521 |
|
|
if ((i_rst)||(clear_pipeline)||(w_clear_icache))
|
522 |
|
|
r_dcdvalid <= 2'b00;
|
523 |
|
|
else if (dcd_ce)
|
524 |
|
|
r_dcdvalid <= { r_dcdvalid[0], pf_valid };
|
525 |
|
|
else if (opa_ce)
|
526 |
|
|
r_dcdvalid <= 1'b0;
|
527 |
|
|
assign dcd_valid = r_dcdvalid[1];
|
528 |
|
|
|
529 |
|
|
ifastdec #(AW, IMPLEMENT_MPY, EARLY_BRANCHING, IMPLEMENT_DIVIDE,
|
530 |
|
|
IMPLEMENT_FPU)
|
531 |
|
|
instruction_decoder(i_clk, (i_rst)||(clear_pipeline),
|
532 |
|
|
dcd_ce, dcd_stalled, instruction, instruction_gie,
|
533 |
|
|
instruction_pc, pf_valid, pf_illegal, dcd_phase,
|
534 |
|
|
dcd_illegal, dcd_pc, dcd_gie,
|
535 |
|
|
{ dcdR_cc, dcdR_pc, dcd_iR },
|
536 |
|
|
{ dcdA_cc, dcdA_pc, dcd_iA },
|
537 |
|
|
{ dcdB_cc, dcdB_pc, dcd_iB },
|
538 |
|
|
dcd_I, dcd_zI, dcdF, dcdF_wr, dcdOp,
|
539 |
|
|
dcdALU, dcdM, dcdDV, dcdFP, dcd_break, dcd_lock,
|
540 |
|
|
dcd_wR,dcd_rA, dcd_rB,
|
541 |
|
|
dcd_early_branch,
|
542 |
|
|
dcd_branch_pc, dcd_ljmp,
|
543 |
|
|
dcd_pipe);
|
544 |
|
|
|
545 |
|
|
reg r_op_pipe;
|
546 |
|
|
|
547 |
|
|
initial r_op_pipe = 1'b0;
|
548 |
|
|
// To be a pipeable operation, there must be
|
549 |
|
|
// two valid adjacent instructions
|
550 |
|
|
// Both must be memory instructions
|
551 |
|
|
// Both must be writes, or both must be reads
|
552 |
|
|
// Both operations must be to the same identical address,
|
553 |
|
|
// or at least a single (one) increment above that address
|
554 |
|
|
//
|
555 |
|
|
// However ... we need to know this before this clock, hence this is
|
556 |
|
|
// calculated in the instruction decoder.
|
557 |
|
|
always @(posedge i_clk)
|
558 |
|
|
if (op_ce)
|
559 |
|
|
r_op_pipe <= dcd_pipe;
|
560 |
|
|
else if (mem_ce) // Clear us any time an op_ is clocked in
|
561 |
|
|
r_op_pipe <= 1'b0;
|
562 |
|
|
assign op_pipe = r_op_pipe;
|
563 |
|
|
|
564 |
|
|
//
|
565 |
|
|
//
|
566 |
|
|
// PIPELINE STAGE #3 :: Read Operands (Registers)
|
567 |
|
|
//
|
568 |
|
|
//
|
569 |
|
|
assign w_opA = regset[dcd_iA];
|
570 |
|
|
assign w_opB = regset[dcd_iB];
|
571 |
|
|
|
572 |
|
|
wire [8:0] w_cpu_info;
|
573 |
|
|
assign w_cpu_info = {
|
574 |
|
|
`ifdef OPT_ILLEGAL_INSTRUCTION
|
575 |
|
|
1'b1,
|
576 |
|
|
`else
|
577 |
|
|
1'b0,
|
578 |
|
|
`endif
|
579 |
|
|
1'b1,
|
580 |
|
|
`ifdef OPT_DIVIDE
|
581 |
|
|
1'b1,
|
582 |
|
|
`else
|
583 |
|
|
1'b0,
|
584 |
|
|
`endif
|
585 |
|
|
`ifdef OPT_IMPLEMENT_FPU
|
586 |
|
|
1'b1,
|
587 |
|
|
`else
|
588 |
|
|
1'b0,
|
589 |
|
|
`endif
|
590 |
|
|
1'b1, 1'b1,
|
591 |
|
|
`ifdef OPT_EARLY_BRANCHING
|
592 |
|
|
1'b1,
|
593 |
|
|
`else
|
594 |
|
|
1'b0,
|
595 |
|
|
`endif
|
596 |
|
|
1'b1,
|
597 |
|
|
`ifdef OPT_VLIW
|
598 |
|
|
1'b1
|
599 |
|
|
`else
|
600 |
|
|
1'b0
|
601 |
|
|
`endif
|
602 |
|
|
};
|
603 |
|
|
|
604 |
|
|
wire [31:0] w_pcA_v;
|
605 |
|
|
generate
|
606 |
|
|
if (AW < 32)
|
607 |
|
|
assign w_pcA_v = {{(32-AW){1'b0}}, (dcd_iA[4] == dcd_gie)?dcd_pc:upc };
|
608 |
|
|
else
|
609 |
|
|
assign w_pcA_v = (dcd_iA[4] == dcd_gie)?dcd_pc:upc;
|
610 |
|
|
endgenerate
|
611 |
|
|
|
612 |
|
|
reg [4:0] opa_Aid, opa_Bid;
|
613 |
|
|
reg opa_Ard, opa_Brd;
|
614 |
|
|
always @(posedge i_clk)
|
615 |
|
|
if (opa_ce)
|
616 |
|
|
begin
|
617 |
|
|
opa_iA <= dcd_iA;
|
618 |
|
|
opa_iB <= dcd_iB;
|
619 |
|
|
opa_rA <= dcd_rA;
|
620 |
|
|
opa_rB <= dcd_rB;
|
621 |
|
|
end
|
622 |
|
|
|
623 |
|
|
always @(posedge i_clk)
|
624 |
|
|
if (opa_ce)
|
625 |
|
|
begin
|
626 |
|
|
if ((wr_reg_ce)&&(wr_reg_id == dcd_iA))
|
627 |
|
|
r_opA <= wr_gpreg_vl;
|
628 |
|
|
else if (dcdA_pc)
|
629 |
|
|
r_opA <= w_pcA_v;
|
630 |
|
|
else if (dcdA_cc)
|
631 |
|
|
r_opA <= { w_cpu_info, w_opA[22:15], (dcd_iA[4])?w_uflags:w_iflags };
|
632 |
|
|
else
|
633 |
|
|
r_opA <= w_opA;
|
634 |
|
|
end else if ((wr_reg_ce)&&(wr_reg_id == opa_iA)&&(opa_rA))
|
635 |
|
|
r_opA <= wr_gpreg_vl;
|
636 |
|
|
|
637 |
|
|
wire [31:0] w_opBnI, w_pcB_v;
|
638 |
|
|
generate
|
639 |
|
|
if (AW < 32)
|
640 |
|
|
assign w_pcB_v = {{(32-AW){1'b0}}, (dcdB[4] == dcd_gie)?dcd_pc:upc };
|
641 |
|
|
else
|
642 |
|
|
assign w_pcB_v = (dcdB[4] == dcd_gie)?dcd_pc:upc;
|
643 |
|
|
endgenerate
|
644 |
|
|
|
645 |
|
|
always @(posedge i_clk)
|
646 |
|
|
if (opa_ce)
|
647 |
|
|
begin
|
648 |
|
|
opa_B <= (~dcdB_rd) ? 32'h00
|
649 |
|
|
: (((wr_reg_ce)&&(wr_reg_id == dcdB)) ? wr_gpreg_vl
|
650 |
|
|
: ((dcdB_pc) ? w_pcB_v
|
651 |
|
|
: ((dcdB_cc) ? { w_cpu_info, w_opB[22:14], // w_opB[31:14],
|
652 |
|
|
(dcdB[4])?w_uflags:w_iflags}
|
653 |
|
|
: w_opB)));
|
654 |
|
|
opa_I <= dcd_I;
|
655 |
|
|
end
|
656 |
|
|
|
657 |
|
|
//
|
658 |
|
|
// B-Inflight
|
659 |
|
|
//
|
660 |
|
|
// We cannot read the B register if it is "in-flight", that is if the
|
661 |
|
|
// result register of any previous instruction still needs to be written.
|
662 |
|
|
//
|
663 |
|
|
// reg [31:0] opa_b_inflight;
|
664 |
|
|
// always @(posedge i_clk)
|
665 |
|
|
// if ((i_reset)||(clear_pipeline))
|
666 |
|
|
// opa_b_inflight <= 32'h00;
|
667 |
|
|
// else begin
|
668 |
|
|
// if (wr_reg_ce)
|
669 |
|
|
// opa_b_inflight[wr_reg_id] <= 1'b0;
|
670 |
|
|
// if (opb_ce)
|
671 |
|
|
// opa_b_inflight[opa_Rid] <= 1'b1;
|
672 |
|
|
// end
|
673 |
|
|
//
|
674 |
|
|
// always @(posedge i_clk)
|
675 |
|
|
// if (opa_b_invalid)
|
676 |
|
|
// opa_b_invalid <= opa_b_inflight[opa_A];
|
677 |
|
|
// else
|
678 |
|
|
// opa_b_invalid <= opa_b_inflight[dcd_iA];
|
679 |
|
|
//
|
680 |
|
|
|
681 |
|
|
always @(posedge i_clk)
|
682 |
|
|
if (opb_ce)
|
683 |
|
|
opb_B <= opa_B + opa_I;
|
684 |
|
|
else if ((wr_reg_ce)&&(opa_Bid == wr_reg_id)&&(opa_Brd))
|
685 |
|
|
opb_B <= wr_gpreg_vl;
|
686 |
|
|
|
687 |
|
|
always @(posedge i_clk)
|
688 |
|
|
if (opa_ce)
|
689 |
|
|
opa_F <= dcdF;
|
690 |
|
|
always @(posedge i_clk)
|
691 |
|
|
if (opb_ce)
|
692 |
|
|
begin
|
693 |
|
|
case(opa_F[2:0])
|
694 |
|
|
3'h0: r_opb_F <= 6'h00; // Always
|
695 |
|
|
// These were remapped as part of the new instruction
|
696 |
|
|
// set in order to make certain that the low order
|
697 |
|
|
// two bits contained the most commonly used
|
698 |
|
|
// conditions: Always, LT, Z, and NZ.
|
699 |
|
|
3'h1: r_opb_F <= 6'h24; // LT
|
700 |
|
|
3'h2: r_opb_F <= 6'h11; // Z
|
701 |
|
|
3'h3: r_opb_F <= 6'h10; // NE
|
702 |
|
|
3'h4: r_opb_F <= 6'h30; // GT (!N&!Z)
|
703 |
|
|
3'h5: r_opb_F <= 6'h20; // GE (!N)
|
704 |
|
|
3'h6: r_opb_F <= 6'h02; // C
|
705 |
|
|
3'h7: r_opb_F <= 6'h08; // V
|
706 |
|
|
endcase
|
707 |
|
|
end // Bit order is { (flags_not_used), VNCZ mask, VNCZ value }
|
708 |
|
|
assign opb_F = { r_opb_F[3], r_opb_F[5], r_opb_F[1], r_opb_F[4:0] };
|
709 |
|
|
|
710 |
|
|
wire w_opa_valid;
|
711 |
|
|
always @(posedge i_clk)
|
712 |
|
|
if (i_rst)
|
713 |
|
|
opa_valid <= 1'b0;
|
714 |
|
|
else if (opa_ce)
|
715 |
|
|
opa_valid <= ((dcd_valid)||(dcd_illegal))&&(~clear_pipeline);
|
716 |
|
|
|
717 |
|
|
always @(posedge i_clk)
|
718 |
|
|
if ((i_rst)||(clear_pipeline))
|
719 |
|
|
begin
|
720 |
|
|
opa_valid <= 1'b0;
|
721 |
|
|
end else if (opa_ce)
|
722 |
|
|
begin
|
723 |
|
|
opa_valid <=(dcd_valid);
|
724 |
|
|
opa_M <= (dcd_valid)&&(opa_M )&&(~opa_illegal);
|
725 |
|
|
opa_DV <= (dcd_valid)&&(opa_DV )&&(~opa_illegal);
|
726 |
|
|
opa_FP <= (dcd_valid)&&(opa_FP )&&(~opa_illegal);
|
727 |
|
|
end else if (opb_ce)
|
728 |
|
|
opa_valid <= 1'b0;
|
729 |
|
|
|
730 |
|
|
initial opb_valid = 1'b0;
|
731 |
|
|
initial opb_valid_alu = 1'b0;
|
732 |
|
|
initial opb_valid_mem = 1'b0;
|
733 |
|
|
initial opb_valid_div = 1'b0;
|
734 |
|
|
initial opb_valid_fpu = 1'b0;
|
735 |
|
|
always @(posedge i_clk)
|
736 |
|
|
if ((i_rst)||(clear_pipeline))
|
737 |
|
|
begin
|
738 |
|
|
opb_valid <= 1'b0;
|
739 |
|
|
opb_valid_alu <= 1'b0;
|
740 |
|
|
opb_valid_mem <= 1'b0;
|
741 |
|
|
opb_valid_div <= 1'b0;
|
742 |
|
|
opb_valid_fpu <= 1'b0;
|
743 |
|
|
end else if (opb_ce)
|
744 |
|
|
begin
|
745 |
|
|
// Do we have a valid instruction?
|
746 |
|
|
// The decoder may vote to stall one of its
|
747 |
|
|
// instructions based upon something we currently
|
748 |
|
|
// have in our queue. This instruction must then
|
749 |
|
|
// move forward, and get a stall cycle inserted.
|
750 |
|
|
// Hence, the test on dcd_stalled here. If we must
|
751 |
|
|
// wait until our operands are valid, then we aren't
|
752 |
|
|
// valid yet until then.
|
753 |
|
|
opb_valid <= (opa_valid);
|
754 |
|
|
opb_valid_alu <=(opa_valid)&&((opa_ALU)||(opa_illegal));
|
755 |
|
|
opb_valid_mem <= (opa_valid)&&(opa_M )&&(~opa_illegal);
|
756 |
|
|
opb_valid_div <= (opa_valid)&&(opa_DV )&&(~opa_illegal);
|
757 |
|
|
opb_valid_fpu <= (opa_valid)&&(opa_FP )&&(~opa_illegal);
|
758 |
|
|
end else if ((clear_pipeline)||(stage_ce))
|
759 |
|
|
begin
|
760 |
|
|
opb_valid <= 1'b0;
|
761 |
|
|
opb_valid_alu <= 1'b0;
|
762 |
|
|
opb_valid_mem <= 1'b0;
|
763 |
|
|
opb_valid_div <= 1'b0;
|
764 |
|
|
opb_valid_fpu <= 1'b0;
|
765 |
|
|
end
|
766 |
|
|
|
767 |
|
|
initial op_break = 1'b0;
|
768 |
|
|
always @(posedge i_clk)
|
769 |
|
|
if (i_rst) opb_break <= 1'b0;
|
770 |
|
|
else if (opb_ce)
|
771 |
|
|
opb_break <= (opa_break)&&((break_en)||(~opa_gie));
|
772 |
|
|
else if ((clear_pipeline)||(~opb_valid))
|
773 |
|
|
opb_break <= 1'b0;
|
774 |
|
|
|
775 |
|
|
reg r_op_lock, r_op_lock_stall;
|
776 |
|
|
|
777 |
|
|
initial r_op_lock_stall = 1'b0;
|
778 |
|
|
always @(posedge i_clk)
|
779 |
|
|
if (i_rst)
|
780 |
|
|
r_op_lock_stall <= 1'b0;
|
781 |
|
|
else
|
782 |
|
|
r_op_lock_stall <= (~opvalid)||(~op_lock)
|
783 |
|
|
||(~dcd_valid)||(~pf_valid);
|
784 |
|
|
|
785 |
|
|
assign op_lock_stall = r_op_lock_stall;
|
786 |
|
|
|
787 |
|
|
initial opa_lock = 1'b0;
|
788 |
|
|
always @(posedge i_clk)
|
789 |
|
|
if ((i_rst)||(clear_pipeline))
|
790 |
|
|
opa_lock <= 1'b0;
|
791 |
|
|
else if (opa_ce)
|
792 |
|
|
opa_lock <= (dcd_lock)&&(~clear_pipeline);
|
793 |
|
|
initial opb_lock = 1'b0;
|
794 |
|
|
always @(posedge i_clk)
|
795 |
|
|
if ((i_rst)||(clear_pipeline))
|
796 |
|
|
opb_lock <= 1'b0;
|
797 |
|
|
else if (opb_ce)
|
798 |
|
|
opb_lock <= (opb_lock)&&(~clear_pipeline);
|
799 |
|
|
|
800 |
|
|
initial opa_illegal = 1'b0;
|
801 |
|
|
always @(posedge i_clk)
|
802 |
|
|
if ((i_rst)||(clear_pipeline))
|
803 |
|
|
opa_illegal <= 1'b0;
|
804 |
|
|
else if(opa_ce)
|
805 |
|
|
opa_illegal <=(dcd_illegal);
|
806 |
|
|
initial opb_illegal = 1'b0;
|
807 |
|
|
always @(posedge i_clk)
|
808 |
|
|
if ((i_rst)||(clear_pipeline))
|
809 |
|
|
opb_illegal <= 1'b0;
|
810 |
|
|
else if(opb_ce)
|
811 |
|
|
opb_illegal <=(opa_illegal);
|
812 |
|
|
|
813 |
|
|
always @(posedge i_clk)
|
814 |
|
|
if (opa_ce)
|
815 |
|
|
begin
|
816 |
|
|
opa_wF <= (dcdF_wr)&&((~dcdR_cc)||(~dcd_wR))
|
817 |
|
|
&&(~dcd_early_branch)&&(~dcd_illegal);
|
818 |
|
|
opa_wR <= (dcd_wR)&&(~dcd_early_branch)&&(~dcd_illegal);
|
819 |
|
|
end
|
820 |
|
|
always @(posedge i_clk)
|
821 |
|
|
if (opb_ce)
|
822 |
|
|
begin
|
823 |
|
|
opb_wF <= opa_wF;
|
824 |
|
|
opb_wR <= opa_wR;
|
825 |
|
|
end
|
826 |
|
|
|
827 |
|
|
always @(posedge i_clk)
|
828 |
|
|
if (opa_ce)
|
829 |
|
|
begin
|
830 |
|
|
opa_opn <= dcdOp; // Which ALU operation?
|
831 |
|
|
opa_R <= dcd_iR;
|
832 |
|
|
opa_ccR <= (dcdR_cc)&&(dcd_wR)&&(dcd_iR[4]==dcd_gie);
|
833 |
|
|
opa_gie <= dcd_gie;
|
834 |
|
|
//
|
835 |
|
|
opa_pc <= dcd_valid;
|
836 |
|
|
opa_rA <= dcd_;
|
837 |
|
|
opa_rB <= dcd_;
|
838 |
|
|
end
|
839 |
|
|
always @(posedge i_clk)
|
840 |
|
|
if (opb_ce)
|
841 |
|
|
begin
|
842 |
|
|
opb_opn <= opa_opn;
|
843 |
|
|
opb_R <= opa_R;
|
844 |
|
|
opb_ccR <= opa_ccR;
|
845 |
|
|
opb_gie <= opa_gie;
|
846 |
|
|
//
|
847 |
|
|
opb_pc <= opa_pc;
|
848 |
|
|
end
|
849 |
|
|
assign opb_Fl = (opb_gie)?(w_uflags):(w_iflags);
|
850 |
|
|
|
851 |
|
|
always @(posedge i_clk)
|
852 |
|
|
if ((i_rst)||(clear_pipeline))
|
853 |
|
|
opa_phase <= 1'b0;
|
854 |
|
|
else if (opa_ce)
|
855 |
|
|
opa_phase <= dcd_phase;
|
856 |
|
|
|
857 |
|
|
always @(posedge i_clk)
|
858 |
|
|
if ((i_rst)||(clear_pipeline))
|
859 |
|
|
opb_phase <= 1'b0;
|
860 |
|
|
else if (opb_ce)
|
861 |
|
|
opb_phase <= opa_phase;
|
862 |
|
|
|
863 |
|
|
assign opA = r_opA;
|
864 |
|
|
|
865 |
|
|
assign dcdA_stall = (dcd_rA) // &&(dcdvalid) is checked for elsewhere
|
866 |
|
|
&&((opa_valid)||(mem_rdbusy)
|
867 |
|
|
||(div_busy)||(fpu_busy))
|
868 |
|
|
&&((opF_wr)&&(dcdA_cc));
|
869 |
|
|
|
870 |
|
|
assign dcdB_stall = (dcdB_rd)
|
871 |
|
|
&&((opa_valid)||(mem_rdbusy)
|
872 |
|
|
||(div_busy)||(fpu_busy)||(alu_busy))
|
873 |
|
|
&&(
|
874 |
|
|
// 1.
|
875 |
|
|
((~dcd_zI)&&(
|
876 |
|
|
((opb_R == dcdB)&&(opb_wR))
|
877 |
|
|
||((mem_rdbusy)&&(~dcd_pipe))
|
878 |
|
|
))
|
879 |
|
|
// 2.
|
880 |
|
|
||((opF_wr)&&(dcdB_cc))
|
881 |
|
|
);
|
882 |
|
|
assign dcdF_stall = ((~dcdF[3])
|
883 |
|
|
||((dcd_rA)&&(dcdA_cc))
|
884 |
|
|
||((dcd_rB)&&(dcdB_cc)))
|
885 |
|
|
&&(opvalid)&&(opb_ccR);
|
886 |
|
|
//
|
887 |
|
|
//
|
888 |
|
|
// PIPELINE STAGE #4 :: Apply Instruction
|
889 |
|
|
//
|
890 |
|
|
//
|
891 |
|
|
fastops fastalu(i_clk, i_rst, alu_ce,
|
892 |
|
|
(opb_valid_alu), opb_opn, opb_A, opb_B,
|
893 |
|
|
alu_result, alu_flags, alu_valid, alu_illegal_op,
|
894 |
|
|
alu_busy);
|
895 |
|
|
|
896 |
|
|
div thedivide(i_clk, (i_rst)||(clear_pipeline), div_ce, opb_opn[0],
|
897 |
|
|
opb_A, opb_B, div_busy, div_valid, div_error, div_result,
|
898 |
|
|
div_flags);
|
899 |
|
|
|
900 |
|
|
generate
|
901 |
|
|
if (IMPLEMENT_FPU != 0)
|
902 |
|
|
begin
|
903 |
|
|
//
|
904 |
|
|
// sfpu thefpu(i_clk, i_rst, fpu_ce,
|
905 |
|
|
// opA, opB, fpu_busy, fpu_valid, fpu_err, fpu_result,
|
906 |
|
|
// fpu_flags);
|
907 |
|
|
//
|
908 |
|
|
assign fpu_error = 1'b0; // Must only be true if fpu_valid
|
909 |
|
|
assign fpu_busy = 1'b0;
|
910 |
|
|
assign fpu_valid = 1'b0;
|
911 |
|
|
assign fpu_result= 32'h00;
|
912 |
|
|
assign fpu_flags = 4'h0;
|
913 |
|
|
end else begin
|
914 |
|
|
assign fpu_error = 1'b0;
|
915 |
|
|
assign fpu_busy = 1'b0;
|
916 |
|
|
assign fpu_valid = 1'b0;
|
917 |
|
|
assign fpu_result= 32'h00;
|
918 |
|
|
assign fpu_flags = 4'h0;
|
919 |
|
|
end endgenerate
|
920 |
|
|
|
921 |
|
|
|
922 |
|
|
assign set_cond = ((opb_F[7:4]&opb_Fl[3:0])==opb_F[3:0]);
|
923 |
|
|
initial alF_wr = 1'b0;
|
924 |
|
|
initial alu_wr = 1'b0;
|
925 |
|
|
always @(posedge i_clk)
|
926 |
|
|
if (i_rst)
|
927 |
|
|
begin
|
928 |
|
|
alu_wr <= 1'b0;
|
929 |
|
|
alF_wr <= 1'b0;
|
930 |
|
|
end else if (alu_ce)
|
931 |
|
|
begin
|
932 |
|
|
// alu_reg <= opR;
|
933 |
|
|
alu_wr <= (opb_wR)&&(set_cond);
|
934 |
|
|
alF_wr <= (opb_wF)&&(set_cond);
|
935 |
|
|
end else if (~alu_busy) begin
|
936 |
|
|
// These are strobe signals, so clear them if not
|
937 |
|
|
// set for any particular clock
|
938 |
|
|
alu_wr <= (i_halt)&&(i_dbg_we);
|
939 |
|
|
alF_wr <= 1'b0;
|
940 |
|
|
end
|
941 |
|
|
|
942 |
|
|
initial alu_phase = 1'b0;
|
943 |
|
|
always @(posedge i_clk)
|
944 |
|
|
if (i_rst)
|
945 |
|
|
alu_phase <= 1'b0;
|
946 |
|
|
else if ((adf_ce_unconditional)||(mem_ce))
|
947 |
|
|
alu_phase <= opb_phase;
|
948 |
|
|
|
949 |
|
|
always @(posedge i_clk)
|
950 |
|
|
if (adf_ce_unconditional)
|
951 |
|
|
alu_reg <= opb_R;
|
952 |
|
|
else if ((i_halt)&&(i_dbg_we))
|
953 |
|
|
alu_reg <= i_dbg_reg;
|
954 |
|
|
|
955 |
|
|
//
|
956 |
|
|
// DEBUG Register write access starts here
|
957 |
|
|
//
|
958 |
|
|
reg dbgv;
|
959 |
|
|
initial dbgv = 1'b0;
|
960 |
|
|
always @(posedge i_clk)
|
961 |
|
|
dbgv <= (~i_rst)&&(i_halt)&&(i_dbg_we)&&(r_halted);
|
962 |
|
|
reg [31:0] dbg_val;
|
963 |
|
|
always @(posedge i_clk)
|
964 |
|
|
dbg_val <= i_dbg_data;
|
965 |
|
|
always @(posedge i_clk)
|
966 |
|
|
if (stage_ce)
|
967 |
|
|
alu_gie <= op_gie;
|
968 |
|
|
always @(posedge i_clk)
|
969 |
|
|
if (stage_ce)
|
970 |
|
|
alu_pc <= opb_pc;
|
971 |
|
|
|
972 |
|
|
initial alu_illegal = 0;
|
973 |
|
|
always @(posedge i_clk)
|
974 |
|
|
if (clear_pipeline)
|
975 |
|
|
alu_illegal <= 1'b0;
|
976 |
|
|
else if (stage_ce)
|
977 |
|
|
alu_illegal <= opb_illegal;
|
978 |
|
|
|
979 |
|
|
initial r_alu_pc_valid = 1'b0;
|
980 |
|
|
initial mem_pc_valid = 1'b0;
|
981 |
|
|
always @(posedge i_clk)
|
982 |
|
|
if (i_rst)
|
983 |
|
|
r_alu_pc_valid <= 1'b0;
|
984 |
|
|
else if (adf_ce_unconditional)//Includes&&(~alu_clear_pipeline)
|
985 |
|
|
r_alu_pc_valid <= 1'b1;
|
986 |
|
|
else if (((~alu_busy)&&(~div_busy)&&(~fpu_busy))||(clear_pipeline))
|
987 |
|
|
r_alu_pc_valid <= 1'b0;
|
988 |
|
|
assign alu_pc_valid = (r_alu_pc_valid)&&((~alu_busy)&&(~div_busy)&&(~fpu_busy));
|
989 |
|
|
always @(posedge i_clk)
|
990 |
|
|
if (i_rst)
|
991 |
|
|
mem_pc_valid <= 1'b0;
|
992 |
|
|
else
|
993 |
|
|
mem_pc_valid <= (mem_ce);
|
994 |
|
|
|
995 |
|
|
wire bus_lock;
|
996 |
|
|
|
997 |
|
|
reg [1:0] r_bus_lock;
|
998 |
|
|
initial r_bus_lock = 2'b00;
|
999 |
|
|
always @(posedge i_clk)
|
1000 |
|
|
if (i_rst)
|
1001 |
|
|
r_bus_lock <= 2'b00;
|
1002 |
|
|
else if ((opb_ce)&&(opb_lock))
|
1003 |
|
|
r_bus_lock <= 2'b11;
|
1004 |
|
|
else if ((|r_bus_lock)&&((~opb_valid_mem)||(~opb_ce)))
|
1005 |
|
|
r_bus_lock <= r_bus_lock + 2'b11; // r_bus_lock -= 1
|
1006 |
|
|
assign bus_lock = |r_bus_lock;
|
1007 |
|
|
|
1008 |
|
|
pipemem #(AW,IMPLEMENT_LOCK) domem(i_clk, i_rst,(mem_ce)&&(set_cond), bus_lock,
|
1009 |
|
|
(opb_opn[0]), opb_B, opb_A, opb_R,
|
1010 |
|
|
mem_busy, mem_pipe_stalled,
|
1011 |
|
|
mem_valid, bus_err, mem_wreg, mem_result,
|
1012 |
|
|
mem_cyc_gbl, mem_cyc_lcl,
|
1013 |
|
|
mem_stb_gbl, mem_stb_lcl,
|
1014 |
|
|
mem_we, mem_addr, mem_data,
|
1015 |
|
|
mem_ack, mem_stall, mem_err, i_wb_data);
|
1016 |
|
|
|
1017 |
|
|
assign mem_rdbusy = ((mem_busy)&&(~mem_we));
|
1018 |
|
|
|
1019 |
|
|
// Either the prefetch or the instruction gets the memory bus, but
|
1020 |
|
|
// never both.
|
1021 |
|
|
wbdblpriarb #(32,AW) pformem(i_clk, i_rst,
|
1022 |
|
|
// Memory access to the arbiter, priority position
|
1023 |
|
|
mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl,
|
1024 |
|
|
mem_we, mem_addr, mem_data, mem_ack, mem_stall, mem_err,
|
1025 |
|
|
// Prefetch access to the arbiter
|
1026 |
|
|
pf_cyc, 1'b0, pf_stb, 1'b0, pf_we, pf_addr, pf_data,
|
1027 |
|
|
pf_ack, pf_stall, pf_err,
|
1028 |
|
|
// Common wires, in and out, of the arbiter
|
1029 |
|
|
o_wb_gbl_cyc, o_wb_lcl_cyc, o_wb_gbl_stb, o_wb_lcl_stb,
|
1030 |
|
|
o_wb_we, o_wb_addr, o_wb_data,
|
1031 |
|
|
i_wb_ack, i_wb_stall, i_wb_err);
|
1032 |
|
|
|
1033 |
|
|
|
1034 |
|
|
|
1035 |
|
|
//
|
1036 |
|
|
//
|
1037 |
|
|
//
|
1038 |
|
|
//
|
1039 |
|
|
//
|
1040 |
|
|
//
|
1041 |
|
|
//
|
1042 |
|
|
//
|
1043 |
|
|
// PIPELINE STAGE #5 :: Write-back results
|
1044 |
|
|
//
|
1045 |
|
|
//
|
1046 |
|
|
|
1047 |
|
|
// Unlike previous versions of the writeback routine(s), this version
|
1048 |
|
|
// requires that everything be registered and clocked as soon as it is
|
1049 |
|
|
// valid. So, let's start by clocking in our results.
|
1050 |
|
|
reg [4:0] r_wr_reg;
|
1051 |
|
|
reg [31:0] r_wr_val;
|
1052 |
|
|
reg r_wr_ce, r_wr_err;
|
1053 |
|
|
|
1054 |
|
|
// 1. Will we need to write a register?
|
1055 |
|
|
always @(posedge i_clk)
|
1056 |
|
|
r_wr_ce <= (dbgv)||(mem_valid)
|
1057 |
|
|
||((~clear_pipeline)&&(~alu_illegal)
|
1058 |
|
|
&&(((alu_wr)&&(alu_valid))
|
1059 |
|
|
||(div_valid)||(fpu_valid)));
|
1060 |
|
|
assign wr_reg_ce = r_wr_ce;
|
1061 |
|
|
|
1062 |
|
|
// 2. Did the ALU/MEM/DIV/FPU stage produce an error of any type?
|
1063 |
|
|
// a. Illegal instruction
|
1064 |
|
|
// b. Division by zero
|
1065 |
|
|
// c. Floating point error
|
1066 |
|
|
// d. Bus Error
|
1067 |
|
|
// these will be causes for an interrupt on the next clock after this
|
1068 |
|
|
// one.
|
1069 |
|
|
always @(posedge i_clk)
|
1070 |
|
|
r_wr_err <= ((div_valid)&&(div_error))
|
1071 |
|
|
||((fpu_valid)&&(fpu_error))
|
1072 |
|
|
||((alu_pc_valid)&&(alu_illegal))
|
1073 |
|
|
||(bus_err);
|
1074 |
|
|
reg r_wr_illegal;
|
1075 |
|
|
always @(posedge i_clk)
|
1076 |
|
|
r_wr_illegal <= (alu_pc_valid)&&(alu_illegal);
|
1077 |
|
|
|
1078 |
|
|
// Which register shall be written?
|
1079 |
|
|
// Note that the alu_reg is the register to write on a divide or
|
1080 |
|
|
// FPU operation.
|
1081 |
|
|
always @(posedge i_clk)
|
1082 |
|
|
r_wr_reg <= (alu_wr|div_valid|fpu_valid)?alu_reg:mem_wreg;
|
1083 |
|
|
assign wr_reg_id = r_wr_reg;
|
1084 |
|
|
|
1085 |
|
|
// Are we writing to the CC register?
|
1086 |
|
|
assign wr_write_cc = (wr_reg_id[3:0] == `CPU_CC_REG);
|
1087 |
|
|
assign wr_write_scc = (wr_reg_id[4:0] == {1'b0, `CPU_CC_REG});
|
1088 |
|
|
assign wr_write_ucc = (wr_reg_id[4:0] == {1'b1, `CPU_CC_REG});
|
1089 |
|
|
// Are we writing to the PC?
|
1090 |
|
|
assign wr_write_pc = (wr_reg_id[3:0] == `CPU_PC_REG);
|
1091 |
|
|
|
1092 |
|
|
// What value to write?
|
1093 |
|
|
always @(posedge i_clk)
|
1094 |
|
|
r_wr_val <= ((mem_valid) ? mem_result
|
1095 |
|
|
:((div_valid|fpu_valid))
|
1096 |
|
|
? ((div_valid) ? div_result:fpu_result)
|
1097 |
|
|
:((dbgv) ? dbg_val : alu_result));
|
1098 |
|
|
assign wr_gpreg_vl = r_wr_val;
|
1099 |
|
|
assign wr_spreg_vl = r_wr_val;
|
1100 |
|
|
|
1101 |
|
|
// Do we write back our flags?
|
1102 |
|
|
reg r_wr_flags_ce;
|
1103 |
|
|
initial r_wr_flags_ce = 1'b0;
|
1104 |
|
|
always @(posedge i_clk)
|
1105 |
|
|
r_wr_flags_ce <= ((alF_wr)||(div_valid)||(fpu_valid))
|
1106 |
|
|
&&(~clear_pipeline)&&(~alu_illegal);
|
1107 |
|
|
assign wr_flags_ce = r_wr_flags_ce;
|
1108 |
|
|
|
1109 |
|
|
reg [3:0] r_wr_newflags;
|
1110 |
|
|
always @(posedge i_clk)
|
1111 |
|
|
if (div_valid)
|
1112 |
|
|
r_wr_newflags <= div_flags;
|
1113 |
|
|
else if (fpu_valid)
|
1114 |
|
|
r_wr_newflags <= fpu_flags;
|
1115 |
|
|
else // if (alu_valid)
|
1116 |
|
|
r_wr_newflags <= alu_flags;
|
1117 |
|
|
|
1118 |
|
|
reg r_wr_gie;
|
1119 |
|
|
always @(posedge i_clk)
|
1120 |
|
|
r_wr_gie <= (~dbgv)&&(alu_gie);
|
1121 |
|
|
|
1122 |
|
|
reg r_wr_pc_valid;
|
1123 |
|
|
initial r_wr_pc_valid = 1'b0;
|
1124 |
|
|
always @(posedge i_clk)
|
1125 |
|
|
r_wr_pc_valid <= ((alu_pc_valid)&&(~clear_pipeline))
|
1126 |
|
|
||(mem_pc_valid);
|
1127 |
|
|
reg [(AW-1):0] r_wr_pc;
|
1128 |
|
|
always @(posedge i_clk)
|
1129 |
|
|
r_wr_pc <= alu_pc; // (alu_pc_valid)?alu_pc : mem_pc;
|
1130 |
|
|
|
1131 |
|
|
////
|
1132 |
|
|
//
|
1133 |
|
|
//
|
1134 |
|
|
// Write back, second clock
|
1135 |
|
|
//
|
1136 |
|
|
//
|
1137 |
|
|
////
|
1138 |
|
|
always @(posedge i_clk)
|
1139 |
|
|
if (wr_reg_ce)
|
1140 |
|
|
regset[wr_reg_id] <= wr_gpreg_vl;
|
1141 |
|
|
|
1142 |
|
|
|
1143 |
|
|
assign w_uflags = { uhalt_phase, ufpu_err_flag,
|
1144 |
|
|
udiv_err_flag, ubus_err_flag, trap, ill_err_u,
|
1145 |
|
|
1'b0, step, 1'b1, sleep,
|
1146 |
|
|
((wr_flags_ce)&&(alu_gie))?r_wr_newflags:flags };
|
1147 |
|
|
assign w_iflags = { ihalt_phase, ifpu_err_flag,
|
1148 |
|
|
idiv_err_flag, ibus_err_flag, trap, ill_err_i,
|
1149 |
|
|
break_en, 1'b0, 1'b0, sleep,
|
1150 |
|
|
((wr_flags_ce)&&(~alu_gie))?r_wr_newflags:iflags };
|
1151 |
|
|
|
1152 |
|
|
|
1153 |
|
|
// What value to write?
|
1154 |
|
|
always @(posedge i_clk)
|
1155 |
|
|
// If explicitly writing the register itself
|
1156 |
|
|
if ((wr_reg_ce)&&(wr_reg_id[4])&&(wr_write_cc))
|
1157 |
|
|
flags <= wr_gpreg_vl[3:0];
|
1158 |
|
|
// Otherwise if we're setting the flags from an ALU operation
|
1159 |
|
|
else if ((wr_flags_ce)&&(alu_gie))
|
1160 |
|
|
flags <= r_wr_newflags;
|
1161 |
|
|
|
1162 |
|
|
always @(posedge i_clk)
|
1163 |
|
|
if ((wr_reg_ce)&&(~wr_reg_id[4])&&(wr_write_cc))
|
1164 |
|
|
iflags <= wr_gpreg_vl[3:0];
|
1165 |
|
|
else if ((wr_flags_ce)&&(~alu_gie))
|
1166 |
|
|
iflags <= r_wr_newflags;
|
1167 |
|
|
|
1168 |
|
|
// The 'break' enable bit. This bit can only be set from supervisor
|
1169 |
|
|
// mode. It control what the CPU does upon encountering a break
|
1170 |
|
|
// instruction.
|
1171 |
|
|
//
|
1172 |
|
|
// The goal, upon encountering a break is that the CPU should stop and
|
1173 |
|
|
// not execute the break instruction, choosing instead to enter into
|
1174 |
|
|
// either interrupt mode or halt first.
|
1175 |
|
|
// if ((break_en) AND (break_instruction)) // user mode or not
|
1176 |
|
|
// HALT CPU
|
1177 |
|
|
// else if (break_instruction) // only in user mode
|
1178 |
|
|
// set an interrupt flag, set the user break bit,
|
1179 |
|
|
// go to supervisor mode, allow supervisor to step the CPU.
|
1180 |
|
|
// Upon a CPU halt, any break condition will be reset. The
|
1181 |
|
|
// external debugger will then need to deal with whatever
|
1182 |
|
|
// condition has taken place.
|
1183 |
|
|
initial break_en = 1'b0;
|
1184 |
|
|
always @(posedge i_clk)
|
1185 |
|
|
if ((i_rst)||(i_halt))
|
1186 |
|
|
break_en <= 1'b0;
|
1187 |
|
|
else if ((wr_reg_ce)&&(~wr_reg_id[4])&&(wr_write_cc))
|
1188 |
|
|
break_en <= wr_spreg_vl[`CPU_BREAK_BIT];
|
1189 |
|
|
|
1190 |
|
|
reg pipe_busy;
|
1191 |
|
|
initial pipe_busy <= 1'b0;
|
1192 |
|
|
always @(posedge i_clk)
|
1193 |
|
|
pipe_busy <= ((mem_ce)||(alu_ce)||(div_ce)||(fpu_ce))
|
1194 |
|
|
||((alu_busy)||(mem_busy)||(div_busy)||(fpu_busy));
|
1195 |
|
|
|
1196 |
|
|
// pending_break <= ((break_en)||(~op_gie))&&(op_break)
|
1197 |
|
|
assign o_break = ((op_break)&&(~pipe_busy)&&(~clear_pipeline))
|
1198 |
|
|
||((~r_wr_gie)&&(r_wr_err));
|
1199 |
|
|
|
1200 |
|
|
|
1201 |
|
|
// The GIE register. Only interrupts can disable the interrupt register
|
1202 |
|
|
reg slow_interrupt, fast_interrupt;
|
1203 |
|
|
initial slow_interrupt = 1'b0;
|
1204 |
|
|
// The key difference between a fast interrupt and a slow interrupt
|
1205 |
|
|
// is that a fast interrupt requires the pipeline to be cleared,
|
1206 |
|
|
// whereas a slow interrupt does not.
|
1207 |
|
|
always @(posedge i_clk)
|
1208 |
|
|
slow_interrupt <= (gie)&&(
|
1209 |
|
|
(i_interrupt)
|
1210 |
|
|
// If we encounter a break instruction, if the break
|
1211 |
|
|
// enable isn't set. This is slow because pre
|
1212 |
|
|
// ALU logic will prevent the break from moving forward.
|
1213 |
|
|
||((op_break)&&(~break_en)));
|
1214 |
|
|
initial fast_interrupt = 1'b0;
|
1215 |
|
|
always @(posedge i_clk) // 12 inputs
|
1216 |
|
|
fast_interrupt <= ((gie)||(alu_gie))&&(
|
1217 |
|
|
((r_wr_pc_valid)&&(step)&&(~alu_phase)&&(~bus_lock))
|
1218 |
|
|
// Or ... if we encountered some form of error in our
|
1219 |
|
|
// instruction ...
|
1220 |
|
|
||(r_wr_err)
|
1221 |
|
|
// Or if we write to the CC register.
|
1222 |
|
|
||((wr_reg_ce)&&(~wr_spreg_vl[`CPU_GIE_BIT])
|
1223 |
|
|
&&(wr_reg_id[4])&&(wr_write_cc)));
|
1224 |
|
|
|
1225 |
|
|
assign w_switch_to_interrupt = fast_interrupt;
|
1226 |
|
|
|
1227 |
|
|
assign w_release_from_interrupt = (~gie)&&(~i_interrupt)
|
1228 |
|
|
// Then if we write the CC register
|
1229 |
|
|
&&(((wr_reg_ce)&&(~r_wr_gie)&&(wr_spreg_vl[`CPU_GIE_BIT])
|
1230 |
|
|
&&(~wr_reg_id[4])&&(wr_write_cc))
|
1231 |
|
|
);
|
1232 |
|
|
always @(posedge i_clk)
|
1233 |
|
|
if (i_rst)
|
1234 |
|
|
gie <= 1'b0;
|
1235 |
|
|
else if ((fast_interrupt)||(slow_interrupt))
|
1236 |
|
|
gie <= 1'b0;
|
1237 |
|
|
else if (w_release_from_interrupt)
|
1238 |
|
|
gie <= 1'b1;
|
1239 |
|
|
|
1240 |
|
|
initial trap = 1'b0;
|
1241 |
|
|
always @(posedge i_clk)
|
1242 |
|
|
if (i_rst)
|
1243 |
|
|
trap <= 1'b0;
|
1244 |
|
|
else if (w_release_from_interrupt)
|
1245 |
|
|
trap <= 1'b0;
|
1246 |
|
|
else if ((r_wr_gie)&&(wr_reg_ce)&&(wr_write_cc)
|
1247 |
|
|
&&(~wr_spreg_vl[`CPU_GIE_BIT]))
|
1248 |
|
|
// &&(wr_reg_id[4]) implied
|
1249 |
|
|
trap <= 1'b1;
|
1250 |
|
|
else if ((wr_reg_ce)&&(wr_write_cc)&&(wr_reg_id[4]))
|
1251 |
|
|
trap <= wr_spreg_vl[`CPU_TRAP_BIT];
|
1252 |
|
|
|
1253 |
|
|
// The sleep register. Setting the sleep register causes the CPU to
|
1254 |
|
|
// sleep until the next interrupt. Setting the sleep register within
|
1255 |
|
|
// interrupt mode causes the processor to halt until a reset. This is
|
1256 |
|
|
// a panic/fault halt. The trick is that you cannot be allowed to
|
1257 |
|
|
// set the sleep bit and switch to supervisor mode in the same
|
1258 |
|
|
// instruction: users are not allowed to halt the CPU.
|
1259 |
|
|
always @(posedge i_clk)
|
1260 |
|
|
if ((i_rst)||(slow_interrupt))
|
1261 |
|
|
sleep <= 1'b0;
|
1262 |
|
|
else if ((wr_reg_ce)&&(wr_write_cc)&&(~r_wr_gie))
|
1263 |
|
|
// In supervisor mode, we have no protections. The
|
1264 |
|
|
// supervisor can set the sleep bit however he wants.
|
1265 |
|
|
// Well ... not quite. Switching to user mode and
|
1266 |
|
|
// sleep mode shouold only be possible if the interrupt
|
1267 |
|
|
// flag isn't set.
|
1268 |
|
|
// Thus: if (i_interrupt)&&(wr_spreg_vl[GIE])
|
1269 |
|
|
// don't set the sleep bit
|
1270 |
|
|
// otherwise however it would o.w. be set
|
1271 |
|
|
sleep <= (wr_spreg_vl[`CPU_SLEEP_BIT])
|
1272 |
|
|
&&((~i_interrupt)||(~wr_spreg_vl[`CPU_GIE_BIT]));
|
1273 |
|
|
else if ((wr_reg_ce)&&(wr_write_cc)&&(wr_spreg_vl[`CPU_GIE_BIT]))
|
1274 |
|
|
// In user mode, however, you can only set the sleep
|
1275 |
|
|
// mode while remaining in user mode. You can't switch
|
1276 |
|
|
// to sleep mode *and* supervisor mode at the same
|
1277 |
|
|
// time, lest you halt the CPU.
|
1278 |
|
|
sleep <= wr_spreg_vl[`CPU_SLEEP_BIT];
|
1279 |
|
|
|
1280 |
|
|
always @(posedge i_clk)
|
1281 |
|
|
if ((i_rst)||(fast_interrupt))
|
1282 |
|
|
step <= 1'b0;
|
1283 |
|
|
else if ((wr_reg_ce)&&(~alu_gie)&&(wr_reg_id[4])&&(wr_write_cc))
|
1284 |
|
|
step <= wr_spreg_vl[`CPU_STEP_BIT];
|
1285 |
|
|
else if (((alu_pc_valid)||(mem_pc_valid))&&(step)&&(gie))
|
1286 |
|
|
step <= 1'b0;
|
1287 |
|
|
|
1288 |
|
|
|
1289 |
|
|
initial ill_err_i = 1'b0;
|
1290 |
|
|
always @(posedge i_clk)
|
1291 |
|
|
if (i_rst)
|
1292 |
|
|
ill_err_i <= 1'b0;
|
1293 |
|
|
// Only the debug interface can clear this bit
|
1294 |
|
|
else if ((dbgv)&&(wr_reg_id == {1'b0, `CPU_CC_REG})
|
1295 |
|
|
&&(~wr_spreg_vl[`CPU_ILL_BIT]))
|
1296 |
|
|
ill_err_i <= 1'b0;
|
1297 |
|
|
else if ((r_wr_illegal)&&(~r_wr_gie))
|
1298 |
|
|
ill_err_i <= 1'b1;
|
1299 |
|
|
initial ill_err_u = 1'b0;
|
1300 |
|
|
always @(posedge i_clk)
|
1301 |
|
|
// The bit is automatically cleared on release from interrupt
|
1302 |
|
|
// or reset
|
1303 |
|
|
if ((i_rst)||(w_release_from_interrupt))
|
1304 |
|
|
ill_err_u <= 1'b0;
|
1305 |
|
|
// If the supervisor writes to this register, clearing the
|
1306 |
|
|
// bit, then clear it
|
1307 |
|
|
else if ((~r_wr_gie)
|
1308 |
|
|
&&(wr_reg_ce)&&(~wr_spreg_vl[`CPU_ILL_BIT])
|
1309 |
|
|
&&(wr_reg_id[4])&&(wr_write_cc))
|
1310 |
|
|
ill_err_u <= 1'b0;
|
1311 |
|
|
else if ((r_wr_gie)&&(r_wr_illegal))
|
1312 |
|
|
ill_err_u <= 1'b1;
|
1313 |
|
|
// Supervisor/interrupt bus error flag -- this will crash the CPU if
|
1314 |
|
|
// ever set.
|
1315 |
|
|
initial ibus_err_flag = 1'b0;
|
1316 |
|
|
always @(posedge i_clk)
|
1317 |
|
|
if (i_rst)
|
1318 |
|
|
ibus_err_flag <= 1'b0;
|
1319 |
|
|
else if ((dbgv)&&(wr_reg_id == {1'b0, `CPU_CC_REG})
|
1320 |
|
|
&&(~wr_spreg_vl[`CPU_BUSERR_BIT]))
|
1321 |
|
|
ibus_err_flag <= 1'b0;
|
1322 |
|
|
else if ((bus_err)&&(~alu_gie))
|
1323 |
|
|
ibus_err_flag <= 1'b1;
|
1324 |
|
|
// User bus error flag -- if ever set, it will cause an interrupt to
|
1325 |
|
|
// supervisor mode.
|
1326 |
|
|
initial ubus_err_flag = 1'b0;
|
1327 |
|
|
always @(posedge i_clk)
|
1328 |
|
|
if (i_rst)
|
1329 |
|
|
ubus_err_flag <= 1'b0;
|
1330 |
|
|
else if (w_release_from_interrupt)
|
1331 |
|
|
ubus_err_flag <= 1'b0;
|
1332 |
|
|
else if (((~alu_gie)||(dbgv))&&(wr_reg_ce)
|
1333 |
|
|
&&(~wr_spreg_vl[`CPU_BUSERR_BIT])
|
1334 |
|
|
&&(wr_reg_id[4])&&(wr_write_cc))
|
1335 |
|
|
ubus_err_flag <= 1'b0;
|
1336 |
|
|
else if ((bus_err)&&(alu_gie))
|
1337 |
|
|
ubus_err_flag <= 1'b1;
|
1338 |
|
|
|
1339 |
|
|
reg r_idiv_err_flag, r_udiv_err_flag;
|
1340 |
|
|
|
1341 |
|
|
// Supervisor/interrupt divide (by zero) error flag -- this will
|
1342 |
|
|
// crash the CPU if ever set. This bit is thus available for us
|
1343 |
|
|
// to be able to tell if/why the CPU crashed.
|
1344 |
|
|
initial r_idiv_err_flag = 1'b0;
|
1345 |
|
|
always @(posedge i_clk)
|
1346 |
|
|
if (i_rst)
|
1347 |
|
|
r_idiv_err_flag <= 1'b0;
|
1348 |
|
|
else if ((dbgv)&&(wr_reg_id == {1'b0, `CPU_CC_REG})
|
1349 |
|
|
&&(~wr_spreg_vl[`CPU_DIVERR_BIT]))
|
1350 |
|
|
r_idiv_err_flag <= 1'b0;
|
1351 |
|
|
else if ((div_error)&&(div_valid)&&(~r_wr_gie))
|
1352 |
|
|
r_idiv_err_flag <= 1'b1;
|
1353 |
|
|
// User divide (by zero) error flag -- if ever set, it will
|
1354 |
|
|
// cause a sudden switch interrupt to supervisor mode.
|
1355 |
|
|
initial r_udiv_err_flag = 1'b0;
|
1356 |
|
|
always @(posedge i_clk)
|
1357 |
|
|
if (i_rst)
|
1358 |
|
|
r_udiv_err_flag <= 1'b0;
|
1359 |
|
|
else if (w_release_from_interrupt)
|
1360 |
|
|
r_udiv_err_flag <= 1'b0;
|
1361 |
|
|
else if (((~r_wr_gie)||(dbgv))&&(wr_reg_ce)
|
1362 |
|
|
&&(~wr_spreg_vl[`CPU_DIVERR_BIT])
|
1363 |
|
|
&&(wr_reg_id[4])&&(wr_write_cc))
|
1364 |
|
|
r_udiv_err_flag <= 1'b0;
|
1365 |
|
|
else if ((div_error)&&(r_wr_gie)&&(div_valid))
|
1366 |
|
|
r_udiv_err_flag <= 1'b1;
|
1367 |
|
|
|
1368 |
|
|
assign idiv_err_flag = r_idiv_err_flag;
|
1369 |
|
|
assign udiv_err_flag = r_udiv_err_flag;
|
1370 |
|
|
|
1371 |
|
|
generate
|
1372 |
|
|
if (IMPLEMENT_FPU !=0)
|
1373 |
|
|
begin
|
1374 |
|
|
// Supervisor/interrupt floating point error flag -- this will
|
1375 |
|
|
// crash the CPU if ever set.
|
1376 |
|
|
reg r_ifpu_err_flag, r_ufpu_err_flag;
|
1377 |
|
|
initial r_ifpu_err_flag = 1'b0;
|
1378 |
|
|
always @(posedge i_clk)
|
1379 |
|
|
if (i_rst)
|
1380 |
|
|
r_ifpu_err_flag <= 1'b0;
|
1381 |
|
|
else if ((dbgv)&&(wr_reg_id == {1'b0, `CPU_CC_REG})
|
1382 |
|
|
&&(~wr_spreg_vl[`CPU_FPUERR_BIT]))
|
1383 |
|
|
r_ifpu_err_flag <= 1'b0;
|
1384 |
|
|
else if ((fpu_error)&&(fpu_valid)&&(~r_wr_gie))
|
1385 |
|
|
r_ifpu_err_flag <= 1'b1;
|
1386 |
|
|
// User floating point error flag -- if ever set, it will cause
|
1387 |
|
|
// a sudden switch interrupt to supervisor mode.
|
1388 |
|
|
initial r_ufpu_err_flag = 1'b0;
|
1389 |
|
|
always @(posedge i_clk)
|
1390 |
|
|
if (i_rst)
|
1391 |
|
|
r_ufpu_err_flag <= 1'b0;
|
1392 |
|
|
else if (w_release_from_interrupt)
|
1393 |
|
|
r_ufpu_err_flag <= 1'b0;
|
1394 |
|
|
else if (((~r_wr_gie)||(dbgv))&&(wr_reg_ce)
|
1395 |
|
|
&&(~wr_spreg_vl[`CPU_FPUERR_BIT])
|
1396 |
|
|
&&(wr_reg_id[4])&&(wr_write_cc))
|
1397 |
|
|
r_ufpu_err_flag <= 1'b0;
|
1398 |
|
|
else if ((fpu_error)&&(r_wr_gie)&&(fpu_valid))
|
1399 |
|
|
r_ufpu_err_flag <= 1'b1;
|
1400 |
|
|
|
1401 |
|
|
assign ifpu_err_flag = r_ifpu_err_flag;
|
1402 |
|
|
assign ufpu_err_flag = r_ufpu_err_flag;
|
1403 |
|
|
end else begin
|
1404 |
|
|
assign ifpu_err_flag = 1'b0;
|
1405 |
|
|
assign ufpu_err_flag = 1'b0;
|
1406 |
|
|
end endgenerate
|
1407 |
|
|
|
1408 |
|
|
`ifdef OPT_VLIW
|
1409 |
|
|
reg r_ihalt_phase, r_uhalt_phase;
|
1410 |
|
|
|
1411 |
|
|
initial r_ihalt_phase = 0;
|
1412 |
|
|
initial r_uhalt_phase = 0;
|
1413 |
|
|
always @(posedge i_clk)
|
1414 |
|
|
if (i_rst)
|
1415 |
|
|
r_ihalt_phase <= 1'b0;
|
1416 |
|
|
else if ((~alu_gie)&&(alu_pc_valid)&&(~clear_pipeline))
|
1417 |
|
|
r_ihalt_phase <= alu_phase;
|
1418 |
|
|
always @(posedge i_clk)
|
1419 |
|
|
if (r_wr_gie)
|
1420 |
|
|
r_uhalt_phase <= alu_phase;
|
1421 |
|
|
else if (w_release_from_interrupt)
|
1422 |
|
|
r_uhalt_phase <= 1'b0;
|
1423 |
|
|
|
1424 |
|
|
assign ihalt_phase = r_ihalt_phase;
|
1425 |
|
|
assign uhalt_phase = r_uhalt_phase;
|
1426 |
|
|
`else
|
1427 |
|
|
assign ihalt_phase = 1'b0;
|
1428 |
|
|
assign uhalt_phase = 1'b0;
|
1429 |
|
|
`endif
|
1430 |
|
|
|
1431 |
|
|
//
|
1432 |
|
|
// Write backs to the PC register, and general increments of it
|
1433 |
|
|
// We support two: upc and ipc. If the instruction is normal,
|
1434 |
|
|
// we increment upc, if interrupt level we increment ipc. If
|
1435 |
|
|
// the instruction writes the PC, we write whichever PC is appropriate.
|
1436 |
|
|
//
|
1437 |
|
|
// Do we need to all our partial results from the pipeline?
|
1438 |
|
|
// What happens when the pipeline has gie and ~gie instructions within
|
1439 |
|
|
// it? Do we clear both? What if a gie instruction tries to clear
|
1440 |
|
|
// a non-gie instruction?
|
1441 |
|
|
always @(posedge i_clk)
|
1442 |
|
|
if ((wr_reg_ce)&&(wr_reg_id[4])&&(wr_write_pc))
|
1443 |
|
|
upc <= wr_spreg_vl[(AW-1):0];
|
1444 |
|
|
else if ((r_wr_gie)&&
|
1445 |
|
|
(((alu_pc_valid)&&(~clear_pipeline))
|
1446 |
|
|
||(mem_pc_valid)))
|
1447 |
|
|
upc <= alu_pc;
|
1448 |
|
|
|
1449 |
|
|
always @(posedge i_clk)
|
1450 |
|
|
if (i_rst)
|
1451 |
|
|
ipc <= RESET_ADDRESS;
|
1452 |
|
|
else if ((wr_reg_ce)&&(~wr_reg_id[4])&&(wr_write_pc))
|
1453 |
|
|
ipc <= wr_spreg_vl[(AW-1):0];
|
1454 |
|
|
else if ((~r_wr_gie)&&
|
1455 |
|
|
(((alu_pc_valid)&&(~clear_pipeline))
|
1456 |
|
|
||(mem_pc_valid)))
|
1457 |
|
|
ipc <= alu_pc;
|
1458 |
|
|
|
1459 |
|
|
always @(posedge i_clk)
|
1460 |
|
|
if (i_rst)
|
1461 |
|
|
pf_pc <= RESET_ADDRESS;
|
1462 |
|
|
else if ((w_switch_to_interrupt)||((~gie)&&(w_clear_icache)))
|
1463 |
|
|
pf_pc <= ipc;
|
1464 |
|
|
else if ((w_release_from_interrupt)||((gie)&&(w_clear_icache)))
|
1465 |
|
|
pf_pc <= upc;
|
1466 |
|
|
else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc))
|
1467 |
|
|
pf_pc <= wr_spreg_vl[(AW-1):0];
|
1468 |
|
|
`ifdef OPT_PIPELINED
|
1469 |
|
|
else if ((dcd_early_branch)&&(~clear_pipeline))
|
1470 |
|
|
pf_pc <= dcd_branch_pc + 1;
|
1471 |
|
|
else if ((new_pc)||((~dcd_stalled)&&(pf_valid)))
|
1472 |
|
|
pf_pc <= pf_pc + {{(AW-1){1'b0}},1'b1};
|
1473 |
|
|
`else
|
1474 |
|
|
else if ((alu_gie==gie)&&(
|
1475 |
|
|
((alu_pc_valid)&&(~clear_pipeline))
|
1476 |
|
|
||(mem_pc_valid)))
|
1477 |
|
|
pf_pc <= alu_pc;
|
1478 |
|
|
`endif
|
1479 |
|
|
|
1480 |
|
|
initial new_pc = 1'b1;
|
1481 |
|
|
always @(posedge i_clk)
|
1482 |
|
|
if ((i_rst)||(i_clear_pf_cache))
|
1483 |
|
|
new_pc <= 1'b1;
|
1484 |
|
|
else if (w_switch_to_interrupt)
|
1485 |
|
|
new_pc <= 1'b1;
|
1486 |
|
|
else if (w_release_from_interrupt)
|
1487 |
|
|
new_pc <= 1'b1;
|
1488 |
|
|
else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc))
|
1489 |
|
|
new_pc <= 1'b1;
|
1490 |
|
|
else
|
1491 |
|
|
new_pc <= 1'b0;
|
1492 |
|
|
|
1493 |
|
|
`ifdef OPT_PIPELINED
|
1494 |
|
|
reg r_clear_icache;
|
1495 |
|
|
initial r_clear_icache = 1'b1;
|
1496 |
|
|
always @(posedge i_clk)
|
1497 |
|
|
if ((i_rst)||(i_clear_pf_cache))
|
1498 |
|
|
r_clear_icache <= 1'b1;
|
1499 |
|
|
else if ((wr_reg_ce)&&(wr_write_scc))
|
1500 |
|
|
r_clear_icache <= wr_spreg_vl[`CPU_CLRCACHE_BIT];
|
1501 |
|
|
else
|
1502 |
|
|
r_clear_icache <= 1'b0;
|
1503 |
|
|
assign w_clear_icache = r_clear_icache;
|
1504 |
|
|
`else
|
1505 |
|
|
assign w_clear_icache = 1'b0;
|
1506 |
|
|
`endif
|
1507 |
|
|
|
1508 |
|
|
//
|
1509 |
|
|
// The debug interface
|
1510 |
|
|
generate
|
1511 |
|
|
if (AW<32)
|
1512 |
|
|
begin
|
1513 |
|
|
always @(posedge i_clk)
|
1514 |
|
|
begin
|
1515 |
|
|
o_dbg_reg <= regset[i_dbg_reg];
|
1516 |
|
|
if (i_dbg_reg[3:0] == `CPU_PC_REG)
|
1517 |
|
|
o_dbg_reg <= {{(32-AW){1'b0}},(i_dbg_reg[4])?upc:ipc};
|
1518 |
|
|
else if (i_dbg_reg[3:0] == `CPU_CC_REG)
|
1519 |
|
|
begin
|
1520 |
|
|
o_dbg_reg[14:0] <= (i_dbg_reg[4])?w_uflags:w_iflags;
|
1521 |
|
|
o_dbg_reg[31:23] <= w_cpu_info;
|
1522 |
|
|
o_dbg_reg[`CPU_GIE_BIT] <= gie;
|
1523 |
|
|
end
|
1524 |
|
|
end
|
1525 |
|
|
end else begin
|
1526 |
|
|
always @(posedge i_clk)
|
1527 |
|
|
begin
|
1528 |
|
|
o_dbg_reg <= regset[i_dbg_reg];
|
1529 |
|
|
if (i_dbg_reg[3:0] == `CPU_PC_REG)
|
1530 |
|
|
o_dbg_reg <= (i_dbg_reg[4])?upc:ipc;
|
1531 |
|
|
else if (i_dbg_reg[3:0] == `CPU_CC_REG)
|
1532 |
|
|
begin
|
1533 |
|
|
o_dbg_reg[14:0] <= (i_dbg_reg[4])?w_uflags:w_iflags;
|
1534 |
|
|
o_dbg_reg[31:23] <= w_cpu_info;
|
1535 |
|
|
o_dbg_reg[`CPU_GIE_BIT] <= gie;
|
1536 |
|
|
end
|
1537 |
|
|
end
|
1538 |
|
|
end endgenerate
|
1539 |
|
|
|
1540 |
|
|
always @(posedge i_clk)
|
1541 |
|
|
o_dbg_cc <= { o_break, bus_err, gie, sleep };
|
1542 |
|
|
|
1543 |
|
|
always @(posedge i_clk)
|
1544 |
|
|
r_halted <= (i_halt)&&(
|
1545 |
|
|
// To be halted, any long lasting instruction must
|
1546 |
|
|
// be completed.
|
1547 |
|
|
(~pf_cyc)&&(~mem_busy)&&(~alu_busy)
|
1548 |
|
|
&&(~div_busy)&&(~fpu_busy)
|
1549 |
|
|
// Operations must either be valid, or illegal
|
1550 |
|
|
&&((opvalid)||(i_rst)||(dcd_illegal))
|
1551 |
|
|
// Decode stage must be either valid, in reset, or ill
|
1552 |
|
|
&&((dcdvalid)||(i_rst)||(pf_illegal)));
|
1553 |
|
|
assign o_dbg_stall = ~r_halted;
|
1554 |
|
|
|
1555 |
|
|
//
|
1556 |
|
|
//
|
1557 |
|
|
// Produce accounting outputs: Account for any CPU stalls, so we can
|
1558 |
|
|
// later evaluate how well we are doing.
|
1559 |
|
|
//
|
1560 |
|
|
//
|
1561 |
|
|
assign o_op_stall = (master_ce)&&(op_stall);
|
1562 |
|
|
assign o_pf_stall = (master_ce)&&(~pf_valid);
|
1563 |
|
|
assign o_i_count = (alu_pc_valid)&&(~clear_pipeline);
|
1564 |
|
|
|
1565 |
|
|
`ifdef DEBUG_SCOPE
|
1566 |
|
|
always @(posedge i_clk)
|
1567 |
|
|
o_debug <= {
|
1568 |
|
|
/*
|
1569 |
|
|
o_break, i_wb_err, pf_pc[1:0],
|
1570 |
|
|
flags,
|
1571 |
|
|
pf_valid, dcdvalid, opvalid, alu_valid, mem_valid,
|
1572 |
|
|
op_ce, alu_ce, mem_ce,
|
1573 |
|
|
//
|
1574 |
|
|
master_ce, opvalid_alu, opvalid_mem,
|
1575 |
|
|
//
|
1576 |
|
|
alu_stall, mem_busy, op_pipe, mem_pipe_stalled,
|
1577 |
|
|
mem_we,
|
1578 |
|
|
// ((opvalid_alu)&&(alu_stall))
|
1579 |
|
|
// ||((opvalid_mem)&&(~op_pipe)&&(mem_busy))
|
1580 |
|
|
// ||((opvalid_mem)&&( op_pipe)&&(mem_pipe_stalled)));
|
1581 |
|
|
// opA[23:20], opA[3:0],
|
1582 |
|
|
gie, sleep, wr_reg_ce, wr_gpreg_vl[4:0]
|
1583 |
|
|
*/
|
1584 |
|
|
/*
|
1585 |
|
|
i_rst, master_ce, (new_pc),
|
1586 |
|
|
((dcd_early_branch)&&(dcdvalid)),
|
1587 |
|
|
pf_valid, pf_illegal,
|
1588 |
|
|
op_ce, dcd_ce, dcdvalid, dcd_stalled,
|
1589 |
|
|
pf_cyc, pf_stb, pf_we, pf_ack, pf_stall, pf_err,
|
1590 |
|
|
pf_pc[7:0], pf_addr[7:0]
|
1591 |
|
|
*/
|
1592 |
|
|
|
1593 |
|
|
i_wb_err, gie, alu_illegal,
|
1594 |
|
|
(new_pc)||((dcd_early_branch)&&(~clear_pipeline)),
|
1595 |
|
|
mem_busy,
|
1596 |
|
|
(mem_busy)?{ (o_wb_gbl_stb|o_wb_lcl_stb), o_wb_we,
|
1597 |
|
|
o_wb_addr[8:0] }
|
1598 |
|
|
: { instruction[31:21] },
|
1599 |
|
|
pf_valid, (pf_valid) ? alu_pc[14:0]
|
1600 |
|
|
:{ pf_cyc, pf_stb, pf_pc[12:0] }
|
1601 |
|
|
|
1602 |
|
|
/*
|
1603 |
|
|
i_wb_err, gie, new_pc, dcd_early_branch, // 4
|
1604 |
|
|
pf_valid, pf_cyc, pf_stb, instruction_pc[0], // 4
|
1605 |
|
|
instruction[30:27], // 4
|
1606 |
|
|
dcd_gie, mem_busy, o_wb_gbl_cyc, o_wb_gbl_stb, // 4
|
1607 |
|
|
dcdvalid,
|
1608 |
|
|
((dcd_early_branch)&&(~clear_pipeline)) // 15
|
1609 |
|
|
? dcd_branch_pc[14:0]:pf_pc[14:0]
|
1610 |
|
|
*/
|
1611 |
|
|
};
|
1612 |
|
|
`endif
|
1613 |
|
|
|
1614 |
|
|
endmodule
|