2021-01-15 04:37:51 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// datapath.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu 9 January 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
2021-01-28 20:18:23 +00:00
|
|
|
// Purpose: Wally Integer Datapath
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
|
|
|
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
|
|
|
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
|
|
// is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
|
|
// OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
2021-01-23 15:48:12 +00:00
|
|
|
`include "wally-config.vh"
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-01-25 20:57:36 +00:00
|
|
|
module datapath (
|
2021-01-15 04:37:51 +00:00
|
|
|
input logic clk, reset,
|
|
|
|
// Decode stage signals
|
2021-01-28 20:18:23 +00:00
|
|
|
input logic [2:0] ImmSrcD,
|
|
|
|
input logic [31:0] InstrD,
|
2021-01-15 04:37:51 +00:00
|
|
|
// Execute stage signals
|
2021-02-08 04:21:55 +00:00
|
|
|
input logic StallE, FlushE,
|
2021-01-28 20:18:23 +00:00
|
|
|
input logic [1:0] ForwardAE, ForwardBE,
|
|
|
|
input logic [4:0] ALUControlE,
|
|
|
|
input logic ALUSrcAE, ALUSrcBE,
|
|
|
|
input logic TargetSrcE,
|
2021-02-27 02:12:27 +00:00
|
|
|
input logic JumpE,
|
2021-01-28 03:49:47 +00:00
|
|
|
input logic [`XLEN-1:0] PCE,
|
2021-02-27 02:12:27 +00:00
|
|
|
input logic [`XLEN-1:0] PCLinkE,
|
2021-01-28 20:18:23 +00:00
|
|
|
output logic [2:0] FlagsE,
|
2021-01-28 03:49:47 +00:00
|
|
|
output logic [`XLEN-1:0] PCTargetE,
|
2021-02-16 03:27:35 +00:00
|
|
|
output logic [`XLEN-1:0] SrcAE, SrcBE,
|
2021-01-15 04:37:51 +00:00
|
|
|
// Memory stage signals
|
2021-02-08 04:21:55 +00:00
|
|
|
input logic StallM, FlushM,
|
2021-05-24 18:44:30 +00:00
|
|
|
input logic [`XLEN-1:0] FWriteDataM,
|
2021-06-24 15:20:21 +00:00
|
|
|
input logic SquashSCM,
|
|
|
|
input logic [2:0] ResultSrcM,
|
|
|
|
input logic [`XLEN-1:0] CSRReadValM, ReadDataM, MulDivResultM,
|
2021-01-28 20:18:23 +00:00
|
|
|
output logic [`XLEN-1:0] SrcAM,
|
2021-02-02 20:09:24 +00:00
|
|
|
output logic [`XLEN-1:0] WriteDataM, MemAdrM,
|
2021-01-15 04:37:51 +00:00
|
|
|
// Writeback stage signals
|
2021-02-08 04:21:55 +00:00
|
|
|
input logic StallW, FlushW,
|
2021-05-21 02:17:59 +00:00
|
|
|
input logic FWriteIntW,
|
|
|
|
input logic [`XLEN-1:0] FPUResultW,
|
2021-01-28 20:18:23 +00:00
|
|
|
input logic RegWriteW,
|
2021-03-01 05:09:45 +00:00
|
|
|
input logic SquashSCW,
|
2021-02-16 03:27:35 +00:00
|
|
|
input logic [2:0] ResultSrcW,
|
2021-03-01 05:09:45 +00:00
|
|
|
input logic [`XLEN-1:0] CSRReadValW, ReadDataW, MulDivResultW,
|
2021-01-15 04:37:51 +00:00
|
|
|
// Hazard Unit signals
|
2021-01-28 20:18:23 +00:00
|
|
|
output logic [4:0] Rs1D, Rs2D, Rs1E, Rs2E,
|
2021-02-02 18:42:23 +00:00
|
|
|
output logic [4:0] RdE, RdM, RdW
|
2021-01-28 20:18:23 +00:00
|
|
|
);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
// Fetch stage signals
|
|
|
|
// Decode stage signals
|
2021-01-23 15:48:12 +00:00
|
|
|
logic [`XLEN-1:0] RD1D, RD2D;
|
|
|
|
logic [`XLEN-1:0] ExtImmD;
|
2021-01-15 04:37:51 +00:00
|
|
|
logic [4:0] RdD;
|
|
|
|
// Execute stage signals
|
2021-01-23 15:48:12 +00:00
|
|
|
logic [`XLEN-1:0] RD1E, RD2E;
|
2021-01-28 03:49:47 +00:00
|
|
|
logic [`XLEN-1:0] ExtImmE;
|
2021-03-04 19:35:46 +00:00
|
|
|
|
|
|
|
logic [`XLEN-1:0] PreSrcAE, SrcAE2, SrcBE2;
|
|
|
|
|
2021-01-23 15:48:12 +00:00
|
|
|
logic [`XLEN-1:0] ALUResultE;
|
|
|
|
logic [`XLEN-1:0] WriteDataE;
|
|
|
|
logic [`XLEN-1:0] TargetBaseE;
|
2021-01-15 04:37:51 +00:00
|
|
|
// Memory stage signals
|
2021-06-24 15:20:21 +00:00
|
|
|
logic [`XLEN-1:0] SCResultM;
|
2021-01-28 06:03:12 +00:00
|
|
|
logic [`XLEN-1:0] ALUResultM;
|
2021-06-24 15:20:21 +00:00
|
|
|
logic [`XLEN-1:0] ResultM;
|
2021-01-15 04:37:51 +00:00
|
|
|
// Writeback stage signals
|
2021-03-01 05:09:45 +00:00
|
|
|
logic [`XLEN-1:0] SCResultW;
|
2021-01-23 15:48:12 +00:00
|
|
|
logic [`XLEN-1:0] ALUResultW;
|
2021-05-21 02:17:59 +00:00
|
|
|
logic [`XLEN-1:0] WriteDataW;
|
2021-01-23 15:48:12 +00:00
|
|
|
logic [`XLEN-1:0] ResultW;
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-02-03 00:44:37 +00:00
|
|
|
// Decode stage
|
2021-01-28 03:49:47 +00:00
|
|
|
assign Rs1D = InstrD[19:15];
|
|
|
|
assign Rs2D = InstrD[24:20];
|
|
|
|
assign RdD = InstrD[11:7];
|
2021-05-21 02:17:59 +00:00
|
|
|
|
|
|
|
//Mux for writting floating point
|
|
|
|
mux2 #(`XLEN) writedatamux(ResultW, FPUResultW, FWriteIntW, WriteDataW);
|
|
|
|
|
|
|
|
regfile regf(clk, reset, {RegWriteW | FWriteIntW}, Rs1D, Rs2D, RdW, WriteDataW, RD1D, RD2D);
|
2021-01-28 03:49:47 +00:00
|
|
|
extend ext(.InstrD(InstrD[31:7]), .*);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
// Execute stage pipeline register and logic
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenrc #(`XLEN) RD1EReg(clk, reset, FlushE, ~StallE, RD1D, RD1E);
|
|
|
|
flopenrc #(`XLEN) RD2EReg(clk, reset, FlushE, ~StallE, RD2D, RD2E);
|
|
|
|
flopenrc #(`XLEN) ExtImmEReg(clk, reset, FlushE, ~StallE, ExtImmD, ExtImmE);
|
|
|
|
flopenrc #(5) Rs1EReg(clk, reset, FlushE, ~StallE, Rs1D, Rs1E);
|
|
|
|
flopenrc #(5) Rs2EReg(clk, reset, FlushE, ~StallE, Rs2D, Rs2E);
|
|
|
|
flopenrc #(5) RdEReg(clk, reset, FlushE, ~StallE, RdD, RdE);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-06-24 15:20:21 +00:00
|
|
|
mux4 #(`XLEN) faemux(RD1E, WriteDataW, ResultM, FWriteDataM, ForwardAE, PreSrcAE);
|
|
|
|
mux4 #(`XLEN) fbemux(RD2E, WriteDataW, ResultM, FWriteDataM, ForwardBE, WriteDataE);
|
2021-01-23 15:48:12 +00:00
|
|
|
mux2 #(`XLEN) srcamux(PreSrcAE, PCE, ALUSrcAE, SrcAE);
|
2021-02-27 02:12:27 +00:00
|
|
|
mux2 #(`XLEN) srcamux2(SrcAE, PCLinkE, JumpE, SrcAE2);
|
2021-01-23 15:48:12 +00:00
|
|
|
mux2 #(`XLEN) srcbmux(WriteDataE, ExtImmE, ALUSrcBE, SrcBE);
|
2021-02-27 02:12:27 +00:00
|
|
|
mux2 #(`XLEN) srcbmux2(SrcBE, {`XLEN{1'b0}}, JumpE, SrcBE2); // *** May be able to remove this mux.
|
|
|
|
alu #(`XLEN) alu(SrcAE2, SrcBE2, ALUControlE, ALUResultE, FlagsE);
|
2021-01-23 15:48:12 +00:00
|
|
|
mux2 #(`XLEN) targetsrcmux(PCE, SrcAE, TargetSrcE, TargetBaseE);
|
2021-01-28 03:49:47 +00:00
|
|
|
assign PCTargetE = ExtImmE + TargetBaseE;
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
// Memory stage pipeline register
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenrc #(`XLEN) SrcAMReg(clk, reset, FlushM, ~StallM, SrcAE, SrcAM);
|
|
|
|
flopenrc #(`XLEN) ALUResultMReg(clk, reset, FlushM, ~StallM, ALUResultE, ALUResultM);
|
2021-02-02 20:09:24 +00:00
|
|
|
assign MemAdrM = ALUResultM;
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenrc #(`XLEN) WriteDataMReg(clk, reset, FlushM, ~StallM, WriteDataE, WriteDataM);
|
|
|
|
flopenrc #(5) RdMEg(clk, reset, FlushM, ~StallM, RdE, RdM);
|
2021-06-24 15:20:21 +00:00
|
|
|
mux5 #(`XLEN) resultmuxM(ALUResultM, ReadDataM, CSRReadValM, MulDivResultM, SCResultM, ResultSrcM, ResultM);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
// Writeback stage pipeline register and logic
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenrc #(`XLEN) ALUResultWReg(clk, reset, FlushW, ~StallW, ALUResultM, ALUResultW);
|
|
|
|
flopenrc #(5) RdWEg(clk, reset, FlushW, ~StallW, RdM, RdW);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-03-01 05:09:45 +00:00
|
|
|
// handle Store Conditional result if atomic extension supported
|
|
|
|
generate
|
2021-06-24 15:20:21 +00:00
|
|
|
if (`A_SUPPORTED) begin
|
|
|
|
assign SCResultM = SquashSCM ? {{(`XLEN-1){1'b0}}, 1'b1} : {{(`XLEN-1){1'b0}}, 1'b0};
|
2021-03-01 05:09:45 +00:00
|
|
|
assign SCResultW = SquashSCW ? {{(`XLEN-1){1'b0}}, 1'b1} : {{(`XLEN-1){1'b0}}, 1'b0};
|
2021-06-24 15:20:21 +00:00
|
|
|
end else begin
|
|
|
|
assign SCResultM = 0;
|
2021-03-01 05:09:45 +00:00
|
|
|
assign SCResultW = 0;
|
2021-06-24 15:20:21 +00:00
|
|
|
end
|
2021-03-01 05:09:45 +00:00
|
|
|
endgenerate
|
|
|
|
|
2021-06-24 15:20:21 +00:00
|
|
|
mux5 #(`XLEN) resultmuxW(ALUResultW, ReadDataW, CSRReadValW, MulDivResultW, SCResultW, ResultSrcW, ResultW);
|
2021-03-04 19:35:46 +00:00
|
|
|
/* -----\/----- EXCLUDED -----\/-----
|
2021-02-27 02:12:27 +00:00
|
|
|
// This mux4:1 no longer needs to include PCLinkW. This is set correctly in the execution stage.
|
|
|
|
// *** need to look at how the decoder is coded to fix.
|
2021-02-02 18:02:31 +00:00
|
|
|
mux4 #(`XLEN) resultmux(ALUResultW, ReadDataW, PCLinkW, CSRReadValW, ResultSrcW, ResultW);
|
2021-03-04 19:35:46 +00:00
|
|
|
>>>>>>> bp
|
|
|
|
-----/\----- EXCLUDED -----/\----- */
|
|
|
|
|
2021-01-15 04:37:51 +00:00
|
|
|
endmodule
|