📄 interlock.v
字号:
`timescale 1ns/10ps`include "pardef"/*****************************************************************************$RCSfile: interlock.v,v $$Revision: 1.5 $$Author: kohlere $$Date: 2000/04/13 21:55:18 $$State: Exp $$Source: /home/lefurgy/tmp/ISC-repository/isc/hardware/ARM10/behavioral/pipelined/fpga2/interlock.v,v $Description: This contains the control logic which interlocks the pipeline for these reasons: 1) Mispredicted Branch 2) Database result -> PC 3) Load destination -> PC 4) Swap Instruction 5) Load-Use Register 6) 3 Registers reads required in Instruction -7) LDM/STM instructions*****************************************************************************/module interlock(nGCLK, nRESET, nWAIT, need_2cycles, second, load_use, ldm, stm, finished, if_enbar, id_enbar, ex_enbar, pc_mod_ex, me_enbar, wb_enbar, mispredicted, fill_state, cop_id, CHSD, CHSE, cop_absent, Rn_ex, Rd_ex, write_Pc_Rn_ex, write_Pc_Rd_ex, reset_write_Rn_me, reset_write_Rd_me, hold_next_ex, load_pc, dabort, prediction_stall, misp_rec, load_pc_ex, ptaken_ex);/*------------------------------------------------------------------------ Ports------------------------------------------------------------------------*/input [4:0] Rd_ex; //Destination Reg in EX Stageinput [4:0] Rn_ex; //Base Reg in EX stageinput [1:0] CHSD; //Coprocessor Hndshk from Decodeinput [1:0] CHSE; //Coprocessor Hndshk from Executeinput nGCLK; //Clock Signalinput nWAIT; //Clock Enableinput nRESET; //Reset Signalinput dabort; //Data Abort Takeninput need_2cycles; //3 Reg Reads Requiredinput second; //2nd Cycle or Reg Reads indicatorinput load_use; //Load-Use Interlock Necessaryinput ldm; //Inst is LDM in ID stageinput stm; //Inst is STM in ID stageinput finished; //Inst (LDM/STM) is finishedinput mispredicted; //Mispredicted a branchinput misp_rec; //Mispredicted but recoverableinput cop_id; //Coprocessor Inst in ID stageinput pc_mod_ex; //One of Last two inst mod pcinput write_Pc_Rd_ex; //Write to PC by Rd possibleinput write_Pc_Rn_ex; //Write to PC by Rn possibleinput hold_next_ex; //Hold Next Instruction for Exinput load_pc_ex; //Load PC Inst in EX Stageinput load_pc; //Load PC from Memoryinput prediction_stall; //Prediction Bubbleoutput [2:0] fill_state; //State of Machineoutput cop_absent; //No Coprocessor Presentoutput if_enbar; //Enable to IF stageoutput id_enbar; //Enable to ID stageoutput ex_enbar; //Enable to EX stageoutput me_enbar; //Enable to ME stageoutput wb_enbar; //Enable to WB stageoutput reset_write_Rn_me; //Reset write signaloutput reset_write_Rd_me; //Reset write signaloutput ptaken_ex; //Pred bubble into->Ex Stage/*------------------------------------------------------------------------ Variable Declarations------------------------------------------------------------------------*///FSM Declarationsreg [2:0] fill_state; //State of Machine wrt pipelinereg [2:0] next_fill_state; //Next State of Mach. wrt pipelinereg [1:0] cop_cyc_count; //Coprocessor Cycle Countreg [1:0] next_cyc_count; //Next Coprocessor Cycle Count//Outputs from Multiplexersreg if_enbar; //Enable to IF stage (active low)reg id_enbar; //Enable to ID stage (active low)reg ex_enbar; //Enable to EX stage (active low)reg me_enbar; //Enable to ME stage (active low)reg wb_enbar; //Enable to WB stage (active low)reg latched_reset; //Catch the Reset Signalreg delayed_reset; //Delayed Reset Signal//Outputs from Latches and Registersreg [1:0] latched_chs; //Latched Coprocessor Hndshkreg dabort_1; //One Behind DABORTreg start_count; //Start the Coprocessor Counterreg load_pc_latch; //Latch the load_pc_signalreg ptaken_ex; //Stall The EX stagereg third_plus; //ID in 3+ Cycle //Outputs from Combinational Logicwire pc_modified; //An Instruction Modified PCreg nRefill; //Signals Refill pipelinewire cop_stall; //Coprocessor Signals Stall Pipewire cop_absent; //Take Undefined Inst Trapwire cop_go; //Multiple Cycles Requiredwire cop_count; //Enable the Counterwire cop_not_first; //Coprocessor Inst Not in 1st Cycwire reset_write_Rd_me; //Reset Write Signalwire reset_write_Rn_me; //Reset Write Signalwire no_interlock_if; //Refillingwire no_interlock_id; //Refilling/*------------------------------------------------------------------------ Basic Assignments------------------------------------------------------------------------*///This signal is one when a write is scheduled for the PC.assign pc_modified = (((write_Pc_Rn_ex) && (Rn_ex == 5'h0F)) || ((write_Pc_Rd_ex) && (Rd_ex == 5'h0F)));//assign refill = (!nRESET || pc_touched || load_pc);//Coprocessor in 2+ cycle of exectutionassign cop_not_first = (cop_cyc_count != `NO_COUNT);//Enable to the Coprocessor Cycle Counterassign cop_count = cop_id & id_enbar & !pc_mod_ex;//Coprocessor is Absent, take Undefined Instruction Trapassign cop_absent = (latched_chs == `ABSENT) && !pc_mod_ex;//Coprocessor is Working on something Elseassign cop_stall = (latched_chs == `WAIT) & !pc_mod_ex;//Coprocessor is Working on requested operationassign cop_go = (latched_chs == `GO) && !pc_mod_ex;//Reset the Write to PC Signalassign reset_write_Rd_me = ((((fill_state == `SECOND_FILL) & ~nRefill) & (Rd_ex == 5'h0F) & !load_pc_ex) | dabort | mispredicted);//Reset the Write to PC Signalassign reset_write_Rn_me = ((((fill_state == `FIRST_FILL) & ~nRefill) & (Rn_ex == 5'h0F) & !load_pc_ex) | dabort | mispredicted);//Set a signal which indicates that neither the IF nor ID //stages should be interlocked. When the pipeline is refilling,//the instructions being squashed could send phony signals.//Also, if in First Mispredict, 1st Inst should be loaded to ID next cycle//The 'no_interlock' signal indicates that these should be ignored.assign no_interlock_if = mispredicted | pc_modified | load_pc_latch | load_pc | dabort | (fill_state == `FIRST_MISPREDICT) | (fill_state == `SECOND_FILL & nRefill);assign no_interlock_id = misp_rec | (fill_state == `FIRST_MISPREDICT) | ((fill_state == `SECOND_FILL & nRefill) & ~prediction_stall) | (dabort);/*------------------------------------------------------------------------ Combinational Always Blocks (Multiplexers)------------------------------------------------------------------------*///The enable signals could/should be done with combinational logic//only, but in order for things to function properly, I need them//to be either 0 or 1, never X.//The IF stage can be stalled due to://1) 2-Cycles for RF Reads (only 2cycles)//2) Load-Use Interlock//3) LDM/STM > 1word//4) Coprocessor Not Ready/Busy//4) Multi-Cycle Multiplicationalways @(no_interlock_if or second or need_2cycles or load_use or ldm or stm or finished or cop_stall or cop_go or hold_next_ex or fill_state or ptaken_ex or third_plus) begin if (!no_interlock_if & ( (!second & !third_plus & (need_2cycles | load_use)) | ((ldm | stm) & !finished) | (cop_stall | cop_go) | (hold_next_ex & (fill_state != `FIRST_MISPREDICT)) )) if_enbar = 1'b1; else if_enbar = 1'b0; end//The ID stage can be stalled due to://1) Same as IF//2) Load to PC from Memory (1 extra delay seen here)//3) Reset assertedalways @(no_interlock_id or if_enbar or load_pc or prediction_stall or latched_reset or fill_state or mispredicted or nRefill) begin if (~no_interlock_id & ( (if_enbar) | (load_pc) | (!latched_reset) | (prediction_stall) |//Adding mispredicted because unless recoverable is set,//shouldn't be loading next instruction into ID (mispredicted) | (fill_state == `SECOND_FILL & ~nRefill) )) id_enbar <= #1 1'b1; else id_enbar <= #1 1'b0; end//The EX stage be stalled due to://1) Multi-Cycle Multiplication//2) Coprocessor Not Ready/Busy//The EX can be squashed due to://1) Mispredicted Branch Instruction//2) Pipeline is being Refilledalways @(fill_state or hold_next_ex or mispredicted or cop_stall or cop_not_first or ptaken_ex or nRefill or dabort) begin if ((fill_state == `FIRST_FILL) | (fill_state == `SECOND_FILL) | (hold_next_ex & ((fill_state != `SECOND_FILL)| (fill_state == `SECOND_FILL & ~nRefill)) & (fill_state != `FIRST_MISPREDICT)) | (mispredicted) | (ptaken_ex) | (fill_state == `FIRST_MISPREDICT) | (dabort) | (cop_stall & cop_not_first)) ex_enbar <= #1 1'b1; else ex_enbar <= #1 1'b0; end//The ME stage can be squashed due to://1) Pipeline is being refilled //2) Mispredicted Branch Instruction//3) Data Abort
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -