TLB cleanup

This commit is contained in:
David Harris 2021-07-04 14:37:53 -04:00
parent b2a003d9ac
commit 81742ef9e2
2 changed files with 8 additions and 11 deletions

View File

@ -121,6 +121,7 @@ module tlb #(parameter ENTRY_BITS = 3,
// Grab the sv mode from SATP and determine whether translation should occur
assign SvMode = SATP_REGW[`XLEN-1:`XLEN-`SVMODE_BITS];
assign EffectivePrivilegeMode = (ITLB == 1) ? PrivilegeModeW : (STATUS_MPRV ? STATUS_MPP : PrivilegeModeW); // DTLB uses MPP mode when MPRV is 1
assign Translate = (SvMode != `NO_TRANSLATE) & (EffectivePrivilegeMode != `M_MODE) & ~ DisableTranslation;
// Decode the integer encoded WriteIndex into the one-hot encoded WriteLines
@ -152,6 +153,7 @@ module tlb #(parameter ENTRY_BITS = 3,
// TLB entries are evicted according to the LRU algorithm
tlblru #(ENTRY_BITS) lru(.*);
// TLB memory
tlbram #(ENTRY_BITS) tlbram(.*);
tlbcam #(ENTRY_BITS, `VPN_BITS, `VPN_SEGMENT_BITS) tlbcam(.*);
@ -164,8 +166,6 @@ module tlb #(parameter ENTRY_BITS = 3,
if (ITLB == 1) begin
logic ImproperPrivilege;
assign EffectivePrivilegeMode = PrivilegeModeW; // ITLB ignores MPRV
// User mode may only execute user mode pages, and supervisor mode may
// only execute non-user mode pages.
assign ImproperPrivilege = ((EffectivePrivilegeMode == `U_MODE) && ~PTE_U) ||
@ -174,8 +174,6 @@ module tlb #(parameter ENTRY_BITS = 3,
end else begin
logic ImproperPrivilege, InvalidRead, InvalidWrite;
assign EffectivePrivilegeMode = STATUS_MPRV ? STATUS_MPP : PrivilegeModeW; // DTLB uses MPP mode when MPRV is 1
// User mode may only load/store from user mode pages, and supervisor mode
// may only access user mode pages when STATUS_SUM is low.
assign ImproperPrivilege = ((EffectivePrivilegeMode == `U_MODE) && ~PTE_U) ||
@ -194,11 +192,11 @@ module tlb #(parameter ENTRY_BITS = 3,
// Replace segments of the virtual page number with segments of the physical
// page number. For 4 KB pages, the entire virtual page number is replaced.
// For superpages, some segments are considered offsets into a larger page.
physicalpagemask PageNumberMixer(VirtualPageNumber, PhysicalPageNumber, HitPageType, PhysicalPageNumberMixed);
tlbphysicalpagemask PageMask(VirtualPageNumber, PhysicalPageNumber, HitPageType, PhysicalPageNumberMixed);
// Provide physical address only on TLBHits to cause catastrophic errors if
// garbage address is used.
assign PhysicalAddressFull = (TLBHit) ? {PhysicalPageNumberMixed, PageOffset} : '0;
assign PhysicalAddressFull = TLBHit ? {PhysicalPageNumberMixed, PageOffset} : '0;
// Output the hit physical address if translation is currently on.
/* generate

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////
// physicalpagemask.sv
// tlbphysicalpagemask.sv
//
// Written: David Harris and kmacsaigoren@hmc.edu 7 June 2021
// Modified:
@ -40,13 +40,11 @@ module physicalpagemask (
logic [`PPN_BITS-1:0] ZeroExtendedVPN;
logic [`PPN_BITS-1:0] PageNumberMask;
assign ZeroExtendedVPN = {{EXTRA_BITS{1'b0}}, VPN}; // forces the VPN to be the same width as PPN.
generate
if (`XLEN == 32) begin
always_comb
case (PageType[0])
// *** the widths of these constansts are hardocded here to match `PPN_BITS in the wally-constants file.
// the widths of these constansts are hardocded here to match `PPN_BITS in the wally-constants file.
0: PageNumberMask = 22'h3FFFFF; // kilopage: 22 bits of PPN, 0 bits of VPN
1: PageNumberMask = 22'h3FFC00; // megapage: 12 bits of PPN, 10 bits of VPN
endcase
@ -57,7 +55,7 @@ module physicalpagemask (
1: PageNumberMask = 44'hFFFFFFFFE00; // megapage: 35 bits of PPN, 9 bits of VPN
2: PageNumberMask = 44'hFFFFFFC0000; // gigapage: 26 bits of PPN, 18 bits of VPN
3: PageNumberMask = 44'hFFFF8000000; // terapage: 17 bits of PPN, 27 bits of VPN
// *** make sure that this doesnt break when using sv39. In that case, all of these
// Bus widths accomodate SV48. In SV39, all of these
// busses are the widths for sv48, but extra bits should be zeroed out by the mux
// in the tlb when it generates VPN from the full virtualadress.
endcase
@ -65,6 +63,7 @@ module physicalpagemask (
endgenerate
// merge low segments of VPN with high segments of PPN decided by the pagetype.
assign ZeroExtendedVPN = {{EXTRA_BITS{1'b0}}, VPN}; // forces the VPN to be the same width as PPN.
assign MixedPageNumber = (ZeroExtendedVPN & ~PageNumberMask) | (PPN & PageNumberMask);
endmodule