2021-01-15 04:37:51 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// wallypipelinedhart.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu 9 January 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: Pipelined RISC-V Processor
|
|
|
|
//
|
|
|
|
// 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-27 11:40:26 +00:00
|
|
|
/* verilator lint_on UNUSED */
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-06-24 18:05:22 +00:00
|
|
|
module wallypipelinedhart
|
|
|
|
(
|
|
|
|
input logic clk, reset,
|
|
|
|
output logic [`XLEN-1:0] PCF,
|
|
|
|
// input logic [31:0] InstrF,
|
|
|
|
// Privileged
|
|
|
|
input logic TimerIntM, ExtIntM, SwIntM,
|
|
|
|
input logic InstrAccessFaultF,
|
|
|
|
input logic DataAccessFaultM,
|
|
|
|
input logic [63:0] MTIME_CLINT, MTIMECMP_CLINT,
|
|
|
|
// Bus Interface
|
|
|
|
input logic [15:0] rd2, // bogus, delete when real multicycle fetch works
|
|
|
|
input logic [`AHBW-1:0] HRDATA,
|
|
|
|
input logic HREADY, HRESP,
|
|
|
|
output logic HCLK, HRESETn,
|
|
|
|
output logic [31:0] HADDR,
|
|
|
|
output logic [`AHBW-1:0] HWDATA,
|
|
|
|
output logic HWRITE,
|
|
|
|
output logic [2:0] HSIZE,
|
|
|
|
output logic [2:0] HBURST,
|
|
|
|
output logic [3:0] HPROT,
|
|
|
|
output logic [1:0] HTRANS,
|
|
|
|
output logic HMASTLOCK,
|
|
|
|
output logic [5:0] HSELRegions,
|
|
|
|
// Delayed signals for subword write
|
|
|
|
output logic [2:0] HADDRD,
|
|
|
|
output logic [3:0] HSIZED,
|
|
|
|
output logic HWRITED
|
|
|
|
);
|
|
|
|
|
|
|
|
// logic [1:0] ForwardAE, ForwardBE;
|
|
|
|
logic StallF, StallD, StallE, StallM, StallW;
|
|
|
|
logic FlushF, FlushD, FlushE, FlushM, FlushW;
|
|
|
|
logic RetM, TrapM, NonBusTrapM;
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-01-27 12:46:52 +00:00
|
|
|
// new signals that must connect through DP
|
2021-06-24 18:05:22 +00:00
|
|
|
logic MulDivE, W64E;
|
|
|
|
logic CSRReadM, CSRWriteM, PrivilegedM;
|
|
|
|
logic [1:0] AtomicM;
|
|
|
|
logic [`XLEN-1:0] SrcAE, SrcBE;
|
|
|
|
logic [`XLEN-1:0] SrcAM;
|
|
|
|
logic [2:0] Funct3E;
|
2021-04-04 01:28:24 +00:00
|
|
|
// logic [31:0] InstrF;
|
2021-06-24 18:05:22 +00:00
|
|
|
logic [31:0] InstrD, InstrE, InstrM, InstrW;
|
|
|
|
logic [`XLEN-1:0] PCD, PCE, PCM, PCLinkE, PCLinkW;
|
|
|
|
logic [`XLEN-1:0] PCTargetE;
|
|
|
|
logic [`XLEN-1:0] CSRReadValW, MulDivResultW;
|
|
|
|
logic [`XLEN-1:0] PrivilegedNextPCM;
|
|
|
|
logic [1:0] MemRWM;
|
|
|
|
logic InstrValidM, InstrValidW;
|
|
|
|
logic InstrMisalignedFaultM;
|
|
|
|
logic DataMisalignedM;
|
|
|
|
logic IllegalBaseInstrFaultD, IllegalIEUInstrFaultD;
|
|
|
|
logic ITLBInstrPageFaultF, DTLBLoadPageFaultM, DTLBStorePageFaultM;
|
|
|
|
logic WalkerInstrPageFaultF, WalkerLoadPageFaultM, WalkerStorePageFaultM;
|
|
|
|
logic LoadMisalignedFaultM, LoadAccessFaultM;
|
|
|
|
logic StoreMisalignedFaultM, StoreAccessFaultM;
|
|
|
|
logic [`XLEN-1:0] InstrMisalignedAdrM;
|
|
|
|
|
|
|
|
logic PCSrcE;
|
|
|
|
logic CSRWritePendingDEM;
|
|
|
|
logic DivDoneE;
|
|
|
|
logic DivBusyE;
|
|
|
|
logic RegWriteD;
|
2021-07-02 16:52:26 +00:00
|
|
|
logic LoadStallD, MulDivStallD, CSRRdStallD;
|
|
|
|
logic SquashSCM, SquashSCW;
|
2021-06-24 22:39:18 +00:00
|
|
|
// floating point unit signals
|
2021-07-02 16:52:26 +00:00
|
|
|
logic [2:0] FRM_REGW;
|
|
|
|
logic [1:0] FMemRWM, FMemRWE;
|
2021-06-24 18:05:22 +00:00
|
|
|
logic FStallD;
|
2021-07-02 16:52:26 +00:00
|
|
|
logic FWriteIntE, FWriteIntM, FWriteIntW;
|
|
|
|
logic [`XLEN-1:0] FWriteDataE;
|
|
|
|
logic [`XLEN-1:0] FIntResM;
|
2021-06-24 18:05:22 +00:00
|
|
|
logic FDivBusyE;
|
|
|
|
logic IllegalFPUInstrD, IllegalFPUInstrE;
|
2021-07-02 16:52:26 +00:00
|
|
|
logic FloatRegWriteW;
|
|
|
|
logic FPUStallD;
|
|
|
|
logic [4:0] SetFflagsM;
|
2021-06-24 18:05:22 +00:00
|
|
|
logic [`XLEN-1:0] FPUResultW;
|
2021-01-30 04:43:48 +00:00
|
|
|
|
2021-03-04 08:11:34 +00:00
|
|
|
// memory management unit signals
|
2021-06-24 18:05:22 +00:00
|
|
|
logic ITLBWriteF, DTLBWriteM;
|
|
|
|
logic ITLBFlushF, DTLBFlushM;
|
|
|
|
logic ITLBMissF, ITLBHitF;
|
|
|
|
logic DTLBMissM, DTLBHitM;
|
|
|
|
logic [`XLEN-1:0] SATP_REGW;
|
|
|
|
logic STATUS_MXR, STATUS_SUM;
|
|
|
|
logic [1:0] PrivilegeModeW;
|
|
|
|
logic [`XLEN-1:0] PageTableEntryF, PageTableEntryM;
|
|
|
|
logic [1:0] PageTypeF, PageTypeM;
|
2021-03-04 08:11:34 +00:00
|
|
|
|
2021-04-22 19:34:02 +00:00
|
|
|
// PMA checker signals
|
2021-07-02 18:56:49 +00:00
|
|
|
|
2021-06-24 18:05:22 +00:00
|
|
|
logic PMPInstrAccessFaultF, PMPLoadAccessFaultM, PMPStoreAccessFaultM;
|
|
|
|
logic PMAInstrAccessFaultF, PMALoadAccessFaultM, PMAStoreAccessFaultM;
|
|
|
|
logic DSquashBusAccessM, ISquashBusAccessF;
|
2021-06-21 05:17:08 +00:00
|
|
|
var logic [`XLEN-1:0] PMPADDR_ARRAY_REGW [`PMP_ENTRIES-1:0];
|
2021-07-04 15:39:59 +00:00
|
|
|
var logic [7:0] PMPCFG_ARRAY_REGW[`PMP_ENTRIES-1:0];
|
2021-04-22 19:34:02 +00:00
|
|
|
|
2021-03-30 19:25:07 +00:00
|
|
|
// IMem stalls
|
2021-06-24 18:05:22 +00:00
|
|
|
logic ICacheStallF;
|
|
|
|
logic DCacheStall;
|
|
|
|
logic [`XLEN-1:0] MMUPAdr, MMUReadPTE;
|
|
|
|
logic MMUStall;
|
|
|
|
logic MMUTranslate, MMUReady;
|
2021-06-30 16:24:26 +00:00
|
|
|
logic HPTWRead;
|
2021-06-25 20:07:41 +00:00
|
|
|
logic HPTWReadyfromLSU;
|
2021-06-28 22:26:11 +00:00
|
|
|
logic HPTWStall;
|
2021-06-25 20:07:41 +00:00
|
|
|
|
2021-03-18 18:35:46 +00:00
|
|
|
|
2021-02-02 18:02:31 +00:00
|
|
|
// bus interface to dmem
|
2021-06-24 18:05:22 +00:00
|
|
|
logic MemReadM, MemWriteM;
|
|
|
|
logic [1:0] AtomicMaskedM;
|
|
|
|
logic [2:0] Funct3M;
|
|
|
|
logic [`XLEN-1:0] MemAdrM, WriteDataM;
|
|
|
|
logic [`PA_BITS-1:0] MemPAdrM;
|
|
|
|
logic [`XLEN-1:0] ReadDataW;
|
|
|
|
logic [`PA_BITS-1:0] InstrPAdrF;
|
|
|
|
logic [`XLEN-1:0] InstrRData;
|
|
|
|
logic InstrReadF;
|
|
|
|
logic DataStall;
|
|
|
|
logic InstrAckF, MemAckW;
|
|
|
|
logic CommitM, CommittedM;
|
|
|
|
|
|
|
|
logic BPPredWrongE;
|
|
|
|
logic BPPredDirWrongM;
|
|
|
|
logic BTBPredPCWrongM;
|
|
|
|
logic RASPredPCWrongM;
|
|
|
|
logic BPPredClassNonCFIWrongM;
|
|
|
|
|
|
|
|
logic [`XLEN-1:0] WriteDatatmpM;
|
|
|
|
|
|
|
|
logic [4:0] InstrClassM;
|
|
|
|
|
|
|
|
logic [`XLEN-1:0] HRDATAW;
|
2021-06-23 23:59:06 +00:00
|
|
|
|
|
|
|
// IEU vs HPTW arbitration signals to send to LSU
|
2021-06-24 18:05:22 +00:00
|
|
|
logic DisableTranslation;
|
|
|
|
logic [1:0] MemRWMtoLSU;
|
|
|
|
logic [2:0] Funct3MtoLSU;
|
|
|
|
logic [1:0] AtomicMtoLSU;
|
|
|
|
logic [`XLEN-1:0] MemAdrMtoLSU;
|
|
|
|
logic [`XLEN-1:0] WriteDataMtoLSU;
|
|
|
|
logic [`XLEN-1:0] ReadDataWFromLSU;
|
|
|
|
logic CommittedMfromLSU;
|
|
|
|
logic SquashSCWfromLSU;
|
|
|
|
logic DataMisalignedMfromLSU;
|
2021-06-28 22:26:11 +00:00
|
|
|
logic StallWtoLSU;
|
|
|
|
logic StallWfromLSU;
|
|
|
|
logic [2:0] Funct3MfromLSU;
|
2021-07-01 22:59:55 +00:00
|
|
|
|
2021-06-24 18:05:22 +00:00
|
|
|
|
2021-07-01 22:59:55 +00:00
|
|
|
ifu ifu(.InstrInF(InstrRData),
|
|
|
|
.WalkerInstrPageFaultF(WalkerInstrPageFaultF),
|
|
|
|
.*); // instruction fetch unit: PC, branch prediction, instruction cache
|
2021-01-28 03:49:47 +00:00
|
|
|
|
2021-02-20 02:09:07 +00:00
|
|
|
ieu ieu(.*); // integer execution unit: integer register file, datapath and controller
|
2021-05-21 02:17:59 +00:00
|
|
|
|
|
|
|
|
2021-06-24 22:39:18 +00:00
|
|
|
// mux2 #(`XLEN) OutputInput2mux(WriteDataM, FWriteDataM, FMemRWM[0], WriteDatatmpM);
|
2021-02-09 16:02:17 +00:00
|
|
|
|
2021-06-30 16:24:26 +00:00
|
|
|
pagetablewalker pagetablewalker(.HPTWRead(HPTWRead),
|
|
|
|
.*); // can send addresses to ahblite, send out pagetablestall
|
2021-06-23 21:43:22 +00:00
|
|
|
// arbiter between IEU and pagetablewalker
|
2021-06-24 18:05:22 +00:00
|
|
|
lsuArb arbiter(// HPTW connection
|
|
|
|
.HPTWTranslate(MMUTranslate),
|
2021-06-30 16:24:26 +00:00
|
|
|
.HPTWRead(HPTWRead),
|
2021-06-24 18:05:22 +00:00
|
|
|
.HPTWPAdr(MMUPAdr),
|
|
|
|
.HPTWReadPTE(MMUReadPTE),
|
|
|
|
.HPTWReady(MMUReady),
|
2021-06-28 22:26:11 +00:00
|
|
|
.HPTWStall(HPTWStall),
|
2021-06-24 18:05:22 +00:00
|
|
|
// CPU connection
|
2021-07-02 16:52:26 +00:00
|
|
|
.MemRWM(MemRWM),
|
2021-06-24 18:05:22 +00:00
|
|
|
.Funct3M(Funct3M),
|
|
|
|
.AtomicM(AtomicM),
|
|
|
|
.MemAdrM(MemAdrM),
|
2021-06-28 22:26:11 +00:00
|
|
|
.StallW(StallW),
|
2021-07-02 16:52:26 +00:00
|
|
|
.WriteDataM(WriteDataM),
|
2021-06-24 18:05:22 +00:00
|
|
|
.ReadDataW(ReadDataW),
|
|
|
|
.CommittedM(CommittedM),
|
|
|
|
.SquashSCW(SquashSCW),
|
|
|
|
.DataMisalignedM(DataMisalignedM),
|
|
|
|
.DCacheStall(DCacheStall),
|
|
|
|
// LSU
|
|
|
|
.DisableTranslation(DisableTranslation),
|
|
|
|
.MemRWMtoLSU(MemRWMtoLSU),
|
|
|
|
.Funct3MtoLSU(Funct3MtoLSU),
|
|
|
|
.AtomicMtoLSU(AtomicMtoLSU),
|
|
|
|
.MemAdrMtoLSU(MemAdrMtoLSU),
|
2021-06-28 22:26:11 +00:00
|
|
|
.WriteDataMtoLSU(WriteDataMtoLSU),
|
|
|
|
.StallWtoLSU(StallWtoLSU),
|
2021-06-24 18:05:22 +00:00
|
|
|
.CommittedMfromLSU(CommittedMfromLSU),
|
|
|
|
.SquashSCWfromLSU(SquashSCWfromLSU),
|
|
|
|
.DataMisalignedMfromLSU(DataMisalignedMfromLSU),
|
|
|
|
.ReadDataWFromLSU(ReadDataWFromLSU),
|
2021-06-25 20:07:41 +00:00
|
|
|
.HPTWReadyfromLSU(HPTWReadyfromLSU),
|
2021-06-24 18:05:22 +00:00
|
|
|
.DataStall(DataStall),
|
|
|
|
.*);
|
|
|
|
|
2021-06-23 21:43:22 +00:00
|
|
|
|
2021-06-24 18:05:22 +00:00
|
|
|
lsu lsu(.MemRWM(MemRWMtoLSU),
|
|
|
|
.Funct3M(Funct3MtoLSU),
|
|
|
|
.AtomicM(AtomicMtoLSU),
|
|
|
|
.MemAdrM(MemAdrMtoLSU),
|
|
|
|
.WriteDataM(WriteDataMtoLSU),
|
|
|
|
.ReadDataW(ReadDataWFromLSU),
|
2021-06-28 22:26:11 +00:00
|
|
|
.StallW(StallWtoLSU),
|
2021-06-23 21:43:22 +00:00
|
|
|
|
2021-06-24 18:05:22 +00:00
|
|
|
.CommittedM(CommittedMfromLSU),
|
|
|
|
.SquashSCW(SquashSCWfromLSU),
|
|
|
|
.DataMisalignedM(DataMisalignedMfromLSU),
|
|
|
|
.DisableTranslation(DisableTranslation),
|
|
|
|
|
2021-06-25 20:07:41 +00:00
|
|
|
.DataStall(DataStall),
|
2021-06-28 22:26:11 +00:00
|
|
|
.HPTWReady(HPTWReadyfromLSU),
|
|
|
|
.Funct3MfromLSU(Funct3MfromLSU),
|
|
|
|
.StallWfromLSU(StallWfromLSU),
|
2021-06-30 03:33:57 +00:00
|
|
|
// .DataStall(LSUStall),
|
2021-06-25 20:07:41 +00:00
|
|
|
.* ); // data cache unit
|
2021-06-23 21:43:22 +00:00
|
|
|
|
|
|
|
ahblite ebu(
|
2021-06-24 18:05:22 +00:00
|
|
|
//.InstrReadF(1'b0),
|
|
|
|
//.InstrRData(InstrF), // hook up InstrF later
|
2021-07-02 16:52:26 +00:00
|
|
|
.ISquashBusAccessF(1'b0), // *** temporary hack to disable PMP instruction fetch checking
|
|
|
|
.WriteDataM(WriteDataM),
|
2021-06-28 22:26:11 +00:00
|
|
|
.MemSizeM(Funct3MfromLSU[1:0]), .UnsignedLoadM(Funct3MfromLSU[2]),
|
2021-06-24 18:05:22 +00:00
|
|
|
.Funct7M(InstrM[31:25]),
|
2021-06-23 21:43:22 +00:00
|
|
|
.HRDATAW(HRDATAW),
|
2021-06-28 22:26:11 +00:00
|
|
|
.StallW(StallWfromLSU),
|
2021-06-24 18:05:22 +00:00
|
|
|
.*);
|
2021-06-23 21:43:22 +00:00
|
|
|
|
2021-06-24 18:05:22 +00:00
|
|
|
|
2021-02-16 03:27:35 +00:00
|
|
|
muldiv mdu(.*); // multiply and divide unit
|
2021-04-03 20:52:26 +00:00
|
|
|
|
2021-01-27 11:40:26 +00:00
|
|
|
hazard hzu(.*); // global stall and flush control
|
|
|
|
|
|
|
|
// Priveleged block operates in M and W stages, handling CSRs and exceptions
|
2021-01-27 12:46:52 +00:00
|
|
|
privileged priv(.*);
|
2021-04-03 20:52:26 +00:00
|
|
|
|
2021-01-27 11:40:26 +00:00
|
|
|
|
2021-06-08 16:32:46 +00:00
|
|
|
fpu fpu(.*); // floating point unit
|
2021-01-15 04:37:51 +00:00
|
|
|
// add FPU here, with SetFflagsM, FRM_REGW
|
|
|
|
// presently stub out SetFlagsM and FloatRegWriteW
|
2021-04-03 20:52:26 +00:00
|
|
|
//assign SetFflagsM = 0;
|
|
|
|
//assign FloatRegWriteW = 0;
|
2021-06-24 18:05:22 +00:00
|
|
|
|
2021-01-15 04:37:51 +00:00
|
|
|
endmodule
|