Updated the ptw, lsuarb and dcache to hopefully solve the interlock issues.

This commit is contained in:
Ross Thompson 2021-07-16 11:12:57 -05:00
parent f01be12162
commit 5ca7dc619c
4 changed files with 399 additions and 524 deletions

View File

@ -53,6 +53,7 @@ module dcache
input logic DTLBMissM, input logic DTLBMissM,
input logic CacheableM, input logic CacheableM,
input logic DTLBWriteM, input logic DTLBWriteM,
input logic SelPTW,
// ahb side // ahb side
output logic [`PA_BITS-1:0] AHBPAdr, // to ahb output logic [`PA_BITS-1:0] AHBPAdr, // to ahb
output logic AHBRead, output logic AHBRead,
@ -443,7 +444,13 @@ module dcache
// The page table walker asserts it's control 1 cycle // The page table walker asserts it's control 1 cycle
// after the TLBs miss. // after the TLBs miss.
DCacheStall = 1'b1; DCacheStall = 1'b1;
NextState = STATE_READY;
end
else if(SelPTW) begin
// Now we have activated the ptw.
// Do not assert Stall as we are now directing the stall the ptw.
NextState = STATE_PTW_READY; NextState = STATE_PTW_READY;
CommittedM = 1'b1;
end end
// amo hit // amo hit
else if(|AtomicM & CacheableM & ~(ExceptionM | PendingInterruptM) & CacheHit & ~DTLBMissM) begin else if(|AtomicM & CacheableM & ~(ExceptionM | PendingInterruptM) & CacheHit & ~DTLBMissM) begin
@ -592,7 +599,7 @@ module dcache
// now all output connect to PTW instead of CPU. // now all output connect to PTW instead of CPU.
CommittedM = 1'b1; CommittedM = 1'b1;
// return to ready if page table walk completed. // return to ready if page table walk completed.
if (DTLBWriteM) begin if (~SelPTW) begin
NextState = STATE_PTW_ACCESS_AFTER_WALK; NextState = STATE_PTW_ACCESS_AFTER_WALK;
// read hit valid cached // read hit valid cached
@ -655,57 +662,11 @@ module dcache
end end
STATE_PTW_ACCESS_AFTER_WALK: begin STATE_PTW_ACCESS_AFTER_WALK: begin
DCacheStall = 1'b1;
SelAdrM = 1'b1; SelAdrM = 1'b1;
// amo hit CommittedM = 1'b1;
if(|AtomicM & CacheableM & ~(ExceptionM | PendingInterruptM) & CacheHit & ~DTLBMissM) begin
NextState = STATE_AMO_UPDATE;
DCacheStall = 1'b1;
if(StallW) NextState = STATE_CPU_BUSY;
else NextState = STATE_AMO_UPDATE;
end
// read hit valid cached
else if(MemRWM[1] & CacheableM & ~(ExceptionM | PendingInterruptM) & CacheHit & ~DTLBMissM) begin
DCacheStall = 1'b0;
if(StallW) NextState = STATE_CPU_BUSY;
else NextState = STATE_READY;
end
// write hit valid cached
else if (MemRWM[0] & CacheableM & ~(ExceptionM | PendingInterruptM) & CacheHit & ~DTLBMissM) begin
DCacheStall = 1'b0;
SRAMWordWriteEnableM = 1'b1;
SetDirtyM = 1'b1;
if(StallW) NextState = STATE_CPU_BUSY;
else NextState = STATE_READY;
end
// read or write miss valid cached
else if((|MemRWM) & CacheableM & ~(ExceptionM | PendingInterruptM) & ~CacheHit & ~DTLBMissM) begin
NextState = STATE_MISS_FETCH_WDV;
CntReset = 1'b1;
DCacheStall = 1'b1;
end
// uncached write
else if(MemRWM[0] & ~CacheableM & ~ExceptionM & ~DTLBMissM) begin
NextState = STATE_UNCACHED_WRITE;
CntReset = 1'b1;
DCacheStall = 1'b1;
AHBWrite = 1'b1;
end
// uncached read
else if(MemRWM[1] & ~CacheableM & ~ExceptionM & ~DTLBMissM) begin
NextState = STATE_UNCACHED_READ;
CntReset = 1'b1;
DCacheStall = 1'b1;
AHBRead = 1'b1;
end
// fault
else if(AnyCPUReqM & (ExceptionM | PendingInterruptM) & ~DTLBMissM) begin
NextState = STATE_READY; NextState = STATE_READY;
end end
else NextState = STATE_READY;
end
STATE_CPU_BUSY : begin STATE_CPU_BUSY : begin
CommittedM = 1'b1; CommittedM = 1'b1;

View File

@ -126,7 +126,6 @@ module lsu
logic HPTWStall; logic HPTWStall;
logic [`XLEN-1:0] HPTWPAdrE; logic [`XLEN-1:0] HPTWPAdrE;
logic [`XLEN-1:0] HPTWPAdrM; logic [`XLEN-1:0] HPTWPAdrM;
logic HPTWTranslate;
logic HPTWReadM; logic HPTWReadM;
logic [1:0] MemRWMtoDCache; logic [1:0] MemRWMtoDCache;
logic [2:0] Funct3MtoDCache; logic [2:0] Funct3MtoDCache;
@ -170,8 +169,8 @@ module lsu
.HPTWStall(HPTWStall), .HPTWStall(HPTWStall),
.HPTWPAdrE(HPTWPAdrE), .HPTWPAdrE(HPTWPAdrE),
.HPTWPAdrM(HPTWPAdrM), .HPTWPAdrM(HPTWPAdrM),
.HPTWTranslate(HPTWTranslate),
.HPTWReadM(HPTWReadM), .HPTWReadM(HPTWReadM),
.SelPTW(SelPTW),
.WalkerInstrPageFaultF(WalkerInstrPageFaultF), .WalkerInstrPageFaultF(WalkerInstrPageFaultF),
.WalkerLoadPageFaultM(WalkerLoadPageFaultM), .WalkerLoadPageFaultM(WalkerLoadPageFaultM),
.WalkerStorePageFaultM(WalkerStorePageFaultM)); .WalkerStorePageFaultM(WalkerStorePageFaultM));
@ -182,7 +181,7 @@ module lsu
lsuArb arbiter(.clk(clk), lsuArb arbiter(.clk(clk),
.reset(reset), .reset(reset),
// HPTW connection // HPTW connection
.HPTWTranslate(HPTWTranslate), .SelPTW(SelPTW),
.HPTWReadM(HPTWReadM), .HPTWReadM(HPTWReadM),
.HPTWPAdrE(HPTWPAdrE), .HPTWPAdrE(HPTWPAdrE),
.HPTWPAdrM(HPTWPAdrM), .HPTWPAdrM(HPTWPAdrM),
@ -214,8 +213,9 @@ module lsu
.ReadDataWfromDCache(ReadDataWfromDCache), .ReadDataWfromDCache(ReadDataWfromDCache),
.CommittedMfromDCache(CommittedMfromDCache), .CommittedMfromDCache(CommittedMfromDCache),
.PendingInterruptMtoDCache(PendingInterruptMtoDCache), .PendingInterruptMtoDCache(PendingInterruptMtoDCache),
.DCacheStall(DCacheStall), .DCacheStall(DCacheStall));
.SelPTW(SelPTW));
mmu #(.TLB_ENTRIES(`DTLB_ENTRIES), .IMMU(0)) mmu #(.TLB_ENTRIES(`DTLB_ENTRIES), .IMMU(0))
@ -243,7 +243,9 @@ module lsu
// .SelRegions(DHSELRegionsM), // .SelRegions(DHSELRegionsM),
.*); // *** the pma/pmp instruction acess faults don't really matter here. is it possible to parameterize which outputs exist? .*); // *** the pma/pmp instruction acess faults don't really matter here. is it possible to parameterize which outputs exist?
// *** BUG, this is most likely wrong
assign CacheableMtoDCache = SelPTW ? 1'b1 : CacheableM; assign CacheableMtoDCache = SelPTW ? 1'b1 : CacheableM;
generate generate
if (`XLEN == 32) assign DCtoAHBSizeM = CacheableMtoDCache ? 3'b010 : Funct3MtoDCache; if (`XLEN == 32) assign DCtoAHBSizeM = CacheableMtoDCache ? 3'b010 : Funct3MtoDCache;
else assign DCtoAHBSizeM = CacheableMtoDCache ? 3'b011 : Funct3MtoDCache; else assign DCtoAHBSizeM = CacheableMtoDCache ? 3'b011 : Funct3MtoDCache;
@ -335,6 +337,7 @@ module lsu
.DTLBMissM(DTLBMissM), .DTLBMissM(DTLBMissM),
.CacheableM(CacheableMtoDCache), .CacheableM(CacheableMtoDCache),
.DTLBWriteM(DTLBWriteM), .DTLBWriteM(DTLBWriteM),
.SelPTW(SelPTW),
// AHB connection // AHB connection
.AHBPAdr(DCtoAHBPAdrM), .AHBPAdr(DCtoAHBPAdrM),

View File

@ -30,7 +30,7 @@ module lsuArb
(input logic clk, reset, (input logic clk, reset,
// from page table walker // from page table walker
input logic HPTWTranslate, input logic SelPTW,
input logic HPTWReadM, input logic HPTWReadM,
input logic [`XLEN-1:0] HPTWPAdrE, input logic [`XLEN-1:0] HPTWPAdrE,
input logic [`XLEN-1:0] HPTWPAdrM, input logic [`XLEN-1:0] HPTWPAdrM,
@ -62,7 +62,6 @@ module lsuArb
output logic [`XLEN-1:0] MemAdrEtoDCache, output logic [`XLEN-1:0] MemAdrEtoDCache,
output logic StallWtoDCache, output logic StallWtoDCache,
output logic PendingInterruptMtoDCache, output logic PendingInterruptMtoDCache,
output logic SelPTW,
// from D Cache // from D Cache
@ -74,72 +73,10 @@ module lsuArb
); );
// HPTWTranslate is the request for memory by the page table walker. When
// this is high the page table walker gains priority over the CPU's data
// input. Note the ptw only makes a request after an instruction or data
// tlb miss. It is entirely possible the dcache is currently processing
// a data cache miss when an instruction tlb miss occurs. If an instruction
// in the E stage causes a d cache miss, the d cache will immediately start
// processing the request. Simultaneously the ITLB misses. By the time
// the TLB miss causes the page table walker to issue the first request
// to data memory the d cache is already busy. We can interlock by
// leveraging Stall as a d cache busy. We will need an FSM to handle this.
typedef enum{StateReady,
StatePTWPending,
StatePTWActive} statetype;
statetype CurrState, NextState;
logic [2:0] PTWSize; logic [2:0] PTWSize;
flopenl #(.TYPE(statetype)) StateReg(.clk(clk),
.load(reset),
.en(1'b1),
.d(NextState),
.val(StateReady),
.q(CurrState));
always_comb begin
case(CurrState)
StateReady:
if (HPTWTranslate) NextState = StatePTWActive;
else NextState = StateReady;
StatePTWActive:
if (HPTWTranslate) NextState = StatePTWActive;
else NextState = StateReady;
default: NextState = StateReady;
endcase
end
/* -----\/----- EXCLUDED -----\/-----
always_comb begin
case(CurrState)
StateReady:
/-* -----\/----- EXCLUDED -----\/-----
if (HPTWTranslate & DataStall) NextState = StatePTWPending;
else
-----/\----- EXCLUDED -----/\----- *-/
if (HPTWTranslate) NextState = StatePTWActive;
else NextState = StateReady;
StatePTWPending:
if (HPTWTranslate & ~DataStall) NextState = StatePTWActive;
else if (HPTWTranslate & DataStall) NextState = StatePTWPending;
else NextState = StateReady;
StatePTWActive:
if (HPTWTranslate) NextState = StatePTWActive;
else NextState = StateReady;
default: NextState = StateReady;
endcase
end
-----/\----- EXCLUDED -----/\----- */
// multiplex the outputs to LSU // multiplex the outputs to LSU
assign DisableTranslation = SelPTW; // change names between SelPTW would be confusing in DTLB. assign DisableTranslation = SelPTW; // change names between SelPTW would be confusing in DTLB.
assign SelPTW = (CurrState == StatePTWActive && HPTWTranslate) || (CurrState == StateReady && HPTWTranslate);
assign MemRWMtoDCache = SelPTW ? {HPTWReadM, 1'b0} : MemRWM; assign MemRWMtoDCache = SelPTW ? {HPTWReadM, 1'b0} : MemRWM;
generate generate

View File

@ -49,8 +49,7 @@ module pagetablewalker
output logic [`XLEN-1:0] PageTableEntryF, PageTableEntryM, output logic [`XLEN-1:0] PageTableEntryF, PageTableEntryM,
output logic [1:0] PageTypeF, PageTypeM, output logic [1:0] PageTypeF, PageTypeM,
output logic ITLBWriteF, DTLBWriteM, output logic ITLBWriteF, DTLBWriteM,
output logic SelPTW,
// *** modify to send to LSU // *** KMG: These are inputs/results from the ahblite whose addresses should have already been checked, so I don't think they need to be sent through the LSU // *** modify to send to LSU // *** KMG: These are inputs/results from the ahblite whose addresses should have already been checked, so I don't think they need to be sent through the LSU
@ -61,7 +60,6 @@ module pagetablewalker
// *** modify to send to LSU // *** modify to send to LSU
output logic [`XLEN-1:0] HPTWPAdrE, // this probalby should be `PA_BITS wide output logic [`XLEN-1:0] HPTWPAdrE, // this probalby should be `PA_BITS wide
output logic [`XLEN-1:0] HPTWPAdrM, // this probalby should be `PA_BITS wide output logic [`XLEN-1:0] HPTWPAdrM, // this probalby should be `PA_BITS wide
output logic HPTWTranslate, // *** rename to HPTWReq
output logic HPTWReadM, output logic HPTWReadM,
@ -86,7 +84,6 @@ module pagetablewalker
logic [`PPN_BITS-1:0] CurrentPPN; logic [`PPN_BITS-1:0] CurrentPPN;
logic [`SVMODE_BITS-1:0] SvMode; logic [`SVMODE_BITS-1:0] SvMode;
logic MemStore; logic MemStore;
logic DTLBWriteM_d;
// PTE Control Bits // PTE Control Bits
logic Dirty, Accessed, Global, User, logic Dirty, Accessed, Global, User,
@ -100,44 +97,34 @@ module pagetablewalker
logic StartWalk; logic StartWalk;
logic EndWalk; logic EndWalk;
typedef enum {LEVEL0_WDV, typedef enum {LEVEL0_SET_ADRE,
LEVEL0_WDV,
LEVEL0, LEVEL0,
LEVEL1_SET_ADRE,
LEVEL1_WDV, LEVEL1_WDV,
LEVEL1, LEVEL1,
LEVEL2_SET_ADRE,
LEVEL2_WDV, LEVEL2_WDV,
LEVEL2, LEVEL2,
LEVEL3_SET_ADRE,
LEVEL3_WDV, LEVEL3_WDV,
LEVEL3, LEVEL3,
LEAF, LEAF,
IDLE, IDLE,
START,
FAULT} statetype; FAULT} statetype;
statetype WalkerState, NextWalkerState; statetype WalkerState, NextWalkerState, PreviousWalkerState;
logic PRegEn; logic PRegEn;
logic SelDataTranslation; logic SelDataTranslation;
logic AnyTLBMissM;
flop #(`XLEN) HPTWPAdrMReg(.clk(clk), flop #(`XLEN) HPTWPAdrMReg(.clk(clk),
.d(HPTWPAdrE), .d(HPTWPAdrE),
.q(HPTWPAdrM)); .q(HPTWPAdrM));
flop #(2) PageTypeReg(.clk(clk),
.d(PageType),
.q(PageTypeM));
flop #(`XLEN) PageTableEntryReg(.clk(clk),
.d(PageTableEntry),
.q(PageTableEntryM));
flop #(1) DTLBWriteReg(.clk(clk),
.d(DTLBWriteM_d),
.q(DTLBWriteM));
flop #(1) HPTWReadMReg(.clk(clk),
.d(HPTWReadE),
.q(HPTWReadM));
assign SvMode = SATP_REGW[`XLEN-1:`XLEN-`SVMODE_BITS]; assign SvMode = SATP_REGW[`XLEN-1:`XLEN-`SVMODE_BITS];
@ -147,7 +134,7 @@ module pagetablewalker
assign MemStore = MemRWM[0]; assign MemStore = MemRWM[0];
// Prefer data address translations over instruction address translations // Prefer data address translations over instruction address translations
assign TranslationVAdr = (SelDataTranslation) ? MemAdrM : PCF; // *** need to register TranslationVAdr assign TranslationVAdr = (SelDataTranslation) ? MemAdrM : PCF;
assign SelDataTranslation = DTLBMissMQ | DTLBMissM; assign SelDataTranslation = DTLBMissMQ | DTLBMissM;
flopenrc #(1) flopenrc #(1)
@ -167,16 +154,10 @@ module pagetablewalker
.q(ITLBMissFQ)); .q(ITLBMissFQ));
assign StartWalk = WalkerState == IDLE && (DTLBMissM | ITLBMissF); assign AnyTLBMissM = DTLBMissM | ITLBMissF;
assign EndWalk = WalkerState == LEAF ||
//(WalkerState == LEVEL0 && ValidPTE && LeafPTE && ~AccessAlert) ||
//(WalkerState == LEVEL1 && ValidPTE && LeafPTE && ~AccessAlert) ||
//(WalkerState == LEVEL2 && ValidPTE && LeafPTE && ~AccessAlert) ||
//(WalkerState == LEVEL3 && ValidPTE && LeafPTE && ~AccessAlert) ||
(WalkerState == FAULT);
assign HPTWTranslate = (DTLBMissMQ | ITLBMissFQ); assign StartWalk = WalkerState == IDLE & AnyTLBMissM;
//assign HPTWTranslate = DTLBMissM | ITLBMissF; assign EndWalk = WalkerState == LEAF || WalkerState == FAULT;
// unswizzle PTE bits // unswizzle PTE bits
assign {Dirty, Accessed, Global, User, assign {Dirty, Accessed, Global, User,
@ -189,9 +170,9 @@ module pagetablewalker
// Assign specific outputs to general outputs // Assign specific outputs to general outputs
assign PageTableEntryF = PageTableEntry; assign PageTableEntryF = PageTableEntry;
//assign PageTableEntryM = PageTableEntry; assign PageTableEntryM = PageTableEntry;
assign PageTypeF = PageType; assign PageTypeF = PageType;
//assign PageTypeM = PageType; assign PageTypeM = PageType;
// generate // generate
@ -211,26 +192,28 @@ module pagetablewalker
HPTWReadE = 1'b0; HPTWReadE = 1'b0;
PageTableEntry = '0; PageTableEntry = '0;
PageType = '0; PageType = '0;
DTLBWriteM_d = '0; DTLBWriteM = '0;
ITLBWriteF = '0; ITLBWriteF = '0;
WalkerInstrPageFaultF = 1'b0; WalkerInstrPageFaultF = 1'b0;
WalkerLoadPageFaultM = 1'b0; WalkerLoadPageFaultM = 1'b0;
WalkerStorePageFaultM = 1'b0; WalkerStorePageFaultM = 1'b0;
SelPTW = 1'b1;
case (WalkerState) case (WalkerState)
IDLE: begin IDLE: begin
if (HPTWTranslate && SvMode == `SV32) begin // *** Added SvMode SelPTW = 1'b0;
NextWalkerState = START; if (AnyTLBMissM & SvMode == `SV32) begin
NextWalkerState = LEVEL1_SET_ADRE;
end else begin end else begin
NextWalkerState = IDLE; NextWalkerState = IDLE;
end end
end end
START: begin LEVEL1_SET_ADRE: begin
NextWalkerState = LEVEL1_WDV; NextWalkerState = LEVEL1_WDV;
TranslationPAdr = {BasePageTablePPN, VPN1, 2'b00}; TranslationPAdr = {BasePageTablePPN, VPN1, 2'b00};
HPTWReadE = 1'b1;
end end
LEVEL1_WDV: begin LEVEL1_WDV: begin
@ -251,15 +234,11 @@ module pagetablewalker
// supposed to perform that check. However, it is untested. // supposed to perform that check. However, it is untested.
if (ValidPTE && LeafPTE && ~BadMegapage) begin if (ValidPTE && LeafPTE && ~BadMegapage) begin
NextWalkerState = LEAF; NextWalkerState = LEAF;
PageTableEntry = CurrentPTE;
PageType = (WalkerState == LEVEL1) ? 2'b01 : 2'b00; // *** not sure about this mux?
DTLBWriteM_d = DTLBMissMQ;
ITLBWriteF = ~DTLBMissMQ; // Prefer data over instructions
TranslationPAdr = {2'b00, TranslationVAdr[31:0]}; TranslationPAdr = {2'b00, TranslationVAdr[31:0]};
end end
// else if (ValidPTE && LeafPTE) NextWalkerState = LEAF; // *** Once the above line is properly tested, delete this line. // else if (ValidPTE && LeafPTE) NextWalkerState = LEAF; // *** Once the above line is properly tested, delete this line.
else if (ValidPTE && ~LeafPTE) begin else if (ValidPTE && ~LeafPTE) begin
NextWalkerState = LEVEL0_WDV; NextWalkerState = LEVEL0_SET_ADRE;
TranslationPAdr = {CurrentPPN, VPN0, 2'b00}; TranslationPAdr = {CurrentPPN, VPN0, 2'b00};
HPTWReadE = 1'b1; HPTWReadE = 1'b1;
end else begin end else begin
@ -267,6 +246,11 @@ module pagetablewalker
end end
end end
LEVEL0_SET_ADRE: begin
NextWalkerState = LEVEL0_WDV;
TranslationPAdr = {CurrentPPN, VPN0, 2'b00};
end
LEVEL0_WDV: begin LEVEL0_WDV: begin
TranslationPAdr = {CurrentPPN, VPN0, 2'b00}; TranslationPAdr = {CurrentPPN, VPN0, 2'b00};
HPTWReadE = 1'b1; HPTWReadE = 1'b1;
@ -281,10 +265,6 @@ module pagetablewalker
LEVEL0: begin LEVEL0: begin
if (ValidPTE & LeafPTE & ~AccessAlert) begin if (ValidPTE & LeafPTE & ~AccessAlert) begin
NextWalkerState = LEAF; NextWalkerState = LEAF;
PageTableEntry = CurrentPTE;
PageType = (WalkerState == LEVEL1) ? 2'b01 : 2'b00;
DTLBWriteM_d = DTLBMissMQ;
ITLBWriteF = ~DTLBMissMQ; // Prefer data over instructions
TranslationPAdr = {2'b00, TranslationVAdr[31:0]}; TranslationPAdr = {2'b00, TranslationVAdr[31:0]};
end else begin end else begin
NextWalkerState = FAULT; NextWalkerState = FAULT;
@ -293,6 +273,11 @@ module pagetablewalker
LEAF: begin LEAF: begin
NextWalkerState = IDLE; NextWalkerState = IDLE;
PageTableEntry = CurrentPTE;
PageType = (PreviousWalkerState == LEVEL1) ? 2'b01 : 2'b00; // *** not sure about this mux?
DTLBWriteM = DTLBMissMQ;
ITLBWriteF = ~DTLBMissMQ; // Prefer data over instructions
TranslationPAdr = {2'b00, TranslationVAdr[31:0]};
end end
FAULT: begin FAULT: begin
@ -356,35 +341,30 @@ module pagetablewalker
HPTWReadE = 1'b0; HPTWReadE = 1'b0;
PageTableEntry = '0; PageTableEntry = '0;
PageType = '0; PageType = '0;
DTLBWriteM_d = '0; DTLBWriteM = '0;
ITLBWriteF = '0; ITLBWriteF = '0;
WalkerInstrPageFaultF = 1'b0; WalkerInstrPageFaultF = 1'b0;
WalkerLoadPageFaultM = 1'b0; WalkerLoadPageFaultM = 1'b0;
WalkerStorePageFaultM = 1'b0; WalkerStorePageFaultM = 1'b0;
SelPTW = 1'b1;
case (WalkerState) case (WalkerState)
IDLE: begin IDLE: begin
if (HPTWTranslate && (SvMode == `SV48 || SvMode == `SV39)) begin SelPTW = 1'b0;
NextWalkerState = START; if (AnyTLBMissM & SvMode == `SV48) begin
NextWalkerState = LEVEL3_SET_ADRE;
end else if (AnyTLBMissM & SvMode == `SV39) begin
NextWalkerState = LEVEL2_SET_ADRE;
end else begin end else begin
NextWalkerState = IDLE; NextWalkerState = IDLE;
end end
end end
START: begin LEVEL3_SET_ADRE: begin
if (HPTWTranslate && SvMode == `SV48) begin
NextWalkerState = LEVEL3_WDV; NextWalkerState = LEVEL3_WDV;
TranslationPAdr = {BasePageTablePPN, VPN3, 3'b000}; TranslationPAdr = {BasePageTablePPN, VPN3, 3'b000};
HPTWReadE = 1'b1;
end else if (HPTWTranslate && SvMode == `SV39) begin
NextWalkerState = LEVEL2_WDV;
TranslationPAdr = {BasePageTablePPN, VPN2, 3'b000};
HPTWReadE = 1'b1;
end else begin // *** should not get here
NextWalkerState = IDLE;
TranslationPAdr = '0;
end
end end
LEVEL3_WDV: begin LEVEL3_WDV: begin
@ -405,23 +385,20 @@ module pagetablewalker
// supposed to perform that check. However, it is untested. // supposed to perform that check. However, it is untested.
if (ValidPTE && LeafPTE && ~BadTerapage) begin if (ValidPTE && LeafPTE && ~BadTerapage) begin
NextWalkerState = LEAF; NextWalkerState = LEAF;
PageTableEntry = CurrentPTE;
PageType = (WalkerState == LEVEL3) ? 2'b11 : // *** not sure about this mux?
((WalkerState == LEVEL2) ? 2'b10 :
((WalkerState == LEVEL1) ? 2'b01 : 2'b00));
DTLBWriteM_d = DTLBMissMQ;
ITLBWriteF = ~DTLBMissMQ; // Prefer data over instructions
TranslationPAdr = TranslationVAdr[`PA_BITS-1:0]; TranslationPAdr = TranslationVAdr[`PA_BITS-1:0];
end end
// else if (ValidPTE && LeafPTE) NextWalkerState = LEAF; // *** Once the above line is properly tested, delete this line. // else if (ValidPTE && LeafPTE) NextWalkerState = LEAF; // *** Once the above line is properly tested, delete this line.
else if (ValidPTE && ~LeafPTE) begin else if (ValidPTE && ~LeafPTE) begin
NextWalkerState = LEVEL2_WDV; NextWalkerState = LEVEL2_SET_ADRE;
TranslationPAdr = {(SvMode == `SV48) ? CurrentPPN : BasePageTablePPN, VPN2, 3'b000}; TranslationPAdr = {(SvMode == `SV48) ? CurrentPPN : BasePageTablePPN, VPN2, 3'b000};
HPTWReadE = 1'b1;
end else begin end else begin
NextWalkerState = FAULT; NextWalkerState = FAULT;
end end
end
LEVEL2_SET_ADRE: begin
NextWalkerState = LEVEL2_WDV;
TranslationPAdr = {(SvMode == `SV48) ? CurrentPPN : BasePageTablePPN, VPN2, 3'b000};
end end
LEVEL2_WDV: begin LEVEL2_WDV: begin
@ -442,23 +419,20 @@ module pagetablewalker
// supposed to perform that check. However, it is untested. // supposed to perform that check. However, it is untested.
if (ValidPTE && LeafPTE && ~BadGigapage) begin if (ValidPTE && LeafPTE && ~BadGigapage) begin
NextWalkerState = LEAF; NextWalkerState = LEAF;
PageTableEntry = CurrentPTE;
PageType = (WalkerState == LEVEL3) ? 2'b11 :
((WalkerState == LEVEL2) ? 2'b10 :
((WalkerState == LEVEL1) ? 2'b01 : 2'b00));
DTLBWriteM_d = DTLBMissMQ;
ITLBWriteF = ~DTLBMissMQ; // Prefer data over instructions
TranslationPAdr = TranslationVAdr[`PA_BITS-1:0]; TranslationPAdr = TranslationVAdr[`PA_BITS-1:0];
end end
// else if (ValidPTE && LeafPTE) NextWalkerState = LEAF; // *** Once the above line is properly tested, delete this line. // else if (ValidPTE && LeafPTE) NextWalkerState = LEAF; // *** Once the above line is properly tested, delete this line.
else if (ValidPTE && ~LeafPTE) begin else if (ValidPTE && ~LeafPTE) begin
NextWalkerState = LEVEL1_WDV; NextWalkerState = LEVEL1_SET_ADRE;
TranslationPAdr = {CurrentPPN, VPN1, 3'b000}; TranslationPAdr = {CurrentPPN, VPN1, 3'b000};
HPTWReadE = 1'b1;
end else begin end else begin
NextWalkerState = FAULT; NextWalkerState = FAULT;
end end
end
LEVEL1_SET_ADRE: begin
NextWalkerState = LEVEL1_WDV;
TranslationPAdr = {CurrentPPN, VPN1, 3'b000};
end end
LEVEL1_WDV: begin LEVEL1_WDV: begin
@ -479,25 +453,23 @@ module pagetablewalker
// supposed to perform that check. However, it is untested. // supposed to perform that check. However, it is untested.
if (ValidPTE && LeafPTE && ~BadMegapage) begin if (ValidPTE && LeafPTE && ~BadMegapage) begin
NextWalkerState = LEAF; NextWalkerState = LEAF;
PageTableEntry = CurrentPTE;
PageType = (WalkerState == LEVEL3) ? 2'b11 :
((WalkerState == LEVEL2) ? 2'b10 :
((WalkerState == LEVEL1) ? 2'b01 : 2'b00));
DTLBWriteM_d = DTLBMissMQ;
ITLBWriteF = ~DTLBMissMQ; // Prefer data over instructions
TranslationPAdr = TranslationVAdr[`PA_BITS-1:0]; TranslationPAdr = TranslationVAdr[`PA_BITS-1:0];
end end
// else if (ValidPTE && LeafPTE) NextWalkerState = LEAF; // *** Once the above line is properly tested, delete this line. // else if (ValidPTE && LeafPTE) NextWalkerState = LEAF; // *** Once the above line is properly tested, delete this line.
else if (ValidPTE && ~LeafPTE) begin else if (ValidPTE && ~LeafPTE) begin
NextWalkerState = LEVEL0_WDV; NextWalkerState = LEVEL0_SET_ADRE;
TranslationPAdr = {CurrentPPN, VPN0, 3'b000}; TranslationPAdr = {CurrentPPN, VPN0, 3'b000};
HPTWReadE = 1'b1;
end else begin end else begin
NextWalkerState = FAULT; NextWalkerState = FAULT;
end end
end end
LEVEL0_SET_ADRE: begin
NextWalkerState = LEVEL0_WDV;
TranslationPAdr = {CurrentPPN, VPN0, 3'b000};
end
LEVEL0_WDV: begin LEVEL0_WDV: begin
TranslationPAdr = {CurrentPPN, VPN0, 3'b000}; TranslationPAdr = {CurrentPPN, VPN0, 3'b000};
HPTWReadE = 1'b1; HPTWReadE = 1'b1;
@ -512,12 +484,6 @@ module pagetablewalker
LEVEL0: begin LEVEL0: begin
if (ValidPTE && LeafPTE && ~AccessAlert) begin if (ValidPTE && LeafPTE && ~AccessAlert) begin
NextWalkerState = LEAF; NextWalkerState = LEAF;
PageTableEntry = CurrentPTE;
PageType = (WalkerState == LEVEL3) ? 2'b11 :
((WalkerState == LEVEL2) ? 2'b10 :
((WalkerState == LEVEL1) ? 2'b01 : 2'b00));
DTLBWriteM_d = DTLBMissMQ;
ITLBWriteF = ~DTLBMissMQ; // Prefer data over instructions
TranslationPAdr = TranslationVAdr[`PA_BITS-1:0]; TranslationPAdr = TranslationVAdr[`PA_BITS-1:0];
end else begin end else begin
NextWalkerState = FAULT; NextWalkerState = FAULT;
@ -525,6 +491,13 @@ module pagetablewalker
end end
LEAF: begin LEAF: begin
PageTableEntry = CurrentPTE;
PageType = (PreviousWalkerState == LEVEL3) ? 2'b11 : // *** not sure about this mux?
((PreviousWalkerState == LEVEL2) ? 2'b10 :
((PreviousWalkerState == LEVEL1) ? 2'b01 : 2'b00));
DTLBWriteM = DTLBMissMQ;
ITLBWriteF = ~DTLBMissMQ; // Prefer data over instructions
TranslationPAdr = TranslationVAdr[`PA_BITS-1:0];
NextWalkerState = IDLE; NextWalkerState = IDLE;
end end
@ -568,7 +541,8 @@ module pagetablewalker
assign CurrentPTE = SavedPTE; assign CurrentPTE = SavedPTE;
assign CurrentPPN = CurrentPTE[`PPN_BITS+9:10]; assign CurrentPPN = CurrentPTE[`PPN_BITS+9:10];
// Assign outputs to ahblite // *** Major issue. We need the full virtual address here.
// When the TLB's are update it use use the orignal address
// *** Currently truncate address to 32 bits. This must be changed if // *** Currently truncate address to 32 bits. This must be changed if
// we support larger physical address spaces // we support larger physical address spaces
assign HPTWPAdrE = {{(`XLEN-`PA_BITS){1'b0}}, TranslationPAdr[`PA_BITS-1:0]}; assign HPTWPAdrE = {{(`XLEN-`PA_BITS){1'b0}}, TranslationPAdr[`PA_BITS-1:0]};
@ -576,11 +550,11 @@ module pagetablewalker
//endgenerate //endgenerate
end else begin end else begin
assign HPTWPAdrE = 0; assign HPTWPAdrE = 0;
assign HPTWTranslate = 0;
assign HPTWReadE = 0; assign HPTWReadE = 0;
assign WalkerInstrPageFaultF = 0; assign WalkerInstrPageFaultF = 0;
assign WalkerLoadPageFaultM = 0; assign WalkerLoadPageFaultM = 0;
assign WalkerStorePageFaultM = 0; assign WalkerStorePageFaultM = 0;
assign SelPTW = 0;
end end
endgenerate endgenerate