mirror of
				https://github.com/openhwgroup/cvw
				synced 2025-02-11 06:05:49 +00:00 
			
		
		
		
	Update csr.sv
Program clean up
This commit is contained in:
		
							parent
							
								
									a1a9d668c5
								
							
						
					
					
						commit
						a2645dd576
					
				@ -29,66 +29,66 @@
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
module csr import cvw::*;  #(parameter cvw_t P) (
 | 
			
		||||
  input  logic             clk, reset,
 | 
			
		||||
  input  logic             FlushM, FlushW,
 | 
			
		||||
  input  logic             StallE, StallM, StallW,
 | 
			
		||||
  input  logic [31:0]      InstrM,                    // current instruction
 | 
			
		||||
  input  logic [31:0]      InstrOrigM,                // Original compressed or uncompressed instruction in Memory stage for Illegal Instruction MTVAL
 | 
			
		||||
  input  logic              clk, reset,
 | 
			
		||||
  input  logic              FlushM, FlushW,
 | 
			
		||||
  input  logic              StallE, StallM, StallW,
 | 
			
		||||
  input  logic [31:0]       InstrM,                    // current instruction
 | 
			
		||||
  input  logic [31:0]       InstrOrigM,                // Original compressed or uncompressed instruction in Memory stage for Illegal Instruction MTVAL
 | 
			
		||||
  input  logic [P.XLEN-1:0] PCM, PC2NextF,             // program counter, next PC going to trap/return logic
 | 
			
		||||
  input  logic [P.XLEN-1:0] SrcAM, IEUAdrM,            // SrcA and memory address from IEU
 | 
			
		||||
  input  logic             CSRReadM, CSRWriteM,       // read or write CSR
 | 
			
		||||
  input  logic             TrapM,                     // trap is occurring
 | 
			
		||||
  input  logic             mretM, sretM, wfiM,        // return or WFI instruction
 | 
			
		||||
  input  logic             IntPendingM,               // at least one interrupt is pending and could occur if enabled
 | 
			
		||||
  input  logic             InterruptM,                // interrupt is occurring
 | 
			
		||||
  input  logic             ExceptionM,                // interrupt is occurring
 | 
			
		||||
  input  logic             MTimerInt,                 // timer interrupt
 | 
			
		||||
  input  logic             MExtInt, SExtInt,          // external interrupt (from PLIC) 
 | 
			
		||||
  input  logic             MSwInt,                    // software interrupt
 | 
			
		||||
  input  logic [63:0]      MTIME_CLINT,               // TIME value from CLINT
 | 
			
		||||
  input  logic             InstrValidM,               // current instruction is valid
 | 
			
		||||
  input  logic             FRegWriteM,                // writes to floating point registers change STATUS.FS
 | 
			
		||||
  input  logic [4:0]       SetFflagsM,                // Set floating point flag bits in FCSR
 | 
			
		||||
  input  logic [1:0]       NextPrivilegeModeM,        // STATUS bits updated based on next privilege mode
 | 
			
		||||
  input  logic [1:0]       PrivilegeModeW,            // current privilege mode
 | 
			
		||||
  input  logic [3:0]       CauseM,                    // Trap cause
 | 
			
		||||
  input  logic             SelHPTW,                   // hardware page table walker active, so base endianness on supervisor mode
 | 
			
		||||
  input  logic              CSRReadM, CSRWriteM,       // read or write CSR
 | 
			
		||||
  input  logic              TrapM,                     // trap is occurring
 | 
			
		||||
  input  logic              mretM, sretM, wfiM,        // return or WFI instruction
 | 
			
		||||
  input  logic              IntPendingM,               // at least one interrupt is pending and could occur if enabled
 | 
			
		||||
  input  logic              InterruptM,                // interrupt is occurring
 | 
			
		||||
  input  logic              ExceptionM,                // interrupt is occurring
 | 
			
		||||
  input  logic              MTimerInt,                 // timer interrupt
 | 
			
		||||
  input  logic              MExtInt, SExtInt,          // external interrupt (from PLIC) 
 | 
			
		||||
  input  logic              MSwInt,                    // software interrupt
 | 
			
		||||
  input  logic [63:0]       MTIME_CLINT,               // TIME value from CLINT
 | 
			
		||||
  input  logic              InstrValidM,               // current instruction is valid
 | 
			
		||||
  input  logic              FRegWriteM,                // writes to floating point registers change STATUS.FS
 | 
			
		||||
  input  logic [4:0]        SetFflagsM,                // Set floating point flag bits in FCSR
 | 
			
		||||
  input  logic [1:0]        NextPrivilegeModeM,        // STATUS bits updated based on next privilege mode
 | 
			
		||||
  input  logic [1:0]        PrivilegeModeW,            // current privilege mode
 | 
			
		||||
  input  logic [3:0]        CauseM,                    // Trap cause
 | 
			
		||||
  input  logic              SelHPTW,                   // hardware page table walker active, so base endianness on supervisor mode
 | 
			
		||||
  // inputs for performance counters
 | 
			
		||||
  input  logic             LoadStallD,
 | 
			
		||||
  input  logic             StoreStallD,
 | 
			
		||||
  input  logic             ICacheStallF,
 | 
			
		||||
  input  logic             DCacheStallM,
 | 
			
		||||
  input  logic             BPDirPredWrongM,
 | 
			
		||||
  input  logic             BTAWrongM,
 | 
			
		||||
  input  logic             RASPredPCWrongM,
 | 
			
		||||
  input  logic             IClassWrongM,
 | 
			
		||||
  input  logic             BPWrongM,                              // branch predictor is wrong
 | 
			
		||||
  input  logic [3:0]       InstrClassM,
 | 
			
		||||
  input  logic             DCacheMiss,
 | 
			
		||||
  input  logic             DCacheAccess,
 | 
			
		||||
  input  logic             ICacheMiss,
 | 
			
		||||
  input  logic             ICacheAccess,
 | 
			
		||||
  input  logic             sfencevmaM,
 | 
			
		||||
  input  logic             InvalidateICacheM,
 | 
			
		||||
  input  logic             DivBusyE,                                  // integer divide busy
 | 
			
		||||
  input  logic             FDivBusyE,                                 // floating point divide busy
 | 
			
		||||
  input  logic              LoadStallD,
 | 
			
		||||
  input  logic              StoreStallD,
 | 
			
		||||
  input  logic              ICacheStallF,
 | 
			
		||||
  input  logic              DCacheStallM,
 | 
			
		||||
  input  logic              BPDirPredWrongM,
 | 
			
		||||
  input  logic              BTAWrongM,
 | 
			
		||||
  input  logic              RASPredPCWrongM,
 | 
			
		||||
  input  logic              IClassWrongM,
 | 
			
		||||
  input  logic              BPWrongM,                  // branch predictor is wrong
 | 
			
		||||
  input  logic [3:0]        InstrClassM,
 | 
			
		||||
  input  logic              DCacheMiss,
 | 
			
		||||
  input  logic              DCacheAccess,
 | 
			
		||||
  input  logic              ICacheMiss,
 | 
			
		||||
  input  logic              ICacheAccess,
 | 
			
		||||
  input  logic              sfencevmaM,
 | 
			
		||||
  input  logic              InvalidateICacheM,
 | 
			
		||||
  input  logic              DivBusyE,                  // integer divide busy
 | 
			
		||||
  input  logic              FDivBusyE,                 // floating point divide busy
 | 
			
		||||
  // outputs from CSRs
 | 
			
		||||
  output logic [1:0]       STATUS_MPP,
 | 
			
		||||
  output logic             STATUS_SPP, STATUS_TSR, STATUS_TVM,
 | 
			
		||||
  output logic [15:0] MEDELEG_REGW, 
 | 
			
		||||
  output logic [1:0]        STATUS_MPP,
 | 
			
		||||
  output logic              STATUS_SPP, STATUS_TSR, STATUS_TVM,
 | 
			
		||||
  output logic [15:0]       MEDELEG_REGW, 
 | 
			
		||||
  output logic [P.XLEN-1:0] SATP_REGW,
 | 
			
		||||
  output logic [11:0]      MIP_REGW, MIE_REGW, MIDELEG_REGW,
 | 
			
		||||
  output logic             STATUS_MIE, STATUS_SIE,
 | 
			
		||||
  output logic             STATUS_MXR, STATUS_SUM, STATUS_MPRV, STATUS_TW,
 | 
			
		||||
  output logic [1:0]       STATUS_FS,
 | 
			
		||||
  output var logic [7:0]   PMPCFG_ARRAY_REGW[P.PMP_ENTRIES-1:0],
 | 
			
		||||
  output logic [11:0]       MIP_REGW, MIE_REGW, MIDELEG_REGW,
 | 
			
		||||
  output logic              STATUS_MIE, STATUS_SIE,
 | 
			
		||||
  output logic              STATUS_MXR, STATUS_SUM, STATUS_MPRV, STATUS_TW,
 | 
			
		||||
  output logic [1:0]        STATUS_FS,
 | 
			
		||||
  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 [2:0]       FRM_REGW, 
 | 
			
		||||
  output logic [2:0]        FRM_REGW, 
 | 
			
		||||
  //
 | 
			
		||||
  output logic [P.XLEN-1:0] CSRReadValW,               // value read from CSR
 | 
			
		||||
  output logic [P.XLEN-1:0] UnalignedPCNextF,          // Next PC, accounting for traps and returns
 | 
			
		||||
  output logic             IllegalCSRAccessM,         // Illegal CSR access: CSR doesn't exist or is inaccessible at this privilege level
 | 
			
		||||
  output logic             BigEndianM                 // memory access is big-endian based on privilege mode and STATUS register endian fields
 | 
			
		||||
  output logic              IllegalCSRAccessM,         // Illegal CSR access: CSR doesn't exist or is inaccessible at this privilege level
 | 
			
		||||
  output logic              BigEndianM                 // memory access is big-endian based on privilege mode and STATUS register endian fields
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
  localparam MIP = 12'h344;
 | 
			
		||||
@ -102,27 +102,27 @@ module csr import cvw::*;  #(parameter cvw_t P) (
 | 
			
		||||
  logic [P.XLEN-1:0]        MSTATUS_REGW, SSTATUS_REGW, MSTATUSH_REGW;
 | 
			
		||||
  logic [P.XLEN-1:0]        STVEC_REGW, MTVEC_REGW;
 | 
			
		||||
  logic [P.XLEN-1:0]        MEPC_REGW, SEPC_REGW;
 | 
			
		||||
  logic [31:0]             MCOUNTINHIBIT_REGW, MCOUNTEREN_REGW, SCOUNTEREN_REGW;
 | 
			
		||||
  logic                    WriteMSTATUSM, WriteMSTATUSHM, WriteSSTATUSM;
 | 
			
		||||
  logic                    CSRMWriteM, CSRSWriteM, CSRUWriteM;
 | 
			
		||||
  logic                    UngatedCSRMWriteM;
 | 
			
		||||
  logic                    WriteFRMM, WriteFFLAGSM;
 | 
			
		||||
  logic [31:0]              MCOUNTINHIBIT_REGW, MCOUNTEREN_REGW, SCOUNTEREN_REGW;
 | 
			
		||||
  logic                     WriteMSTATUSM, WriteMSTATUSHM, WriteSSTATUSM;
 | 
			
		||||
  logic                     CSRMWriteM, CSRSWriteM, CSRUWriteM;
 | 
			
		||||
  logic                     UngatedCSRMWriteM;
 | 
			
		||||
  logic                     WriteFRMM, WriteFFLAGSM;
 | 
			
		||||
  logic [P.XLEN-1:0]        UnalignedNextEPCM, NextEPCM, NextMtvalM;
 | 
			
		||||
  logic [4:0]              NextCauseM;
 | 
			
		||||
  logic [11:0]             CSRAdrM;
 | 
			
		||||
  logic                    IllegalCSRCAccessM, IllegalCSRMAccessM, IllegalCSRSAccessM, IllegalCSRUAccessM;
 | 
			
		||||
  logic                    InsufficientCSRPrivilegeM;
 | 
			
		||||
  logic                    IllegalCSRMWriteReadonlyM;
 | 
			
		||||
  logic [4:0]               NextCauseM;
 | 
			
		||||
  logic [11:0]              CSRAdrM;
 | 
			
		||||
  logic                     IllegalCSRCAccessM, IllegalCSRMAccessM, IllegalCSRSAccessM, IllegalCSRUAccessM;
 | 
			
		||||
  logic                     InsufficientCSRPrivilegeM;
 | 
			
		||||
  logic                     IllegalCSRMWriteReadonlyM;
 | 
			
		||||
  logic [P.XLEN-1:0]        CSRReadVal2M;
 | 
			
		||||
  logic [11:0]             MIP_REGW_writeable;
 | 
			
		||||
  logic [11:0]              MIP_REGW_writeable;
 | 
			
		||||
  logic [P.XLEN-1:0]        TVecM, TrapVectorM, NextFaultMtvalM;
 | 
			
		||||
  logic                    MTrapM, STrapM;
 | 
			
		||||
  logic                     MTrapM, STrapM;
 | 
			
		||||
  logic [P.XLEN-1:0]        EPC;
 | 
			
		||||
  logic                    RetM;
 | 
			
		||||
  logic                    SelMtvecM;
 | 
			
		||||
  logic                     RetM;
 | 
			
		||||
  logic                     SelMtvecM;
 | 
			
		||||
  logic [P.XLEN-1:0]        TVecAlignedM;
 | 
			
		||||
  logic                    InstrValidNotFlushedM;
 | 
			
		||||
  logic                    STimerInt;
 | 
			
		||||
  logic                     InstrValidNotFlushedM;
 | 
			
		||||
  logic                     STimerInt;
 | 
			
		||||
 | 
			
		||||
  // only valid unflushed instructions can access CSRs
 | 
			
		||||
  assign InstrValidNotFlushedM = InstrValidM & ~StallW & ~FlushW;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user