/////////////////////////////////////////// // csrm.sv // // Written: David_Harris@hmc.edu 9 January 2021 // Modified: // dottolia@hmc.edu 7 April 2021 // // Purpose: Machine-Mode Control and Status Registers // See RISC-V Privileged Mode Specification 20190608 // Note: the CSRs do not support the following optional features // - Disabling portions of the instruction set with bits of the MISA register // - Changing from RV64 to RV32 by writing the SXL/UXL bits of the STATUS register // // Documentation: RISC-V System on Chip Design Chapter 5 // // A component of the CORE-V-WALLY configurable RISC-V project. // https://github.com/openhwgroup/cvw // // Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University // // SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 // // Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file // except in compliance with the License, or, at your option, the Apache License version 2.0. You // may obtain a copy of the License at // // https://solderpad.org/licenses/SHL-2.1/ // // Unless required by applicable law or agreed to in writing, any work distributed under the // License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, // either express or implied. See the License for the specific language governing permissions // and limitations under the License. //////////////////////////////////////////////////////////////////////////////////////////////// module csrm import cvw::*; #(parameter cvw_t P) ( input logic clk, reset, input logic UngatedCSRMWriteM, CSRMWriteM, MTrapM, input logic [11:0] CSRAdrM, input logic [P.XLEN-1:0] NextEPCM, NextMtvalM, MSTATUS_REGW, MSTATUSH_REGW, input logic [4:0] NextCauseM, input logic [P.XLEN-1:0] CSRWriteValM, input logic [11:0] MIP_REGW, MIE_REGW, output logic [P.XLEN-1:0] CSRMReadValM, MTVEC_REGW, output logic [P.XLEN-1:0] MEPC_REGW, output logic [31:0] MCOUNTEREN_REGW, MCOUNTINHIBIT_REGW, output logic [15:0] MEDELEG_REGW, output logic [11:0] MIDELEG_REGW, output var logic [7:0] PMPCFG_ARRAY_REGW[P.PMP_ENTRIES-1:0], output var logic [P.PA_BITS-3:0] PMPADDR_ARRAY_REGW [P.PMP_ENTRIES-1:0], output logic WriteMSTATUSM, WriteMSTATUSHM, output logic IllegalCSRMAccessM, IllegalCSRMWriteReadonlyM, output logic [63:0] MENVCFG_REGW, // Debug scan chain input logic DebugCapture, input logic DebugScanEn, input logic DebugScanIn, output logic DebugScanOut ); logic [P.XLEN-1:0] MISA_REGW, MHARTID_REGW, DCSR_REGW, DPC_REGW; logic [P.XLEN-1:0] MSCRATCH_REGW, MTVAL_REGW, MCAUSE_REGW; logic [P.XLEN-1:0] MENVCFGH_REGW; logic WriteMTVECM, WriteMEDELEGM, WriteMIDELEGM; logic WriteMSCRATCHM, WriteMEPCM, WriteMCAUSEM, WriteMTVALM; logic WriteMCOUNTERENM, WriteMCOUNTINHIBITM; // Machine CSRs localparam MVENDORID = 12'hF11; localparam MARCHID = 12'hF12; // github.com/riscv/riscv-isa-manual/blob/main/marchid.md localparam MIMPID = 12'hF13; localparam MHARTID = 12'hF14; localparam MCONFIGPTR = 12'hF15; localparam MSTATUS = 12'h300; localparam MISA_ADR = 12'h301; localparam MEDELEG = 12'h302; localparam MIDELEG = 12'h303; localparam MIE = 12'h304; localparam MTVEC = 12'h305; localparam MCOUNTEREN = 12'h306; localparam MENVCFG = 12'h30A; localparam MSTATUSH = 12'h310; localparam MENVCFGH = 12'h31A; localparam MCOUNTINHIBIT = 12'h320; localparam MSCRATCH = 12'h340; localparam MEPC = 12'h341; localparam MCAUSE = 12'h342; localparam MTVAL = 12'h343; localparam MIP = 12'h344; localparam PMPCFG0 = 12'h3A0; // .. up to 15 more at consecutive addresses localparam PMPADDR0 = 12'h3B0; // ... up to 63 more at consecutive addresses localparam TSELECT = 12'h7A0; localparam TDATA1 = 12'h7A1; localparam TDATA2 = 12'h7A2; localparam TDATA3 = 12'h7A3; localparam DCSR = 12'h7B0; // Debug Control and Status Register localparam DPC = 12'h7B1; // Debug PC localparam DSCRATCH0 = 12'h7B2; // Debug Scratch Register 0 (opt) localparam DSCRATCH1 = 12'h7B3; // Debug Scratch Register 1 (opt) // Constants localparam ZERO = {(P.XLEN){1'b0}}; // when compressed instructions are supported, there can't be misaligned instructions localparam MEDELEG_MASK = P.ZCA_SUPPORTED ? 16'hB3FE : 16'hB3FF; localparam MIDELEG_MASK = 12'h222; // we choose to not make machine interrupts delegable // There are PMP_ENTRIES = 0, 16, or 64 PMPADDR registers, each of which has its own flop genvar i; if (P.PMP_ENTRIES > 0) begin:pmp logic [P.PMP_ENTRIES-1:0] WritePMPCFGM; logic [P.PMP_ENTRIES-1:0] WritePMPADDRM ; logic [P.PMP_ENTRIES-1:0] ADDRLocked, CFGLocked; for(i=0; i