forked from Github_Repos/cvw
		
	Export SATP_REGW from csrs to MMU modules
This commit is contained in:
		
							parent
							
								
									3303a013ef
								
							
						
					
					
						commit
						7e11317a2d
					
				@ -51,25 +51,19 @@ module dmem (
 | 
				
			|||||||
  output logic             StoreMisalignedFaultM, StoreAccessFaultM,
 | 
					  output logic             StoreMisalignedFaultM, StoreAccessFaultM,
 | 
				
			||||||
  // TLB management
 | 
					  // TLB management
 | 
				
			||||||
  //input logic  [`XLEN-1:0] PageTableEntryM,
 | 
					  //input logic  [`XLEN-1:0] PageTableEntryM,
 | 
				
			||||||
 | 
					  input logic  [`XLEN-1:0] SATP_REGW,
 | 
				
			||||||
  //input logic              DTLBWriteM, DTLBFlushM,
 | 
					  //input logic              DTLBWriteM, DTLBFlushM,
 | 
				
			||||||
  // *** satp value will come from CSRs
 | 
					 | 
				
			||||||
  // input logic [`XLEN-1:0] SATP,
 | 
					 | 
				
			||||||
  output logic             DTLBMissM, DTLBHitM
 | 
					  output logic             DTLBMissM, DTLBHitM
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logic             SquashSCM;
 | 
					  logic             SquashSCM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Initially no MMU
 | 
					 | 
				
			||||||
  // *** temporary hack until we can figure out how to get actual satp value
 | 
					 | 
				
			||||||
  // from priv unit -- Thomas F
 | 
					 | 
				
			||||||
  logic [`XLEN-1:0] SATP = '0;
 | 
					 | 
				
			||||||
  // *** temporary hack until walker is hooked up -- Thomas F
 | 
					  // *** temporary hack until walker is hooked up -- Thomas F
 | 
				
			||||||
  logic  [`XLEN-1:0] PageTableEntryM = '0;
 | 
					  logic  [`XLEN-1:0] PageTableEntryM = '0;
 | 
				
			||||||
  logic DTLBFlushM = '0;
 | 
					  logic DTLBFlushM = '0;
 | 
				
			||||||
  logic DTLBWriteM = '0;
 | 
					  logic DTLBWriteM = '0;
 | 
				
			||||||
  tlb #(3) dtlb(clk, reset, SATP, MemAdrM, PageTableEntryM, DTLBWriteM,
 | 
					  tlb #(3) dtlb(clk, reset, SATP_REGW, MemAdrM, PageTableEntryM, DTLBWriteM,
 | 
				
			||||||
    DTLBFlushM, MemPAdrM, DTLBMissM, DTLBHitM);
 | 
					    DTLBFlushM, MemPAdrM, DTLBMissM, DTLBHitM);
 | 
				
			||||||
  //assign MemPAdrM = MemAdrM;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Determine if an Unaligned access is taking place
 | 
						// Determine if an Unaligned access is taking place
 | 
				
			||||||
	always_comb
 | 
						always_comb
 | 
				
			||||||
 | 
				
			|||||||
@ -44,6 +44,8 @@ module ahblite (
 | 
				
			|||||||
  input  logic             MemReadM, MemWriteM,
 | 
					  input  logic             MemReadM, MemWriteM,
 | 
				
			||||||
  input  logic [`XLEN-1:0] WriteDataM,
 | 
					  input  logic [`XLEN-1:0] WriteDataM,
 | 
				
			||||||
  input  logic [1:0]       MemSizeM,
 | 
					  input  logic [1:0]       MemSizeM,
 | 
				
			||||||
 | 
					  // Signals from MMU ***
 | 
				
			||||||
 | 
					  // MMUPAdr;
 | 
				
			||||||
  // Return from bus
 | 
					  // Return from bus
 | 
				
			||||||
  output logic [`XLEN-1:0] ReadDataW,
 | 
					  output logic [`XLEN-1:0] ReadDataW,
 | 
				
			||||||
  // AHB-Lite external signals
 | 
					  // AHB-Lite external signals
 | 
				
			||||||
@ -64,6 +66,7 @@ module ahblite (
 | 
				
			|||||||
  output logic             HWRITED,
 | 
					  output logic             HWRITED,
 | 
				
			||||||
  // Stalls
 | 
					  // Stalls
 | 
				
			||||||
  output logic             InstrStall,/*InstrUpdate, */DataStall
 | 
					  output logic             InstrStall,/*InstrUpdate, */DataStall
 | 
				
			||||||
 | 
					  // *** add a chip-level ready signal as part of handshake
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logic GrantData;
 | 
					  logic GrantData;
 | 
				
			||||||
@ -75,7 +78,7 @@ module ahblite (
 | 
				
			|||||||
  assign HCLK = clk;
 | 
					  assign HCLK = clk;
 | 
				
			||||||
  assign HRESETn = ~reset;
 | 
					  assign HRESETn = ~reset;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // *** initially support HABW = XLEN
 | 
					  // *** initially support AHBW = XLEN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // track bus state
 | 
					  // track bus state
 | 
				
			||||||
  // Data accesses have priority over instructions.  However, if a data access comes
 | 
					  // Data accesses have priority over instructions.  However, if a data access comes
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
///////////////////////////////////////////
 | 
					///////////////////////////////////////////
 | 
				
			||||||
// ahblite.sv
 | 
					// pagetablewalker.sv
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Written: tfleming@hmc.edu 2 March 2021
 | 
					// Written: tfleming@hmc.edu 2 March 2021
 | 
				
			||||||
// Modified: 
 | 
					// Modified: 
 | 
				
			||||||
@ -29,16 +29,17 @@
 | 
				
			|||||||
module pagetablewalker (
 | 
					module pagetablewalker (
 | 
				
			||||||
  input  logic             clk, reset,
 | 
					  input  logic             clk, reset,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  input  logic [`XLEN-1:0] satp,
 | 
					  input  logic [`XLEN-1:0] SATP_REGW,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  input  logic             TLBMissF,
 | 
					  input  logic             ITLBMissF, DTLBMissM,
 | 
				
			||||||
  input  logic [`XLEN-1:0] TranslationVAdr,
 | 
					  input  logic [`XLEN-1:0] TranslationVAdr,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  input  logic             HCLK, HRESETn,
 | 
					  input  logic             HCLK, HRESETn,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  input  logic             HREADY,
 | 
					  input  logic             HREADY,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  output logic [`XLEN-1:0] PageTableEntryF,
 | 
					  output logic [`XLEN-1:0] PageTableEntryF, PageTableEntryM,
 | 
				
			||||||
 | 
					  output logic             ITLBWriteF, DTLBWriteM,
 | 
				
			||||||
  output logic             TranslationComplete
 | 
					  output logic             TranslationComplete
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -52,15 +53,15 @@ module pagetablewalker (
 | 
				
			|||||||
  endgenerate
 | 
					  endgenerate
 | 
				
			||||||
  */
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logic Sv_Mode = satp[31];
 | 
					  logic Sv_Mode = SATP_REGW[31];
 | 
				
			||||||
  logic BasePageTablePPN [21:0] = satp[21:0];
 | 
					  logic BasePageTablePPN [21:0] = SATP_REGW[21:0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logic VPN1 [9:0] = TranslationVAdr[31:22];
 | 
					  logic VPN1 [9:0] = TranslationVAdr[31:22];
 | 
				
			||||||
  logic VPN0 [9:0] = TranslationVAdr[21:12]; // *** could optimize by not passing offset?
 | 
					  logic VPN0 [9:0] = TranslationVAdr[21:12]; // *** could optimize by not passing offset?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logic TranslationPAdr [33:0];
 | 
					  logic TranslationPAdr [33:0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  typedef enum {IDLE, LEVEL1, LEVEL0, LEAF, FAULT} statetype;
 | 
					  typedef enum {IDLE, DATA_LEVEL1, DATA_LEVEL0, DATA_LEAF, DATA FAULT} statetype;
 | 
				
			||||||
  statetype WalkerState, NextWalkerState;
 | 
					  statetype WalkerState, NextWalkerState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  always_ff @(posedge HCLK, negedge HRESETn)
 | 
					  always_ff @(posedge HCLK, negedge HRESETn)
 | 
				
			||||||
@ -92,11 +93,14 @@ module pagetablewalker (
 | 
				
			|||||||
      case (NextWalkerState)
 | 
					      case (NextWalkerState)
 | 
				
			||||||
        LEVEL1: TranslationPAdr <= {BasePageTablePPN, VPN1, 2'b00};
 | 
					        LEVEL1: TranslationPAdr <= {BasePageTablePPN, VPN1, 2'b00};
 | 
				
			||||||
        LEVEL2: TranslationPAdr <= {CurrentPPN, VPN0, 2'b00};
 | 
					        LEVEL2: TranslationPAdr <= {CurrentPPN, VPN0, 2'b00};
 | 
				
			||||||
        LEAF:   PageTableEntryF <= CurrentPageTableEntry;
 | 
					        LEAF: begin
 | 
				
			||||||
                TranslationComplete <= '1;
 | 
					          PageTableEntryF <= CurrentPageTableEntry;
 | 
				
			||||||
 | 
					          TranslationComplete <= '1;
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					      endcase
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  assign #1 Translate = (NextWalkerState = LEVEL1);
 | 
					  assign #1 Translate = (NextWalkerState == LEVEL1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
endmodule
 | 
					endmodule
 | 
				
			||||||
@ -54,9 +54,8 @@ module ifu (
 | 
				
			|||||||
  output logic [`XLEN-1:0] InstrMisalignedAdrM,
 | 
					  output logic [`XLEN-1:0] InstrMisalignedAdrM,
 | 
				
			||||||
  // TLB management
 | 
					  // TLB management
 | 
				
			||||||
  //input logic  [`XLEN-1:0] PageTableEntryF,
 | 
					  //input logic  [`XLEN-1:0] PageTableEntryF,
 | 
				
			||||||
 | 
					  input logic  [`XLEN-1:0] SATP_REGW,
 | 
				
			||||||
  //input logic              ITLBWriteF, ITLBFlushF,
 | 
					  //input logic              ITLBWriteF, ITLBFlushF,
 | 
				
			||||||
  // *** satp value will come from CSRs
 | 
					 | 
				
			||||||
  // input logic [`XLEN-1:0] SATP,
 | 
					 | 
				
			||||||
  output logic             ITLBMissF, ITLBHitF,
 | 
					  output logic             ITLBMissF, ITLBHitF,
 | 
				
			||||||
  // bogus
 | 
					  // bogus
 | 
				
			||||||
  input  logic [15:0] rd2
 | 
					  input  logic [15:0] rd2
 | 
				
			||||||
@ -71,14 +70,11 @@ module ifu (
 | 
				
			|||||||
  logic [31:0]     InstrF, InstrRawD, InstrE, InstrW;
 | 
					  logic [31:0]     InstrF, InstrRawD, InstrE, InstrW;
 | 
				
			||||||
  logic [31:0]     nop = 32'h00000013; // instruction for NOP
 | 
					  logic [31:0]     nop = 32'h00000013; // instruction for NOP
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // *** temporary hack until we can figure out how to get actual satp value
 | 
					 | 
				
			||||||
  // from priv unit -- Thomas F
 | 
					 | 
				
			||||||
  logic [`XLEN-1:0] SATP = '0;
 | 
					 | 
				
			||||||
  // *** temporary hack until walker is hooked up -- Thomas F
 | 
					  // *** temporary hack until walker is hooked up -- Thomas F
 | 
				
			||||||
  logic  [`XLEN-1:0] PageTableEntryF = '0;
 | 
					  logic  [`XLEN-1:0] PageTableEntryF = '0;
 | 
				
			||||||
  logic ITLBFlushF = '0;
 | 
					  logic ITLBFlushF = '0;
 | 
				
			||||||
  logic ITLBWriteF = '0;
 | 
					  logic ITLBWriteF = '0;
 | 
				
			||||||
  tlb #(3) itlb(clk, reset, SATP, PCF, PageTableEntryF, ITLBWriteF, ITLBFlushF,
 | 
					  tlb #(3) itlb(clk, reset, SATP_REGW, PCF, PageTableEntryF, ITLBWriteF, ITLBFlushF,
 | 
				
			||||||
    InstrPAdrF, ITLBMissF, ITLBHitF);
 | 
					    InstrPAdrF, ITLBMissF, ITLBHitF);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // *** put memory interface on here, InstrF becomes output
 | 
					  // *** put memory interface on here, InstrF becomes output
 | 
				
			||||||
 | 
				
			|||||||
@ -40,6 +40,7 @@ module csr (
 | 
				
			|||||||
  output logic             STATUS_SPP, STATUS_TSR,
 | 
					  output logic             STATUS_SPP, STATUS_TSR,
 | 
				
			||||||
  output logic [`XLEN-1:0] MEPC_REGW, SEPC_REGW, UEPC_REGW, UTVEC_REGW, STVEC_REGW, MTVEC_REGW,
 | 
					  output logic [`XLEN-1:0] MEPC_REGW, SEPC_REGW, UEPC_REGW, UTVEC_REGW, STVEC_REGW, MTVEC_REGW,
 | 
				
			||||||
  output logic [`XLEN-1:0] MEDELEG_REGW, MIDELEG_REGW, SEDELEG_REGW, SIDELEG_REGW, 
 | 
					  output logic [`XLEN-1:0] MEDELEG_REGW, MIDELEG_REGW, SEDELEG_REGW, SIDELEG_REGW, 
 | 
				
			||||||
 | 
					  output logic [`XLEN-1:0] SATP_REGW,
 | 
				
			||||||
  output logic [11:0]      MIP_REGW, MIE_REGW,
 | 
					  output logic [11:0]      MIP_REGW, MIE_REGW,
 | 
				
			||||||
  output logic             STATUS_MIE, STATUS_SIE,
 | 
					  output logic             STATUS_MIE, STATUS_SIE,
 | 
				
			||||||
  input  logic [4:0]       SetFflagsM,
 | 
					  input  logic [4:0]       SetFflagsM,
 | 
				
			||||||
@ -126,6 +127,7 @@ module csr (
 | 
				
			|||||||
      assign MIDELEG_REGW = 0;
 | 
					      assign MIDELEG_REGW = 0;
 | 
				
			||||||
      assign SEDELEG_REGW = 0;
 | 
					      assign SEDELEG_REGW = 0;
 | 
				
			||||||
      assign SIDELEG_REGW = 0;
 | 
					      assign SIDELEG_REGW = 0;
 | 
				
			||||||
 | 
					      assign SATP_REGW = 0;
 | 
				
			||||||
      assign MIP_REGW = 0;
 | 
					      assign MIP_REGW = 0;
 | 
				
			||||||
      assign MIE_REGW = 0;
 | 
					      assign MIE_REGW = 0;
 | 
				
			||||||
      assign STATUS_MIE = 0;
 | 
					      assign STATUS_MIE = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -48,6 +48,7 @@ module csrs #(parameter
 | 
				
			|||||||
    output logic [`XLEN-1:0] CSRSReadValM, SEPC_REGW, STVEC_REGW, 
 | 
					    output logic [`XLEN-1:0] CSRSReadValM, SEPC_REGW, STVEC_REGW, 
 | 
				
			||||||
    output logic [31:0]      SCOUNTEREN_REGW,     
 | 
					    output logic [31:0]      SCOUNTEREN_REGW,     
 | 
				
			||||||
    output logic [`XLEN-1:0] SEDELEG_REGW, SIDELEG_REGW, 
 | 
					    output logic [`XLEN-1:0] SEDELEG_REGW, SIDELEG_REGW, 
 | 
				
			||||||
 | 
					    output logic [`XLEN-1:0] SATP_REGW,
 | 
				
			||||||
    input  logic [11:0]      SIP_REGW, SIE_REGW,
 | 
					    input  logic [11:0]      SIP_REGW, SIE_REGW,
 | 
				
			||||||
    output logic             WriteSSTATUSM,
 | 
					    output logic             WriteSSTATUSM,
 | 
				
			||||||
    output logic             IllegalCSRSAccessM
 | 
					    output logic             IllegalCSRSAccessM
 | 
				
			||||||
@ -63,7 +64,7 @@ module csrs #(parameter
 | 
				
			|||||||
      logic WriteSTVECM;
 | 
					      logic WriteSTVECM;
 | 
				
			||||||
      logic WriteSSCRATCHM, WriteSEPCM;
 | 
					      logic WriteSSCRATCHM, WriteSEPCM;
 | 
				
			||||||
      logic WriteSCAUSEM, WriteSTVALM, WriteSATPM, WriteSCOUNTERENM;
 | 
					      logic WriteSCAUSEM, WriteSTVALM, WriteSATPM, WriteSCOUNTERENM;
 | 
				
			||||||
      logic [`XLEN-1:0] SSCRATCH_REGW, SCAUSE_REGW, STVAL_REGW, SATP_REGW;
 | 
					      logic [`XLEN-1:0] SSCRATCH_REGW, SCAUSE_REGW, STVAL_REGW;
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      assign WriteSSTATUSM = CSRSWriteM && (CSRAdrM == SSTATUS);
 | 
					      assign WriteSSTATUSM = CSRSWriteM && (CSRAdrM == SSTATUS);
 | 
				
			||||||
      assign WriteSTVECM = CSRSWriteM && (CSRAdrM == STVEC);
 | 
					      assign WriteSTVECM = CSRSWriteM && (CSRAdrM == STVEC);
 | 
				
			||||||
@ -123,6 +124,7 @@ module csrs #(parameter
 | 
				
			|||||||
      assign SEDELEG_REGW = 0;
 | 
					      assign SEDELEG_REGW = 0;
 | 
				
			||||||
      assign SIDELEG_REGW = 0;
 | 
					      assign SIDELEG_REGW = 0;
 | 
				
			||||||
      assign SCOUNTEREN_REGW = 0;
 | 
					      assign SCOUNTEREN_REGW = 0;
 | 
				
			||||||
 | 
					      assign SATP_REGW = 0;
 | 
				
			||||||
      assign IllegalCSRSAccessM = 1;
 | 
					      assign IllegalCSRSAccessM = 1;
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  endgenerate
 | 
					  endgenerate
 | 
				
			||||||
 | 
				
			|||||||
@ -44,6 +44,7 @@ module privileged (
 | 
				
			|||||||
  input  logic             TimerIntM, ExtIntM, SwIntM,
 | 
					  input  logic             TimerIntM, ExtIntM, SwIntM,
 | 
				
			||||||
  input  logic [`XLEN-1:0] InstrMisalignedAdrM, MemAdrM,
 | 
					  input  logic [`XLEN-1:0] InstrMisalignedAdrM, MemAdrM,
 | 
				
			||||||
  input  logic [4:0]       SetFflagsM,
 | 
					  input  logic [4:0]       SetFflagsM,
 | 
				
			||||||
 | 
					  output logic [`XLEN-1:0] SATP_REGW,
 | 
				
			||||||
  output logic [2:0]       FRM_REGW,
 | 
					  output logic [2:0]       FRM_REGW,
 | 
				
			||||||
  input  logic             FlushD, FlushE, FlushM, StallD, StallW
 | 
					  input  logic             FlushD, FlushE, FlushM, StallD, StallW
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
				
			|||||||
@ -88,8 +88,12 @@ module wallypipelinedhart (
 | 
				
			|||||||
  logic       SquashSCW;
 | 
					  logic       SquashSCW;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // memory management unit signals
 | 
					  // memory management unit signals
 | 
				
			||||||
 | 
					  logic             ITLBWriteF, DTLBWriteM;
 | 
				
			||||||
  logic             ITLBMissF, ITLBHitF;
 | 
					  logic             ITLBMissF, ITLBHitF;
 | 
				
			||||||
  logic             DTLBMissM, DTLBHitM;
 | 
					  logic             DTLBMissM, DTLBHitM;
 | 
				
			||||||
 | 
					  logic [`XLEN-1:0] SATP_REGW;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  logic [`XLEN-1:0] PageTableEntryF, PageTableEntryM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // bus interface to dmem
 | 
					  // bus interface to dmem
 | 
				
			||||||
  logic             MemReadM, MemWriteM;
 | 
					  logic             MemReadM, MemWriteM;
 | 
				
			||||||
@ -114,6 +118,8 @@ module wallypipelinedhart (
 | 
				
			|||||||
    .MemSizeM(Funct3M[1:0]), .UnsignedLoadM(Funct3M[2]),
 | 
					    .MemSizeM(Funct3M[1:0]), .UnsignedLoadM(Funct3M[2]),
 | 
				
			||||||
    .*);
 | 
					    .*);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // walker walker(.*); *** // can send addresses to ahblite, send out pagetablestall
 | 
				
			||||||
 | 
					  // *** can connect to hazard unit
 | 
				
			||||||
// changing from this to the line above breaks the program.  auipc at 104 fails; seems to be flushed.
 | 
					// changing from this to the line above breaks the program.  auipc at 104 fails; seems to be flushed.
 | 
				
			||||||
// Would need to insertinstruction as InstrD, not InstrF
 | 
					// Would need to insertinstruction as InstrD, not InstrF
 | 
				
			||||||
    /*ahblite ebu( 
 | 
					    /*ahblite ebu( 
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user