2021-06-23 05:41:00 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// lsu.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu 9 January 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: Load/Store Unit
|
|
|
|
// Top level of the memory-stage hart logic
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
// *** Ross Thompson amo misalignment check?
|
2021-07-06 15:41:36 +00:00
|
|
|
module lsu
|
|
|
|
(
|
|
|
|
input logic clk, reset,
|
|
|
|
input logic StallM, FlushM, StallW, FlushW,
|
2021-07-09 20:16:38 +00:00
|
|
|
output logic LSUStall,
|
2021-07-06 15:41:36 +00:00
|
|
|
// Memory Stage
|
|
|
|
|
|
|
|
// connected to cpu (controls)
|
|
|
|
input logic [1:0] MemRWM,
|
|
|
|
input logic [2:0] Funct3M,
|
2021-07-09 20:16:38 +00:00
|
|
|
input logic [6:0] Funct7M,
|
2021-07-06 15:41:36 +00:00
|
|
|
input logic [1:0] AtomicM,
|
2021-07-14 20:00:33 +00:00
|
|
|
input logic ExceptionM,
|
|
|
|
input logic PendingInterruptM,
|
2021-07-06 15:41:36 +00:00
|
|
|
output logic CommittedM,
|
|
|
|
output logic SquashSCW,
|
|
|
|
output logic DataMisalignedM,
|
2021-07-20 03:12:20 +00:00
|
|
|
output logic DCacheMiss,
|
|
|
|
output logic DCacheAccess,
|
2021-07-06 15:41:36 +00:00
|
|
|
|
|
|
|
// address and write data
|
|
|
|
input logic [`XLEN-1:0] MemAdrM,
|
2021-07-09 20:16:38 +00:00
|
|
|
input logic [`XLEN-1:0] MemAdrE,
|
2021-07-06 15:41:36 +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
|
|
|
|
input logic [1:0] PrivilegeModeW,
|
|
|
|
input logic DTLBFlushM,
|
|
|
|
// faults
|
|
|
|
output logic DTLBLoadPageFaultM, DTLBStorePageFaultM,
|
|
|
|
output logic LoadMisalignedFaultM, LoadAccessFaultM,
|
|
|
|
// cpu hazard unit (trap)
|
|
|
|
output logic StoreMisalignedFaultM, StoreAccessFaultM,
|
|
|
|
|
|
|
|
// connect to ahb
|
|
|
|
input logic CommitM, // should this be generated in the abh interface?
|
2021-07-13 22:24:59 +00:00
|
|
|
output logic [`PA_BITS-1:0] DCtoAHBPAdrM,
|
2021-07-09 20:16:38 +00:00
|
|
|
output logic DCtoAHBReadM,
|
|
|
|
output logic DCtoAHBWriteM,
|
2021-07-13 22:24:59 +00:00
|
|
|
input logic DCfromAHBAck,
|
|
|
|
input logic [`XLEN-1:0] DCfromAHBReadData,
|
|
|
|
output logic [`XLEN-1:0] DCtoAHBWriteData,
|
|
|
|
output logic [2:0] DCtoAHBSizeM,
|
2021-07-06 15:41:36 +00:00
|
|
|
|
|
|
|
// mmu management
|
|
|
|
|
|
|
|
// 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,
|
2021-07-17 19:01:01 +00:00
|
|
|
output logic [`XLEN-1:0] PTE,
|
2021-07-17 06:31:23 +00:00
|
|
|
output logic [1:0] PageType,
|
2021-07-06 15:41:36 +00:00
|
|
|
output logic ITLBWriteF,
|
|
|
|
output logic WalkerInstrPageFaultF,
|
|
|
|
output logic WalkerLoadPageFaultM,
|
|
|
|
output logic WalkerStorePageFaultM,
|
|
|
|
|
|
|
|
output logic DTLBHitM, // not connected
|
|
|
|
|
|
|
|
input var logic [7:0] PMPCFG_ARRAY_REGW[`PMP_ENTRIES-1:0],
|
2021-07-09 20:16:38 +00:00
|
|
|
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.
|
2021-07-06 15:41:36 +00:00
|
|
|
|
|
|
|
// output logic [5:0] DHSELRegionsM
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
logic SquashSCM;
|
|
|
|
logic DTLBPageFaultM;
|
|
|
|
logic MemAccessM;
|
|
|
|
|
2021-07-14 03:43:42 +00:00
|
|
|
/* -----\/----- EXCLUDED -----\/-----
|
2021-07-06 15:41:36 +00:00
|
|
|
logic preCommittedM;
|
2021-07-14 03:43:42 +00:00
|
|
|
-----/\----- EXCLUDED -----/\----- */
|
2021-07-06 15:41:36 +00:00
|
|
|
|
|
|
|
typedef enum {STATE_READY,
|
|
|
|
STATE_FETCH,
|
|
|
|
STATE_FETCH_AMO_1,
|
|
|
|
STATE_FETCH_AMO_2,
|
|
|
|
STATE_STALLED,
|
|
|
|
STATE_PTW_READY,
|
|
|
|
STATE_PTW_FETCH,
|
|
|
|
STATE_PTW_DONE} statetype;
|
2021-06-30 21:25:03 +00:00
|
|
|
statetype CurrState, NextState;
|
2021-07-06 15:41:36 +00:00
|
|
|
|
2021-07-09 20:16:38 +00:00
|
|
|
logic [`PA_BITS-1:0] MemPAdrM; // from mmu to dcache
|
2021-07-15 16:55:20 +00:00
|
|
|
|
2021-07-06 15:41:36 +00:00
|
|
|
logic DTLBMissM;
|
2021-07-17 19:01:01 +00:00
|
|
|
// logic [`XLEN-1:0] PTE;
|
2021-07-06 15:41:36 +00:00
|
|
|
logic DTLBWriteM;
|
|
|
|
logic HPTWStall;
|
2021-07-15 03:26:07 +00:00
|
|
|
logic [`XLEN-1:0] HPTWPAdrE;
|
2021-07-17 23:39:18 +00:00
|
|
|
// logic [`XLEN-1:0] HPTWPAdrM;
|
2021-07-17 23:02:18 +00:00
|
|
|
logic [`PA_BITS-1:0] TranslationPAdr;
|
2021-07-06 15:41:36 +00:00
|
|
|
logic HPTWRead;
|
2021-07-08 23:03:52 +00:00
|
|
|
logic [1:0] MemRWMtoDCache;
|
2021-07-18 01:58:49 +00:00
|
|
|
logic [1:0] MemRWMtoLRSC;
|
2021-07-09 20:16:38 +00:00
|
|
|
logic [2:0] Funct3MtoDCache;
|
2021-07-08 23:03:52 +00:00
|
|
|
logic [1:0] AtomicMtoDCache;
|
2021-07-19 15:33:27 +00:00
|
|
|
logic [`PA_BITS-1:0] MemPAdrMtoDCache;
|
|
|
|
logic [11:0] MemAdrEtoDCache;
|
2021-07-08 23:03:52 +00:00
|
|
|
logic [`XLEN-1:0] ReadDataWfromDCache;
|
|
|
|
logic StallWtoDCache;
|
2021-07-18 01:11:41 +00:00
|
|
|
logic MemReadM;
|
2021-07-08 23:03:52 +00:00
|
|
|
logic DataMisalignedMfromDCache;
|
2021-07-06 15:41:36 +00:00
|
|
|
logic HPTWReady;
|
|
|
|
logic DisableTranslation; // used to stop intermediate PTE physical addresses being saved to TLB.
|
2021-07-09 20:16:38 +00:00
|
|
|
logic DCacheStall;
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2021-07-13 22:24:59 +00:00
|
|
|
logic CacheableM;
|
2021-07-15 03:26:07 +00:00
|
|
|
logic CacheableMtoDCache;
|
|
|
|
logic SelPTW;
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2021-07-14 21:18:09 +00:00
|
|
|
logic CommittedMfromDCache;
|
|
|
|
logic PendingInterruptMtoDCache;
|
2021-07-15 15:16:16 +00:00
|
|
|
logic FlushWtoDCache;
|
2021-07-16 17:22:13 +00:00
|
|
|
logic WalkerPageFaultM;
|
2021-07-23 00:42:19 +00:00
|
|
|
|
|
|
|
logic [`XLEN-1:0] LSUData;
|
|
|
|
|
2021-07-18 08:11:33 +00:00
|
|
|
hptw hptw(
|
2021-07-19 15:33:27 +00:00
|
|
|
.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.SATP_REGW(SATP_REGW),
|
|
|
|
.PCF(PCF),
|
|
|
|
.MemAdrM(MemAdrM),
|
|
|
|
.ITLBMissF(ITLBMissF),
|
|
|
|
.DTLBMissM(DTLBMissM),
|
|
|
|
.MemRWM(MemRWM),
|
|
|
|
.PTE(PTE),
|
|
|
|
.PageType,
|
|
|
|
.ITLBWriteF(ITLBWriteF),
|
|
|
|
.DTLBWriteM(DTLBWriteM),
|
2021-07-23 00:42:19 +00:00
|
|
|
.HPTWReadPTE(LSUData),
|
2021-07-19 15:33:27 +00:00
|
|
|
.HPTWStall(HPTWStall),
|
|
|
|
.TranslationPAdr,
|
|
|
|
.HPTWRead(HPTWRead),
|
|
|
|
.SelPTW(SelPTW),
|
|
|
|
.WalkerInstrPageFaultF(WalkerInstrPageFaultF),
|
|
|
|
.WalkerLoadPageFaultM(WalkerLoadPageFaultM),
|
|
|
|
.WalkerStorePageFaultM(WalkerStorePageFaultM));
|
2021-07-17 18:48:44 +00:00
|
|
|
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2021-07-16 17:22:13 +00:00
|
|
|
assign WalkerPageFaultM = WalkerStorePageFaultM | WalkerLoadPageFaultM;
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2021-07-18 08:11:33 +00:00
|
|
|
// arbiter between IEU and hptw
|
2021-07-04 18:49:38 +00:00
|
|
|
lsuArb arbiter(.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
// HPTW connection
|
2021-07-16 16:12:57 +00:00
|
|
|
.SelPTW(SelPTW),
|
2021-07-04 18:49:38 +00:00
|
|
|
.HPTWRead(HPTWRead),
|
2021-07-19 15:33:27 +00:00
|
|
|
.TranslationPAdrE(TranslationPAdr),
|
2021-07-04 18:49:38 +00:00
|
|
|
.HPTWStall(HPTWStall),
|
|
|
|
// CPU connection
|
|
|
|
.MemRWM(MemRWM),
|
|
|
|
.Funct3M(Funct3M),
|
|
|
|
.AtomicM(AtomicM),
|
|
|
|
.MemAdrM(MemAdrM),
|
2021-07-15 03:26:07 +00:00
|
|
|
.MemAdrE(MemAdrE),
|
2021-07-14 21:18:09 +00:00
|
|
|
.CommittedM(CommittedM),
|
|
|
|
.PendingInterruptM(PendingInterruptM),
|
2021-07-04 18:49:38 +00:00
|
|
|
.StallW(StallW),
|
|
|
|
.DataMisalignedM(DataMisalignedM),
|
2021-07-09 20:16:38 +00:00
|
|
|
.LSUStall(LSUStall),
|
|
|
|
// DCACHE
|
2021-07-04 18:49:38 +00:00
|
|
|
.DisableTranslation(DisableTranslation),
|
2021-07-18 01:58:49 +00:00
|
|
|
.MemRWMtoLRSC(MemRWMtoLRSC),
|
2021-07-09 20:16:38 +00:00
|
|
|
.Funct3MtoDCache(Funct3MtoDCache),
|
2021-07-08 23:03:52 +00:00
|
|
|
.AtomicMtoDCache(AtomicMtoDCache),
|
2021-07-19 15:33:27 +00:00
|
|
|
.MemPAdrMtoDCache(MemPAdrMtoDCache),
|
2021-07-15 03:26:07 +00:00
|
|
|
.MemAdrEtoDCache(MemAdrEtoDCache),
|
2021-07-08 23:03:52 +00:00
|
|
|
.StallWtoDCache(StallWtoDCache),
|
|
|
|
.DataMisalignedMfromDCache(DataMisalignedMfromDCache),
|
2021-07-14 21:18:09 +00:00
|
|
|
.CommittedMfromDCache(CommittedMfromDCache),
|
|
|
|
.PendingInterruptMtoDCache(PendingInterruptMtoDCache),
|
2021-07-16 16:12:57 +00:00
|
|
|
.DCacheStall(DCacheStall));
|
2021-07-04 18:49:38 +00:00
|
|
|
|
2021-07-16 16:12:57 +00:00
|
|
|
|
2021-07-09 20:16:38 +00:00
|
|
|
|
2021-07-06 15:41:36 +00:00
|
|
|
|
2021-07-04 22:05:22 +00:00
|
|
|
mmu #(.TLB_ENTRIES(`DTLB_ENTRIES), .IMMU(0))
|
2021-07-19 15:33:27 +00:00
|
|
|
dmmu(.PAdr(MemPAdrMtoDCache),
|
|
|
|
.VAdr(MemAdrM),
|
2021-07-09 20:16:38 +00:00
|
|
|
.Size(Funct3MtoDCache[1:0]),
|
2021-07-17 19:01:01 +00:00
|
|
|
.PTE(PTE),
|
2021-07-17 06:31:23 +00:00
|
|
|
.PageTypeWriteVal(PageType),
|
2021-06-24 18:05:22 +00:00
|
|
|
.TLBWrite(DTLBWriteM),
|
|
|
|
.TLBFlush(DTLBFlushM),
|
|
|
|
.PhysicalAddress(MemPAdrM),
|
|
|
|
.TLBMiss(DTLBMissM),
|
|
|
|
.TLBHit(DTLBHitM),
|
|
|
|
.TLBPageFault(DTLBPageFaultM),
|
2021-07-02 18:56:49 +00:00
|
|
|
.ExecuteAccessF(1'b0),
|
2021-07-09 20:16:38 +00:00
|
|
|
//.AtomicAccessM(AtomicMaskedM[1]),
|
|
|
|
.AtomicAccessM(1'b0),
|
2021-07-18 01:58:49 +00:00
|
|
|
.WriteAccessM(MemRWMtoLRSC[0]),
|
|
|
|
.ReadAccessM(MemRWMtoLRSC[1]),
|
2021-07-09 20:16:38 +00:00
|
|
|
.SquashBusAccess(),
|
2021-07-04 18:49:38 +00:00
|
|
|
.DisableTranslation(DisableTranslation),
|
2021-07-06 18:43:53 +00:00
|
|
|
.InstrAccessFaultF(),
|
2021-07-13 22:24:59 +00:00
|
|
|
.Cacheable(CacheableM),
|
|
|
|
.Idempotent(),
|
|
|
|
.AtomicAllowed(),
|
2021-06-24 18:05:22 +00:00
|
|
|
.*); // *** the pma/pmp instruction acess faults don't really matter here. is it possible to parameterize which outputs exist?
|
2021-06-23 05:41:00 +00:00
|
|
|
|
2021-07-18 01:58:49 +00:00
|
|
|
|
|
|
|
assign MemReadM = MemRWMtoLRSC[1] & ~(ExceptionM | PendingInterruptMtoDCache) & ~DTLBMissM; // & ~NonBusTrapM & ~DTLBMissM & CurrState != STATE_STALLED;
|
|
|
|
lrsc lrsc(.clk, .reset, .FlushW, .StallWtoDCache, .MemReadM, .MemRWMtoLRSC, .AtomicMtoDCache, .MemPAdrM,
|
|
|
|
.SquashSCM, .SquashSCW, .MemRWMtoDCache);
|
2021-07-18 01:11:41 +00:00
|
|
|
|
2021-07-16 16:12:57 +00:00
|
|
|
// *** BUG, this is most likely wrong
|
2021-07-15 03:26:07 +00:00
|
|
|
assign CacheableMtoDCache = SelPTW ? 1'b1 : CacheableM;
|
2021-07-16 16:12:57 +00:00
|
|
|
|
2021-07-13 22:24:59 +00:00
|
|
|
generate
|
2021-07-15 03:26:07 +00:00
|
|
|
if (`XLEN == 32) assign DCtoAHBSizeM = CacheableMtoDCache ? 3'b010 : Funct3MtoDCache;
|
|
|
|
else assign DCtoAHBSizeM = CacheableMtoDCache ? 3'b011 : Funct3MtoDCache;
|
2021-07-13 22:24:59 +00:00
|
|
|
endgenerate;
|
|
|
|
|
|
|
|
|
2021-06-23 05:41:00 +00:00
|
|
|
// Specify which type of page fault is occurring
|
2021-07-18 01:58:49 +00:00
|
|
|
assign DTLBLoadPageFaultM = DTLBPageFaultM & MemRWMtoLRSC[1];
|
|
|
|
assign DTLBStorePageFaultM = DTLBPageFaultM & MemRWMtoLRSC[0];
|
2021-06-23 05:41:00 +00:00
|
|
|
|
2021-06-24 18:05:22 +00:00
|
|
|
// Determine if an Unaligned access is taking place
|
|
|
|
always_comb
|
2021-07-09 20:16:38 +00:00
|
|
|
case(Funct3MtoDCache[1:0])
|
2021-07-08 23:03:52 +00:00
|
|
|
2'b00: DataMisalignedMfromDCache = 0; // lb, sb, lbu
|
2021-07-19 15:33:27 +00:00
|
|
|
2'b01: DataMisalignedMfromDCache = MemPAdrMtoDCache[0]; // lh, sh, lhu
|
|
|
|
2'b10: DataMisalignedMfromDCache = MemPAdrMtoDCache[1] | MemPAdrMtoDCache[0]; // lw, sw, flw, fsw, lwu
|
|
|
|
2'b11: DataMisalignedMfromDCache = |MemPAdrMtoDCache[2:0]; // ld, sd, fld, fsd
|
2021-06-24 18:05:22 +00:00
|
|
|
endcase
|
2021-06-23 05:41:00 +00:00
|
|
|
|
|
|
|
// Squash unaligned data accesses and failed store conditionals
|
|
|
|
// *** this is also the place to squash if the cache is hit
|
2021-07-08 23:03:52 +00:00
|
|
|
// Changed DataMisalignedMfromDCache to a larger combination of trap sources
|
2021-06-23 05:41:00 +00:00
|
|
|
// NonBusTrapM is anything that the bus doesn't contribute to producing
|
|
|
|
// By contrast, using TrapM results in circular logic errors
|
2021-07-09 20:16:38 +00:00
|
|
|
/* -----\/----- EXCLUDED -----\/-----
|
|
|
|
|
|
|
|
// *** BUG for now leave this out. come back later after the d cache is working. July 09, 2021
|
|
|
|
|
2021-07-18 01:58:49 +00:00
|
|
|
assign MemReadM = MemRWMtoLRSC[1] & ~NonBusTrapM & ~DTLBMissM & CurrState != STATE_STALLED;
|
|
|
|
assign MemWriteM = MemRWMtoLRSC[0] & ~NonBusTrapM & ~DTLBMissM & ~SquashSCM & CurrState != STATE_STALLED;
|
2021-07-08 23:03:52 +00:00
|
|
|
assign AtomicMaskedM = CurrState != STATE_STALLED ? AtomicMtoDCache : 2'b00 ;
|
2021-06-25 16:00:42 +00:00
|
|
|
assign MemAccessM = MemReadM | MemWriteM;
|
2021-06-23 05:41:00 +00:00
|
|
|
|
|
|
|
// Determine if M stage committed
|
|
|
|
// Reset whenever unstalled. Set when access successfully occurs
|
2021-07-08 23:03:52 +00:00
|
|
|
flopr #(1) committedMreg(clk,reset,(CommittedMfromDCache | CommitM) & StallM,preCommittedM);
|
|
|
|
assign CommittedMfromDCache = preCommittedM | CommitM;
|
2021-06-23 05:41:00 +00:00
|
|
|
|
|
|
|
|
2021-07-09 20:16:38 +00:00
|
|
|
-----/\----- EXCLUDED -----/\----- */
|
|
|
|
|
2021-07-09 22:14:54 +00:00
|
|
|
// Determine if address is valid
|
2021-07-18 01:58:49 +00:00
|
|
|
assign LoadMisalignedFaultM = DataMisalignedMfromDCache & MemRWMtoLRSC[1];
|
|
|
|
assign StoreMisalignedFaultM = DataMisalignedMfromDCache & MemRWMtoLRSC[0];
|
2021-07-09 20:16:38 +00:00
|
|
|
|
|
|
|
dcache dcache(.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.StallM(StallM),
|
2021-07-22 19:51:14 +00:00
|
|
|
.StallWtoDCache(StallWtoDCache),
|
2021-07-09 20:16:38 +00:00
|
|
|
.FlushM(FlushM),
|
2021-07-15 03:26:07 +00:00
|
|
|
.FlushW(FlushWtoDCache),
|
2021-07-09 20:16:38 +00:00
|
|
|
.MemRWM(MemRWMtoDCache),
|
|
|
|
.Funct3M(Funct3MtoDCache),
|
|
|
|
.Funct7M(Funct7M),
|
|
|
|
.AtomicM(AtomicMtoDCache),
|
2021-07-15 03:26:07 +00:00
|
|
|
.MemAdrE(MemAdrEtoDCache),
|
2021-07-09 20:16:38 +00:00
|
|
|
.MemPAdrM(MemPAdrM),
|
2021-07-21 19:55:09 +00:00
|
|
|
.VAdr(MemAdrM[11:0]),
|
2021-07-09 20:16:38 +00:00
|
|
|
.WriteDataM(WriteDataM),
|
2021-07-22 19:51:14 +00:00
|
|
|
.ReadDataM(ReadDataM),
|
2021-07-23 00:42:19 +00:00
|
|
|
.LSUData(LSUData),
|
2021-07-09 20:16:38 +00:00
|
|
|
.DCacheStall(DCacheStall),
|
2021-07-14 21:18:09 +00:00
|
|
|
.CommittedM(CommittedMfromDCache),
|
2021-07-20 03:12:20 +00:00
|
|
|
.DCacheMiss,
|
|
|
|
.DCacheAccess,
|
2021-07-14 20:00:33 +00:00
|
|
|
.ExceptionM(ExceptionM),
|
2021-07-18 01:58:49 +00:00
|
|
|
.PendingInterruptM(PendingInterruptMtoDCache),
|
2021-07-09 20:16:38 +00:00
|
|
|
.DTLBMissM(DTLBMissM),
|
2021-07-15 03:26:07 +00:00
|
|
|
.CacheableM(CacheableMtoDCache),
|
2021-07-14 22:23:28 +00:00
|
|
|
.DTLBWriteM(DTLBWriteM),
|
2021-07-16 20:56:06 +00:00
|
|
|
.ITLBWriteF(ITLBWriteF),
|
2021-07-16 16:12:57 +00:00
|
|
|
.SelPTW(SelPTW),
|
2021-07-16 17:22:13 +00:00
|
|
|
.WalkerPageFaultM(WalkerPageFaultM),
|
2021-07-22 19:04:56 +00:00
|
|
|
.WalkerInstrPageFaultF(WalkerInstrPageFaultF),
|
2021-07-09 20:16:38 +00:00
|
|
|
|
|
|
|
// AHB connection
|
|
|
|
.AHBPAdr(DCtoAHBPAdrM),
|
|
|
|
.AHBRead(DCtoAHBReadM),
|
|
|
|
.AHBWrite(DCtoAHBWriteM),
|
|
|
|
.AHBAck(DCfromAHBAck),
|
|
|
|
.HWDATA(DCtoAHBWriteData),
|
|
|
|
.HRDATA(DCfromAHBReadData)
|
|
|
|
);
|
|
|
|
|
|
|
|
// assign AtomicMaskedM = 2'b00; // *** Remove from AHB
|
|
|
|
|
2021-06-23 05:41:00 +00:00
|
|
|
|
|
|
|
// Data stall
|
2021-07-04 18:49:38 +00:00
|
|
|
//assign LSUStall = (NextState == STATE_FETCH) || (NextState == STATE_FETCH_AMO_1) || (NextState == STATE_FETCH_AMO_2);
|
2021-07-09 20:16:38 +00:00
|
|
|
// BUG *** July 09, 2021
|
|
|
|
//assign HPTWReady = (CurrState == STATE_READY);
|
2021-06-25 20:07:41 +00:00
|
|
|
|
2021-06-23 05:41:00 +00:00
|
|
|
|
|
|
|
// Ross Thompson April 22, 2021
|
|
|
|
// for now we need to handle the issue where the data memory interface repeately
|
|
|
|
// requests data from memory rather than issuing a single request.
|
|
|
|
|
2021-07-09 20:16:38 +00:00
|
|
|
/* -----\/----- EXCLUDED -----\/-----
|
|
|
|
// *** BUG will need to modify this so we can handle the ptw. July 09, 2021
|
2021-06-23 05:41:00 +00:00
|
|
|
|
2021-06-30 21:25:03 +00:00
|
|
|
flopenl #(.TYPE(statetype)) stateReg(.clk(clk),
|
|
|
|
.load(reset),
|
|
|
|
.en(1'b1),
|
|
|
|
.d(NextState),
|
|
|
|
.val(STATE_READY),
|
|
|
|
.q(CurrState));
|
2021-06-23 05:41:00 +00:00
|
|
|
|
|
|
|
always_comb begin
|
|
|
|
case (CurrState)
|
2021-06-25 19:49:27 +00:00
|
|
|
STATE_READY:
|
2021-06-30 21:25:03 +00:00
|
|
|
if (DTLBMissM) begin
|
2021-07-01 17:49:09 +00:00
|
|
|
NextState = STATE_PTW_READY;
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-06-30 21:25:03 +00:00
|
|
|
end else if (AtomicMaskedM[1]) begin
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_FETCH_AMO_1; // *** should be some misalign check
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-07-08 23:03:52 +00:00
|
|
|
end else if((MemReadM & AtomicMtoDCache[0]) | (MemWriteM & AtomicMtoDCache[0])) begin
|
2021-06-25 20:42:07 +00:00
|
|
|
NextState = STATE_FETCH_AMO_2;
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-07-08 23:03:52 +00:00
|
|
|
end else if (MemAccessM & ~DataMisalignedMfromDCache) begin
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_FETCH;
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-06-25 19:49:27 +00:00
|
|
|
end else begin
|
|
|
|
NextState = STATE_READY;
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b0;
|
2021-06-25 19:49:27 +00:00
|
|
|
end
|
2021-06-25 20:07:41 +00:00
|
|
|
STATE_FETCH_AMO_1: begin
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-07-09 20:16:38 +00:00
|
|
|
if (DCfromAHBAck) begin
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_FETCH_AMO_2;
|
|
|
|
end else begin
|
|
|
|
NextState = STATE_FETCH_AMO_1;
|
|
|
|
end
|
2021-06-25 20:07:41 +00:00
|
|
|
end
|
2021-06-25 19:49:27 +00:00
|
|
|
STATE_FETCH_AMO_2: begin
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-07-09 20:16:38 +00:00
|
|
|
if (DCfromAHBAck & ~StallWtoDCache) begin
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_FETCH_AMO_2;
|
2021-07-09 20:16:38 +00:00
|
|
|
end else if (DCfromAHBAck & StallWtoDCache) begin
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_STALLED;
|
|
|
|
end else begin
|
|
|
|
NextState = STATE_FETCH_AMO_2;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_FETCH: begin
|
2021-07-06 15:41:36 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-07-09 20:16:38 +00:00
|
|
|
if (DCfromAHBAck & ~StallWtoDCache) begin
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_READY;
|
2021-07-09 20:16:38 +00:00
|
|
|
end else if (DCfromAHBAck & StallWtoDCache) begin
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_STALLED;
|
|
|
|
end else begin
|
|
|
|
NextState = STATE_FETCH;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_STALLED: begin
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b0;
|
2021-07-08 23:03:52 +00:00
|
|
|
if (~StallWtoDCache) begin
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_READY;
|
|
|
|
end else begin
|
|
|
|
NextState = STATE_STALLED;
|
|
|
|
end
|
|
|
|
end
|
2021-07-01 17:49:09 +00:00
|
|
|
STATE_PTW_READY: begin
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b0;
|
2021-06-30 21:25:03 +00:00
|
|
|
if (DTLBWriteM) begin
|
2021-07-01 21:55:16 +00:00
|
|
|
NextState = STATE_READY;
|
2021-07-06 15:41:36 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-07-08 23:03:52 +00:00
|
|
|
end else if (MemReadM & ~DataMisalignedMfromDCache) begin
|
2021-07-01 17:49:09 +00:00
|
|
|
NextState = STATE_PTW_FETCH;
|
2021-06-30 21:25:03 +00:00
|
|
|
end else begin
|
2021-07-01 17:49:09 +00:00
|
|
|
NextState = STATE_PTW_READY;
|
2021-06-30 21:25:03 +00:00
|
|
|
end
|
|
|
|
end
|
2021-07-01 17:49:09 +00:00
|
|
|
STATE_PTW_FETCH : begin
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b1;
|
2021-07-09 20:16:38 +00:00
|
|
|
if (DCfromAHBAck & ~DTLBWriteM) begin
|
2021-07-01 17:49:09 +00:00
|
|
|
NextState = STATE_PTW_READY;
|
2021-07-09 20:16:38 +00:00
|
|
|
end else if (DCfromAHBAck & DTLBWriteM) begin
|
2021-07-01 21:55:16 +00:00
|
|
|
NextState = STATE_READY;
|
2021-07-01 17:49:09 +00:00
|
|
|
end else begin
|
|
|
|
NextState = STATE_PTW_FETCH;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_PTW_DONE: begin
|
|
|
|
NextState = STATE_READY;
|
|
|
|
end
|
2021-06-25 19:49:27 +00:00
|
|
|
default: begin
|
2021-07-04 18:49:38 +00:00
|
|
|
LSUStall = 1'b0;
|
2021-06-25 19:49:27 +00:00
|
|
|
NextState = STATE_READY;
|
|
|
|
end
|
2021-06-24 23:59:29 +00:00
|
|
|
endcase
|
2021-06-28 22:26:11 +00:00
|
|
|
end // always_comb
|
2021-07-09 20:16:38 +00:00
|
|
|
-----/\----- EXCLUDED -----/\----- */
|
2021-06-28 22:26:11 +00:00
|
|
|
|
2021-06-23 05:41:00 +00:00
|
|
|
|
|
|
|
endmodule
|
|
|
|
|