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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [cpu/] [zipcpu.v] - Blame information for rev 118

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 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 117 dgisselq
//      RISC as you can get, with only 26 instruction types currently supported.
11
//      (There are still 8-instruction Op-Codes reserved for floating point,
12
//      and 5 which can be used for transactions not requiring registers.)
13 21 dgisselq
//      Please see the accompanying spec.pdf file for a description of these
14
//      instructions.
15
//
16
//      All instructions are 32-bits wide.  All bus accesses, both address and
17
//      data, are 32-bits over a wishbone bus.
18
//
19
//      The Zip CPU is fully pipelined with the following pipeline stages:
20
//
21
//              1. Prefetch, returns the instruction from memory. 
22
//
23
//              2. Instruction Decode
24
//
25
//              3. Read Operands
26
//
27
//              4. Apply Instruction
28
//
29
//              4. Write-back Results
30
//
31 117 dgisselq
//      Further information about the inner workings of this CPU, such as
32
//      what causes pipeline stalls, may be found in the spec.pdf file.  (The
33
//      documentation within this file had become out of date and out of sync
34
//      with the spec.pdf, so look to the spec.pdf for accurate and up to date
35
//      information.)
36 21 dgisselq
//
37
//
38
//      In general, the pipelining is controlled by three pieces of logic
39
//      per stage: _ce, _stall, and _valid.  _valid means that the stage
40
//      holds a valid instruction.  _ce means that the instruction from the
41
//      previous stage is to move into this one, and _stall means that the
42
//      instruction from the previous stage may not move into this one.
43
//      The difference between these control signals allows individual stages
44
//      to propagate instructions independently.  In general, the logic works
45
//      as:
46
//
47
//
48
//      assign  (n)_ce = (n-1)_valid && (~(n)_stall)
49
//
50
//
51
//      always @(posedge i_clk)
52
//              if ((i_rst)||(clear_pipeline))
53
//                      (n)_valid = 0
54
//              else if (n)_ce
55
//                      (n)_valid = 1
56
//              else if (n+1)_ce
57
//                      (n)_valid = 0
58
//
59
//      assign (n)_stall = (  (n-1)_valid && ( pipeline hazard detection )  )
60
//                      || (  (n)_valid && (n+1)_stall );
61
//
62
//      and ...
63
//
64
//      always @(posedge i_clk)
65
//              if (n)_ce
66
//                      (n)_variable = ... whatever logic for this stage
67
//
68
//      Note that a stage can stall even if no instruction is loaded into
69
//      it.
70
//
71
//
72
// Creator:     Dan Gisselquist, Ph.D.
73
//              Gisselquist Technology, LLC
74
//
75
///////////////////////////////////////////////////////////////////////////////
76
//
77 89 dgisselq
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
78 21 dgisselq
//
79
// This program is free software (firmware): you can redistribute it and/or
80
// modify it under the terms of  the GNU General Public License as published
81
// by the Free Software Foundation, either version 3 of the License, or (at
82
// your option) any later version.
83
//
84
// This program is distributed in the hope that it will be useful, but WITHOUT
85
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
86
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
87
// for more details.
88
//
89
// License:     GPL, v3, as defined and found on www.gnu.org,
90
//              http://www.gnu.org/licenses/gpl.html
91
//
92
//
93
///////////////////////////////////////////////////////////////////////////////
94
//
95
// We can either pipeline our fetches, or issue one fetch at a time.  Pipelined
96
// fetches are more complicated and therefore use more FPGA resources, while
97
// single fetches will cause the CPU to stall for about 5 stalls each 
98
// instruction cycle, effectively reducing the instruction count per clock to
99
// about 0.2.  However, the area cost may be worth it.  Consider:
100
//
101
//      Slice LUTs              ZipSystem       ZipCPU
102
//      Single Fetching         2521            1734
103
//      Pipelined fetching      2796            2046
104
//
105
//
106
//
107
`define CPU_CC_REG      4'he
108
`define CPU_PC_REG      4'hf
109 118 dgisselq
`define CPU_CLRCACHE_BIT 14     // Set to clear the I-cache, automatically clears
110
`define CPU_PHASE_BIT   13      // Set if we are executing the latter half of a VLIW
111 21 dgisselq
`define CPU_FPUERR_BIT  12      // Floating point error flag, set on error
112
`define CPU_DIVERR_BIT  11      // Divide error flag, set on divide by zero
113
`define CPU_BUSERR_BIT  10      // Bus error flag, set on error
114
`define CPU_TRAP_BIT    9       // User TRAP has taken place
115
`define CPU_ILL_BIT     8       // Illegal instruction
116
`define CPU_BREAK_BIT   7
117
`define CPU_STEP_BIT    6       // Will step one or two (VLIW) instructions
118
`define CPU_GIE_BIT     5
119
`define CPU_SLEEP_BIT   4
120
// Compile time defines
121
//
122
`include "cpudefs.v"
123
//
124
//
125
module  zipcpu(i_clk, i_rst, i_interrupt,
126
                // Debug interface
127
                i_halt, i_clear_pf_cache, i_dbg_reg, i_dbg_we, i_dbg_data,
128
                        o_dbg_stall, o_dbg_reg, o_dbg_cc,
129
                        o_break,
130
                // CPU interface to the wishbone bus
131
                o_wb_gbl_cyc, o_wb_gbl_stb,
132
                        o_wb_lcl_cyc, o_wb_lcl_stb,
133
                        o_wb_we, o_wb_addr, o_wb_data,
134
                        i_wb_ack, i_wb_stall, i_wb_data,
135
                        i_wb_err,
136
                // Accounting/CPU usage interface
137
                o_op_stall, o_pf_stall, o_i_count
138
`ifdef  DEBUG_SCOPE
139
                , o_debug
140
`endif
141
                );
142 118 dgisselq
        parameter       RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=32,
143 117 dgisselq
                        LGICACHE=8;
144 21 dgisselq
`ifdef  OPT_MULTIPLY
145 52 dgisselq
        parameter       IMPLEMENT_MPY = `OPT_MULTIPLY;
146 21 dgisselq
`else
147
        parameter       IMPLEMENT_MPY = 0;
148
`endif
149
`ifdef  OPT_DIVIDE
150
        parameter       IMPLEMENT_DIVIDE = 1;
151
`else
152
        parameter       IMPLEMENT_DIVIDE = 0;
153
`endif
154
`ifdef  OPT_IMPLEMENT_FPU
155
        parameter       IMPLEMENT_FPU = 1,
156
`else
157
        parameter       IMPLEMENT_FPU = 0,
158
`endif
159
                        IMPLEMENT_LOCK=1;
160
`ifdef  OPT_EARLY_BRANCHING
161
        parameter       EARLY_BRANCHING = 1;
162
`else
163
        parameter       EARLY_BRANCHING = 0;
164
`endif
165 118 dgisselq
        localparam      AW=ADDRESS_WIDTH;
166 21 dgisselq
        input                   i_clk, i_rst, i_interrupt;
167
        // Debug interface -- inputs
168
        input                   i_halt, i_clear_pf_cache;
169
        input           [4:0]    i_dbg_reg;
170
        input                   i_dbg_we;
171
        input           [31:0]   i_dbg_data;
172
        // Debug interface -- outputs
173 73 dgisselq
        output  wire            o_dbg_stall;
174 21 dgisselq
        output  reg     [31:0]   o_dbg_reg;
175
        output  reg     [3:0]    o_dbg_cc;
176
        output  wire            o_break;
177
        // Wishbone interface -- outputs
178
        output  wire            o_wb_gbl_cyc, o_wb_gbl_stb;
179
        output  wire            o_wb_lcl_cyc, o_wb_lcl_stb, o_wb_we;
180
        output  wire    [(AW-1):0]       o_wb_addr;
181
        output  wire    [31:0]   o_wb_data;
182
        // Wishbone interface -- inputs
183
        input                   i_wb_ack, i_wb_stall;
184
        input           [31:0]   i_wb_data;
185
        input                   i_wb_err;
186
        // Accounting outputs ... to help us count stalls and usage
187
        output  wire            o_op_stall;
188
        output  wire            o_pf_stall;
189
        output  wire            o_i_count;
190
        //
191
`ifdef  DEBUG_SCOPE
192
        output  reg     [31:0]   o_debug;
193
`endif
194
 
195
 
196
        // Registers
197
        //
198
        //      The distributed RAM style comment is necessary on the
199
        // SPARTAN6 with XST to prevent XST from oversimplifying the register
200
        // set and in the process ruining everything else.  It basically
201
        // optimizes logic away, to where it no longer works.  The logic
202
        // as described herein will work, this just makes sure XST implements
203
        // that logic.
204
        //
205
        (* ram_style = "distributed" *)
206
        reg     [31:0]   regset [0:31];
207
 
208
        // Condition codes
209
        // (BUS, TRAP,ILL,BREAKEN,STEP,GIE,SLEEP ), V, N, C, Z
210
        reg     [3:0]    flags, iflags;
211 113 dgisselq
        wire    [14:0]   w_uflags, w_iflags;
212 117 dgisselq
        reg             trap, break_en, step, gie, sleep, r_halted;
213
        wire            break_pending;
214 113 dgisselq
        wire            w_clear_icache;
215 21 dgisselq
`ifdef  OPT_ILLEGAL_INSTRUCTION
216
        reg             ill_err_u, ill_err_i;
217
`else
218
        wire            ill_err_u, ill_err_i;
219
`endif
220 113 dgisselq
        reg             ubreak;
221 21 dgisselq
        reg             ibus_err_flag, ubus_err_flag;
222
        wire            idiv_err_flag, udiv_err_flag;
223
        wire            ifpu_err_flag, ufpu_err_flag;
224
        wire            ihalt_phase, uhalt_phase;
225
 
226
        // The master chip enable
227
        wire            master_ce;
228
 
229
        //
230
        //
231
        //      PIPELINE STAGE #1 :: Prefetch
232
        //              Variable declarations
233
        //
234
        reg     [(AW-1):0]       pf_pc;
235
        reg     new_pc;
236
        wire    clear_pipeline;
237 113 dgisselq
        assign  clear_pipeline = new_pc;
238 21 dgisselq
 
239
        wire            dcd_stalled;
240
        wire            pf_cyc, pf_stb, pf_we, pf_busy, pf_ack, pf_stall, pf_err;
241
        wire    [(AW-1):0]       pf_addr;
242
        wire    [31:0]           pf_data;
243
        wire    [31:0]           instruction;
244
        wire    [(AW-1):0]       instruction_pc;
245
        wire    pf_valid, instruction_gie, pf_illegal;
246
 
247
        //
248
        //
249
        //      PIPELINE STAGE #2 :: Instruction Decode
250
        //              Variable declarations
251
        //
252
        //
253
        reg             opvalid, opvalid_mem, opvalid_alu;
254
        reg             opvalid_div, opvalid_fpu;
255
        wire            op_stall, dcd_ce, dcd_phase;
256
        wire    [3:0]    dcdOp;
257
        wire    [4:0]    dcdA, dcdB, dcdR;
258
        wire            dcdA_cc, dcdB_cc, dcdA_pc, dcdB_pc, dcdR_cc, dcdR_pc;
259
        wire    [3:0]    dcdF;
260
        wire            dcdR_wr, dcdA_rd, dcdB_rd,
261
                                dcdALU, dcdM, dcdDV, dcdFP,
262
                                dcdF_wr, dcd_gie, dcd_break, dcd_lock,
263 26 dgisselq
                                dcd_pipe, dcd_ljmp;
264 21 dgisselq
        reg             r_dcdvalid;
265
        wire            dcdvalid;
266
        wire    [(AW-1):0]       dcd_pc;
267
        wire    [31:0]   dcdI;
268
        wire            dcd_zI; // true if dcdI == 0
269
        wire    dcdA_stall, dcdB_stall, dcdF_stall;
270
 
271
        wire    dcd_illegal;
272
        wire                    dcd_early_branch;
273
        wire    [(AW-1):0]       dcd_branch_pc;
274
 
275
 
276
        //
277
        //
278
        //      PIPELINE STAGE #3 :: Read Operands
279
        //              Variable declarations
280
        //
281
        //
282
        //
283
        // Now, let's read our operands
284
        reg     [4:0]    alu_reg;
285 117 dgisselq
        wire    [3:0]    opn;
286
        wire    [4:0]    opR;
287 21 dgisselq
        reg     [31:0]   r_opA, r_opB;
288
        reg     [(AW-1):0]       op_pc;
289
        wire    [31:0]   w_opA, w_opB;
290
        wire    [31:0]   opA_nowait, opB_nowait, opA, opB;
291 117 dgisselq
        reg             opR_wr, opF_wr;
292
        wire            op_gie, opR_cc;
293 113 dgisselq
        wire    [14:0]   opFl;
294 21 dgisselq
        reg     [5:0]    r_opF;
295
        wire    [7:0]    opF;
296 73 dgisselq
        wire            op_ce, op_phase, op_pipe, op_change_data_ce;
297 21 dgisselq
        // Some pipeline control wires
298
`ifdef  OPT_PIPELINED
299
        reg     opA_alu, opA_mem;
300
        reg     opB_alu, opB_mem;
301
`endif
302
`ifdef  OPT_ILLEGAL_INSTRUCTION
303
        reg     op_illegal;
304 89 dgisselq
`else
305
        wire    op_illegal;
306
        assign  op_illegal = 1'b0;
307 21 dgisselq
`endif
308 117 dgisselq
        wire    op_break;
309 21 dgisselq
        wire    op_lock;
310
 
311
 
312
        //
313
        //
314
        //      PIPELINE STAGE #4 :: ALU / Memory
315
        //              Variable declarations
316
        //
317
        //
318 117 dgisselq
        wire    [(AW-1):0]       alu_pc;
319 73 dgisselq
        reg             r_alu_pc_valid, mem_pc_valid;
320
        wire            alu_pc_valid;
321 21 dgisselq
        wire            alu_phase;
322
        wire            alu_ce, alu_stall;
323
        wire    [31:0]   alu_result;
324
        wire    [3:0]    alu_flags;
325
        wire            alu_valid, alu_busy;
326
        wire            set_cond;
327 117 dgisselq
        reg             alu_wr, alF_wr;
328 118 dgisselq
        wire            alu_gie, alu_illegal;
329 21 dgisselq
 
330
 
331
 
332
        wire    mem_ce, mem_stalled;
333
`ifdef  OPT_PIPELINED_BUS_ACCESS
334
        wire    mem_pipe_stalled;
335
`endif
336
        wire    mem_valid, mem_ack, mem_stall, mem_err, bus_err,
337
                mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl, mem_we;
338
        wire    [4:0]            mem_wreg;
339
 
340
        wire                    mem_busy, mem_rdbusy;
341
        wire    [(AW-1):0]       mem_addr;
342
        wire    [31:0]           mem_data, mem_result;
343
 
344
        wire    div_ce, div_error, div_busy, div_valid;
345
        wire    [31:0]   div_result;
346
        wire    [3:0]    div_flags;
347
 
348
        assign  div_ce = (master_ce)&&(~clear_pipeline)&&(opvalid_div)
349
                                &&(~mem_rdbusy)&&(~div_busy)&&(~fpu_busy)
350
                                &&(set_cond);
351
 
352
        wire    fpu_ce, fpu_error, fpu_busy, fpu_valid;
353
        wire    [31:0]   fpu_result;
354
        wire    [3:0]    fpu_flags;
355
 
356
        assign  fpu_ce = (master_ce)&&(~clear_pipeline)&&(opvalid_fpu)
357
                                &&(~mem_rdbusy)&&(~div_busy)&&(~fpu_busy)
358
                                &&(set_cond);
359
 
360 113 dgisselq
        wire    adf_ce_unconditional;
361 89 dgisselq
 
362 21 dgisselq
        //
363
        //
364
        //      PIPELINE STAGE #5 :: Write-back
365
        //              Variable declarations
366
        //
367 113 dgisselq
        wire            wr_reg_ce, wr_flags_ce, wr_write_pc, wr_write_cc,
368
                        wr_write_scc, wr_write_ucc;
369 21 dgisselq
        wire    [4:0]    wr_reg_id;
370 73 dgisselq
        wire    [31:0]   wr_gpreg_vl, wr_spreg_vl;
371 21 dgisselq
        wire    w_switch_to_interrupt, w_release_from_interrupt;
372
        reg     [(AW-1):0]       upc, ipc;
373
 
374
 
375
 
376
        //
377
        //      MASTER: clock enable.
378
        //
379
        assign  master_ce = (~i_halt)&&(~o_break)&&(~sleep);
380
 
381
 
382
        //
383
        //      PIPELINE STAGE #1 :: Prefetch
384
        //              Calculate stall conditions
385
        //
386
        //      These are calculated externally, within the prefetch module.
387
        //
388
 
389
        //
390
        //      PIPELINE STAGE #2 :: Instruction Decode
391
        //              Calculate stall conditions
392
        assign          dcd_ce = ((~dcdvalid)||(~dcd_stalled))&&(~clear_pipeline);
393 73 dgisselq
 
394 21 dgisselq
`ifdef  OPT_PIPELINED
395
        assign          dcd_stalled = (dcdvalid)&&(op_stall);
396
`else
397
        // If not pipelined, there will be no opvalid_ anything, and the
398
        // op_stall will be false, dcdX_stall will be false, thus we can simply
399
        // do a ...
400
        assign          dcd_stalled = 1'b0;
401
`endif
402
        //
403
        //      PIPELINE STAGE #3 :: Read Operands
404
        //              Calculate stall conditions
405
        wire    op_lock_stall;
406
`ifdef  OPT_PIPELINED
407 113 dgisselq
        reg     cc_invalid_for_dcd;
408
        always @(posedge i_clk)
409
                cc_invalid_for_dcd <= (wr_flags_ce)
410
                        ||(wr_reg_ce)&&(wr_reg_id[3:0] == `CPU_CC_REG)
411
                        ||(opvalid)&&((opF_wr)||((opR_wr)&&(opR[3:0] == `CPU_CC_REG)))
412
                        ||((alF_wr)||((alu_wr)&&(alu_reg[3:0] == `CPU_CC_REG)))
413
                        ||(mem_busy)||(div_busy)||(fpu_busy);
414
 
415 21 dgisselq
        assign  op_stall = (opvalid)&&( // Only stall if we're loaded w/validins
416
                        // Stall if we're stopped, and not allowed to execute
417
                        // an instruction
418
                        // (~master_ce)         // Already captured in alu_stall
419
                        //
420
                        // Stall if going into the ALU and the ALU is stalled
421
                        //      i.e. if the memory is busy, or we are single
422
                        //      stepping.  This also includes our stalls for
423
                        //      op_break and op_lock, so we don't need to
424
                        //      include those as well here.
425
                        // This also includes whether or not the divide or
426
                        // floating point units are busy.
427
                        (alu_stall)
428
                        //
429
                        // Stall if we are going into memory with an operation
430
                        //      that cannot be pipelined, and the memory is
431
                        //      already busy
432
                        ||(mem_stalled) // &&(opvalid_mem) part of mem_stalled
433 113 dgisselq
                        ||(opR_cc)
434 21 dgisselq
                        )
435
                        ||(dcdvalid)&&(
436
                                // Stall if we need to wait for an operand A
437
                                // to be ready to read
438
                                (dcdA_stall)
439
                                // Likewise for B, also includes logic
440
                                // regarding immediate offset (register must
441
                                // be in register file if we need to add to
442
                                // an immediate)
443
                                ||(dcdB_stall)
444
                                // Or if we need to wait on flags to work on the
445
                                // CC register
446
                                ||(dcdF_stall)
447
                        );
448
        assign  op_ce = ((dcdvalid)||(dcd_illegal))&&(~op_stall)&&(~clear_pipeline);
449 113 dgisselq
 
450
 
451 73 dgisselq
        // BUT ... op_ce is too complex for many of the data operations.  So
452
        // let's make their circuit enable code simpler.  In particular, if
453
        // op_ doesn't need to be preserved, we can change it all we want
454
        // ... right?  The clear_pipeline code, for example, really only needs
455
        // to determine whether opvalid is true.
456
        assign  op_change_data_ce = (~op_stall);
457 21 dgisselq
`else
458
        assign  op_stall = (opvalid)&&(~master_ce);
459 73 dgisselq
        assign  op_ce = ((dcdvalid)||(dcd_illegal))&&(~clear_pipeline);
460
        assign  op_change_data_ce = 1'b1;
461 21 dgisselq
`endif
462
 
463
        //
464
        //      PIPELINE STAGE #4 :: ALU / Memory
465
        //              Calculate stall conditions
466
        //
467
        // 1. Basic stall is if the previous stage is valid and the next is
468
        //      busy.  
469
        // 2. Also stall if the prior stage is valid and the master clock enable
470
        //      is de-selected
471
        // 3. Stall if someone on the other end is writing the CC register,
472
        //      since we don't know if it'll put us to sleep or not.
473
        // 4. Last case: Stall if we would otherwise move a break instruction
474
        //      through the ALU.  Break instructions are not allowed through
475
        //      the ALU.
476
`ifdef  OPT_PIPELINED
477
        assign  alu_stall = (((~master_ce)||(mem_rdbusy)||(alu_busy))&&(opvalid_alu)) //Case 1&2
478
                        ||((opvalid)&&(op_lock)&&(op_lock_stall))
479 118 dgisselq
                        ||((opvalid)&&(op_break))       // || op_illegal
480 113 dgisselq
                        ||(wr_reg_ce)&&(wr_write_cc)
481 21 dgisselq
                        ||(div_busy)||(fpu_busy);
482 89 dgisselq
        assign  alu_ce = (master_ce)&&(opvalid_alu)&&(~alu_stall)
483 21 dgisselq
                                &&(~clear_pipeline);
484
`else
485 113 dgisselq
        assign  alu_stall = (opvalid_alu)&&((~master_ce)||(op_break));
486 118 dgisselq
        assign  alu_ce = (master_ce)&&(opvalid_alu)&&(~alu_stall)&&(~clear_pipeline);
487 21 dgisselq
`endif
488
        //
489
 
490
        //
491
        // Note: if you change the conditions for mem_ce, you must also change
492
        // alu_pc_valid.
493
        //
494
`ifdef  OPT_PIPELINED
495
        assign  mem_ce = (master_ce)&&(opvalid_mem)&&(~mem_stalled)
496
                        &&(~clear_pipeline);
497
`else
498
        // If we aren't pipelined, then no one will be changing what's in the
499
        // pipeline (i.e. clear_pipeline), while our only instruction goes
500
        // through the ... pipeline.
501 73 dgisselq
        //
502
        // However, in hind sight this logic didn't work.  What happens when
503
        // something gets in the pipeline and then (due to interrupt or some
504
        // such) needs to be voided?  Thus we avoid simplification and keep
505
        // what worked here.
506
        assign  mem_ce = (master_ce)&&(opvalid_mem)&&(~mem_stalled)
507
                        &&(~clear_pipeline);
508 21 dgisselq
`endif
509
`ifdef  OPT_PIPELINED_BUS_ACCESS
510
        assign  mem_stalled = (~master_ce)||(alu_busy)||((opvalid_mem)&&(
511
                                (mem_pipe_stalled)
512
                                ||((~op_pipe)&&(mem_busy))
513
                                ||(div_busy)
514
                                ||(fpu_busy)
515
                                // Stall waiting for flags to be valid
516
                                // Or waiting for a write to the PC register
517
                                // Or CC register, since that can change the
518
                                //  PC as well
519
                                ||((wr_reg_ce)&&(wr_reg_id[4] == op_gie)
520
                                        &&((wr_write_pc)||(wr_write_cc)))));
521
`else
522
`ifdef  OPT_PIPELINED
523
        assign  mem_stalled = (mem_busy)||((opvalid_mem)&&(
524
                                (~master_ce)
525
                                // Stall waiting for flags to be valid
526
                                // Or waiting for a write to the PC register
527
                                // Or CC register, since that can change the
528
                                //  PC as well
529
                                ||((wr_reg_ce)&&(wr_reg_id[4] == op_gie)&&((wr_write_pc)||(wr_write_cc)))));
530
`else
531
        assign  mem_stalled = (opvalid_mem)&&(~master_ce);
532
`endif
533
`endif
534
 
535 113 dgisselq
        // ALU, DIV, or FPU CE ... equivalent to the OR of all three of these
536
        assign  adf_ce_unconditional = (master_ce)&&(~clear_pipeline)&&(opvalid)
537
                                &&(~opvalid_mem)&&(~mem_rdbusy)
538
                                &&((~opvalid_alu)||(~alu_stall))&&(~op_break)
539
                                &&(~div_busy)&&(~fpu_busy)&&(~clear_pipeline);
540 21 dgisselq
 
541
        //
542
        //
543
        //      PIPELINE STAGE #1 :: Prefetch
544
        //
545
        //
546
`ifdef  OPT_SINGLE_FETCH
547
        wire            pf_ce;
548
 
549 73 dgisselq
        assign          pf_ce = (~pf_valid)&&(~dcdvalid)&&(~opvalid)&&(~alu_busy)&&(~mem_busy)&&(~alu_pc_valid)&&(~mem_pc_valid);
550 21 dgisselq
        prefetch        #(ADDRESS_WIDTH)
551 73 dgisselq
                        pf(i_clk, (i_rst), (pf_ce), (~dcd_stalled), pf_pc, gie,
552 21 dgisselq
                                instruction, instruction_pc, instruction_gie,
553
                                        pf_valid, pf_illegal,
554
                                pf_cyc, pf_stb, pf_we, pf_addr, pf_data,
555
                                pf_ack, pf_stall, pf_err, i_wb_data);
556
 
557
        initial r_dcdvalid = 1'b0;
558
        always @(posedge i_clk)
559 73 dgisselq
                if ((i_rst)||(clear_pipeline))
560 21 dgisselq
                        r_dcdvalid <= 1'b0;
561
                else if (dcd_ce)
562 113 dgisselq
                        r_dcdvalid <= (pf_valid)||(pf_illegal);
563 26 dgisselq
                else if (op_ce)
564 21 dgisselq
                        r_dcdvalid <= 1'b0;
565
        assign  dcdvalid = r_dcdvalid;
566
 
567
`else // Pipe fetch
568
 
569
`ifdef  OPT_TRADITIONAL_PFCACHE
570
        pfcache #(LGICACHE, ADDRESS_WIDTH)
571 26 dgisselq
                pf(i_clk, i_rst, (new_pc)||((dcd_early_branch)&&(~clear_pipeline)),
572 113 dgisselq
                                        w_clear_icache,
573 21 dgisselq
                                // dcd_pc,
574
                                ~dcd_stalled,
575 26 dgisselq
                                ((dcd_early_branch)&&(~clear_pipeline))
576 21 dgisselq
                                        ? dcd_branch_pc:pf_pc,
577
                                instruction, instruction_pc, pf_valid,
578
                                pf_cyc, pf_stb, pf_we, pf_addr, pf_data,
579
                                        pf_ack, pf_stall, pf_err, i_wb_data,
580
                                pf_illegal);
581
`else
582
        pipefetch       #(RESET_ADDRESS, LGICACHE, ADDRESS_WIDTH)
583 113 dgisselq
                        pf(i_clk, i_rst, (new_pc)||(dcd_early_branch),
584
                                        w_clear_icache, ~dcd_stalled,
585 21 dgisselq
                                        (new_pc)?pf_pc:dcd_branch_pc,
586
                                        instruction, instruction_pc, pf_valid,
587
                                pf_cyc, pf_stb, pf_we, pf_addr, pf_data,
588
                                        pf_ack, pf_stall, pf_err, i_wb_data,
589
//`ifdef        OPT_PRECLEAR_BUS
590
                                //((dcd_clear_bus)&&(dcdvalid))
591
                                //||((op_clear_bus)&&(opvalid))
592
                                //||
593
//`endif
594
                                (mem_cyc_lcl)||(mem_cyc_gbl),
595
                                pf_illegal);
596
`endif
597
        assign  instruction_gie = gie;
598
 
599
        initial r_dcdvalid = 1'b0;
600
        always @(posedge i_clk)
601 113 dgisselq
                if ((i_rst)||(clear_pipeline)||(w_clear_icache))
602 21 dgisselq
                        r_dcdvalid <= 1'b0;
603
                else if (dcd_ce)
604 113 dgisselq
                        r_dcdvalid <= (pf_valid)&&(~dcd_ljmp)&&(~dcd_early_branch);
605 21 dgisselq
                else if (op_ce)
606
                        r_dcdvalid <= 1'b0;
607
        assign  dcdvalid = r_dcdvalid;
608
`endif
609
 
610 113 dgisselq
        // If not pipelined, there will be no opvalid_ anything, and the
611 21 dgisselq
        idecode #(AW, IMPLEMENT_MPY, EARLY_BRANCHING, IMPLEMENT_DIVIDE,
612
                        IMPLEMENT_FPU)
613
                instruction_decoder(i_clk, (i_rst)||(clear_pipeline),
614 113 dgisselq
                        (~dcdvalid)||(~op_stall), dcd_stalled, instruction, instruction_gie,
615 21 dgisselq
                        instruction_pc, pf_valid, pf_illegal, dcd_phase,
616
                        dcd_illegal, dcd_pc, dcd_gie,
617
                        { dcdR_cc, dcdR_pc, dcdR },
618
                        { dcdA_cc, dcdA_pc, dcdA },
619
                        { dcdB_cc, dcdB_pc, dcdB },
620
                        dcdI, dcd_zI, dcdF, dcdF_wr, dcdOp,
621
                        dcdALU, dcdM, dcdDV, dcdFP, dcd_break, dcd_lock,
622
                        dcdR_wr,dcdA_rd, dcdB_rd,
623
                        dcd_early_branch,
624 26 dgisselq
                        dcd_branch_pc, dcd_ljmp,
625 21 dgisselq
                        dcd_pipe);
626
 
627
`ifdef  OPT_PIPELINED_BUS_ACCESS
628 51 dgisselq
        reg             r_op_pipe;
629 21 dgisselq
 
630 51 dgisselq
        initial r_op_pipe = 1'b0;
631 21 dgisselq
        // To be a pipeable operation, there must be 
632
        //      two valid adjacent instructions
633
        //      Both must be memory instructions
634
        //      Both must be writes, or both must be reads
635
        //      Both operations must be to the same identical address,
636
        //              or at least a single (one) increment above that address
637
        //
638
        // However ... we need to know this before this clock, hence this is
639
        // calculated in the instruction decoder.
640
        always @(posedge i_clk)
641
                if (op_ce)
642 51 dgisselq
                        r_op_pipe <= dcd_pipe;
643 73 dgisselq
                else if (mem_ce) // Clear us any time an op_ is clocked in
644
                        r_op_pipe <= 1'b0;
645 51 dgisselq
        assign  op_pipe = r_op_pipe;
646
`else
647
        assign  op_pipe = 1'b0;
648 21 dgisselq
`endif
649
 
650
        //
651
        //
652
        //      PIPELINE STAGE #3 :: Read Operands (Registers)
653
        //
654
        //
655
        assign  w_opA = regset[dcdA];
656
        assign  w_opB = regset[dcdB];
657
 
658 51 dgisselq
        wire    [8:0]    w_cpu_info;
659
        assign  w_cpu_info = {
660
`ifdef  OPT_ILLEGAL_INSTRUCTION
661
        1'b1,
662
`else
663
        1'b0,
664
`endif
665
`ifdef  OPT_MULTIPLY
666
        1'b1,
667
`else
668
        1'b0,
669
`endif
670
`ifdef  OPT_DIVIDE
671
        1'b1,
672
`else
673
        1'b0,
674
`endif
675
`ifdef  OPT_IMPLEMENT_FPU
676
        1'b1,
677
`else
678
        1'b0,
679
`endif
680
`ifdef  OPT_PIPELINED
681
        1'b1,
682
`else
683
        1'b0,
684
`endif
685
`ifdef  OPT_TRADITIONAL_CACHE
686
        1'b1,
687
`else
688
        1'b0,
689
`endif
690
`ifdef  OPT_EARLY_BRANCHING
691
        1'b1,
692
`else
693
        1'b0,
694
`endif
695
`ifdef  OPT_PIPELINED_BUS_ACCESS
696
        1'b1,
697
`else
698
        1'b0,
699
`endif
700
`ifdef  OPT_VLIW
701
        1'b1
702
`else
703
        1'b0
704
`endif
705
        };
706
 
707 21 dgisselq
        wire    [31:0]   w_pcA_v;
708
        generate
709
        if (AW < 32)
710
                assign  w_pcA_v = {{(32-AW){1'b0}}, (dcdA[4] == dcd_gie)?dcd_pc:upc };
711
        else
712
                assign  w_pcA_v = (dcdA[4] == dcd_gie)?dcd_pc:upc;
713
        endgenerate
714
 
715
`ifdef  OPT_PIPELINED
716
        reg     [4:0]    opA_id, opB_id;
717
        reg             opA_rd, opB_rd;
718
        always @(posedge i_clk)
719
                if (op_ce)
720
                begin
721
                        opA_id <= dcdA;
722
                        opB_id <= dcdB;
723
                        opA_rd <= dcdA_rd;
724
                        opB_rd <= dcdB_rd;
725
                end
726
`endif
727
 
728
        always @(posedge i_clk)
729 117 dgisselq
`ifdef  OPT_PIPELINED
730 73 dgisselq
                if (op_change_data_ce)
731 117 dgisselq
`endif
732 21 dgisselq
                begin
733 117 dgisselq
`ifdef  OPT_PIPELINED
734 21 dgisselq
                        if ((wr_reg_ce)&&(wr_reg_id == dcdA))
735 73 dgisselq
                                r_opA <= wr_gpreg_vl;
736 117 dgisselq
                        else
737
`endif
738
                        if (dcdA_pc)
739 21 dgisselq
                                r_opA <= w_pcA_v;
740
                        else if (dcdA_cc)
741 117 dgisselq
                                r_opA <= { w_cpu_info, w_opA[22:16], 1'b0, (dcdA[4])?w_uflags:w_iflags };
742 21 dgisselq
                        else
743
                                r_opA <= w_opA;
744
`ifdef  OPT_PIPELINED
745
                end else
746
                begin // We were going to pick these up when they became valid,
747
                        // but for some reason we're stuck here as they became
748
                        // valid.  Pick them up now anyway
749
                        // if (((opA_alu)&&(alu_wr))||((opA_mem)&&(mem_valid)))
750 73 dgisselq
                                // r_opA <= wr_gpreg_vl;
751 21 dgisselq
                        if ((wr_reg_ce)&&(wr_reg_id == opA_id)&&(opA_rd))
752 73 dgisselq
                                r_opA <= wr_gpreg_vl;
753 21 dgisselq
`endif
754
                end
755
 
756
        wire    [31:0]   w_opBnI, w_pcB_v;
757
        generate
758
        if (AW < 32)
759
                assign  w_pcB_v = {{(32-AW){1'b0}}, (dcdB[4] == dcd_gie)?dcd_pc:upc };
760
        else
761
                assign  w_pcB_v = (dcdB[4] == dcd_gie)?dcd_pc:upc;
762
        endgenerate
763
 
764
        assign  w_opBnI = (~dcdB_rd) ? 32'h00
765 117 dgisselq
`ifdef  OPT_PIPELINED
766
                : ((wr_reg_ce)&&(wr_reg_id == dcdB)) ? wr_gpreg_vl
767
`endif
768 21 dgisselq
                : ((dcdB_pc) ? w_pcB_v
769 117 dgisselq
                : ((dcdB_cc) ? { w_cpu_info, w_opB[22:16], // w_opB[31:14],
770
                        1'b0, (dcdB[4])?w_uflags:w_iflags}
771
                : w_opB));
772 21 dgisselq
 
773
        always @(posedge i_clk)
774 117 dgisselq
`ifdef  OPT_PIPELINED
775 73 dgisselq
                if (op_change_data_ce)
776 21 dgisselq
                        r_opB <= w_opBnI + dcdI;
777
                else if ((wr_reg_ce)&&(opB_id == wr_reg_id)&&(opB_rd))
778 73 dgisselq
                        r_opB <= wr_gpreg_vl;
779 117 dgisselq
`else
780
                r_opB <= w_opBnI + dcdI;
781 21 dgisselq
`endif
782
 
783
        // The logic here has become more complex than it should be, no thanks
784
        // to Xilinx's Vivado trying to help.  The conditions are supposed to
785
        // be two sets of four bits: the top bits specify what bits matter, the
786
        // bottom specify what those top bits must equal.  However, two of
787
        // conditions check whether bits are on, and those are the only two
788
        // conditions checking those bits.  Therefore, Vivado complains that
789
        // these two bits are redundant.  Hence the convoluted expression
790
        // below, arriving at what we finally want in the (now wire net)
791
        // opF.
792
        always @(posedge i_clk)
793 117 dgisselq
`ifdef  OPT_PIPELINED
794 73 dgisselq
                if (op_ce) // Cannot do op_change_data_ce here since opF depends
795
                        // upon being either correct for a valid op, or correct
796
                        // for the last valid op
797 117 dgisselq
`endif
798 21 dgisselq
                begin // Set the flag condition codes, bit order is [3:0]=VNCZ
799
                        case(dcdF[2:0])
800
                        3'h0:   r_opF <= 6'h00; // Always
801
                        // These were remapped as part of the new instruction
802
                        // set in order to make certain that the low order
803
                        // two bits contained the most commonly used 
804
                        // conditions: Always, LT, Z, and NZ.
805
                        3'h1:   r_opF <= 6'h24; // LT
806
                        3'h2:   r_opF <= 6'h11; // Z
807
                        3'h3:   r_opF <= 6'h10; // NE
808
                        3'h4:   r_opF <= 6'h30; // GT (!N&!Z)
809
                        3'h5:   r_opF <= 6'h20; // GE (!N)
810
                        3'h6:   r_opF <= 6'h02; // C
811
                        3'h7:   r_opF <= 6'h08; // V
812
                        endcase
813
                end // Bit order is { (flags_not_used), VNCZ mask, VNCZ value }
814
        assign  opF = { r_opF[3], r_opF[5], r_opF[1], r_opF[4:0] };
815
 
816
        wire    w_opvalid;
817 26 dgisselq
        assign  w_opvalid = (~clear_pipeline)&&(dcdvalid)&&(~dcd_ljmp);
818 21 dgisselq
        initial opvalid     = 1'b0;
819
        initial opvalid_alu = 1'b0;
820
        initial opvalid_mem = 1'b0;
821 26 dgisselq
        initial opvalid_div = 1'b0;
822
        initial opvalid_fpu = 1'b0;
823 21 dgisselq
        always @(posedge i_clk)
824 118 dgisselq
                if ((i_rst)||(clear_pipeline))
825 21 dgisselq
                begin
826
                        opvalid     <= 1'b0;
827
                        opvalid_alu <= 1'b0;
828
                        opvalid_mem <= 1'b0;
829 113 dgisselq
                        opvalid_div <= 1'b0;
830
                        opvalid_fpu <= 1'b0;
831 21 dgisselq
                end else if (op_ce)
832
                begin
833
                        // Do we have a valid instruction?
834
                        //   The decoder may vote to stall one of its
835
                        //   instructions based upon something we currently
836
                        //   have in our queue.  This instruction must then
837
                        //   move forward, and get a stall cycle inserted.
838
                        //   Hence, the test on dcd_stalled here.  If we must
839
                        //   wait until our operands are valid, then we aren't
840
                        //   valid yet until then.
841 113 dgisselq
                        opvalid<= (w_opvalid)||(dcd_illegal)&&(dcdvalid);
842 21 dgisselq
`ifdef  OPT_ILLEGAL_INSTRUCTION
843 113 dgisselq
                        opvalid_alu <= (w_opvalid)&&((dcdALU)||(dcd_illegal));
844 21 dgisselq
                        opvalid_mem <= (dcdM)&&(~dcd_illegal)&&(w_opvalid);
845
                        opvalid_div <= (dcdDV)&&(~dcd_illegal)&&(w_opvalid);
846
                        opvalid_fpu <= (dcdFP)&&(~dcd_illegal)&&(w_opvalid);
847
`else
848
                        opvalid_alu <= (dcdALU)&&(w_opvalid);
849
                        opvalid_mem <= (dcdM)&&(w_opvalid);
850
                        opvalid_div <= (dcdDV)&&(w_opvalid);
851
                        opvalid_fpu <= (dcdFP)&&(w_opvalid);
852
`endif
853 118 dgisselq
                end else if ((adf_ce_unconditional)||(mem_ce))
854 21 dgisselq
                begin
855
                        opvalid     <= 1'b0;
856
                        opvalid_alu <= 1'b0;
857
                        opvalid_mem <= 1'b0;
858
                        opvalid_div <= 1'b0;
859
                        opvalid_fpu <= 1'b0;
860
                end
861
 
862
        // Here's part of our debug interface.  When we recognize a break
863
        // instruction, we set the op_break flag.  That'll prevent this
864
        // instruction from entering the ALU, and cause an interrupt before
865
        // this instruction.  Thus, returning to this code will cause the
866
        // break to repeat and continue upon return.  To get out of this
867
        // condition, replace the break instruction with what it is supposed
868
        // to be, step through it, and then replace it back.  In this fashion,
869
        // a debugger can step through code.
870
        // assign w_op_break = (dcd_break)&&(r_dcdI[15:0] == 16'h0001);
871 117 dgisselq
`ifdef  OPT_PIPELINED
872
        reg     r_op_break;
873
 
874
        initial r_op_break = 1'b0;
875 21 dgisselq
        always @(posedge i_clk)
876 117 dgisselq
                if (i_rst)      r_op_break <= 1'b0;
877 118 dgisselq
                else if (op_ce) r_op_break <= (dcd_break);
878 21 dgisselq
                else if ((clear_pipeline)||(~opvalid))
879 117 dgisselq
                                r_op_break <= 1'b0;
880
        assign  op_break = r_op_break;
881
`else
882
        assign  op_break = dcd_break;
883
`endif
884 21 dgisselq
 
885
`ifdef  OPT_PIPELINED
886
        generate
887
        if (IMPLEMENT_LOCK != 0)
888
        begin
889
                reg     r_op_lock, r_op_lock_stall;
890
 
891
                initial r_op_lock_stall = 1'b0;
892
                always @(posedge i_clk)
893
                        if (i_rst)
894
                                r_op_lock_stall <= 1'b0;
895
                        else
896
                                r_op_lock_stall <= (~opvalid)||(~op_lock)
897
                                                ||(~dcdvalid)||(~pf_valid);
898
 
899
                assign  op_lock_stall = r_op_lock_stall;
900
 
901
                initial r_op_lock = 1'b0;
902
                always @(posedge i_clk)
903 73 dgisselq
                        if ((i_rst)||(clear_pipeline))
904 21 dgisselq
                                r_op_lock <= 1'b0;
905 52 dgisselq
                        else if (op_ce)
906
                                r_op_lock <= (dcd_lock)&&(~clear_pipeline);
907 21 dgisselq
                assign  op_lock = r_op_lock;
908
 
909
        end else begin
910
                assign  op_lock_stall = 1'b0;
911
                assign  op_lock = 1'b0;
912
        end endgenerate
913
 
914
`else
915
        assign op_lock_stall = 1'b0;
916
        assign op_lock       = 1'b0;
917
`endif
918
 
919
`ifdef  OPT_ILLEGAL_INSTRUCTION
920
        initial op_illegal = 1'b0;
921
        always @(posedge i_clk)
922
                if ((i_rst)||(clear_pipeline))
923
                        op_illegal <= 1'b0;
924
                else if(op_ce)
925
`ifdef  OPT_PIPELINED
926 113 dgisselq
                        op_illegal <= (dcdvalid)&&((dcd_illegal)||((dcd_lock)&&(IMPLEMENT_LOCK == 0)));
927 21 dgisselq
`else
928 113 dgisselq
                        op_illegal <= (dcdvalid)&&((dcd_illegal)||(dcd_lock));
929 21 dgisselq
`endif
930 113 dgisselq
                else if(alu_ce)
931
                        op_illegal <= 1'b0;
932 117 dgisselq
`endif
933 21 dgisselq
 
934
        // No generate on EARLY_BRANCHING here, since if EARLY_BRANCHING is not
935
        // set, dcd_early_branch will simply be a wire connected to zero and
936
        // this logic should just optimize.
937 117 dgisselq
`ifdef  OPT_PIPELINED
938 21 dgisselq
        always @(posedge i_clk)
939
                if (op_ce)
940
                begin
941
                        opF_wr <= (dcdF_wr)&&((~dcdR_cc)||(~dcdR_wr))
942
                                &&(~dcd_early_branch)&&(~dcd_illegal);
943
                        opR_wr <= (dcdR_wr)&&(~dcd_early_branch)&&(~dcd_illegal);
944
                end
945 117 dgisselq
`else
946
        always @(posedge i_clk)
947
        begin
948
                opF_wr <= (dcdF_wr)&&((~dcdR_cc)||(~dcdR_wr))
949
                        &&(~dcd_early_branch)&&(~dcd_illegal);
950
                opR_wr <= (dcdR_wr)&&(~dcd_early_branch)&&(~dcd_illegal);
951
        end
952
`endif
953 21 dgisselq
 
954 117 dgisselq
`ifdef  OPT_PIPELINED
955
        reg     [3:0]    r_opn;
956
        reg     [4:0]    r_opR;
957
        reg             r_opR_cc;
958
        reg             r_op_gie;
959 21 dgisselq
        always @(posedge i_clk)
960 73 dgisselq
                if (op_change_data_ce)
961 21 dgisselq
                begin
962 117 dgisselq
                        r_opn    <= dcdOp;      // Which ALU operation?
963 21 dgisselq
                        // opM  <= dcdM;        // Is this a memory operation?
964
                        // What register will these results be written into?
965 117 dgisselq
                        r_opR    <= dcdR;
966
                        r_opR_cc <= (dcdR_cc)&&(dcdR_wr)&&(dcdR[4]==dcd_gie);
967 21 dgisselq
                        // User level (1), vs supervisor (0)/interrupts disabled
968 117 dgisselq
                        r_op_gie <= dcd_gie;
969 21 dgisselq
 
970
 
971
                        //
972
                        op_pc  <= (dcd_early_branch)?dcd_branch_pc:dcd_pc;
973
                end
974 117 dgisselq
        assign  opn = r_opn;
975
        assign  opR = r_opR;
976
        assign  op_gie = r_op_gie;
977
        assign  opR_cc = r_opR_cc;
978
`else
979
        assign  opn = dcdOp;
980
        assign  opR = dcdR;
981
        assign  op_gie = dcd_gie;
982
        // With no pipelining, there is no early branching.  We keep it
983
        always @(posedge i_clk)
984
                op_pc <= (dcd_early_branch)?dcd_branch_pc:dcd_pc;
985
`endif
986 21 dgisselq
        assign  opFl = (op_gie)?(w_uflags):(w_iflags);
987
 
988
`ifdef  OPT_VLIW
989
        reg     r_op_phase;
990
        initial r_op_phase = 1'b0;
991
        always @(posedge i_clk)
992
                if ((i_rst)||(clear_pipeline))
993
                        r_op_phase <= 1'b0;
994 73 dgisselq
                else if (op_change_data_ce)
995 21 dgisselq
                        r_op_phase <= dcd_phase;
996
        assign  op_phase = r_op_phase;
997
`else
998
        assign  op_phase = 1'b0;
999
`endif
1000
 
1001
        // This is tricky.  First, the PC and Flags registers aren't kept in
1002
        // register set but in special registers of their own.  So step one
1003
        // is to select the right register.  Step to is to replace that
1004
        // register with the results of an ALU or memory operation, if such
1005
        // results are now available.  Otherwise, we'd need to insert a wait
1006
        // state of some type.
1007
        //
1008
        // The alternative approach would be to define some sort of
1009
        // op_stall wire, which would stall any upstream stage.
1010
        // We'll create a flag here to start our coordination.  Once we
1011
        // define this flag to something other than just plain zero, then
1012
        // the stalls will already be in place.
1013
`ifdef  OPT_PIPELINED
1014
        assign  opA = ((wr_reg_ce)&&(wr_reg_id == opA_id)) // &&(opA_rd))
1015 73 dgisselq
                        ?  wr_gpreg_vl : r_opA;
1016 21 dgisselq
`else
1017
        assign  opA = r_opA;
1018
`endif
1019
 
1020
`ifdef  OPT_PIPELINED
1021
        // Stall if we have decoded an instruction that will read register A
1022
        //      AND ... something that may write a register is running
1023
        //      AND (series of conditions here ...)
1024
        //              The operation might set flags, and we wish to read the
1025
        //                      CC register
1026
        //              OR ... (No other conditions)
1027
        assign  dcdA_stall = (dcdA_rd) // &&(dcdvalid) is checked for elsewhere
1028
                                &&((opvalid)||(mem_rdbusy)
1029
                                        ||(div_busy)||(fpu_busy))
1030 113 dgisselq
                                &&(((opF_wr)||(cc_invalid_for_dcd))&&(dcdA_cc))
1031
                        ||((dcdA_rd)&&(dcdA_cc)&&(cc_invalid_for_dcd));
1032 21 dgisselq
`else
1033
        // There are no pipeline hazards, if we aren't pipelined
1034
        assign  dcdA_stall = 1'b0;
1035
`endif
1036
 
1037
`ifdef  OPT_PIPELINED
1038
        assign  opB = ((wr_reg_ce)&&(wr_reg_id == opB_id)&&(opB_rd))
1039 73 dgisselq
                        ? wr_gpreg_vl: r_opB;
1040 21 dgisselq
`else
1041
        assign  opB = r_opB;
1042
`endif
1043
 
1044
`ifdef  OPT_PIPELINED
1045
        // Stall if we have decoded an instruction that will read register B
1046
        //      AND ... something that may write a (unknown) register is running
1047
        //      AND (series of conditions here ...)
1048
        //              The operation might set flags, and we wish to read the
1049
        //                      CC register
1050
        //              OR the operation might set register B, and we still need
1051
        //                      a clock to add the offset to it
1052
        assign  dcdB_stall = (dcdB_rd) // &&(dcdvalid) is checked for elsewhere
1053
                                // If the op stage isn't valid, yet something
1054
                                // is running, then it must have been valid.
1055
                                // We'll use the last values from that stage
1056
                                // (opR_wr, opF_wr, opR) in our logic below.
1057
                                &&((opvalid)||(mem_rdbusy)
1058 51 dgisselq
                                        ||(div_busy)||(fpu_busy)||(alu_busy))
1059 21 dgisselq
                                &&(
1060 73 dgisselq
                                // Okay, what happens if the result register
1061
                                // from instruction 1 becomes the input for
1062
                                // instruction two, *and* there's an immediate
1063
                                // offset in instruction two?  In that case, we
1064
                                // need an extra clock between the two 
1065
                                // instructions to calculate the base plus 
1066
                                // offset.
1067
                                //
1068
                                // What if instruction 1 (or before) is in a
1069
                                // memory pipeline?  We may no longer know what
1070
                                // the register was!  We will then need  to 
1071
                                // blindly wait.  We'll temper this only waiting
1072
                                // if we're not piping this new instruction.
1073
                                // If we were piping, the pipe logic in the
1074
                                // decode circuit has told us that the hazard
1075
                                // is clear, so we're okay then.
1076
                                //
1077 51 dgisselq
                                ((~dcd_zI)&&(
1078
                                        ((opR == dcdB)&&(opR_wr))
1079 73 dgisselq
                                        ||((mem_rdbusy)&&(~dcd_pipe))
1080
                                        ))
1081 21 dgisselq
                                // Stall following any instruction that will
1082
                                // set the flags, if we're going to need the
1083
                                // flags (CC) register for opB.
1084 113 dgisselq
                                ||(((opF_wr)||(cc_invalid_for_dcd))&&(dcdB_cc))
1085 21 dgisselq
                                // Stall on any ongoing memory operation that
1086
                                // will write to opB -- captured above
1087
                                // ||((mem_busy)&&(~mem_we)&&(mem_last_reg==dcdB)&&(~dcd_zI))
1088 113 dgisselq
                                )
1089
                        ||((dcdB_rd)&&(dcdB_cc)&&(cc_invalid_for_dcd));
1090 26 dgisselq
        assign  dcdF_stall = ((~dcdF[3])
1091
                                        ||((dcdA_rd)&&(dcdA_cc))
1092
                                        ||((dcdB_rd)&&(dcdB_cc)))
1093
                                        &&(opvalid)&&(opR_cc);
1094
                                // &&(dcdvalid) is checked for elsewhere
1095 21 dgisselq
`else
1096
        // No stalls without pipelining, 'cause how can you have a pipeline
1097
        // hazard without the pipeline?
1098
        assign  dcdB_stall = 1'b0;
1099 26 dgisselq
        assign  dcdF_stall = 1'b0;
1100 21 dgisselq
`endif
1101
        //
1102
        //
1103
        //      PIPELINE STAGE #4 :: Apply Instruction
1104
        //
1105
        //
1106 118 dgisselq
        cpuops  #(IMPLEMENT_MPY) doalu(i_clk, (i_rst)||(clear_pipeline),
1107
                        alu_ce, opn, opA, opB,
1108
                        alu_result, alu_flags, alu_valid, alu_busy);
1109 21 dgisselq
 
1110
        generate
1111
        if (IMPLEMENT_DIVIDE != 0)
1112
        begin
1113
                div thedivide(i_clk, (i_rst)||(clear_pipeline), div_ce, opn[0],
1114
                        opA, opB, div_busy, div_valid, div_error, div_result,
1115
                        div_flags);
1116
        end else begin
1117 113 dgisselq
                assign  div_error = 1'b0; // Can't be high unless div_valid
1118 21 dgisselq
                assign  div_busy  = 1'b0;
1119
                assign  div_valid = 1'b0;
1120
                assign  div_result= 32'h00;
1121
                assign  div_flags = 4'h0;
1122
        end endgenerate
1123
 
1124
        generate
1125
        if (IMPLEMENT_FPU != 0)
1126
        begin
1127
                //
1128
                // sfpu thefpu(i_clk, i_rst, fpu_ce,
1129
                //      opA, opB, fpu_busy, fpu_valid, fpu_err, fpu_result,
1130
                //      fpu_flags);
1131
                //
1132 113 dgisselq
                assign  fpu_error = 1'b0; // Must only be true if fpu_valid
1133 21 dgisselq
                assign  fpu_busy  = 1'b0;
1134
                assign  fpu_valid = 1'b0;
1135
                assign  fpu_result= 32'h00;
1136
                assign  fpu_flags = 4'h0;
1137
        end else begin
1138 113 dgisselq
                assign  fpu_error = 1'b0;
1139 21 dgisselq
                assign  fpu_busy  = 1'b0;
1140
                assign  fpu_valid = 1'b0;
1141
                assign  fpu_result= 32'h00;
1142
                assign  fpu_flags = 4'h0;
1143
        end endgenerate
1144
 
1145
 
1146
        assign  set_cond = ((opF[7:4]&opFl[3:0])==opF[3:0]);
1147
        initial alF_wr   = 1'b0;
1148
        initial alu_wr   = 1'b0;
1149
        always @(posedge i_clk)
1150
                if (i_rst)
1151
                begin
1152
                        alu_wr   <= 1'b0;
1153
                        alF_wr   <= 1'b0;
1154
                end else if (alu_ce)
1155
                begin
1156
                        // alu_reg <= opR;
1157
                        alu_wr  <= (opR_wr)&&(set_cond);
1158
                        alF_wr  <= (opF_wr)&&(set_cond);
1159
                end else if (~alu_busy) begin
1160
                        // These are strobe signals, so clear them if not
1161
                        // set for any particular clock
1162
                        alu_wr <= (i_halt)&&(i_dbg_we);
1163
                        alF_wr <= 1'b0;
1164
                end
1165
 
1166
`ifdef  OPT_VLIW
1167
        reg     r_alu_phase;
1168
        initial r_alu_phase = 1'b0;
1169
        always @(posedge i_clk)
1170
                if (i_rst)
1171
                        r_alu_phase <= 1'b0;
1172 89 dgisselq
                else if ((adf_ce_unconditional)||(mem_ce))
1173 21 dgisselq
                        r_alu_phase <= op_phase;
1174
        assign  alu_phase = r_alu_phase;
1175
`else
1176
        assign  alu_phase = 1'b0;
1177
`endif
1178
 
1179 117 dgisselq
`ifdef  OPT_PIPELINED
1180 21 dgisselq
        always @(posedge i_clk)
1181 89 dgisselq
                if (adf_ce_unconditional)
1182 21 dgisselq
                        alu_reg <= opR;
1183
                else if ((i_halt)&&(i_dbg_we))
1184
                        alu_reg <= i_dbg_reg;
1185 117 dgisselq
`else
1186
        always @(posedge i_clk)
1187
                if ((i_halt)&&(i_dbg_we))
1188
                        alu_reg <= i_dbg_reg;
1189
                else
1190
                        alu_reg <= opR;
1191
`endif
1192 21 dgisselq
 
1193 51 dgisselq
        //
1194
        // DEBUG Register write access starts here
1195
        //
1196 21 dgisselq
        reg             dbgv;
1197
        initial dbgv = 1'b0;
1198
        always @(posedge i_clk)
1199 73 dgisselq
                dbgv <= (~i_rst)&&(i_halt)&&(i_dbg_we)&&(r_halted);
1200 51 dgisselq
        reg     [31:0]   dbg_val;
1201 21 dgisselq
        always @(posedge i_clk)
1202 51 dgisselq
                dbg_val <= i_dbg_data;
1203 117 dgisselq
`ifdef  OPT_PIPELINED
1204
        reg     r_alu_gie;
1205
 
1206 51 dgisselq
        always @(posedge i_clk)
1207 89 dgisselq
                if ((adf_ce_unconditional)||(mem_ce))
1208 117 dgisselq
                        r_alu_gie  <= op_gie;
1209
        assign  alu_gie = r_alu_gie;
1210
 
1211
        reg     [(AW-1):0]       r_alu_pc;
1212 21 dgisselq
        always @(posedge i_clk)
1213 89 dgisselq
                if ((adf_ce_unconditional)
1214 73 dgisselq
                        ||((master_ce)&&(opvalid_mem)&&(~clear_pipeline)
1215 21 dgisselq
                                &&(~mem_stalled)))
1216 117 dgisselq
                        r_alu_pc  <= op_pc;
1217
        assign  alu_pc = r_alu_pc;
1218
`else
1219
        assign  alu_gie = op_gie;
1220
        assign  alu_pc = op_pc;
1221
`endif
1222 21 dgisselq
 
1223
`ifdef  OPT_ILLEGAL_INSTRUCTION
1224
        reg     r_alu_illegal;
1225
        initial r_alu_illegal = 0;
1226
        always @(posedge i_clk)
1227 113 dgisselq
                if ((i_rst)||(clear_pipeline))
1228 21 dgisselq
                        r_alu_illegal <= 1'b0;
1229 113 dgisselq
                else if (alu_ce)
1230 21 dgisselq
                        r_alu_illegal <= op_illegal;
1231 113 dgisselq
                else
1232
                        r_alu_illegal <= 1'b0;
1233 118 dgisselq
        assign  alu_illegal = (r_alu_illegal);
1234 113 dgisselq
`else
1235
        assign  alu_illegal = 1'b0;
1236 21 dgisselq
`endif
1237
 
1238 73 dgisselq
        initial r_alu_pc_valid = 1'b0;
1239 51 dgisselq
        initial mem_pc_valid = 1'b0;
1240 21 dgisselq
        always @(posedge i_clk)
1241 51 dgisselq
                if (i_rst)
1242 73 dgisselq
                        r_alu_pc_valid <= 1'b0;
1243 89 dgisselq
                else if (adf_ce_unconditional)//Includes&&(~alu_clear_pipeline)
1244 73 dgisselq
                        r_alu_pc_valid <= 1'b1;
1245
                else if (((~alu_busy)&&(~div_busy)&&(~fpu_busy))||(clear_pipeline))
1246
                        r_alu_pc_valid <= 1'b0;
1247
        assign  alu_pc_valid = (r_alu_pc_valid)&&((~alu_busy)&&(~div_busy)&&(~fpu_busy));
1248 51 dgisselq
        always @(posedge i_clk)
1249
                if (i_rst)
1250
                        mem_pc_valid <= 1'b0;
1251
                else
1252
                        mem_pc_valid <= (mem_ce);
1253 21 dgisselq
 
1254
        wire    bus_lock;
1255
`ifdef  OPT_PIPELINED
1256
        generate
1257
        if (IMPLEMENT_LOCK != 0)
1258
        begin
1259 52 dgisselq
                reg     [1:0]    r_bus_lock;
1260
                initial r_bus_lock = 2'b00;
1261 21 dgisselq
                always @(posedge i_clk)
1262
                        if (i_rst)
1263 52 dgisselq
                                r_bus_lock <= 2'b00;
1264 21 dgisselq
                        else if ((op_ce)&&(op_lock))
1265 52 dgisselq
                                r_bus_lock <= 2'b11;
1266
                        else if ((|r_bus_lock)&&((~opvalid_mem)||(~op_ce)))
1267
                                r_bus_lock <= r_bus_lock + 2'b11;
1268
                assign  bus_lock = |r_bus_lock;
1269 21 dgisselq
        end else begin
1270
                assign  bus_lock = 1'b0;
1271
        end endgenerate
1272
`else
1273
        assign  bus_lock = 1'b0;
1274
`endif
1275
 
1276
`ifdef  OPT_PIPELINED_BUS_ACCESS
1277
        pipemem #(AW,IMPLEMENT_LOCK) domem(i_clk, i_rst,(mem_ce)&&(set_cond), bus_lock,
1278
                                (opn[0]), opB, opA, opR,
1279
                                mem_busy, mem_pipe_stalled,
1280
                                mem_valid, bus_err, mem_wreg, mem_result,
1281
                        mem_cyc_gbl, mem_cyc_lcl,
1282
                                mem_stb_gbl, mem_stb_lcl,
1283
                                mem_we, mem_addr, mem_data,
1284
                                mem_ack, mem_stall, mem_err, i_wb_data);
1285
 
1286
`else // PIPELINED_BUS_ACCESS
1287
        memops  #(AW,IMPLEMENT_LOCK) domem(i_clk, i_rst,(mem_ce)&&(set_cond), bus_lock,
1288
                                (opn[0]), opB, opA, opR,
1289
                                mem_busy,
1290
                                mem_valid, bus_err, mem_wreg, mem_result,
1291
                        mem_cyc_gbl, mem_cyc_lcl,
1292
                                mem_stb_gbl, mem_stb_lcl,
1293
                                mem_we, mem_addr, mem_data,
1294
                                mem_ack, mem_stall, mem_err, i_wb_data);
1295
`endif // PIPELINED_BUS_ACCESS
1296
        assign  mem_rdbusy = ((mem_busy)&&(~mem_we));
1297
 
1298
        // Either the prefetch or the instruction gets the memory bus, but 
1299
        // never both.
1300
        wbdblpriarb     #(32,AW) pformem(i_clk, i_rst,
1301
                // Memory access to the arbiter, priority position
1302
                mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl,
1303
                        mem_we, mem_addr, mem_data, mem_ack, mem_stall, mem_err,
1304
                // Prefetch access to the arbiter
1305
                pf_cyc, 1'b0, pf_stb, 1'b0, pf_we, pf_addr, pf_data,
1306
                        pf_ack, pf_stall, pf_err,
1307
                // Common wires, in and out, of the arbiter
1308
                o_wb_gbl_cyc, o_wb_lcl_cyc, o_wb_gbl_stb, o_wb_lcl_stb,
1309
                        o_wb_we, o_wb_addr, o_wb_data,
1310
                        i_wb_ack, i_wb_stall, i_wb_err);
1311
 
1312 51 dgisselq
 
1313
 
1314 21 dgisselq
        //
1315
        //
1316 51 dgisselq
        //
1317
        //
1318
        //
1319
        //
1320
        //
1321
        //
1322 21 dgisselq
        //      PIPELINE STAGE #5 :: Write-back results
1323
        //
1324
        //
1325
        // This stage is not allowed to stall.  If results are ready to be
1326
        // written back, they are written back at all cost.  Sleepy CPU's
1327
        // won't prevent write back, nor debug modes, halting the CPU, nor
1328
        // anything else.  Indeed, the (master_ce) bit is only as relevant
1329
        // as knowinig something is available for writeback.
1330
 
1331
        //
1332
        // Write back to our generic register set ...
1333
        // When shall we write back?  On one of two conditions
1334
        //      Note that the flags needed to be checked before issuing the
1335
        //      bus instruction, so they don't need to be checked here.
1336
        //      Further, alu_wr includes (set_cond), so we don't need to
1337
        //      check for that here either.
1338
`ifdef  OPT_ILLEGAL_INSTRUCTION
1339 73 dgisselq
        assign  wr_reg_ce = (dbgv)||(mem_valid)
1340
                                ||((~clear_pipeline)&&(~alu_illegal)
1341
                                        &&(((alu_wr)&&(alu_valid))
1342
                                                ||(div_valid)||(fpu_valid)));
1343 21 dgisselq
`else
1344 73 dgisselq
        assign  wr_reg_ce = (dbgv)||(mem_valid)
1345
                                ||((~clear_pipeline)
1346
                                        &&(((alu_wr)&&(alu_valid))
1347
                                                ||(div_valid)||(fpu_valid)));
1348 21 dgisselq
`endif
1349
        // Which register shall be written?
1350
        //      COULD SIMPLIFY THIS: by adding three bits to these registers,
1351
        //              One or PC, one for CC, and one for GIE match
1352
        //      Note that the alu_reg is the register to write on a divide or
1353
        //      FPU operation.
1354 73 dgisselq
        assign  wr_reg_id = (alu_wr|div_valid|fpu_valid)?alu_reg:mem_wreg;
1355 21 dgisselq
        // Are we writing to the CC register?
1356
        assign  wr_write_cc = (wr_reg_id[3:0] == `CPU_CC_REG);
1357 113 dgisselq
        assign  wr_write_scc = (wr_reg_id[4:0] == {1'b0, `CPU_CC_REG});
1358
        assign  wr_write_ucc = (wr_reg_id[4:0] == {1'b1, `CPU_CC_REG});
1359 21 dgisselq
        // Are we writing to the PC?
1360
        assign  wr_write_pc = (wr_reg_id[3:0] == `CPU_PC_REG);
1361 117 dgisselq
 
1362 21 dgisselq
        // What value to write?
1363 73 dgisselq
        assign  wr_gpreg_vl = ((mem_valid) ? mem_result
1364 21 dgisselq
                                :((div_valid|fpu_valid))
1365
                                        ? ((div_valid) ? div_result:fpu_result)
1366
                                :((dbgv) ? dbg_val : alu_result));
1367 73 dgisselq
        assign  wr_spreg_vl = ((mem_valid) ? mem_result
1368
                                :((dbgv) ? dbg_val : alu_result));
1369 21 dgisselq
        always @(posedge i_clk)
1370
                if (wr_reg_ce)
1371 73 dgisselq
                        regset[wr_reg_id] <= wr_gpreg_vl;
1372 21 dgisselq
 
1373
        //
1374
        // Write back to the condition codes/flags register ...
1375
        // When shall we write to our flags register?  alF_wr already
1376
        // includes the set condition ...
1377
        assign  wr_flags_ce = ((alF_wr)||(div_valid)||(fpu_valid))&&(~clear_pipeline)&&(~alu_illegal);
1378 113 dgisselq
        assign  w_uflags = { 1'b0, uhalt_phase, ufpu_err_flag,
1379 21 dgisselq
                        udiv_err_flag, ubus_err_flag, trap, ill_err_u,
1380 113 dgisselq
                        ubreak, step, 1'b1, sleep,
1381 21 dgisselq
                        ((wr_flags_ce)&&(alu_gie))?alu_flags:flags };
1382 113 dgisselq
        assign  w_iflags = { 1'b0, ihalt_phase, ifpu_err_flag,
1383 21 dgisselq
                        idiv_err_flag, ibus_err_flag, trap, ill_err_i,
1384
                        break_en, 1'b0, 1'b0, sleep,
1385
                        ((wr_flags_ce)&&(~alu_gie))?alu_flags:iflags };
1386
 
1387
 
1388
        // What value to write?
1389
        always @(posedge i_clk)
1390
                // If explicitly writing the register itself
1391 113 dgisselq
                if ((wr_reg_ce)&&(wr_write_ucc))
1392 73 dgisselq
                        flags <= wr_gpreg_vl[3:0];
1393 21 dgisselq
                // Otherwise if we're setting the flags from an ALU operation
1394
                else if ((wr_flags_ce)&&(alu_gie))
1395
                        flags <= (div_valid)?div_flags:((fpu_valid)?fpu_flags
1396
                                : alu_flags);
1397
 
1398
        always @(posedge i_clk)
1399 113 dgisselq
                if ((wr_reg_ce)&&(wr_write_scc))
1400 73 dgisselq
                        iflags <= wr_gpreg_vl[3:0];
1401 21 dgisselq
                else if ((wr_flags_ce)&&(~alu_gie))
1402
                        iflags <= (div_valid)?div_flags:((fpu_valid)?fpu_flags
1403
                                : alu_flags);
1404
 
1405
        // The 'break' enable  bit.  This bit can only be set from supervisor
1406
        // mode.  It control what the CPU does upon encountering a break
1407
        // instruction.
1408
        //
1409
        // The goal, upon encountering a break is that the CPU should stop and
1410
        // not execute the break instruction, choosing instead to enter into
1411
        // either interrupt mode or halt first.  
1412
        //      if ((break_en) AND (break_instruction)) // user mode or not
1413
        //              HALT CPU
1414
        //      else if (break_instruction) // only in user mode
1415 113 dgisselq
        //              set an interrupt flag, set the user break bit,
1416
        //              go to supervisor mode, allow supervisor to step the CPU.
1417 21 dgisselq
        //      Upon a CPU halt, any break condition will be reset.  The
1418
        //      external debugger will then need to deal with whatever
1419
        //      condition has taken place.
1420
        initial break_en = 1'b0;
1421
        always @(posedge i_clk)
1422
                if ((i_rst)||(i_halt))
1423
                        break_en <= 1'b0;
1424 113 dgisselq
                else if ((wr_reg_ce)&&(wr_write_scc))
1425 73 dgisselq
                        break_en <= wr_spreg_vl[`CPU_BREAK_BIT];
1426 113 dgisselq
 
1427 117 dgisselq
`ifdef  OPT_PIPELINED
1428
        reg     r_break_pending;
1429
 
1430
        initial r_break_pending = 1'b0;
1431 113 dgisselq
        always @(posedge i_clk)
1432
                if ((i_rst)||(clear_pipeline)||(~opvalid))
1433 117 dgisselq
                        r_break_pending <= 1'b0;
1434 113 dgisselq
                else if (op_break)
1435 118 dgisselq
                        r_break_pending <= (~alu_busy)&&(~div_busy)&&(~fpu_busy)&&(~mem_busy)&&(!wr_reg_ce);
1436 113 dgisselq
                else
1437 117 dgisselq
                        r_break_pending <= 1'b0;
1438
        assign  break_pending = r_break_pending;
1439
`else
1440
        assign  break_pending = op_break;
1441
`endif
1442 113 dgisselq
 
1443
 
1444
        assign  o_break = ((break_en)||(~op_gie))&&(break_pending)
1445 21 dgisselq
                                &&(~clear_pipeline)
1446
                        ||((~alu_gie)&&(bus_err))
1447 113 dgisselq
                        ||((~alu_gie)&&(div_error))
1448
                        ||((~alu_gie)&&(fpu_error))
1449 118 dgisselq
                        ||((~alu_gie)&&(alu_illegal)&&(!clear_pipeline));
1450 21 dgisselq
 
1451
        // The sleep register.  Setting the sleep register causes the CPU to
1452
        // sleep until the next interrupt.  Setting the sleep register within
1453
        // interrupt mode causes the processor to halt until a reset.  This is
1454
        // a panic/fault halt.  The trick is that you cannot be allowed to
1455
        // set the sleep bit and switch to supervisor mode in the same 
1456
        // instruction: users are not allowed to halt the CPU.
1457
        always @(posedge i_clk)
1458
                if ((i_rst)||(w_switch_to_interrupt))
1459
                        sleep <= 1'b0;
1460
                else if ((wr_reg_ce)&&(wr_write_cc)&&(~alu_gie))
1461
                        // In supervisor mode, we have no protections.  The
1462
                        // supervisor can set the sleep bit however he wants.
1463
                        // Well ... not quite.  Switching to user mode and
1464
                        // sleep mode shouold only be possible if the interrupt
1465
                        // flag isn't set.
1466 73 dgisselq
                        //      Thus: if (i_interrupt)&&(wr_spreg_vl[GIE])
1467 21 dgisselq
                        //              don't set the sleep bit
1468
                        //      otherwise however it would o.w. be set
1469 73 dgisselq
                        sleep <= (wr_spreg_vl[`CPU_SLEEP_BIT])
1470
                                &&((~i_interrupt)||(~wr_spreg_vl[`CPU_GIE_BIT]));
1471
                else if ((wr_reg_ce)&&(wr_write_cc)&&(wr_spreg_vl[`CPU_GIE_BIT]))
1472 21 dgisselq
                        // In user mode, however, you can only set the sleep
1473
                        // mode while remaining in user mode.  You can't switch
1474
                        // to sleep mode *and* supervisor mode at the same
1475
                        // time, lest you halt the CPU.
1476 73 dgisselq
                        sleep <= wr_spreg_vl[`CPU_SLEEP_BIT];
1477 21 dgisselq
 
1478
        always @(posedge i_clk)
1479 118 dgisselq
                if (i_rst)
1480 21 dgisselq
                        step <= 1'b0;
1481 113 dgisselq
                else if ((wr_reg_ce)&&(~alu_gie)&&(wr_write_ucc))
1482 73 dgisselq
                        step <= wr_spreg_vl[`CPU_STEP_BIT];
1483 21 dgisselq
 
1484
        // The GIE register.  Only interrupts can disable the interrupt register
1485
        assign  w_switch_to_interrupt = (gie)&&(
1486
                        // On interrupt (obviously)
1487
                        ((i_interrupt)&&(~alu_phase)&&(~bus_lock))
1488
                        // If we are stepping the CPU
1489 51 dgisselq
                        ||(((alu_pc_valid)||(mem_pc_valid))&&(step)&&(~alu_phase)&&(~bus_lock))
1490 21 dgisselq
                        // If we encounter a break instruction, if the break
1491
                        //      enable isn't set.
1492 113 dgisselq
                        ||((master_ce)&&(break_pending)&&(~break_en))
1493 21 dgisselq
`ifdef  OPT_ILLEGAL_INSTRUCTION
1494
                        // On an illegal instruction
1495 118 dgisselq
                        ||((alu_illegal)&&(!clear_pipeline))
1496 21 dgisselq
`endif
1497
                        // On division by zero.  If the divide isn't
1498
                        // implemented, div_valid and div_error will be short
1499
                        // circuited and that logic will be bypassed
1500 113 dgisselq
                        ||(div_error)
1501
                        // Same thing on a floating point error.  Note that
1502
                        // fpu_error must *never* be set unless fpu_valid is
1503
                        // also set as well, else this will fail.
1504
                        ||(fpu_error)
1505 21 dgisselq
                        //      
1506
                        ||(bus_err)
1507
                        // If we write to the CC register
1508 73 dgisselq
                        ||((wr_reg_ce)&&(~wr_spreg_vl[`CPU_GIE_BIT])
1509 21 dgisselq
                                &&(wr_reg_id[4])&&(wr_write_cc))
1510
                        );
1511
        assign  w_release_from_interrupt = (~gie)&&(~i_interrupt)
1512 113 dgisselq
                        // Then if we write the sCC register
1513 73 dgisselq
                        &&(((wr_reg_ce)&&(wr_spreg_vl[`CPU_GIE_BIT])
1514 113 dgisselq
                                &&(wr_write_scc))
1515 21 dgisselq
                        );
1516
        always @(posedge i_clk)
1517
                if (i_rst)
1518
                        gie <= 1'b0;
1519
                else if (w_switch_to_interrupt)
1520
                        gie <= 1'b0;
1521
                else if (w_release_from_interrupt)
1522
                        gie <= 1'b1;
1523
 
1524
        initial trap = 1'b0;
1525
        always @(posedge i_clk)
1526 113 dgisselq
                if ((i_rst)||(w_release_from_interrupt))
1527 21 dgisselq
                        trap <= 1'b0;
1528 73 dgisselq
                else if ((alu_gie)&&(wr_reg_ce)&&(~wr_spreg_vl[`CPU_GIE_BIT])
1529 113 dgisselq
                                &&(wr_write_ucc)) // &&(wr_reg_id[4]) implied
1530 21 dgisselq
                        trap <= 1'b1;
1531 113 dgisselq
                else if ((wr_reg_ce)&&(wr_write_ucc)&&(~alu_gie))
1532
                        trap <= (trap)&&(wr_spreg_vl[`CPU_TRAP_BIT]);
1533 21 dgisselq
 
1534 113 dgisselq
        initial ubreak = 1'b0;
1535
        always @(posedge i_clk)
1536
                if ((i_rst)||(w_release_from_interrupt))
1537
                        ubreak <= 1'b0;
1538
                else if ((op_gie)&&(break_pending)&&(w_switch_to_interrupt))
1539
                        ubreak <= 1'b1;
1540
                else if (((~alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc))
1541
                        ubreak <= (ubreak)&&(wr_spreg_vl[`CPU_BREAK_BIT]);
1542
 
1543
 
1544 21 dgisselq
`ifdef  OPT_ILLEGAL_INSTRUCTION
1545
        initial ill_err_i = 1'b0;
1546
        always @(posedge i_clk)
1547
                if (i_rst)
1548
                        ill_err_i <= 1'b0;
1549 52 dgisselq
                // Only the debug interface can clear this bit
1550 113 dgisselq
                else if ((dbgv)&&(wr_write_scc))
1551
                        ill_err_i <= (ill_err_i)&&(wr_spreg_vl[`CPU_ILL_BIT]);
1552 118 dgisselq
                else if ((alu_illegal)&&(~alu_gie)&&(!clear_pipeline))
1553 21 dgisselq
                        ill_err_i <= 1'b1;
1554
        initial ill_err_u = 1'b0;
1555
        always @(posedge i_clk)
1556
                // The bit is automatically cleared on release from interrupt
1557 113 dgisselq
                // or reset
1558
                if ((i_rst)||(w_release_from_interrupt))
1559 21 dgisselq
                        ill_err_u <= 1'b0;
1560 113 dgisselq
                // If the supervisor (or debugger) writes to this register,
1561
                // clearing the bit, then clear it
1562
                else if (((~alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc))
1563
                        ill_err_u <=((ill_err_u)&&(wr_spreg_vl[`CPU_ILL_BIT]));
1564 118 dgisselq
                else if ((alu_illegal)&&(alu_gie)&&(!clear_pipeline))
1565 21 dgisselq
                        ill_err_u <= 1'b1;
1566
`else
1567
        assign ill_err_u = 1'b0;
1568
        assign ill_err_i = 1'b0;
1569
`endif
1570
        // Supervisor/interrupt bus error flag -- this will crash the CPU if
1571
        // ever set.
1572
        initial ibus_err_flag = 1'b0;
1573
        always @(posedge i_clk)
1574
                if (i_rst)
1575
                        ibus_err_flag <= 1'b0;
1576 113 dgisselq
                else if ((dbgv)&&(wr_write_scc))
1577
                        ibus_err_flag <= (ibus_err_flag)&&(wr_spreg_vl[`CPU_BUSERR_BIT]);
1578 21 dgisselq
                else if ((bus_err)&&(~alu_gie))
1579
                        ibus_err_flag <= 1'b1;
1580
        // User bus error flag -- if ever set, it will cause an interrupt to
1581
        // supervisor mode.  
1582
        initial ubus_err_flag = 1'b0;
1583
        always @(posedge i_clk)
1584 113 dgisselq
                if ((i_rst)||(w_release_from_interrupt))
1585 21 dgisselq
                        ubus_err_flag <= 1'b0;
1586 113 dgisselq
                else if (((~alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc))
1587
                        ubus_err_flag <= (ubus_err_flag)&&(wr_spreg_vl[`CPU_BUSERR_BIT]);
1588 21 dgisselq
                else if ((bus_err)&&(alu_gie))
1589
                        ubus_err_flag <= 1'b1;
1590
 
1591
        generate
1592
        if (IMPLEMENT_DIVIDE != 0)
1593
        begin
1594
                reg     r_idiv_err_flag, r_udiv_err_flag;
1595
 
1596
                // Supervisor/interrupt divide (by zero) error flag -- this will
1597
                // crash the CPU if ever set.  This bit is thus available for us
1598
                // to be able to tell if/why the CPU crashed.
1599
                initial r_idiv_err_flag = 1'b0;
1600
                always @(posedge i_clk)
1601
                        if (i_rst)
1602
                                r_idiv_err_flag <= 1'b0;
1603 113 dgisselq
                        else if ((dbgv)&&(wr_write_scc))
1604
                                r_idiv_err_flag <= (r_idiv_err_flag)&&(wr_spreg_vl[`CPU_DIVERR_BIT]);
1605
                        else if ((div_error)&&(~alu_gie))
1606 21 dgisselq
                                r_idiv_err_flag <= 1'b1;
1607
                // User divide (by zero) error flag -- if ever set, it will
1608
                // cause a sudden switch interrupt to supervisor mode.  
1609
                initial r_udiv_err_flag = 1'b0;
1610
                always @(posedge i_clk)
1611 113 dgisselq
                        if ((i_rst)||(w_release_from_interrupt))
1612 21 dgisselq
                                r_udiv_err_flag <= 1'b0;
1613
                        else if (((~alu_gie)||(dbgv))&&(wr_reg_ce)
1614 113 dgisselq
                                        &&(wr_write_ucc))
1615
                                r_udiv_err_flag <= (r_udiv_err_flag)&&(wr_spreg_vl[`CPU_DIVERR_BIT]);
1616
                        else if ((div_error)&&(alu_gie))
1617 21 dgisselq
                                r_udiv_err_flag <= 1'b1;
1618
 
1619
                assign  idiv_err_flag = r_idiv_err_flag;
1620
                assign  udiv_err_flag = r_udiv_err_flag;
1621
        end else begin
1622
                assign  idiv_err_flag = 1'b0;
1623
                assign  udiv_err_flag = 1'b0;
1624
        end endgenerate
1625
 
1626
        generate
1627
        if (IMPLEMENT_FPU !=0)
1628
        begin
1629
                // Supervisor/interrupt floating point error flag -- this will
1630
                // crash the CPU if ever set.
1631
                reg             r_ifpu_err_flag, r_ufpu_err_flag;
1632
                initial r_ifpu_err_flag = 1'b0;
1633
                always @(posedge i_clk)
1634
                        if (i_rst)
1635
                                r_ifpu_err_flag <= 1'b0;
1636 113 dgisselq
                        else if ((dbgv)&&(wr_write_scc))
1637
                                r_ifpu_err_flag <= (r_ifpu_err_flag)&&(wr_spreg_vl[`CPU_FPUERR_BIT]);
1638 21 dgisselq
                        else if ((fpu_error)&&(fpu_valid)&&(~alu_gie))
1639
                                r_ifpu_err_flag <= 1'b1;
1640
                // User floating point error flag -- if ever set, it will cause
1641
                // a sudden switch interrupt to supervisor mode.  
1642
                initial r_ufpu_err_flag = 1'b0;
1643
                always @(posedge i_clk)
1644 113 dgisselq
                        if ((i_rst)&&(w_release_from_interrupt))
1645 21 dgisselq
                                r_ufpu_err_flag <= 1'b0;
1646
                        else if (((~alu_gie)||(dbgv))&&(wr_reg_ce)
1647 113 dgisselq
                                        &&(wr_write_ucc))
1648
                                r_ufpu_err_flag <= (r_ufpu_err_flag)&&(wr_spreg_vl[`CPU_FPUERR_BIT]);
1649 21 dgisselq
                        else if ((fpu_error)&&(alu_gie)&&(fpu_valid))
1650
                                r_ufpu_err_flag <= 1'b1;
1651
 
1652
                assign  ifpu_err_flag = r_ifpu_err_flag;
1653
                assign  ufpu_err_flag = r_ufpu_err_flag;
1654
        end else begin
1655
                assign  ifpu_err_flag = 1'b0;
1656
                assign  ufpu_err_flag = 1'b0;
1657
        end endgenerate
1658
 
1659
`ifdef  OPT_VLIW
1660
        reg             r_ihalt_phase, r_uhalt_phase;
1661
 
1662
        initial r_ihalt_phase = 0;
1663
        initial r_uhalt_phase = 0;
1664
        always @(posedge i_clk)
1665 113 dgisselq
                if (i_rst)
1666
                        r_ihalt_phase <= 1'b0;
1667
                else if ((~alu_gie)&&(alu_pc_valid)&&(~clear_pipeline))
1668 21 dgisselq
                        r_ihalt_phase <= alu_phase;
1669
        always @(posedge i_clk)
1670 113 dgisselq
                if ((i_rst)||(w_release_from_interrupt))
1671
                        r_uhalt_phase <= 1'b0;
1672
                else if ((alu_gie)&&(alu_pc_valid))
1673 21 dgisselq
                        r_uhalt_phase <= alu_phase;
1674 113 dgisselq
                else if ((~alu_gie)&&(wr_reg_ce)&&(wr_write_ucc))
1675
                        r_uhalt_phase <= wr_spreg_vl[`CPU_PHASE_BIT];
1676 21 dgisselq
 
1677
        assign  ihalt_phase = r_ihalt_phase;
1678
        assign  uhalt_phase = r_uhalt_phase;
1679
`else
1680
        assign  ihalt_phase = 1'b0;
1681
        assign  uhalt_phase = 1'b0;
1682
`endif
1683
 
1684
        //
1685
        // Write backs to the PC register, and general increments of it
1686
        //      We support two: upc and ipc.  If the instruction is normal,
1687
        // we increment upc, if interrupt level we increment ipc.  If
1688
        // the instruction writes the PC, we write whichever PC is appropriate.
1689
        //
1690
        // Do we need to all our partial results from the pipeline?
1691
        // What happens when the pipeline has gie and ~gie instructions within
1692
        // it?  Do we clear both?  What if a gie instruction tries to clear
1693
        // a non-gie instruction?
1694
        always @(posedge i_clk)
1695
                if ((wr_reg_ce)&&(wr_reg_id[4])&&(wr_write_pc))
1696 73 dgisselq
                        upc <= wr_spreg_vl[(AW-1):0];
1697 51 dgisselq
                else if ((alu_gie)&&
1698 118 dgisselq
                                (((alu_pc_valid)&&(~clear_pipeline)&&(!alu_illegal))
1699 51 dgisselq
                                ||(mem_pc_valid)))
1700 21 dgisselq
                        upc <= alu_pc;
1701
 
1702
        always @(posedge i_clk)
1703
                if (i_rst)
1704
                        ipc <= RESET_ADDRESS;
1705
                else if ((wr_reg_ce)&&(~wr_reg_id[4])&&(wr_write_pc))
1706 73 dgisselq
                        ipc <= wr_spreg_vl[(AW-1):0];
1707 51 dgisselq
                else if ((~alu_gie)&&
1708 118 dgisselq
                                (((alu_pc_valid)&&(~clear_pipeline)&&(!alu_illegal))
1709 51 dgisselq
                                ||(mem_pc_valid)))
1710 21 dgisselq
                        ipc <= alu_pc;
1711
 
1712
        always @(posedge i_clk)
1713
                if (i_rst)
1714
                        pf_pc <= RESET_ADDRESS;
1715 113 dgisselq
                else if ((w_switch_to_interrupt)||((~gie)&&(w_clear_icache)))
1716 21 dgisselq
                        pf_pc <= ipc;
1717 113 dgisselq
                else if ((w_release_from_interrupt)||((gie)&&(w_clear_icache)))
1718 21 dgisselq
                        pf_pc <= upc;
1719
                else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc))
1720 73 dgisselq
                        pf_pc <= wr_spreg_vl[(AW-1):0];
1721 21 dgisselq
`ifdef  OPT_PIPELINED
1722 26 dgisselq
                else if ((dcd_early_branch)&&(~clear_pipeline))
1723 21 dgisselq
                        pf_pc <= dcd_branch_pc + 1;
1724
                else if ((new_pc)||((~dcd_stalled)&&(pf_valid)))
1725
                        pf_pc <= pf_pc + {{(AW-1){1'b0}},1'b1};
1726
`else
1727 73 dgisselq
                else if ((alu_gie==gie)&&(
1728
                                ((alu_pc_valid)&&(~clear_pipeline))
1729
                                ||(mem_pc_valid)))
1730 21 dgisselq
                        pf_pc <= alu_pc;
1731
`endif
1732
 
1733
        initial new_pc = 1'b1;
1734
        always @(posedge i_clk)
1735
                if ((i_rst)||(i_clear_pf_cache))
1736
                        new_pc <= 1'b1;
1737
                else if (w_switch_to_interrupt)
1738
                        new_pc <= 1'b1;
1739
                else if (w_release_from_interrupt)
1740
                        new_pc <= 1'b1;
1741
                else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc))
1742
                        new_pc <= 1'b1;
1743
                else
1744
                        new_pc <= 1'b0;
1745
 
1746 113 dgisselq
`ifdef  OPT_PIPELINED
1747
        reg     r_clear_icache;
1748
        initial r_clear_icache = 1'b1;
1749
        always @(posedge i_clk)
1750
                if ((i_rst)||(i_clear_pf_cache))
1751
                        r_clear_icache <= 1'b1;
1752
                else if ((wr_reg_ce)&&(wr_write_scc))
1753
                        r_clear_icache <=  wr_spreg_vl[`CPU_CLRCACHE_BIT];
1754
                else
1755
                        r_clear_icache <= 1'b0;
1756
        assign  w_clear_icache = r_clear_icache;
1757
`else
1758
        assign  w_clear_icache = 1'b0;
1759
`endif
1760
 
1761 21 dgisselq
        //
1762
        // The debug interface
1763
        generate
1764
        if (AW<32)
1765
        begin
1766
                always @(posedge i_clk)
1767
                begin
1768
                        o_dbg_reg <= regset[i_dbg_reg];
1769
                        if (i_dbg_reg[3:0] == `CPU_PC_REG)
1770
                                o_dbg_reg <= {{(32-AW){1'b0}},(i_dbg_reg[4])?upc:ipc};
1771
                        else if (i_dbg_reg[3:0] == `CPU_CC_REG)
1772
                        begin
1773 113 dgisselq
                                o_dbg_reg[14:0] <= (i_dbg_reg[4])?w_uflags:w_iflags;
1774 117 dgisselq
                                o_dbg_reg[15] <= 1'b0;
1775 113 dgisselq
                                o_dbg_reg[31:23] <= w_cpu_info;
1776 21 dgisselq
                                o_dbg_reg[`CPU_GIE_BIT] <= gie;
1777
                        end
1778
                end
1779
        end else begin
1780
                always @(posedge i_clk)
1781
                begin
1782
                        o_dbg_reg <= regset[i_dbg_reg];
1783
                        if (i_dbg_reg[3:0] == `CPU_PC_REG)
1784
                                o_dbg_reg <= (i_dbg_reg[4])?upc:ipc;
1785
                        else if (i_dbg_reg[3:0] == `CPU_CC_REG)
1786
                        begin
1787 113 dgisselq
                                o_dbg_reg[14:0] <= (i_dbg_reg[4])?w_uflags:w_iflags;
1788 117 dgisselq
                                o_dbg_reg[15] <= 1'b0;
1789 113 dgisselq
                                o_dbg_reg[31:23] <= w_cpu_info;
1790 21 dgisselq
                                o_dbg_reg[`CPU_GIE_BIT] <= gie;
1791
                        end
1792
                end
1793
        end endgenerate
1794
 
1795
        always @(posedge i_clk)
1796
                o_dbg_cc <= { o_break, bus_err, gie, sleep };
1797
 
1798 117 dgisselq
`ifdef  OPT_PIPELINED
1799 21 dgisselq
        always @(posedge i_clk)
1800 73 dgisselq
                r_halted <= (i_halt)&&(
1801 113 dgisselq
                        // To be halted, any long lasting instruction must
1802
                        // be completed.
1803
                        (~pf_cyc)&&(~mem_busy)&&(~alu_busy)
1804
                                &&(~div_busy)&&(~fpu_busy)
1805
                        // Operations must either be valid, or illegal
1806
                        &&((opvalid)||(i_rst)||(dcd_illegal))
1807
                        // Decode stage must be either valid, in reset, or ill
1808
                        &&((dcdvalid)||(i_rst)||(pf_illegal)));
1809 117 dgisselq
`else
1810
        always @(posedge i_clk)
1811
                r_halted <= (i_halt)&&((opvalid)||(i_rst));
1812
`endif
1813 113 dgisselq
        assign  o_dbg_stall = ~r_halted;
1814 21 dgisselq
 
1815
        //
1816
        //
1817
        // Produce accounting outputs: Account for any CPU stalls, so we can
1818
        // later evaluate how well we are doing.
1819
        //
1820
        //
1821
        assign  o_op_stall = (master_ce)&&(op_stall);
1822
        assign  o_pf_stall = (master_ce)&&(~pf_valid);
1823
        assign  o_i_count  = (alu_pc_valid)&&(~clear_pipeline);
1824
 
1825
`ifdef  DEBUG_SCOPE
1826 113 dgisselq
        reg     [31:0]   r_stack;
1827 21 dgisselq
        always @(posedge i_clk)
1828 113 dgisselq
                if ((wr_reg_ce)&&(wr_reg_id == 5'h0d))
1829
                        r_stack <= wr_gpreg_vl;
1830
        reg     r_stack_pre, r_stack_post;
1831
        always @(posedge i_clk)
1832
                r_stack_pre  <= (r_stack == 32'h03fff);
1833
        always @(posedge i_clk)
1834
                r_stack_post <= (r_stack == 32'h03eeb);
1835
 
1836
        always @(posedge i_clk)
1837 21 dgisselq
                o_debug <= {
1838 98 dgisselq
                /*
1839 52 dgisselq
                        o_break, i_wb_err, pf_pc[1:0],
1840 51 dgisselq
                        flags,
1841 98 dgisselq
                        pf_valid, dcdvalid, opvalid, alu_valid, mem_valid,
1842 21 dgisselq
                        op_ce, alu_ce, mem_ce,
1843
                        //
1844 98 dgisselq
                        master_ce, opvalid_alu, opvalid_mem,
1845 21 dgisselq
                        //
1846 98 dgisselq
                        alu_stall, mem_busy, op_pipe, mem_pipe_stalled,
1847 21 dgisselq
                        mem_we,
1848
                        // ((opvalid_alu)&&(alu_stall))
1849
                        // ||((opvalid_mem)&&(~op_pipe)&&(mem_busy))
1850
                        // ||((opvalid_mem)&&( op_pipe)&&(mem_pipe_stalled)));
1851
                        // opA[23:20], opA[3:0],
1852 98 dgisselq
                        gie, sleep, wr_reg_ce, wr_gpreg_vl[4:0]
1853
                */
1854 21 dgisselq
                /*
1855
                        i_rst, master_ce, (new_pc),
1856
                        ((dcd_early_branch)&&(dcdvalid)),
1857
                        pf_valid, pf_illegal,
1858
                        op_ce, dcd_ce, dcdvalid, dcd_stalled,
1859
                        pf_cyc, pf_stb, pf_we, pf_ack, pf_stall, pf_err,
1860
                        pf_pc[7:0], pf_addr[7:0]
1861
                */
1862 98 dgisselq
 
1863 113 dgisselq
                        (i_wb_err)||(r_stack_post), (gie)||(r_stack_pre), (alu_illegal)||(r_stack_post),
1864 51 dgisselq
                              (new_pc)||((dcd_early_branch)&&(~clear_pipeline)),
1865
                        mem_busy,
1866
                                (mem_busy)?{ (o_wb_gbl_stb|o_wb_lcl_stb), o_wb_we,
1867
                                        o_wb_addr[8:0] }
1868
                                        : { instruction[31:21] },
1869
                        pf_valid, (pf_valid) ? alu_pc[14:0]
1870
                                :{ pf_cyc, pf_stb, pf_pc[12:0] }
1871 98 dgisselq
 
1872 52 dgisselq
                /*
1873 51 dgisselq
                        i_wb_err, gie, new_pc, dcd_early_branch,        // 4
1874
                        pf_valid, pf_cyc, pf_stb, instruction_pc[0],    // 4
1875
                        instruction[30:27],                             // 4
1876
                        dcd_gie, mem_busy, o_wb_gbl_cyc, o_wb_gbl_stb,  // 4
1877
                        dcdvalid,
1878
                        ((dcd_early_branch)&&(~clear_pipeline))         // 15
1879
                                        ? dcd_branch_pc[14:0]:pf_pc[14:0]
1880 52 dgisselq
                */
1881 21 dgisselq
                        };
1882
`endif
1883 113 dgisselq
 
1884
/*
1885
always  @(posedge i_clk)
1886
        o_debug <= {
1887
                // External control interaction (4b)
1888
                i_halt, i_rst, i_clear_cache, o_break,
1889
                // Bus interaction (8b)
1890
                pf_cyc,(o_wb_gbl_cyc|o_wb_lcl_cyc), o_wb_gbl_stb, o_wb_lcl_stb,
1891
                        o_wb_we, i_wb_ack, i_wb_stall, i_wb_err,
1892
                // PC control (4b)
1893
                gie, new_pc, dcd_early_branch, 1'b0,
1894
                // Our list of pipeline stage values (8b)
1895
                pf_valid, pf_illegal, dcdvalid, opvalid, alu_valid, mem_valid,
1896
                        alu_pc_valid, mem_pc_valid,
1897
                // Our list of circuit enables ... (8b)
1898
                (new_pc)||((dcd_early_branch)&&(~clear_pipeline)),
1899
                        dcd_ce, op_ce, alu_ce, mem_ce, wr_reg_ce, wr_flags_ce,
1900
                        1'b0,
1901
                // Useful PC values (64b)
1902
                ((dcd_early_branch)&&(~clear_pipeline))
1903
                                        ? dcd_branch_pc[15:0]:pf_pc[15:0],
1904
                (gie)?upc[15:0]:ipc[15:0], instruction_pc[15:0], instruction[31:16] };
1905
*/
1906 21 dgisselq
 
1907
endmodule

powered by: WebSVN 2.1.0

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