2021-06-23 05:41:00 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// lsu.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu 9 January 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: Load/Store Unit
|
2022-01-20 16:02:08 +00:00
|
|
|
// Top level of the memory-stage core logic
|
2021-06-23 05:41:00 +00:00
|
|
|
// Contains data cache, DTLB, subword read/write datapath, interface to external bus
|
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
2022-01-07 12:58:40 +00:00
|
|
|
// MIT LICENSE
|
|
|
|
// 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:
|
2021-06-23 05:41:00 +00:00
|
|
|
//
|
2022-01-07 12:58:40 +00:00
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
// substantial portions of the Software.
|
2021-06-23 05:41:00 +00:00
|
|
|
//
|
2022-01-07 12:58:40 +00:00
|
|
|
// 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-06-23 05:41:00 +00:00
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
2022-01-15 01:19:44 +00:00
|
|
|
module lsu (
|
2021-12-20 03:34:40 +00:00
|
|
|
input logic clk, reset,
|
|
|
|
input logic StallM, FlushM, StallW, FlushW,
|
2022-01-15 00:24:16 +00:00
|
|
|
output logic LSUStallM,
|
2021-07-06 15:41:36 +00:00
|
|
|
// connected to cpu (controls)
|
2021-12-20 03:34:40 +00:00
|
|
|
input logic [1:0] MemRWM,
|
|
|
|
input logic [2:0] Funct3M,
|
|
|
|
input logic [6:0] Funct7M,
|
|
|
|
input logic [1:0] AtomicM,
|
2022-01-07 23:55:34 +00:00
|
|
|
input logic TrapM,
|
2021-12-20 03:34:40 +00:00
|
|
|
input logic FlushDCacheM,
|
2021-12-29 04:27:12 +00:00
|
|
|
output logic CommittedM,
|
2021-12-20 03:34:40 +00:00
|
|
|
output logic SquashSCW,
|
|
|
|
output logic DCacheMiss,
|
|
|
|
output logic DCacheAccess,
|
2021-07-06 15:41:36 +00:00
|
|
|
// address and write data
|
2021-12-20 03:34:40 +00:00
|
|
|
input logic [`XLEN-1:0] IEUAdrE,
|
2021-12-20 16:03:19 +00:00
|
|
|
(* mark_debug = "true" *)output logic [`XLEN-1:0] IEUAdrM,
|
2021-12-20 03:34:40 +00:00
|
|
|
input logic [`XLEN-1:0] WriteDataM,
|
2021-07-22 19:51:14 +00:00
|
|
|
output logic [`XLEN-1:0] ReadDataM,
|
2021-07-06 15:41:36 +00:00
|
|
|
// cpu privilege
|
2021-12-20 03:34:40 +00:00
|
|
|
input logic [1:0] PrivilegeModeW,
|
|
|
|
input logic DTLBFlushM,
|
2021-07-06 15:41:36 +00:00
|
|
|
// faults
|
2022-01-27 23:11:27 +00:00
|
|
|
output logic LoadPageFaultM, StoreAmoPageFaultM,
|
2021-12-20 03:34:40 +00:00
|
|
|
output logic LoadMisalignedFaultM, LoadAccessFaultM,
|
2021-07-06 15:41:36 +00:00
|
|
|
// cpu hazard unit (trap)
|
2022-01-27 23:11:27 +00:00
|
|
|
output logic StoreAmoMisalignedFaultM, StoreAmoAccessFaultM,
|
2021-07-06 15:41:36 +00:00
|
|
|
// connect to ahb
|
2022-01-07 04:30:00 +00:00
|
|
|
(* mark_debug = "true" *) output logic [`PA_BITS-1:0] LSUBusAdr,
|
|
|
|
(* mark_debug = "true" *) output logic LSUBusRead,
|
|
|
|
(* mark_debug = "true" *) output logic LSUBusWrite,
|
|
|
|
(* mark_debug = "true" *) input logic LSUBusAck,
|
|
|
|
(* mark_debug = "true" *) input logic [`XLEN-1:0] LSUBusHRDATA,
|
|
|
|
(* mark_debug = "true" *) output logic [`XLEN-1:0] LSUBusHWDATA,
|
|
|
|
(* mark_debug = "true" *) output logic [2:0] LSUBusSize,
|
2021-07-06 15:41:36 +00:00
|
|
|
// page table walker
|
2021-12-20 03:34:40 +00:00
|
|
|
input logic [`XLEN-1:0] SATP_REGW, // from csr
|
|
|
|
input logic STATUS_MXR, STATUS_SUM, STATUS_MPRV,
|
|
|
|
input logic [1:0] STATUS_MPP,
|
|
|
|
input logic [`XLEN-1:0] PCF,
|
|
|
|
input logic ITLBMissF,
|
2021-07-17 19:01:01 +00:00
|
|
|
output logic [`XLEN-1:0] PTE,
|
2021-12-20 03:34:40 +00:00
|
|
|
output logic [1:0] PageType,
|
|
|
|
output logic ITLBWriteF,
|
|
|
|
input var logic [7:0] PMPCFG_ARRAY_REGW[`PMP_ENTRIES-1:0],
|
|
|
|
input var logic [`XLEN-1:0] PMPADDR_ARRAY_REGW[`PMP_ENTRIES-1:0] // *** this one especially has a large note attached to it in pmpchecker.
|
2022-01-15 01:19:44 +00:00
|
|
|
);
|
2021-07-06 15:41:36 +00:00
|
|
|
|
2022-01-07 04:30:00 +00:00
|
|
|
logic [`PA_BITS-1:0] LSUPAdrM; // from mmu to dcache
|
2021-12-20 16:03:56 +00:00
|
|
|
logic [`XLEN+1:0] IEUAdrExtM;
|
2021-12-20 03:34:40 +00:00
|
|
|
logic DTLBMissM;
|
|
|
|
logic DTLBWriteM;
|
2022-01-07 04:30:00 +00:00
|
|
|
logic [1:0] LSURWM;
|
|
|
|
logic [1:0] PreLSURWM;
|
|
|
|
logic [2:0] LSUFunct3M;
|
2022-01-07 05:28:02 +00:00
|
|
|
logic [6:0] LSUFunct7M;
|
2022-01-07 04:30:00 +00:00
|
|
|
logic [1:0] LSUAtomicM;
|
|
|
|
(* mark_debug = "true" *) logic [`PA_BITS-1:0] PreLSUPAdrM, LocalLSUBusAdr;
|
|
|
|
logic [11:0] PreLSUAdrE, LSUAdrE;
|
2021-12-20 04:21:03 +00:00
|
|
|
logic CPUBusy;
|
2021-12-20 03:34:40 +00:00
|
|
|
logic MemReadM;
|
2022-01-15 00:39:07 +00:00
|
|
|
logic DCacheStallM;
|
2021-12-20 03:34:40 +00:00
|
|
|
logic CacheableM;
|
2021-12-20 04:24:07 +00:00
|
|
|
logic SelHPTW;
|
2021-12-28 00:12:59 +00:00
|
|
|
logic BusStall;
|
2021-12-20 03:34:40 +00:00
|
|
|
logic InterlockStall;
|
|
|
|
logic IgnoreRequest;
|
2021-12-29 17:21:44 +00:00
|
|
|
logic BusCommittedM, DCacheCommittedM;
|
2021-12-28 18:11:45 +00:00
|
|
|
|
2022-01-14 23:55:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2022-01-14 23:02:28 +00:00
|
|
|
// HPTW and Interlock FSM (only needed if VM supported)
|
2022-01-14 23:55:27 +00:00
|
|
|
// MMU include PMP and is needed if any privileged supported
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2022-01-15 00:24:16 +00:00
|
|
|
flopenrc #(`XLEN) AddressMReg(clk, reset, FlushM, ~StallM, IEUAdrE, IEUAdrM);
|
|
|
|
assign IEUAdrExtM = {2'b00, IEUAdrM};
|
|
|
|
|
2022-01-05 16:25:08 +00:00
|
|
|
if(`MEM_VIRTMEM) begin : MEM_VIRTMEM
|
2022-01-27 15:53:59 +00:00
|
|
|
// *** encapsulate as lsuvirtmem
|
2022-01-05 16:25:08 +00:00
|
|
|
logic AnyCPUReqM;
|
|
|
|
logic [`PA_BITS-1:0] HPTWAdr;
|
|
|
|
logic HPTWRead;
|
|
|
|
logic [2:0] HPTWSize;
|
|
|
|
logic SelReplayCPURequest;
|
|
|
|
|
|
|
|
assign AnyCPUReqM = (|MemRWM) | (|AtomicM);
|
|
|
|
|
|
|
|
interlockfsm interlockfsm (.clk, .reset, .AnyCPUReqM, .ITLBMissF, .ITLBWriteF,
|
2022-01-15 00:39:07 +00:00
|
|
|
.DTLBMissM, .DTLBWriteM, .TrapM, .DCacheStallM,
|
2022-01-05 16:25:08 +00:00
|
|
|
.InterlockStall, .SelReplayCPURequest, .SelHPTW,
|
|
|
|
.IgnoreRequest);
|
|
|
|
|
|
|
|
hptw hptw(.clk, .reset, .SATP_REGW, .PCF, .IEUAdrM,
|
2022-01-07 23:55:34 +00:00
|
|
|
.ITLBMissF(ITLBMissF & ~TrapM),
|
|
|
|
.DTLBMissM(DTLBMissM & ~TrapM),
|
2022-01-13 17:04:48 +00:00
|
|
|
.PTE, .PageType, .ITLBWriteF, .DTLBWriteM,
|
2022-01-05 16:25:08 +00:00
|
|
|
.HPTWReadPTE(ReadDataM),
|
2022-01-15 00:39:07 +00:00
|
|
|
.DCacheStallM, .HPTWAdr, .HPTWRead, .HPTWSize);
|
2022-01-05 16:25:08 +00:00
|
|
|
|
|
|
|
// arbiter between IEU and hptw
|
|
|
|
|
|
|
|
// multiplex the outputs to LSU
|
2022-01-07 04:30:00 +00:00
|
|
|
mux2 #(2) rwmux(MemRWM, {HPTWRead, 1'b0}, SelHPTW, PreLSURWM);
|
|
|
|
mux2 #(3) sizemux(Funct3M, HPTWSize, SelHPTW, LSUFunct3M);
|
2022-01-07 05:28:02 +00:00
|
|
|
mux2 #(7) funct7mux(Funct7M, 7'b0, SelHPTW, LSUFunct7M);
|
2022-01-07 04:30:00 +00:00
|
|
|
mux2 #(2) atomicmux(AtomicM, 2'b00, SelHPTW, LSUAtomicM);
|
|
|
|
mux2 #(12) adremux(IEUAdrE[11:0], HPTWAdr[11:0], SelHPTW, PreLSUAdrE);
|
2022-01-27 22:03:00 +00:00
|
|
|
mux2 #(12) replaymux(PreLSUAdrE, IEUAdrM[11:0], SelReplayCPURequest, LSUAdrE); // replay cpu request after hptw.
|
2022-01-07 04:30:00 +00:00
|
|
|
mux2 #(`PA_BITS) lsupadrmux(IEUAdrExtM[`PA_BITS-1:0], HPTWAdr, SelHPTW, PreLSUPAdrM);
|
2022-01-05 16:25:08 +00:00
|
|
|
|
|
|
|
// always block interrupts when using the hardware page table walker.
|
|
|
|
assign CPUBusy = StallW & ~SelHPTW;
|
|
|
|
|
|
|
|
end // if (`MEM_VIRTMEM)
|
|
|
|
else begin
|
2022-01-26 23:37:04 +00:00
|
|
|
assign {InterlockStall, SelHPTW, PTE, PageType, DTLBWriteM, ITLBWriteF} = '0;
|
|
|
|
assign IgnoreRequest = TrapM;
|
2022-01-05 16:25:08 +00:00
|
|
|
assign CPUBusy = StallW;
|
2022-01-15 00:24:16 +00:00
|
|
|
assign LSUAdrE = PreLSUAdrE; assign LSUFunct3M = Funct3M; assign LSUFunct7M = Funct7M; assign LSUAtomicM = AtomicM;
|
|
|
|
assign PreLSURWM = MemRWM; assign PreLSUAdrE = IEUAdrE[11:0]; assign PreLSUPAdrM = IEUAdrExtM;
|
|
|
|
end
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2022-01-14 23:02:28 +00:00
|
|
|
|
2021-12-29 20:48:09 +00:00
|
|
|
// **** look into this confusing signal.
|
2021-12-29 23:40:24 +00:00
|
|
|
// This signal is confusing. CommittedM tells the CPU's trap unit the current instruction
|
|
|
|
// in the memory stage is a memory operaton and that memory operation is either completed
|
|
|
|
// or is partially executed. This signal is only low for the first cycle of a memory
|
|
|
|
// operation.
|
|
|
|
// **** I think there is also a bug here. Data cache misses and TLB misses both
|
|
|
|
// set this bit in the first cycle. It is not strickly wrong, but it may be better
|
|
|
|
// to flush the memory operation at that time.
|
2021-12-29 17:21:44 +00:00
|
|
|
assign CommittedM = SelHPTW | DCacheCommittedM | BusCommittedM;
|
2021-12-28 22:14:10 +00:00
|
|
|
|
2022-01-14 23:02:28 +00:00
|
|
|
// MMU and Misalignment fault logic required if privileged unit exists
|
2022-01-05 16:25:08 +00:00
|
|
|
if(`ZICSR_SUPPORTED == 1) begin : dmmu
|
|
|
|
|
|
|
|
mmu #(.TLB_ENTRIES(`DTLB_ENTRIES), .IMMU(0))
|
|
|
|
dmmu(.clk, .reset, .SATP_REGW, .STATUS_MXR, .STATUS_SUM, .STATUS_MPRV, .STATUS_MPP,
|
|
|
|
.PrivilegeModeW, .DisableTranslation(SelHPTW),
|
2022-01-07 04:30:00 +00:00
|
|
|
.PAdr(PreLSUPAdrM),
|
2022-01-05 16:25:08 +00:00
|
|
|
.VAdr(IEUAdrM),
|
2022-01-07 04:30:00 +00:00
|
|
|
.Size(LSUFunct3M[1:0]),
|
2022-01-05 16:25:08 +00:00
|
|
|
.PTE,
|
|
|
|
.PageTypeWriteVal(PageType),
|
|
|
|
.TLBWrite(DTLBWriteM),
|
|
|
|
.TLBFlush(DTLBFlushM),
|
2022-01-07 04:30:00 +00:00
|
|
|
.PhysicalAddress(LSUPAdrM),
|
2022-01-05 16:25:08 +00:00
|
|
|
.TLBMiss(DTLBMissM),
|
|
|
|
.Cacheable(CacheableM),
|
|
|
|
.Idempotent(), .AtomicAllowed(),
|
2022-01-27 23:11:27 +00:00
|
|
|
.InstrAccessFaultF(), .LoadAccessFaultM, .StoreAmoAccessFaultM,
|
|
|
|
.InstrPageFaultF(),.LoadPageFaultM, .StoreAmoPageFaultM,
|
|
|
|
.LoadMisalignedFaultM, .StoreAmoMisalignedFaultM,
|
|
|
|
.AtomicAccessM(|LSUAtomicM), .ExecuteAccessF(1'b0), // **** change this to just use PreLSURWM
|
2022-01-07 04:30:00 +00:00
|
|
|
.WriteAccessM(PreLSURWM[0]), .ReadAccessM(PreLSURWM[1]),
|
2022-01-05 16:25:08 +00:00
|
|
|
.PMPCFG_ARRAY_REGW, .PMPADDR_ARRAY_REGW
|
2022-01-15 00:24:16 +00:00
|
|
|
);
|
2022-01-05 16:25:08 +00:00
|
|
|
|
2022-01-27 23:11:27 +00:00
|
|
|
// *** lsumisaligned lsumisaligned(Funct3M, IEUAdrM, MemRW, LoadMisalignedFaultM, StoreAmoMisalignedFaultM);
|
2022-01-14 23:02:28 +00:00
|
|
|
// *** lump into lsumislaigned module
|
2022-01-05 16:25:08 +00:00
|
|
|
// Determine if an Unaligned access is taking place
|
|
|
|
// hptw guarantees alignment, only check inputs from IEU.
|
2022-01-27 15:53:59 +00:00
|
|
|
|
|
|
|
// *** modify MMU to put out LoadMisalignedFault and StoreMisalignedFault rather than DataMisalignedM
|
2022-01-05 16:25:08 +00:00
|
|
|
|
2022-01-27 23:11:27 +00:00
|
|
|
|
2022-01-05 16:25:08 +00:00
|
|
|
end else begin
|
2022-01-27 23:11:27 +00:00
|
|
|
assign {DTLBMissM, LoadAccessFaultM, StoreAmoAccessFaultM, LoadMisalignedFaultM, StoreAmoMisalignedFaultM} = '0;
|
2022-01-07 04:30:00 +00:00
|
|
|
assign LSUPAdrM = PreLSUPAdrM;
|
2022-01-05 16:25:08 +00:00
|
|
|
assign CacheableM = 1;
|
2022-01-27 23:11:27 +00:00
|
|
|
assign {LoadPageFaultM, StoreAmoPageFaultM} = '0;
|
2022-01-05 16:25:08 +00:00
|
|
|
end
|
2022-01-15 00:39:07 +00:00
|
|
|
assign LSUStallM = DCacheStallM | InterlockStall | BusStall;
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2022-01-14 23:55:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Hart Memory System
|
|
|
|
// Either Data Cache or Data Tightly Integrated Memory or just bus interface
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-07-18 01:11:41 +00:00
|
|
|
|
2022-01-05 04:08:18 +00:00
|
|
|
localparam integer WORDSPERLINE = `MEM_DCACHE ? `DCACHE_LINELENINBITS/`XLEN : 1;
|
2021-12-30 21:26:32 +00:00
|
|
|
localparam integer LOGWPL = `MEM_DCACHE ? $clog2(WORDSPERLINE) : 1;
|
2022-01-05 04:08:18 +00:00
|
|
|
localparam integer LINELEN = `MEM_DCACHE ? `DCACHE_LINELENINBITS : `XLEN;
|
2021-12-30 04:24:37 +00:00
|
|
|
localparam integer WordCountThreshold = `MEM_DCACHE ? WORDSPERLINE - 1 : 0;
|
2021-12-29 23:12:20 +00:00
|
|
|
|
2022-01-05 04:08:18 +00:00
|
|
|
localparam integer LINEBYTELEN = LINELEN/8;
|
|
|
|
localparam integer OFFSETLEN = $clog2(LINEBYTELEN);
|
2021-12-27 22:45:49 +00:00
|
|
|
|
2021-12-27 21:56:18 +00:00
|
|
|
logic [`XLEN-1:0] FinalAMOWriteDataM, FinalWriteDataM;
|
2022-01-07 04:30:00 +00:00
|
|
|
(* mark_debug = "true" *) logic [`XLEN-1:0] PreLSUBusHWDATA;
|
2021-12-27 21:56:18 +00:00
|
|
|
logic [`XLEN-1:0] ReadDataWordM;
|
2022-01-05 04:08:18 +00:00
|
|
|
logic [LINELEN-1:0] DCacheMemWriteData;
|
2021-12-27 21:56:18 +00:00
|
|
|
logic [`XLEN-1:0] ReadDataWordMuxM;
|
2021-12-29 16:44:37 +00:00
|
|
|
logic [`PA_BITS-1:0] DCacheBusAdr;
|
2022-01-05 04:08:18 +00:00
|
|
|
logic [`XLEN-1:0] ReadDataLineSetsM [WORDSPERLINE-1:0];
|
2021-12-29 17:21:44 +00:00
|
|
|
logic DCacheWriteLine;
|
|
|
|
logic DCacheFetchLine;
|
|
|
|
logic DCacheBusAck;
|
2021-12-29 16:44:37 +00:00
|
|
|
logic SelUncachedAdr;
|
2021-06-23 05:41:00 +00:00
|
|
|
|
2022-01-14 23:55:27 +00:00
|
|
|
if (`MEM_DTIM) begin : dtim
|
2022-01-27 15:53:59 +00:00
|
|
|
/* Consider restructuring with higher level blocks. Try drawing block diagrams with several pages of schematics,
|
|
|
|
one for top level, one for each sublevel, alternate with either dtim or bus. If this looks more satisfactory,
|
|
|
|
restructure code accordingly.
|
|
|
|
|
|
|
|
dtim dtim (.clk, .CPUBusy, .LSURWM, .IEUAdrM, .IEUAdrE, .TrapM, .FinalWriteDataM, .ReadDataWordM,
|
|
|
|
.BusStallM, .LSUBusWrite, .LSUBusRead, .DCacheBusAck, .BusCommittedM, .SelUncachedAdr,
|
|
|
|
.ReadDataWordMuxM, .DCacheStallM, .DCacheCommittedM, .DCacheWriteLine, .DCacheFetchLine, .DCacheBusAdr,
|
|
|
|
.ReadDataLineSetsM, .DCacheMiss, .DCacheAccess); */
|
|
|
|
|
2022-01-25 19:46:13 +00:00
|
|
|
// *** adjust interface so write address doesn't need delaying; switch to standard RAM?
|
2022-01-15 01:19:44 +00:00
|
|
|
simpleram #(.BASE(`RAM_BASE), .RANGE(`RAM_RANGE)) ram (
|
2022-01-25 17:34:15 +00:00
|
|
|
.clk,
|
2022-01-26 23:37:04 +00:00
|
|
|
.a(CPUBusy | LSURWM[0] ? IEUAdrM[31:0] : IEUAdrE[31:0]),
|
|
|
|
.we(LSURWM[0] & ~TrapM), // have to ignore write if Trap.
|
2022-01-25 18:26:31 +00:00
|
|
|
.wd(FinalWriteDataM), .rd(ReadDataWordM));
|
2022-01-13 23:00:46 +00:00
|
|
|
|
|
|
|
// since we have a local memory the bus connections are all disabled.
|
|
|
|
// There are no peripherals supported.
|
2022-01-14 23:55:27 +00:00
|
|
|
assign {BusStall, LSUBusWrite, LSUBusRead, DCacheBusAck, BusCommittedM, SelUncachedAdr} = '0;
|
2022-01-15 00:03:03 +00:00
|
|
|
assign ReadDataWordMuxM = ReadDataWordM;
|
2022-01-15 01:11:17 +00:00
|
|
|
assign {DCacheStallM, DCacheCommittedM, DCacheWriteLine, DCacheFetchLine, DCacheBusAdr} = '0;
|
|
|
|
assign ReadDataLineSetsM[0] = 0;
|
|
|
|
assign DCacheMiss = 1'b0; assign DCacheAccess = 1'b0;
|
2022-01-27 15:53:59 +00:00
|
|
|
end else begin : bus
|
|
|
|
// replace from here up to if (`MEM_DCACHE) with busdp ***
|
2022-01-13 23:00:46 +00:00
|
|
|
// Bus Side logic
|
|
|
|
// register the fetch data from the next level of memory.
|
|
|
|
// This register should be necessary for timing. There is no register in the uncore or
|
|
|
|
// ahblite controller between the memories and this cache.
|
|
|
|
logic [LOGWPL-1:0] WordCount;
|
|
|
|
|
|
|
|
genvar index;
|
|
|
|
for (index = 0; index < WORDSPERLINE; index++) begin:fetchbuffer
|
2022-01-15 01:19:44 +00:00
|
|
|
flopen #(`XLEN) fb(.clk, .en(LSUBusAck & LSUBusRead & (index == WordCount)),
|
|
|
|
.d(LSUBusHRDATA), .q(DCacheMemWriteData[(index+1)*`XLEN-1:index*`XLEN]));
|
2022-01-13 23:00:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
assign LocalLSUBusAdr = SelUncachedAdr ? LSUPAdrM : DCacheBusAdr ;
|
|
|
|
assign LSUBusAdr = ({{`PA_BITS-LOGWPL{1'b0}}, WordCount} << $clog2(`XLEN/8)) + LocalLSUBusAdr;
|
|
|
|
assign PreLSUBusHWDATA = ReadDataLineSetsM[WordCount];
|
|
|
|
// exclude the subword write for uncached. We don't read the data first so we cannot
|
|
|
|
// select the subword by masking. Subword write also exists inside the uncore to
|
|
|
|
// suport subword masking for i/o. I'm not sure if this is necessary.
|
|
|
|
assign LSUBusHWDATA = SelUncachedAdr ? FinalAMOWriteDataM : PreLSUBusHWDATA;
|
|
|
|
|
2022-01-15 00:39:07 +00:00
|
|
|
assign LSUBusSize = SelUncachedAdr ? LSUFunct3M : (`XLEN == 32 ? 3'b010 : 3'b011);
|
2022-01-13 23:00:46 +00:00
|
|
|
|
2022-01-14 23:55:27 +00:00
|
|
|
// select between dcache and direct from the BUS. Always selected if no dcache.
|
|
|
|
mux2 #(`XLEN) UnCachedDataMux(.d0(ReadDataWordM),
|
|
|
|
.d1(DCacheMemWriteData[`XLEN-1:0]),
|
|
|
|
.s(SelUncachedAdr),
|
|
|
|
.y(ReadDataWordMuxM));
|
|
|
|
|
2022-01-13 23:00:46 +00:00
|
|
|
busfsm #(WordCountThreshold, LOGWPL, `MEM_DCACHE)
|
|
|
|
busfsm(.clk, .reset, .IgnoreRequest, .LSURWM, .DCacheFetchLine, .DCacheWriteLine,
|
|
|
|
.LSUBusAck, .CPUBusy, .CacheableM, .BusStall, .LSUBusWrite, .LSUBusRead,
|
|
|
|
.DCacheBusAck, .BusCommittedM, .SelUncachedAdr, .WordCount);
|
2022-01-15 00:39:07 +00:00
|
|
|
|
|
|
|
if(`MEM_DCACHE) begin : dcache
|
|
|
|
cache #(.LINELEN(`DCACHE_LINELENINBITS), .NUMLINES(`DCACHE_WAYSIZEINBYTES*8/LINELEN),
|
|
|
|
.NUMWAYS(`DCACHE_NUMWAYS), .DCACHE(1))
|
|
|
|
dcache(.clk, .reset, .CPUBusy,
|
|
|
|
.RW(CacheableM ? LSURWM : 2'b00), .FlushCache(FlushDCacheM), .Atomic(CacheableM ? LSUAtomicM : 2'b00),
|
|
|
|
.NextAdr(LSUAdrE), .PAdr(LSUPAdrM),
|
|
|
|
.FinalWriteData(FinalWriteDataM), .ReadDataWord(ReadDataWordM), .CacheStall(DCacheStallM),
|
|
|
|
.CacheMiss(DCacheMiss), .CacheAccess(DCacheAccess),
|
|
|
|
.IgnoreRequest, .CacheCommitted(DCacheCommittedM),
|
|
|
|
.CacheBusAdr(DCacheBusAdr), .ReadDataLineSets(ReadDataLineSetsM), .CacheMemWriteData(DCacheMemWriteData),
|
|
|
|
.CacheFetchLine(DCacheFetchLine), .CacheWriteLine(DCacheWriteLine), .CacheBusAck(DCacheBusAck), .InvalidateCacheM(1'b0));
|
|
|
|
|
|
|
|
end else begin : passthrough
|
|
|
|
assign {ReadDataWordM, DCacheStallM, DCacheCommittedM, DCacheWriteLine, DCacheFetchLine, DCacheBusAdr} = '0;
|
|
|
|
assign ReadDataLineSetsM[0] = 0;
|
|
|
|
assign DCacheMiss = CacheableM; assign DCacheAccess = CacheableM;
|
|
|
|
end
|
2022-01-13 23:00:46 +00:00
|
|
|
end
|
2022-01-14 23:55:27 +00:00
|
|
|
|
|
|
|
// sub word selection for read and writes and optional amo alu.
|
|
|
|
subwordread subwordread(.ReadDataWordMuxM,
|
|
|
|
.LSUPAdrM(LSUPAdrM[2:0]),
|
|
|
|
.Funct3M(LSUFunct3M),
|
|
|
|
.ReadDataM);
|
|
|
|
|
|
|
|
// this might only get instantiated if there is a dcache or dtim.
|
2022-01-15 00:39:07 +00:00
|
|
|
// There is a copy in the ebu. *** is it needed there, or can data come in from ebu, get muxed here and sent back out
|
2022-01-27 15:53:59 +00:00
|
|
|
// Explore changing feedback path from output of AMOALU to subword write ***
|
2022-01-14 23:55:27 +00:00
|
|
|
subwordwrite subwordwrite(.HRDATA(ReadDataWordM),
|
|
|
|
.HADDRD(LSUPAdrM[2:0]),
|
|
|
|
.HSIZED({LSUFunct3M[2], 1'b0, LSUFunct3M[1:0]}),
|
|
|
|
.HWDATAIN(FinalAMOWriteDataM),
|
|
|
|
.HWDATA(FinalWriteDataM));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Atomic operations
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (`A_SUPPORTED) begin:lrsc
|
2022-01-27 15:53:59 +00:00
|
|
|
/*atomic atomic(.clk, .reset, .FlushW, .CPUBusy, .MemRead, .PreLSURWM, .LSUAtomicM, .LSUPAdrM,
|
|
|
|
.SquashSCM, .LSURWM, ... ); *** */
|
2022-01-14 23:55:27 +00:00
|
|
|
logic [`XLEN-1:0] AMOResult;
|
|
|
|
amoalu amoalu(.srca(ReadDataM), .srcb(WriteDataM), .funct(LSUFunct7M), .width(LSUFunct3M[1:0]),
|
|
|
|
.result(AMOResult));
|
|
|
|
mux2 #(`XLEN) wdmux(WriteDataM, AMOResult, LSUAtomicM[1], FinalAMOWriteDataM);
|
|
|
|
assign MemReadM = PreLSURWM[1] & ~(IgnoreRequest) & ~DTLBMissM;
|
|
|
|
lrsc lrsc(.clk, .reset, .FlushW, .CPUBusy, .MemReadM, .PreLSURWM, .LSUAtomicM, .LSUPAdrM,
|
|
|
|
.SquashSCW, .LSURWM);
|
|
|
|
end else begin:lrsc
|
2022-01-15 00:39:07 +00:00
|
|
|
assign SquashSCW = 0;
|
|
|
|
assign LSURWM = PreLSURWM;
|
2022-01-14 23:55:27 +00:00
|
|
|
assign FinalAMOWriteDataM = WriteDataM;
|
|
|
|
end
|
2021-06-23 05:41:00 +00:00
|
|
|
endmodule
|
|
|
|
|