📄 me.v
字号:
`timescale 1ns/10ps`include "pardef"/*****************************************************************************$RCSfile: me.v,v $$Revision: 1.5 $$Author: kohlere $$Date: 2000/04/17 18:12:50 $$State: Exp $$Source: /home/lefurgy/tmp/ISC-repository/isc/hardware/ARM10/behavioral/pipelined/fpga2/me.v,v $Description: This is the Memory Stage. It controls all accesses to and from memory and passes on the results to the WB stage.*****************************************************************************/module me(nGCLK, nWAIT, nRESET, BIGEND, me_enbar, store_addr, ex_result, inst_type_ex, Rd_ex, Rn_ex, write_Rd_ex, second_ex, write_Rn_ex, unsigned_byte_ex, signed_byte_ex, base_ex, unsigned_hw_ex, signed_hw_ex, stop_ex, stop_me, data_bus, mem_rd_wr, me_result, Rd_me, Rn_me, write_Rd_me, mem_ena, addr_me, write_Rn_me, base_me, double_ex, double_me, byte, halfword, load_pc, mcr_ex, reset_write_Rd_me, reset_write_Rn_me, store_ex, cop_mem_ld, cop_mem_st);/*------------------------------------------------------------------------ Ports------------------------------------------------------------------------*/input [31:0] store_addr; //Address from Ex Stageinput [31:0] ex_result; //Result from Ex Stageinput [31:0] base_ex; //Base Addressinput [3:0] inst_type_ex; //Instruction Codeinput [4:0] Rd_ex; //1st Destination Reginput [4:0] Rn_ex; //2nd Destination Reginput nGCLK; //Clock Signalinput nRESET; //Reset Signalinput nWAIT; //Clock Enableinput BIGEND; //Big Endian?input me_enbar; //Memory Stage Enableinput store_ex; //Inst is a Storeinput write_Rd_ex; //Conditions Failed?input second_ex; //Second Cycle of Instructioninput write_Rn_ex; //Write Back Signalinput unsigned_byte_ex; //Inst uses Unsigned Bytesinput signed_byte_ex; //Inst uses Signed Bytesinput unsigned_hw_ex; //Inst uses Unsigned Halfwordsinput signed_hw_ex; //Inst uses Signed Halfwordsinput double_ex; //64-Bit Memory Accessinput mcr_ex; //MCR Inst comin Ininput reset_write_Rd_me; //Reset the write Signalinput reset_write_Rn_me; //Reset the write Signalinput cop_mem_ld; //Coprocessor Loadinginput cop_mem_st; //Coprocessor Storinginput stop_ex; //Stop Executioninout [63:0] data_bus; //Data Bus To Memoryoutput [31:0] me_result; //Data to pass to WB Stageoutput [31:0] addr_me; //Output for Storing Baseoutput [31:0] base_me; //Base Value to Write Backoutput [4:0] Rd_me; //1st Destination Regoutput [4:0] Rn_me; //2nd Destination Regoutput write_Rd_me; //Latched Condition Failed?output mem_rd_wr; //Memory Read/Writeoutput mem_ena; //Memory Access Requiredoutput write_Rn_me; //Write Back?output double_me; //64-Bit Memory Accessoutput byte; //8-Bit Memory Accessoutput halfword; //16-Bit Memory Accessoutput load_pc; //Load to the PCoutput stop_me; //Stop Execution/*------------------------------------------------------------------------ Variable Declarations------------------------------------------------------------------------*///Declare Output of Multiplexers and Regisetersreg [31:0] data; //Latched ex_resultreg [31:0] addr_me; //Latched store_addrreg [31:0] me_result; //Muxed Resultreg [31:0] base_me; //Output Base Valuereg [31:0] base; //Base Valuereg [3:0] inst_type_me; //Latched Inst Codereg [4:0] Rd_me; //Latched 1st Dest Regreg [4:0] Rn_me; //Latched 2nd Dest Regreg store_me; //Store the Datareg write_Rd_me; //Latched Cond Failedreg second_me; //Latched 2nd Cycle of Instreg write_Rn_me; //Latched Write-Backreg unsigned_byte_me; //Unsigned Bytes Usedreg signed_byte_me; //Signed Bytes Usedreg unsigned_hw_me; //Unsigned Halfwords Usedreg signed_hw_me; //Signed Halfwords Usedreg double_me; //64-Bit Memory Accessreg mcr_me; //MCR in herereg cop_ld_me; //Cop Loadingreg cop_st_me; //Cop Storingreg stop_me; //Stop Execution//Declare Outputs of Combinational Logic & Tri-Stated Buseswire [63:0] data_bus; //Memory Data Buswire [63:0] loaded_data; //Aligned Load Datawire [1:0] lowbits; //Low Address Bitswire load; //Instruction is a LDRW/LDRHwire swap; //Instruction is a SWAP/Bwire ldm; //Instruction is a LDMwire mem_rd_wr; //Read = 1, Write = 0wire mem_ena; //Memory Enablewire byte; //Byte Accesswire halfword; //Halfword Accesswire cop; //Coprocessor Instrucitonreg load_pc; //Load to the PCwire data_out_ena; //Drive the Data Bus?/*------------------------------------------------------------------------ Component Instantiations------------------------------------------------------------------------*/// instantiate alignalign xalign (.data({base,data}), .data_bus(data_bus), .addr_low(lowbits), .loaded_data(loaded_data), .BIGEND(BIGEND), .out_ena(data_out_ena), .unsigned_byte(unsigned_byte_me), .unsigned_hw(unsigned_hw_me), .signed_byte(signed_byte_me), .signed_hw(signed_hw_me)); /*------------------------------------------------------------------------ Basic Assignments (Combinational Logic)------------------------------------------------------------------------*/assign byte = signed_byte_me || unsigned_byte_me;assign halfword = signed_hw_me || unsigned_hw_me;assign cop = (inst_type_me == `COP);assign data_out_ena = store_me | mcr_me;assign lowbits = (load | store_me) ? addr_me[1:0] : 2'h0;//Load should be high whenever there is a load. If the instruction//is not executed, then the loaded value will not be written. To reduce//memory accesses, this logic could be changed, but for now is fine.assign #1 load = ((inst_type_me == `LDRW)|| (inst_type_me == `LDRH)|| (ldm) || (swap && !second_me)) ? 1'b1 : 1'b0;//Recognize a load to the PCalways @(Rd_me or write_Rd_me or Rn_me or double_me or write_Rn_me or load) begin load_pc <= load & (((Rd_me == 5'h0F) & write_Rd_me) | ((Rn_me == 5'h0F) & double_me & write_Rn_me)); end//Detect swap instructions.assign #1 swap = (inst_type_me == `SWAP);//Detect LDM instructionsassign #1 ldm = (inst_type_me == `LDM);//mem_rd_wr = 0 for stores.assign mem_rd_wr = !(store_me | cop_st_me);//Enable a memory access for any load or store.assign mem_ena = (load | store_me | cop_ld_me | cop_st_me);/*------------------------------------------------------------------------ Combinational Always Block (Multiplexers)------------------------------------------------------------------------*/ //Set up the me_result//For Load instructions, the data will be on the data bus. //For all other instructions, the data comes from the EX stage and//will be in the data register.always @(load or loaded_data or data or cop) begin if (load | cop) me_result = loaded_data[31:0]; else me_result = data; end//Set up the base_me to the WB stagealways @(ldm or double_me or base or loaded_data) begin if (ldm && double_me) base_me = loaded_data[63:32]; else base_me = base; end/*------------------------------------------------------------------------ Sequential Always Block (Registers)------------------------------------------------------------------------*///This block controls the data latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) data <= 32'h00000000; else if (nWAIT) begin if (!me_enbar) data <= #1 ex_result; end end//This block controls the addr_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) addr_me <= 32'h00000000; else if (nWAIT) begin if (!me_enbar) addr_me <= #1 store_addr; end end//This block controls the base_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) base <= 32'h00000000; else if (nWAIT) begin if (!me_enbar) base <= #1 base_ex; end end//This block controls the inst_type_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) inst_type_me <= 4'h0; else if (nWAIT) begin if (!me_enbar) inst_type_me <= #2 inst_type_ex; end end//This block controls the Rd_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) Rd_me <= 5'h00; else if (nWAIT) begin if (!me_enbar) Rd_me <= #2 Rd_ex; end end//This block controls the Rn_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) Rn_me <= 5'h00; else if (nWAIT) begin if (!me_enbar) Rn_me <= #2 Rn_ex; end end//This block controls the write_Rd_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) write_Rd_me <= 1'h0; else if (nWAIT) begin if (!me_enbar | reset_write_Rd_me) write_Rd_me <= #2 write_Rd_ex & !reset_write_Rd_me; end end//This block controls the second_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) second_me <= 1'h0; else if (nWAIT) begin if (!me_enbar) second_me <= #2 second_ex; end end//This block controls the w_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) write_Rn_me <= 1'h0; else if (nWAIT) begin if (!me_enbar | reset_write_Rn_me) write_Rn_me <= #2 write_Rn_ex & !reset_write_Rn_me; end end//This block controls the unsigned_byte_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) unsigned_byte_me <= 1'h0; else if (nWAIT) begin if (!me_enbar) unsigned_byte_me <= #2 unsigned_byte_ex; end end//This block controls the signed_byte_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) signed_byte_me <= 1'h0; else if (nWAIT) begin if (!me_enbar) signed_byte_me <= #2 signed_byte_ex; end end//This block controls the unsigned_hw_me latch//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (!nRESET) unsigned_hw_me <= 1'h0; else if (nWAIT) begin if (!me_enbar) unsigned_hw_me <= #2 unsigned_hw_ex; end end//This block controls the signed_hw_me latchalways @(posedge nGCLK or negedge nRESET) begin if (!nRESET) signed_hw_me <= 1'h0; else if (nWAIT) begin if (!me_enbar) signed_hw_me <= #2 signed_hw_ex; end end//This block controls the double_me latchalways @(posedge nGCLK or negedge nRESET) begin if (!nRESET) double_me <= 1'h0; else if (nWAIT) begin if (!me_enbar) double_me <= #2 double_ex; end end//This block latches the store_ex signal//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (~nRESET) store_me <= 1'b0; else if (nWAIT) begin if (!me_enbar) store_me <= #2 store_ex; end end//This block latches the mcr_ex signal//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (~nRESET) mcr_me <= 1'b0; else if (nWAIT) begin if (!me_enbar) mcr_me <= mcr_ex; end end//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (~nRESET) cop_ld_me <= 1'b0; else if (nWAIT) begin if (!me_enbar) cop_ld_me <= cop_mem_ld; end end//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (~nRESET) cop_st_me <= 1'b0; else if (nWAIT) begin if (!me_enbar) cop_st_me <= cop_mem_st; end end//synopsys async_set_reset "nRESET"always @(posedge nGCLK or negedge nRESET) begin if (~nRESET) stop_me <= 1'b0; else if (nWAIT) begin if (~me_enbar) stop_me <= stop_ex; end end/*======================================================================*/endmodule //me/*======================================================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -