2021-06-04 15:59:14 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// mmu.sv
|
|
|
|
//
|
|
|
|
// Written: david_harris@hmc.edu and kmacsaigoren@hmc.edu 4 June 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: Memory management unit, including TLB, PMA, PMP
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
|
|
|
// The TLB will have 2**ENTRY_BITS total entries
|
|
|
|
|
2021-06-04 21:05:07 +00:00
|
|
|
module mmu #(parameter ENTRY_BITS = 3,
|
|
|
|
parameter IMMU = 0) (
|
|
|
|
|
|
|
|
input logic clk, reset,
|
2021-06-04 15:59:14 +00:00
|
|
|
// Current value of satp CSR (from privileged unit)
|
2021-06-04 21:05:07 +00:00
|
|
|
input logic [`XLEN-1:0] SATP_REGW,
|
|
|
|
input logic STATUS_MXR, STATUS_SUM,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
// Current privilege level of the processeor
|
2021-06-04 21:05:07 +00:00
|
|
|
input logic [1:0] PrivilegeModeW,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
// 00 - TLB is not being accessed
|
|
|
|
// 1x - TLB is accessed for a read (or an instruction)
|
|
|
|
// x1 - TLB is accessed for a write
|
|
|
|
// 11 - TLB is accessed for both read and write
|
2021-06-04 21:05:07 +00:00
|
|
|
input logic [1:0] TLBAccessType,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
// Virtual address input
|
2021-06-04 21:05:07 +00:00
|
|
|
input logic [`XLEN-1:0] VirtualAddress,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
// Controls for writing a new entry to the TLB
|
2021-06-04 21:05:07 +00:00
|
|
|
input logic [`XLEN-1:0] PageTableEntryWrite,
|
|
|
|
input logic [1:0] PageTypeWrite,
|
|
|
|
input logic TLBWrite,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
// Invalidate all TLB entries
|
2021-06-04 21:05:07 +00:00
|
|
|
input logic TLBFlush,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
// Physical address outputs
|
2021-06-04 21:05:07 +00:00
|
|
|
output logic [`XLEN-1:0] PhysicalAddress,
|
|
|
|
output logic TLBMiss,
|
|
|
|
output logic TLBHit,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
// Faults
|
2021-06-04 21:05:07 +00:00
|
|
|
output logic TLBPageFault,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
2021-06-04 21:05:07 +00:00
|
|
|
// PMA checker signals
|
2021-06-04 15:59:14 +00:00
|
|
|
input logic [31:0] HADDR,
|
|
|
|
input logic [2:0] HSIZE, HBURST,
|
|
|
|
input logic HWRITE,
|
|
|
|
input logic AtomicAccessM, ExecuteAccessF, WriteAccessM, ReadAccessM,
|
2021-06-04 21:05:07 +00:00
|
|
|
input logic STATUS_MPRV,
|
|
|
|
input logic [1:0] STATUS_MPP,
|
|
|
|
input logic [63:0] PMPCFG01_REGW, PMPCFG23_REGW, // *** all of these come from the privileged unit, so thwyre gonna have to come over into ifu and dmem
|
|
|
|
input logic [`XLEN-1:0] PMPADDR_ARRAY_REGW [0:15], // *** this one especially has a large note attached to it in pmpchecker.
|
|
|
|
|
2021-06-04 15:59:14 +00:00
|
|
|
output logic Cacheable, Idempotent, AtomicAllowed,
|
2021-06-04 21:05:07 +00:00
|
|
|
output logic SquashBusAccess, // *** send to privileged unit
|
|
|
|
output logic PMPInstrAccessFaultF, PMPLoadAccessFaultM, PMPStoreAccessFaultM,
|
|
|
|
output logic PMAInstrAccessFaultF, PMALoadAccessFaultM, PMAStoreAccessFaultM,
|
2021-06-04 15:59:14 +00:00
|
|
|
output logic [5:0] HSELRegions
|
|
|
|
|
|
|
|
);
|
|
|
|
|
2021-06-04 21:05:07 +00:00
|
|
|
logic PMPSquashBusAccess, PMASquashBusAccess;
|
|
|
|
|
2021-06-04 15:59:14 +00:00
|
|
|
// Translation lookaside buffer
|
|
|
|
|
2021-06-04 21:05:07 +00:00
|
|
|
tlb #(.ENTRY_BITS(ENTRY_BITS), .ITLB(IMMU)) tlb(.*);
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
// Check physical memory accesses
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
pmachecker pmachecker(.*);
|
|
|
|
pmpchecker pmpchecker(.*);
|
|
|
|
|
2021-06-04 21:05:07 +00:00
|
|
|
|
|
|
|
assign SquashBusAccess = PMASquashBusAccess || PMPSquashBusAccess;
|
2021-06-04 15:59:14 +00:00
|
|
|
|
|
|
|
endmodule
|