2021-04-08 07:24:10 +00:00
|
|
|
///////////////////////////////////////////
|
2021-06-07 22:54:05 +00:00
|
|
|
// tlbcam.sv
|
2021-04-08 07:24:10 +00:00
|
|
|
//
|
|
|
|
// Written: jtorrey@hmc.edu 16 February 2021
|
2021-06-01 21:50:37 +00:00
|
|
|
// Modified: kmacsaigoren@hmc.edu 1 June 2021
|
|
|
|
// Implemented SV48 on top of SV39. This included adding the SvMode signal input and wally constants
|
|
|
|
// Mostly this was to make the cam_lines work.
|
2021-04-08 07:24:10 +00:00
|
|
|
//
|
|
|
|
// Purpose: Stores virtual page numbers with cached translations.
|
|
|
|
// Determines whether a given virtual page number is in the TLB.
|
|
|
|
//
|
|
|
|
// 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-04-08 07:24:10 +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-04-08 07:24:10 +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-04-08 07:24:10 +00:00
|
|
|
|
2021-06-07 16:37:46 +00:00
|
|
|
`include "wally-config.vh"
|
2021-06-01 21:50:37 +00:00
|
|
|
|
2021-07-04 21:52:00 +00:00
|
|
|
module tlbcam #(parameter TLB_ENTRIES = 8,
|
|
|
|
parameter KEY_BITS = 20,
|
|
|
|
parameter SEGMENT_BITS = 10) (
|
2021-06-08 17:39:32 +00:00
|
|
|
input logic clk, reset,
|
2021-07-08 20:58:11 +00:00
|
|
|
input logic [`VPN_BITS-1:0] VPN,
|
2021-06-08 17:39:32 +00:00
|
|
|
input logic [1:0] PageTypeWriteVal,
|
2021-07-06 14:38:30 +00:00
|
|
|
input logic SV39Mode,
|
2021-06-08 17:39:32 +00:00
|
|
|
input logic TLBFlush,
|
2021-07-04 21:52:00 +00:00
|
|
|
input logic [TLB_ENTRIES-1:0] WriteEnables,
|
2021-07-08 20:52:06 +00:00
|
|
|
input logic [TLB_ENTRIES-1:0] PTE_Gs,
|
|
|
|
input logic [`ASID_BITS-1:0] SATP_ASID,
|
2021-07-07 10:32:26 +00:00
|
|
|
output logic [TLB_ENTRIES-1:0] Matches,
|
2021-06-08 17:39:32 +00:00
|
|
|
output logic [1:0] HitPageType,
|
|
|
|
output logic CAMHit
|
2021-04-08 07:24:10 +00:00
|
|
|
);
|
|
|
|
|
2021-07-04 21:52:00 +00:00
|
|
|
logic [1:0] PageTypeRead [TLB_ENTRIES-1:0];
|
2021-04-08 07:24:10 +00:00
|
|
|
|
2021-07-04 21:52:00 +00:00
|
|
|
// Create TLB_ENTRIES CAM lines, each of which will independently consider
|
2021-04-08 07:24:10 +00:00
|
|
|
// whether the requested virtual address is a match. Each line stores the
|
|
|
|
// original virtual page number from when the address was written, regardless
|
|
|
|
// of page type. However, matches are determined based on a subset of the
|
|
|
|
// page number segments.
|
2021-07-04 16:32:27 +00:00
|
|
|
|
2021-07-04 21:52:00 +00:00
|
|
|
tlbcamline #(KEY_BITS, SEGMENT_BITS) camlines[TLB_ENTRIES-1:0](
|
2021-07-08 20:58:11 +00:00
|
|
|
.clk, .reset, .VPN, .SATP_ASID, .SV39Mode, .PTE_G(PTE_Gs), .PageTypeWriteVal, .TLBFlush,
|
2021-07-07 10:32:26 +00:00
|
|
|
.WriteEnable(WriteEnables), .PageTypeRead, .Match(Matches));
|
|
|
|
assign CAMHit = |Matches & ~TLBFlush;
|
2021-07-13 13:32:02 +00:00
|
|
|
or_rows #(TLB_ENTRIES,2) PageTypeOr(PageTypeRead, HitPageType);
|
2021-04-08 07:24:10 +00:00
|
|
|
endmodule
|
2021-07-06 22:39:30 +00:00
|
|
|
|