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
|
|
|
|
2022-08-28 04:44:17 +00:00
|
|
|
// committed means the memory operation in flight cannot be interrupted.
|
|
|
|
// cpubusy means the cpu is stalled and the lsu must ensure ReadDataM stalls constant until the stall is removed.
|
|
|
|
// chap 5 handling faults to memory by delaying writes to memory stage.
|
|
|
|
// chap 6 combing bus with dtim
|
2022-08-28 18:10:47 +00:00
|
|
|
// chap 9 complete lsu.
|
2022-08-28 04:44:17 +00:00
|
|
|
|
2021-06-23 05:41:00 +00:00
|
|
|
`include "wally-config.vh"
|
|
|
|
|
2022-01-15 01:19:44 +00:00
|
|
|
module lsu (
|
2022-01-31 18:11:42 +00:00
|
|
|
input logic clk, reset,
|
|
|
|
input logic StallM, FlushM, StallW, FlushW,
|
|
|
|
output logic LSUStallM,
|
2021-07-06 15:41:36 +00:00
|
|
|
// connected to cpu (controls)
|
2022-01-31 18:11:42 +00:00
|
|
|
input logic [1:0] MemRWM,
|
|
|
|
input logic [2:0] Funct3M,
|
|
|
|
input logic [6:0] Funct7M,
|
|
|
|
input logic [1:0] AtomicM,
|
|
|
|
input logic TrapM,
|
|
|
|
input logic FlushDCacheM,
|
|
|
|
output logic CommittedM,
|
|
|
|
output logic SquashSCW,
|
|
|
|
output logic DCacheMiss,
|
|
|
|
output logic DCacheAccess,
|
2021-07-06 15:41:36 +00:00
|
|
|
// address and write data
|
2022-01-31 18:11:42 +00:00
|
|
|
input logic [`XLEN-1:0] IEUAdrE,
|
|
|
|
(* mark_debug = "true" *)output logic [`XLEN-1:0] IEUAdrM,
|
2022-08-29 18:01:24 +00:00
|
|
|
(* mark_debug = "true" *)input logic [`XLEN-1:0] WriteDataM,
|
2022-06-20 22:53:13 +00:00
|
|
|
output logic [`LLEN-1:0] ReadDataW,
|
2021-07-06 15:41:36 +00:00
|
|
|
// cpu privilege
|
2022-05-08 06:46:35 +00:00
|
|
|
input logic [1:0] PrivilegeModeW,
|
|
|
|
input logic BigEndianM,
|
2022-06-02 14:18:55 +00:00
|
|
|
input logic sfencevmaM,
|
2022-06-20 22:53:13 +00:00
|
|
|
// fpu
|
2022-06-28 21:33:31 +00:00
|
|
|
input logic [`FLEN-1:0] FWriteDataM,
|
|
|
|
input logic FpLoadStoreM,
|
2021-07-06 15:41:36 +00:00
|
|
|
// faults
|
2022-01-31 18:11:42 +00:00
|
|
|
output logic LoadPageFaultM, StoreAmoPageFaultM,
|
|
|
|
output logic LoadMisalignedFaultM, LoadAccessFaultM,
|
2021-07-06 15:41:36 +00:00
|
|
|
// cpu hazard unit (trap)
|
2022-01-31 18:11:42 +00:00
|
|
|
output logic StoreAmoMisalignedFaultM, StoreAmoAccessFaultM,
|
|
|
|
// connect to ahb
|
2022-08-25 16:52:08 +00:00
|
|
|
(* mark_debug = "true" *) output logic [`PA_BITS-1:0] LSUHADDR,
|
2022-08-25 17:20:02 +00:00
|
|
|
(* mark_debug = "true" *) input logic [`XLEN-1:0] HRDATA,
|
|
|
|
(* mark_debug = "true" *) output logic [`XLEN-1:0] LSUHWDATA,
|
2022-08-29 18:01:24 +00:00
|
|
|
(* mark_debug = "true" *) input logic LSUHREADY,
|
|
|
|
(* mark_debug = "true" *) output logic LSUHWRITE,
|
2022-08-25 16:52:08 +00:00
|
|
|
(* mark_debug = "true" *) output logic [2:0] LSUHSIZE,
|
|
|
|
(* mark_debug = "true" *) output logic [2:0] LSUHBURST,
|
|
|
|
(* mark_debug = "true" *) output logic [1:0] LSUHTRANS,
|
2022-08-29 22:11:27 +00:00
|
|
|
(* mark_debug = "true" *) output logic [`XLEN/8-1:0] LSUHWSTRB,
|
2022-01-31 18:11:42 +00:00
|
|
|
// page table walker
|
|
|
|
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,
|
2022-02-17 05:37:36 +00:00
|
|
|
input logic InstrDAPageFaultF,
|
2022-01-31 18:11:42 +00:00
|
|
|
output logic [`XLEN-1:0] PTE,
|
|
|
|
output logic [1:0] PageType,
|
2022-05-08 06:46:35 +00:00
|
|
|
output logic ITLBWriteF, SelHPTW,
|
2022-01-31 18:11:42 +00:00
|
|
|
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-31 19:16:23 +00:00
|
|
|
logic [`XLEN+1:0] IEUAdrExtM;
|
2022-08-28 04:44:17 +00:00
|
|
|
logic [`XLEN+1:0] IEUAdrExtE;
|
2022-01-31 19:16:23 +00:00
|
|
|
logic [`PA_BITS-1:0] LSUPAdrM;
|
2022-01-31 18:11:42 +00:00
|
|
|
logic DTLBMissM;
|
|
|
|
logic DTLBWriteM;
|
2022-08-28 03:31:09 +00:00
|
|
|
logic [1:0] NonDTIMMemRWM, PreLSURWM, LSURWM;
|
2022-01-31 18:11:42 +00:00
|
|
|
logic [2:0] LSUFunct3M;
|
|
|
|
logic [6:0] LSUFunct7M;
|
|
|
|
logic [1:0] LSUAtomicM;
|
2022-03-25 04:47:28 +00:00
|
|
|
(* mark_debug = "true" *) logic [`XLEN+1:0] PreLSUPAdrM;
|
2022-05-12 15:21:09 +00:00
|
|
|
logic [11:0] LSUAdrE;
|
2022-08-27 12:31:56 +00:00
|
|
|
logic SelDTIM;
|
2022-01-31 18:11:42 +00:00
|
|
|
logic CPUBusy;
|
|
|
|
logic DCacheStallM;
|
|
|
|
logic CacheableM;
|
|
|
|
logic BusStall;
|
|
|
|
logic InterlockStall;
|
2022-08-19 23:07:44 +00:00
|
|
|
logic IgnoreRequestTLB;
|
2022-01-31 18:11:42 +00:00
|
|
|
logic BusCommittedM, DCacheCommittedM;
|
2022-02-17 05:37:36 +00:00
|
|
|
logic DataDAPageFaultM;
|
2022-08-23 15:34:39 +00:00
|
|
|
logic [`XLEN-1:0] IMWriteDataM, IMAWriteDataM;
|
|
|
|
logic [`LLEN-1:0] IMAFWriteDataM;
|
2022-06-20 22:53:13 +00:00
|
|
|
logic [`LLEN-1:0] ReadDataM;
|
2022-08-23 15:34:39 +00:00
|
|
|
logic [(`LLEN-1)/8:0] ByteMaskM;
|
2022-03-10 21:48:31 +00:00
|
|
|
|
2022-01-15 00:24:16 +00:00
|
|
|
flopenrc #(`XLEN) AddressMReg(clk, reset, FlushM, ~StallM, IEUAdrE, IEUAdrM);
|
2022-01-31 19:16:23 +00:00
|
|
|
assign IEUAdrExtM = {2'b00, IEUAdrM};
|
2022-08-28 04:44:17 +00:00
|
|
|
assign IEUAdrExtE = {2'b00, IEUAdrE};
|
2022-01-31 19:16:23 +00:00
|
|
|
assign LSUStallM = DCacheStallM | InterlockStall | BusStall;
|
2022-01-31 18:11:42 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HPTW and Interlock FSM (only needed if VM supported)
|
|
|
|
// MMU include PMP and is needed if any privileged supported
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
2022-01-05 16:25:08 +00:00
|
|
|
|
2022-02-03 01:08:34 +00:00
|
|
|
if(`VIRTMEM_SUPPORTED) begin : VIRTMEM_SUPPORTED
|
2022-08-28 03:31:09 +00:00
|
|
|
lsuvirtmem lsuvirtmem(.clk, .reset, .StallW, .MemRWM(NonDTIMMemRWM), .AtomicM, .ITLBMissF, .ITLBWriteF,
|
2022-03-04 00:07:31 +00:00
|
|
|
.DTLBMissM, .DTLBWriteM, .InstrDAPageFaultF, .DataDAPageFaultM,
|
|
|
|
.TrapM, .DCacheStallM, .SATP_REGW, .PCF,
|
|
|
|
.STATUS_MXR, .STATUS_SUM, .STATUS_MPRV, .STATUS_MPP, .PrivilegeModeW,
|
2022-06-20 22:53:13 +00:00
|
|
|
.ReadDataM(ReadDataM[`XLEN-1:0]), .WriteDataM, .Funct3M, .LSUFunct3M, .Funct7M, .LSUFunct7M,
|
2022-08-23 15:34:39 +00:00
|
|
|
.IEUAdrExtM, .PTE, .IMWriteDataM, .PageType, .PreLSURWM, .LSUAtomicM, .IEUAdrE,
|
2022-03-04 00:07:31 +00:00
|
|
|
.LSUAdrE, .PreLSUPAdrM, .CPUBusy, .InterlockStall, .SelHPTW,
|
2022-08-19 23:07:44 +00:00
|
|
|
.IgnoreRequestTLB);
|
2022-01-31 18:11:42 +00:00
|
|
|
end else begin
|
2022-02-10 01:20:10 +00:00
|
|
|
assign {InterlockStall, SelHPTW, PTE, PageType, DTLBWriteM, ITLBWriteF, IgnoreRequestTLB} = '0;
|
2022-08-28 03:31:09 +00:00
|
|
|
assign CPUBusy = StallW; assign PreLSURWM = NonDTIMMemRWM;
|
2022-05-12 15:21:09 +00:00
|
|
|
assign LSUAdrE = IEUAdrE[11:0];
|
2022-03-25 04:47:28 +00:00
|
|
|
assign PreLSUPAdrM = IEUAdrExtM;
|
2022-01-31 19:16:23 +00:00
|
|
|
assign LSUFunct3M = Funct3M; assign LSUFunct7M = Funct7M; assign LSUAtomicM = AtomicM;
|
2022-08-23 15:34:39 +00:00
|
|
|
assign IMWriteDataM = WriteDataM;
|
2022-01-15 00:24:16 +00:00
|
|
|
end
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2022-02-10 17:40:10 +00:00
|
|
|
// CommittedM tells the CPU's privilege unit the current instruction
|
2021-12-29 23:40:24 +00:00
|
|
|
// in the memory stage is a memory operaton and that memory operation is either completed
|
2022-02-10 17:40:10 +00:00
|
|
|
// or is partially executed. Partially completed memory operations need to prevent an interrupts.
|
|
|
|
// There is not a clean way to restore back to a partial executed instruction. CommiteedM will
|
|
|
|
// delay the interrupt until the LSU is in a clean state.
|
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-04-18 03:18:38 +00:00
|
|
|
// *** DH: This is too strong a requirement. Separate MMU in `VIRTMEM_SUPPORTED from simpler faults in `ZICSR_SUPPORTED
|
2022-01-05 16:25:08 +00:00
|
|
|
if(`ZICSR_SUPPORTED == 1) begin : dmmu
|
2022-02-19 20:38:17 +00:00
|
|
|
logic DisableTranslation;
|
|
|
|
assign DisableTranslation = SelHPTW | FlushDCacheM;
|
2022-01-05 16:25:08 +00:00
|
|
|
mmu #(.TLB_ENTRIES(`DTLB_ENTRIES), .IMMU(0))
|
|
|
|
dmmu(.clk, .reset, .SATP_REGW, .STATUS_MXR, .STATUS_SUM, .STATUS_MPRV, .STATUS_MPP,
|
2022-08-28 18:50:50 +00:00
|
|
|
.PrivilegeModeW, .DisableTranslation,
|
2022-03-25 04:47:28 +00:00
|
|
|
.VAdr(PreLSUPAdrM),
|
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),
|
2022-06-02 14:18:55 +00:00
|
|
|
.TLBFlush(sfencevmaM),
|
2022-01-07 04:30:00 +00:00
|
|
|
.PhysicalAddress(LSUPAdrM),
|
2022-01-05 16:25:08 +00:00
|
|
|
.TLBMiss(DTLBMissM),
|
2022-01-28 20:02:05 +00:00
|
|
|
.Cacheable(CacheableM), .Idempotent(), .AtomicAllowed(),
|
2022-01-27 23:11:27 +00:00
|
|
|
.InstrAccessFaultF(), .LoadAccessFaultM, .StoreAmoAccessFaultM,
|
|
|
|
.InstrPageFaultF(),.LoadPageFaultM, .StoreAmoPageFaultM,
|
2022-03-22 21:52:07 +00:00
|
|
|
.LoadMisalignedFaultM, .StoreAmoMisalignedFaultM, // *** these faults need to be supressed during hptw.
|
2022-02-17 05:37:36 +00:00
|
|
|
.DAPageFault(DataDAPageFaultM),
|
2022-02-19 20:38:17 +00:00
|
|
|
// *** should use LSURWM as this is includes the lr/sc squash. However this introduces a combo loop
|
|
|
|
// from squash, depends on LSUPAdrM, depends on TLBHit, depends on these *AccessM inputs.
|
|
|
|
.AtomicAccessM(|LSUAtomicM), .ExecuteAccessF(1'b0),
|
2022-01-07 04:30:00 +00:00
|
|
|
.WriteAccessM(PreLSURWM[0]), .ReadAccessM(PreLSURWM[1]),
|
2022-01-28 20:02:05 +00:00
|
|
|
.PMPCFG_ARRAY_REGW, .PMPADDR_ARRAY_REGW);
|
2022-01-05 16:25:08 +00:00
|
|
|
|
|
|
|
end else begin
|
2022-08-29 14:48:00 +00:00
|
|
|
// Determine which region of physical memory (if any) is being accessed
|
|
|
|
|
|
|
|
// conditionally move adredecs to here and ifu.
|
|
|
|
// the lsu will output LSUHSel to EBU (need the same for ifu).
|
|
|
|
// The ebu will have a mux to select between LSUHSel, IFUHSel
|
|
|
|
// mux for HWSTRB
|
|
|
|
// adrdecs out of uncore.
|
|
|
|
|
2022-01-27 23:11:27 +00:00
|
|
|
assign {DTLBMissM, LoadAccessFaultM, StoreAmoAccessFaultM, LoadMisalignedFaultM, StoreAmoMisalignedFaultM} = '0;
|
|
|
|
assign {LoadPageFaultM, StoreAmoPageFaultM} = '0;
|
2022-01-28 20:02:05 +00:00
|
|
|
assign LSUPAdrM = PreLSUPAdrM;
|
|
|
|
assign CacheableM = '1;
|
2022-01-05 16:25:08 +00:00
|
|
|
end
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2022-01-31 18:11:42 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
2022-02-03 15:36:11 +00:00
|
|
|
// Memory System
|
2022-01-14 23:55:27 +00:00
|
|
|
// Either Data Cache or Data Tightly Integrated Memory or just bus interface
|
2022-01-31 18:11:42 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
2022-08-23 15:34:39 +00:00
|
|
|
logic [`LLEN-1:0] LSUWriteDataM, LittleEndianWriteDataM;
|
2022-06-20 22:53:13 +00:00
|
|
|
logic [`LLEN-1:0] ReadDataWordM, LittleEndianReadDataWordM;
|
|
|
|
logic [`LLEN-1:0] ReadDataWordMuxM;
|
2022-02-10 17:27:15 +00:00
|
|
|
logic IgnoreRequest;
|
2022-08-19 23:07:44 +00:00
|
|
|
assign IgnoreRequest = IgnoreRequestTLB | TrapM;
|
2022-02-05 04:30:04 +00:00
|
|
|
|
2022-08-27 03:26:12 +00:00
|
|
|
if (`DTIM_SUPPORTED) begin : dtim
|
2022-08-27 12:31:56 +00:00
|
|
|
logic [`PA_BITS-1:0] DTIMAdr;
|
|
|
|
logic DTIMAccessRW;
|
2022-08-28 03:31:09 +00:00
|
|
|
logic MemStage;
|
2022-08-27 12:31:56 +00:00
|
|
|
|
2022-08-27 03:12:03 +00:00
|
|
|
// The DTIM uses untranslated addresses, so it is not compatible with virtual memory.
|
2022-08-27 12:31:56 +00:00
|
|
|
// Don't perform size checking on DTIM
|
|
|
|
/* verilator lint_off WIDTH */
|
2022-08-28 03:31:09 +00:00
|
|
|
assign MemStage = CPUBusy | MemRWM[0] | reset; // 1 = M stage; 0 = E stage
|
2022-08-28 04:44:17 +00:00
|
|
|
assign DTIMAdr = MemStage ? IEUAdrExtM : IEUAdrExtE; // zero extend or contract to PA_BITS
|
2022-08-27 12:31:56 +00:00
|
|
|
/* verilator lint_on WIDTH */
|
|
|
|
assign DTIMAccessRW = |MemRWM;
|
2022-08-28 18:50:50 +00:00
|
|
|
adrdec dtimdec(IEUAdrExtM, `DTIM_BASE, `DTIM_RANGE, `DTIM_SUPPORTED, DTIMAccessRW, 2'b10, 4'b1111, SelDTIM); // maybe we pull this out of the mmu?
|
|
|
|
//assign NonDTIMMemRWM = MemRWM & ~{2{SelDTIM}}; // disable access to bus-based memory map when DTIM is selected
|
|
|
|
assign NonDTIMMemRWM = MemRWM; // *** fix
|
2022-08-27 12:31:56 +00:00
|
|
|
|
|
|
|
dtim dtim(.clk, .reset, .MemRWM,
|
|
|
|
.Adr(DTIMAdr),
|
2022-08-25 20:52:25 +00:00
|
|
|
.TrapM, .WriteDataM(LSUWriteDataM),
|
2022-08-26 01:52:42 +00:00
|
|
|
.ReadDataWordM(ReadDataWordM[`XLEN-1:0]), .ByteMaskM(ByteMaskM[`XLEN/8-1:0]));
|
2022-08-27 12:31:56 +00:00
|
|
|
end else begin
|
2022-08-28 03:31:09 +00:00
|
|
|
assign SelDTIM = 0; assign NonDTIMMemRWM = MemRWM;
|
2022-08-27 12:31:56 +00:00
|
|
|
end
|
2022-08-26 03:02:38 +00:00
|
|
|
if (`BUS) begin : bus
|
2022-08-24 17:35:15 +00:00
|
|
|
localparam integer WORDSPERLINE = `DCACHE ? `DCACHE_LINELENINBITS/`XLEN : 1;
|
|
|
|
localparam integer LOGBWPL = `DCACHE ? $clog2(WORDSPERLINE) : 1;
|
|
|
|
if(`DCACHE) begin : dcache
|
2022-08-26 03:02:38 +00:00
|
|
|
localparam integer LINELEN = `DCACHE ? `DCACHE_LINELENINBITS : `XLEN;
|
|
|
|
logic [LINELEN-1:0] FetchBuffer;
|
|
|
|
logic [`PA_BITS-1:0] DCacheBusAdr;
|
|
|
|
logic DCacheWriteLine;
|
|
|
|
logic DCacheFetchLine;
|
|
|
|
logic [LOGBWPL-1:0] WordCount;
|
2022-08-26 01:17:34 +00:00
|
|
|
logic SelUncachedAdr, DCacheBusAck;
|
2022-08-26 03:02:38 +00:00
|
|
|
logic SelBusWord;
|
2022-08-30 20:27:19 +00:00
|
|
|
logic [`XLEN-1:0] LSUHWDATA_noDELAY; //*** change name
|
|
|
|
logic [`XLEN/8-1:0] ByteMaskMDelay;
|
2022-08-31 16:21:02 +00:00
|
|
|
logic [1:0] CacheRW, UnCacheRW;
|
|
|
|
|
|
|
|
assign CacheRW = {DCacheFetchLine, DCacheWriteLine} & ~{IgnoreRequest, IgnoreRequest};
|
|
|
|
assign UnCacheRW = LSURWM & ~{IgnoreRequest, IgnoreRequest} & ~{CacheableM, CacheableM};
|
2022-08-26 01:15:59 +00:00
|
|
|
|
2022-01-15 00:39:07 +00:00
|
|
|
cache #(.LINELEN(`DCACHE_LINELENINBITS), .NUMLINES(`DCACHE_WAYSIZEINBYTES*8/LINELEN),
|
2022-08-02 02:06:36 +00:00
|
|
|
.NUMWAYS(`DCACHE_NUMWAYS), .LOGBWPL(LOGBWPL), .WORDLEN(`LLEN), .MUXINTERVAL(`XLEN), .DCACHE(1)) dcache(
|
2022-08-25 18:18:13 +00:00
|
|
|
.clk, .reset, .CPUBusy, .SelBusWord, .RW(LSURWM), .Atomic(LSUAtomicM),
|
2022-02-10 17:27:15 +00:00
|
|
|
.FlushCache(FlushDCacheM), .NextAdr(LSUAdrE), .PAdr(LSUPAdrM),
|
2022-08-23 15:34:39 +00:00
|
|
|
.ByteMask(ByteMaskM), .WordCount,
|
|
|
|
.FinalWriteData(LSUWriteDataM), .Cacheable(CacheableM),
|
2022-02-03 15:36:11 +00:00
|
|
|
.CacheStall(DCacheStallM), .CacheMiss(DCacheMiss), .CacheAccess(DCacheAccess),
|
2022-08-21 20:59:54 +00:00
|
|
|
.IgnoreRequestTLB, .TrapM, .CacheCommitted(DCacheCommittedM),
|
2022-03-11 17:03:36 +00:00
|
|
|
.CacheBusAdr(DCacheBusAdr), .ReadDataWord(ReadDataWordM),
|
2022-08-25 17:44:39 +00:00
|
|
|
.FetchBuffer, .CacheFetchLine(DCacheFetchLine),
|
2022-07-23 04:36:27 +00:00
|
|
|
.CacheWriteLine(DCacheWriteLine), .CacheBusAck(DCacheBusAck), .InvalidateCache(1'b0));
|
2022-08-31 19:12:19 +00:00
|
|
|
ahbcacheinterface #(WORDSPERLINE, LINELEN, LOGBWPL, `DCACHE) ahbcacheinterface(
|
2022-08-30 15:58:07 +00:00
|
|
|
.HCLK(clk), .HRESETn(~reset),
|
|
|
|
.HRDATA,
|
|
|
|
.HSIZE(LSUHSIZE), .HBURST(LSUHBURST), .HTRANS(LSUHTRANS), .HWRITE(LSUHWRITE), .HREADY(LSUHREADY),
|
2022-08-26 00:54:04 +00:00
|
|
|
.WordCount, .SelBusWord,
|
2022-08-31 16:21:02 +00:00
|
|
|
.Funct3(LSUFunct3M), .HADDR(LSUHADDR), .CacheBusAdr(DCacheBusAdr), .CacheRW,
|
2022-08-30 15:58:07 +00:00
|
|
|
.CacheBusAck(DCacheBusAck), .FetchBuffer, .PAdr(LSUPAdrM),
|
2022-08-31 16:21:02 +00:00
|
|
|
.SelUncachedAdr, .RW(UnCacheRW), .CPUBusy,
|
2022-08-26 00:54:04 +00:00
|
|
|
.BusStall, .BusCommitted(BusCommittedM));
|
|
|
|
|
2022-08-30 20:27:19 +00:00
|
|
|
mux2 #(`LLEN) UnCachedDataMux(.d0(LittleEndianReadDataWordM), .d1({{`LLEN-`XLEN{1'b0}}, FetchBuffer[`XLEN-1:0] }),
|
2022-08-26 00:54:04 +00:00
|
|
|
.s(SelUncachedAdr), .y(ReadDataWordMuxM));
|
|
|
|
mux2 #(`XLEN) LSUHWDATAMux(.d0(ReadDataWordM[`XLEN-1:0]), .d1(LSUWriteDataM[`XLEN-1:0]),
|
2022-08-30 20:27:19 +00:00
|
|
|
.s(SelUncachedAdr), .y(LSUHWDATA_noDELAY));
|
|
|
|
|
|
|
|
flop #(`XLEN) wdreg(clk, LSUHWDATA_noDELAY, LSUHWDATA); // delay HWDATA by 1 cycle per spec; *** assumes AHBW = XLEN
|
2022-08-30 21:23:10 +00:00
|
|
|
|
|
|
|
// *** bummer need a second byte mask for bus as it is XLEN rather than LLEN.
|
2022-08-31 14:50:39 +00:00
|
|
|
// probably can merge by muxing LSUPAdrM's LLEN/8-1 index bit based on HTRANS being != 0.
|
2022-08-30 21:23:10 +00:00
|
|
|
logic [`XLEN/8-1:0] BusByteMaskM;
|
2022-08-30 23:08:34 +00:00
|
|
|
swbytemask #(`XLEN) busswbytemask(.Size(LSUHSIZE), .Adr(LSUPAdrM[$clog2(`XLEN/8)-1:0]), .ByteMask(BusByteMaskM));
|
2022-08-30 21:23:10 +00:00
|
|
|
|
|
|
|
flop #(`XLEN/8) HWSTRBReg(clk, BusByteMaskM[`XLEN/8-1:0], LSUHWSTRB);
|
2022-08-30 20:27:19 +00:00
|
|
|
|
2022-08-26 00:54:04 +00:00
|
|
|
end else begin : passthrough // just needs a register to hold the value from the bus
|
2022-08-29 22:04:53 +00:00
|
|
|
logic CaptureEn;
|
2022-08-31 16:21:02 +00:00
|
|
|
logic [1:0] RW;
|
|
|
|
assign RW = LSURWM & ~{IgnoreRequest, IgnoreRequest};
|
|
|
|
|
2022-08-26 03:02:38 +00:00
|
|
|
assign LSUHADDR = LSUPAdrM;
|
|
|
|
assign LSUHSIZE = LSUFunct3M;
|
2022-08-26 00:54:04 +00:00
|
|
|
|
2022-08-31 19:45:01 +00:00
|
|
|
ahbinterface #(1) ahbinterface(.HCLK(clk), .HRESETn(~reset), .HREADY(LSUHREADY),
|
|
|
|
.HRDATA(HRDATA), .HTRANS(LSUHTRANS), .HWRITE(LSUHWRITE), .HWDATA(LSUHWDATA),
|
2022-08-31 19:49:08 +00:00
|
|
|
.HWSTRB(LSUHWSTRB), .RW, .ByteMask(ByteMaskM), .WriteData(LSUWriteDataM),
|
|
|
|
.CPUBusy, .BusStall, .BusCommitted(BusCommittedM), .ReadDataWordM);
|
2022-08-29 18:01:24 +00:00
|
|
|
|
2022-08-28 18:50:50 +00:00
|
|
|
assign ReadDataWordMuxM = LittleEndianReadDataWordM; // from byte swapping
|
2022-08-26 01:30:46 +00:00
|
|
|
assign LSUHBURST = 3'b0;
|
2022-08-27 02:58:04 +00:00
|
|
|
assign {DCacheStallM, DCacheCommittedM, DCacheMiss, DCacheAccess} = '0;
|
|
|
|
end
|
2022-03-11 21:18:56 +00:00
|
|
|
end else begin: nobus // block: bus
|
2022-08-26 01:15:59 +00:00
|
|
|
assign LSUHWDATA = '0;
|
2022-05-08 06:46:35 +00:00
|
|
|
assign ReadDataWordMuxM = LittleEndianReadDataWordM;
|
2022-08-26 01:52:42 +00:00
|
|
|
assign {BusStall, BusCommittedM} = '0;
|
|
|
|
assign {DCacheMiss, DCacheAccess} = '0;
|
|
|
|
assign {DCacheStallM, DCacheCommittedM} = '0;
|
2022-01-13 23:00:46 +00:00
|
|
|
end
|
2022-01-14 23:55:27 +00:00
|
|
|
|
2022-01-31 18:11:42 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
2022-01-14 23:55:27 +00:00
|
|
|
// Atomic operations
|
2022-01-31 18:11:42 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
2022-01-31 18:54:18 +00:00
|
|
|
if (`A_SUPPORTED) begin:atomic
|
2022-08-23 15:34:39 +00:00
|
|
|
atomic atomic(.clk, .reset, .StallW, .ReadDataM(ReadDataM[`XLEN-1:0]), .IMWriteDataM, .LSUPAdrM,
|
2022-02-10 17:27:15 +00:00
|
|
|
.LSUFunct7M, .LSUFunct3M, .LSUAtomicM, .PreLSURWM, .IgnoreRequest,
|
2022-08-23 15:34:39 +00:00
|
|
|
.IMAWriteDataM, .SquashSCW, .LSURWM);
|
2022-01-14 23:55:27 +00:00
|
|
|
end else begin:lrsc
|
2022-08-23 15:34:39 +00:00
|
|
|
assign SquashSCW = 0; assign LSURWM = PreLSURWM; assign IMAWriteDataM = IMWriteDataM;
|
2022-01-14 23:55:27 +00:00
|
|
|
end
|
2022-03-11 00:44:50 +00:00
|
|
|
|
2022-08-23 15:34:39 +00:00
|
|
|
if (`F_SUPPORTED)
|
2022-08-23 15:43:47 +00:00
|
|
|
mux2 #(`LLEN) datamux({{{`LLEN-`XLEN}{1'b0}}, IMAWriteDataM}, FWriteDataM, FpLoadStoreM, IMAFWriteDataM);
|
2022-08-23 15:34:39 +00:00
|
|
|
else assign IMAFWriteDataM = IMAWriteDataM;
|
|
|
|
|
2022-05-08 06:46:35 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Subword Accesses
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
subwordread subwordread(.ReadDataWordMuxM, .LSUPAdrM(LSUPAdrM[2:0]),
|
2022-06-28 21:33:31 +00:00
|
|
|
.FpLoadStoreM, .Funct3M(LSUFunct3M), .ReadDataM);
|
2022-07-05 15:51:35 +00:00
|
|
|
subwordwrite subwordwrite(.LSUPAdrM(LSUPAdrM[2:0]),
|
2022-08-23 15:34:39 +00:00
|
|
|
.LSUFunct3M, .IMAFWriteDataM, .LittleEndianWriteDataM);
|
2022-08-02 01:48:45 +00:00
|
|
|
|
|
|
|
// Compute byte masks
|
2022-08-26 00:32:16 +00:00
|
|
|
swbytemask #(`LLEN) swbytemask(.Size(LSUFunct3M), .Adr(LSUPAdrM[$clog2(`LLEN/8)-1:0]), .ByteMask(ByteMaskM));
|
2022-06-20 22:53:13 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// MW Pipeline Register
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
flopen #(`LLEN) ReadDataMWReg(clk, ~StallW, ReadDataM, ReadDataW);
|
2022-05-08 06:46:35 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Big Endian Byte Swapper
|
|
|
|
// hart works little-endian internally
|
|
|
|
// swap the bytes when read from big-endian memory
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
if (`BIGENDIAN_SUPPORTED) begin:endian
|
2022-08-23 15:34:39 +00:00
|
|
|
bigendianswap #(`LLEN) storeswap(.BigEndianM, .a(LittleEndianWriteDataM), .y(LSUWriteDataM));
|
2022-06-20 22:53:13 +00:00
|
|
|
bigendianswap #(`LLEN) loadswap(.BigEndianM, .a(ReadDataWordM), .y(LittleEndianReadDataWordM));
|
2022-05-08 06:46:35 +00:00
|
|
|
end else begin
|
2022-08-23 15:34:39 +00:00
|
|
|
assign LSUWriteDataM = LittleEndianWriteDataM;
|
2022-05-08 06:46:35 +00:00
|
|
|
assign LittleEndianReadDataWordM = ReadDataWordM;
|
|
|
|
end
|
2022-03-11 00:44:50 +00:00
|
|
|
|
2021-06-23 05:41:00 +00:00
|
|
|
endmodule
|