2021-05-03 21:37:42 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// pmpadrdec.sv
|
|
|
|
//
|
|
|
|
// Written: tfleming@hmc.edu 28 April 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: Address decoder for the PMP checker. Decides whether a given address
|
|
|
|
// falls within the PMP range for each address-matching mode
|
|
|
|
// (top-of-range/TOR, naturally aligned four-byte region/NA4, and
|
|
|
|
// naturally aligned power-of-two region/NAPOT), then selects the
|
|
|
|
// output based on which mode is input.
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
|
|
|
module pmpadrdec (
|
2021-06-24 23:59:29 +00:00
|
|
|
input logic [`PA_BITS-1:0] PhysicalAddress,
|
2021-07-03 07:29:33 +00:00
|
|
|
input logic [7:0] PMPCfg,
|
|
|
|
input logic [`XLEN-1:0] PMPAdr,
|
|
|
|
input logic PAgePMPAdrIn,
|
2021-07-19 19:06:14 +00:00
|
|
|
// input logic NoLowerMatchIn,
|
|
|
|
input logic FirstMatch,
|
2021-07-03 07:29:33 +00:00
|
|
|
output logic PAgePMPAdrOut,
|
2021-07-19 19:06:14 +00:00
|
|
|
// output logic NoLowerMatchOut,
|
2021-07-03 07:29:33 +00:00
|
|
|
output logic Match, Active,
|
|
|
|
output logic L, X, W, R
|
2021-05-03 21:37:42 +00:00
|
|
|
);
|
2021-07-03 07:29:33 +00:00
|
|
|
|
2021-05-03 21:37:42 +00:00
|
|
|
localparam TOR = 2'b01;
|
|
|
|
localparam NA4 = 2'b10;
|
|
|
|
localparam NAPOT = 2'b11;
|
|
|
|
|
2021-06-23 06:31:50 +00:00
|
|
|
logic TORMatch, NAMatch;
|
2021-07-03 07:29:33 +00:00
|
|
|
logic PAltPMPAdr;
|
2021-07-19 19:06:14 +00:00
|
|
|
// logic FirstMatch;
|
2021-06-23 06:31:50 +00:00
|
|
|
logic [`PA_BITS-1:0] CurrentAdrFull;
|
2021-07-03 07:29:33 +00:00
|
|
|
logic [1:0] AdrMode;
|
|
|
|
|
|
|
|
|
|
|
|
assign AdrMode = PMPCfg[4:3];
|
2021-05-04 05:56:05 +00:00
|
|
|
|
2021-07-03 06:25:31 +00:00
|
|
|
// The two lsb of the physical address don't matter for this checking.
|
|
|
|
// The following code includes them, but hardwires the PMP checker lsbs to 00
|
|
|
|
// and masks them later. Logic synthesis should optimize away these bottom bits.
|
2021-06-23 06:31:50 +00:00
|
|
|
|
2021-05-03 21:37:42 +00:00
|
|
|
// Top-of-range (TOR)
|
2021-06-23 06:31:50 +00:00
|
|
|
// Append two implicit trailing 0's to PMPAdr value
|
2021-07-03 07:29:33 +00:00
|
|
|
assign CurrentAdrFull = {PMPAdr[`PA_BITS-3:0], 2'b00};
|
|
|
|
assign PAltPMPAdr = {1'b0, PhysicalAddress} < {1'b0, CurrentAdrFull}; // unsigned comparison
|
|
|
|
assign PAgePMPAdrOut = ~PAltPMPAdr;
|
|
|
|
assign TORMatch = PAgePMPAdrIn && PAltPMPAdr;
|
2021-05-03 21:37:42 +00:00
|
|
|
|
2021-06-23 06:31:50 +00:00
|
|
|
// Naturally aligned regions
|
2021-05-03 21:37:42 +00:00
|
|
|
|
2021-06-23 06:31:50 +00:00
|
|
|
// verilator lint_off UNOPTFLAT
|
|
|
|
logic [`PA_BITS-1:0] Mask;
|
2021-07-19 19:06:14 +00:00
|
|
|
//genvar i;
|
2021-06-23 06:31:50 +00:00
|
|
|
|
|
|
|
// create a mask of which bits to ignore
|
2021-07-19 19:06:14 +00:00
|
|
|
// generate
|
|
|
|
// assign Mask[1:0] = 2'b11;
|
|
|
|
// assign Mask[2] = (AdrMode == NAPOT); // mask has 0s in upper bis for NA4 region
|
|
|
|
// for (i=3; i < `PA_BITS; i=i+1) begin:mask
|
|
|
|
// assign Mask[i] = Mask[i-1] & PMPAdr[i-3]; // NAPOT mask: 1's indicate bits to ignore
|
|
|
|
// end
|
|
|
|
// endgenerate
|
|
|
|
prioritycircuit #(.ENTRIES(`PA_BITS-2), .FINAL_OP("NONE")) maskgen(.a(~PMPAdr[`PA_BITS-3:0]), .FirstPin(AdrMode==NAPOT), .y(Mask[`PA_BITS-1:2]));
|
|
|
|
assign Mask[1:0] = 2'b11;
|
|
|
|
|
|
|
|
// *** possible experiments:
|
|
|
|
/* PA < PMP addr could be in its own module,
|
|
|
|
preeserving hierarchy so we can know if this is the culprit on the critical path
|
|
|
|
Should take logarthmic time, so more like 6 levels than 40 should be expected
|
|
|
|
|
|
|
|
update mask generation
|
|
|
|
Should be concurrent with the subtraction/comparison
|
|
|
|
if one is the critical path, the other shouldn't be which makes us think the mask generation is the culprit.
|
|
|
|
|
|
|
|
Hopefully just use the priority circuit here
|
|
|
|
*/
|
2021-06-23 06:31:50 +00:00
|
|
|
// verilator lint_on UNOPTFLAT
|
|
|
|
|
2021-06-24 23:59:29 +00:00
|
|
|
assign NAMatch = &((PhysicalAddress ~^ CurrentAdrFull) | Mask);
|
2021-06-23 06:31:50 +00:00
|
|
|
|
2021-05-03 21:37:42 +00:00
|
|
|
assign Match = (AdrMode == TOR) ? TORMatch :
|
2021-06-23 06:31:50 +00:00
|
|
|
(AdrMode == NA4 || AdrMode == NAPOT) ? NAMatch :
|
2021-05-03 21:37:42 +00:00
|
|
|
0;
|
|
|
|
|
2021-07-03 07:29:33 +00:00
|
|
|
assign L = PMPCfg[7] & FirstMatch;
|
|
|
|
assign X = PMPCfg[2] & FirstMatch;
|
|
|
|
assign W = PMPCfg[1] & FirstMatch;
|
|
|
|
assign R = PMPCfg[0] & FirstMatch;
|
|
|
|
assign Active = |PMPCfg[4:3];
|
|
|
|
endmodule
|
2021-05-03 21:37:42 +00:00
|
|
|
|