2021-01-15 04:37:51 +00:00
|
|
|
///////////////////////////////////////////
|
2021-01-28 03:49:47 +00:00
|
|
|
// ifu.sv
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu 9 January 2021
|
2021-03-30 19:25:07 +00:00
|
|
|
// Modified:
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2021-01-28 03:49:47 +00:00
|
|
|
// Purpose: Instrunction Fetch Unit
|
|
|
|
// PC, branch prediction, instruction cache
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
2021-01-23 15:48:12 +00:00
|
|
|
`include "wally-config.vh"
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-01-28 03:49:47 +00:00
|
|
|
module ifu (
|
2021-11-21 04:35:47 +00:00
|
|
|
input logic clk, reset,
|
|
|
|
input logic StallF, StallD, StallE, StallM, StallW,
|
|
|
|
input logic FlushF, FlushD, FlushE, FlushM, FlushW,
|
2021-02-02 04:44:41 +00:00
|
|
|
// Fetch
|
2021-11-21 04:35:47 +00:00
|
|
|
input logic [`XLEN-1:0] InstrInF,
|
|
|
|
input logic InstrAckF,
|
2021-12-17 20:40:25 +00:00
|
|
|
(* mark_debug = "true" *) output logic [`XLEN-1:0] PCF,
|
2021-11-21 04:35:47 +00:00
|
|
|
output logic [`PA_BITS-1:0] InstrPAdrF,
|
|
|
|
output logic InstrReadF,
|
|
|
|
output logic ICacheStallF,
|
2021-02-02 04:44:41 +00:00
|
|
|
// Execute
|
2021-11-21 04:35:47 +00:00
|
|
|
output logic [`XLEN-1:0] PCLinkE,
|
|
|
|
input logic PCSrcE,
|
2021-12-15 20:10:45 +00:00
|
|
|
input logic [`XLEN-1:0] IEUAdrE,
|
2021-11-21 04:35:47 +00:00
|
|
|
output logic [`XLEN-1:0] PCE,
|
|
|
|
output logic BPPredWrongE,
|
2021-02-02 04:44:41 +00:00
|
|
|
// Mem
|
2021-11-21 04:35:47 +00:00
|
|
|
input logic RetM, TrapM,
|
|
|
|
input logic [`XLEN-1:0] PrivilegedNextPCM,
|
|
|
|
input logic InvalidateICacheM,
|
|
|
|
output logic [31:0] InstrD, InstrM,
|
|
|
|
output logic [`XLEN-1:0] PCM,
|
|
|
|
output logic [4:0] InstrClassM,
|
|
|
|
output logic BPPredDirWrongM,
|
|
|
|
output logic BTBPredPCWrongM,
|
|
|
|
output logic RASPredPCWrongM,
|
|
|
|
output logic BPPredClassNonCFIWrongM,
|
2021-02-02 04:44:41 +00:00
|
|
|
// Writeback
|
2021-03-18 20:31:21 +00:00
|
|
|
// output logic [`XLEN-1:0] PCLinkW,
|
2021-02-02 04:44:41 +00:00
|
|
|
// Faults
|
2021-11-21 04:35:47 +00:00
|
|
|
input logic IllegalBaseInstrFaultD,
|
|
|
|
output logic ITLBInstrPageFaultF,
|
|
|
|
output logic IllegalIEUInstrFaultD,
|
|
|
|
output logic InstrMisalignedFaultM,
|
|
|
|
output logic [`XLEN-1:0] InstrMisalignedAdrM,
|
|
|
|
input logic ExceptionM, PendingInterruptM,
|
|
|
|
|
2021-06-04 21:05:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
// mmu management
|
2021-11-21 04:35:47 +00:00
|
|
|
input logic [1:0] PrivilegeModeW,
|
|
|
|
input logic [`XLEN-1:0] PTE,
|
|
|
|
input logic [1:0] PageType,
|
|
|
|
input logic [`XLEN-1:0] SATP_REGW,
|
|
|
|
input logic STATUS_MXR, STATUS_SUM, STATUS_MPRV,
|
|
|
|
input logic [1:0] STATUS_MPP,
|
|
|
|
input logic ITLBWriteF, ITLBFlushF,
|
|
|
|
input logic WalkerInstrPageFaultF,
|
2021-07-01 22:59:55 +00:00
|
|
|
|
2021-11-21 04:35:47 +00:00
|
|
|
output logic ITLBMissF,
|
2021-06-04 15:59:14 +00:00
|
|
|
|
2021-06-04 21:05:07 +00:00
|
|
|
// pmp/pma (inside mmu) signals. *** temporarily from AHB bus but eventually replace with internal versions pre H
|
2021-11-21 04:35:47 +00:00
|
|
|
input var logic [7:0] PMPCFG_ARRAY_REGW[`PMP_ENTRIES-1:0],
|
|
|
|
input var logic [`XLEN-1:0] PMPADDR_ARRAY_REGW[`PMP_ENTRIES-1:0],
|
2021-06-04 21:05:07 +00:00
|
|
|
|
2021-11-21 04:35:47 +00:00
|
|
|
output logic InstrAccessFaultF
|
2021-01-28 03:49:47 +00:00
|
|
|
);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-10-27 19:43:55 +00:00
|
|
|
logic [`XLEN-1:0] PCCorrectE, UnalignedPCNextF, PCNextF;
|
|
|
|
logic misaligned, BranchMisalignedFaultE, BranchMisalignedFaultM, TrapMisalignedFaultM;
|
|
|
|
logic PrivilegedChangePCM;
|
|
|
|
logic IllegalCompInstrD;
|
|
|
|
logic [`XLEN-1:0] PCPlus2or4F, PCLinkD;
|
|
|
|
logic [`XLEN-3:0] PCPlusUpperF;
|
|
|
|
logic CompressedF;
|
|
|
|
logic [31:0] InstrRawD, FinalInstrRawF;
|
|
|
|
logic [31:0] InstrE;
|
|
|
|
logic [`XLEN-1:0] PCD;
|
2021-10-23 19:00:32 +00:00
|
|
|
|
2021-04-21 21:06:27 +00:00
|
|
|
localparam [31:0] nop = 32'h00000013; // instruction for NOP
|
2021-10-27 19:43:55 +00:00
|
|
|
logic reset_q; // *** look at this later.
|
2021-01-28 03:49:47 +00:00
|
|
|
|
2021-10-27 19:43:55 +00:00
|
|
|
logic BPPredDirWrongE, BTBPredPCWrongE, RASPredPCWrongE, BPPredClassNonCFIWrongE;
|
2021-07-06 18:43:53 +00:00
|
|
|
|
2021-12-17 20:40:25 +00:00
|
|
|
(* mark_debug = "true" *) logic [`PA_BITS-1:0] PCPFmmu, PCNextFPhys; // used to either truncate or expand PCPF and PCNextF into `PA_BITS width.
|
2021-10-27 19:43:55 +00:00
|
|
|
logic [`XLEN+1:0] PCFExt;
|
2021-06-18 13:11:31 +00:00
|
|
|
|
|
|
|
generate
|
2021-06-24 23:59:29 +00:00
|
|
|
if (`XLEN==32) begin
|
2021-10-23 19:00:32 +00:00
|
|
|
//assign PCPF = PCPFmmu[31:0];
|
2021-06-24 23:59:29 +00:00
|
|
|
assign PCNextFPhys = {{(`PA_BITS-`XLEN){1'b0}}, PCNextF};
|
|
|
|
end else begin
|
2021-10-23 19:00:32 +00:00
|
|
|
//assign PCPF = {8'b0, PCPFmmu};
|
2021-06-24 23:59:29 +00:00
|
|
|
assign PCNextFPhys = PCNextF[`PA_BITS-1:0];
|
|
|
|
end
|
2021-06-18 13:11:31 +00:00
|
|
|
endgenerate
|
|
|
|
|
2021-07-19 15:33:27 +00:00
|
|
|
assign PCFExt = {2'b00, PCF};
|
2021-12-14 20:46:29 +00:00
|
|
|
//
|
2021-07-04 21:52:00 +00:00
|
|
|
mmu #(.TLB_ENTRIES(`ITLB_ENTRIES), .IMMU(1))
|
2021-07-19 15:33:27 +00:00
|
|
|
immu(.PAdr(PCFExt[`PA_BITS-1:0]),
|
|
|
|
.VAdr(PCF),
|
2021-06-24 18:05:22 +00:00
|
|
|
.Size(2'b10),
|
2021-07-17 19:04:39 +00:00
|
|
|
.PTE(PTE),
|
2021-07-17 06:31:23 +00:00
|
|
|
.PageTypeWriteVal(PageType),
|
2021-06-24 18:05:22 +00:00
|
|
|
.TLBWrite(ITLBWriteF),
|
|
|
|
.TLBFlush(ITLBFlushF),
|
|
|
|
.PhysicalAddress(PCPFmmu),
|
|
|
|
.TLBMiss(ITLBMissF),
|
|
|
|
.TLBPageFault(ITLBInstrPageFaultF),
|
2021-07-03 07:29:33 +00:00
|
|
|
.ExecuteAccessF(1'b1), // ***dh -- this should eventually change to only true if an instruction fetch is occurring
|
2021-06-24 18:05:22 +00:00
|
|
|
.AtomicAccessM(1'b0),
|
2021-07-02 18:56:49 +00:00
|
|
|
.ReadAccessM(1'b0),
|
|
|
|
.WriteAccessM(1'b0),
|
2021-07-06 18:43:53 +00:00
|
|
|
.LoadAccessFaultM(),
|
|
|
|
.StoreAccessFaultM(),
|
2021-06-24 18:05:22 +00:00
|
|
|
.DisableTranslation(1'b0),
|
2021-12-02 17:45:55 +00:00
|
|
|
.Cacheable(), .Idempotent(), .AtomicAllowed(),
|
2021-03-04 08:11:34 +00:00
|
|
|
|
2021-12-02 17:45:55 +00:00
|
|
|
.clk, .reset,
|
|
|
|
.SATP_REGW,
|
|
|
|
.STATUS_MXR, .STATUS_SUM, .STATUS_MPRV,
|
|
|
|
.STATUS_MPP,
|
|
|
|
.PrivilegeModeW,
|
|
|
|
.InstrAccessFaultF,
|
2021-12-02 18:32:35 +00:00
|
|
|
.PMPCFG_ARRAY_REGW,
|
2021-12-02 17:45:55 +00:00
|
|
|
.PMPADDR_ARRAY_REGW
|
|
|
|
);
|
2021-06-04 15:59:14 +00:00
|
|
|
|
2021-12-02 17:45:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
// branch predictor signal
|
2021-10-27 19:43:55 +00:00
|
|
|
logic SelBPPredF;
|
|
|
|
logic [`XLEN-1:0] BPPredPCF, PCNext0F, PCNext1F, PCNext2F, PCNext3F;
|
|
|
|
logic [4:0] InstrClassD, InstrClassE;
|
2021-03-04 15:23:35 +00:00
|
|
|
|
2021-02-18 04:19:17 +00:00
|
|
|
|
2021-01-28 03:49:47 +00:00
|
|
|
// *** put memory interface on here, InstrF becomes output
|
2021-03-04 08:11:34 +00:00
|
|
|
//assign InstrPAdrF = PCF; // *** no MMU
|
2021-02-15 15:10:50 +00:00
|
|
|
//assign InstrReadF = ~StallD; // *** & ICacheMissF; add later
|
2021-03-30 19:25:07 +00:00
|
|
|
// assign InstrReadF = 1; // *** & ICacheMissF; add later
|
|
|
|
|
2021-12-14 20:46:29 +00:00
|
|
|
// conditional
|
2021-12-14 21:43:06 +00:00
|
|
|
// 1. ram // controlled by `MEM_IROM
|
2021-12-14 20:46:29 +00:00
|
|
|
// 2. cache // `MEM_ICACHE
|
|
|
|
// 3. wire pass-through
|
2021-12-02 18:32:35 +00:00
|
|
|
icache icache(.clk, .reset, .StallF, .ExceptionM, .PendingInterruptM, .InstrInF, .InstrAckF,
|
|
|
|
.InstrPAdrF, .InstrReadF, .CompressedF, .ICacheStallF, .ITLBMissF, .ITLBWriteF, .FinalInstrRawF,
|
|
|
|
|
2021-10-27 19:43:55 +00:00
|
|
|
.PCNextF(PCNextFPhys),
|
|
|
|
.PCPF(PCPFmmu),
|
2021-12-19 20:57:42 +00:00
|
|
|
.PCF,
|
2021-10-27 19:43:55 +00:00
|
|
|
.WalkerInstrPageFaultF,
|
|
|
|
.InvalidateICacheM);
|
2021-05-03 17:03:17 +00:00
|
|
|
|
2021-06-23 20:13:56 +00:00
|
|
|
flopenl #(32) AlignedInstrRawDFlop(clk, reset | reset_q, ~StallD, FlushD ? nop : FinalInstrRawF, nop, InstrRawD);
|
2021-05-03 17:03:17 +00:00
|
|
|
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
assign PrivilegedChangePCM = RetM | TrapM;
|
|
|
|
|
2021-02-18 04:19:17 +00:00
|
|
|
mux2 #(`XLEN) pcmux0(.d0(PCPlus2or4F),
|
2021-10-27 19:43:55 +00:00
|
|
|
.d1(BPPredPCF),
|
|
|
|
.s(SelBPPredF),
|
|
|
|
.y(PCNext0F));
|
2021-02-18 04:19:17 +00:00
|
|
|
|
|
|
|
mux2 #(`XLEN) pcmux1(.d0(PCNext0F),
|
2021-10-27 19:43:55 +00:00
|
|
|
.d1(PCCorrectE),
|
|
|
|
.s(BPPredWrongE),
|
|
|
|
.y(PCNext1F));
|
2021-02-18 04:19:17 +00:00
|
|
|
|
|
|
|
mux2 #(`XLEN) pcmux2(.d0(PCNext1F),
|
2021-10-27 19:43:55 +00:00
|
|
|
.d1(PCE),
|
|
|
|
.s(InvalidateICacheM),
|
|
|
|
.y(PCNext2F));
|
2021-09-17 15:25:21 +00:00
|
|
|
|
|
|
|
mux2 #(`XLEN) pcmux3(.d0(PCNext2F),
|
2021-10-27 19:43:55 +00:00
|
|
|
.d1(PrivilegedNextPCM),
|
|
|
|
.s(PrivilegedChangePCM),
|
|
|
|
.y(PCNext3F));
|
2021-04-21 00:55:49 +00:00
|
|
|
|
2021-09-17 15:25:21 +00:00
|
|
|
mux2 #(`XLEN) pcmux4(.d0(PCNext3F),
|
2021-10-27 19:43:55 +00:00
|
|
|
.d1(`RESET_VECTOR),
|
|
|
|
.s(reset_q),
|
|
|
|
.y(UnalignedPCNextF));
|
2021-04-22 15:20:36 +00:00
|
|
|
|
2021-04-21 00:55:49 +00:00
|
|
|
flop #(1) resetReg (.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.d(reset),
|
|
|
|
.q(reset_q));
|
2021-04-21 00:55:49 +00:00
|
|
|
|
2021-02-18 04:19:17 +00:00
|
|
|
|
2021-01-23 15:48:12 +00:00
|
|
|
assign PCNextF = {UnalignedPCNextF[`XLEN-1:1], 1'b0}; // hart-SPEC p. 21 about 16-bit alignment
|
2021-03-30 19:25:07 +00:00
|
|
|
flopenl #(`XLEN) pcreg(clk, reset, ~StallF & ~ICacheStallF, PCNextF, `RESET_VECTOR, PCF);
|
2021-01-19 01:16:53 +00:00
|
|
|
|
2021-02-18 04:19:17 +00:00
|
|
|
// branch and jump predictor
|
2021-07-04 22:52:16 +00:00
|
|
|
generate
|
2021-04-26 19:27:42 +00:00
|
|
|
if (`BPRED_ENABLED == 1) begin : bpred
|
|
|
|
// I am making the port connection explicit for now as I want to see them and they will be changing.
|
2021-12-02 18:32:35 +00:00
|
|
|
|
|
|
|
bpred bpred(.clk, .reset,
|
|
|
|
.StallF, .StallD, .StallE,
|
|
|
|
.FlushF, .FlushD, .FlushE,
|
|
|
|
|
2021-10-27 19:43:55 +00:00
|
|
|
.PCNextF(PCNextF),
|
|
|
|
.BPPredPCF(BPPredPCF),
|
|
|
|
.SelBPPredF(SelBPPredF),
|
|
|
|
.PCE(PCE),
|
|
|
|
.PCSrcE(PCSrcE),
|
2021-12-15 20:10:45 +00:00
|
|
|
.IEUAdrE(IEUAdrE),
|
2021-10-27 19:43:55 +00:00
|
|
|
.PCD(PCD),
|
|
|
|
.PCLinkE(PCLinkE),
|
|
|
|
.InstrClassE(InstrClassE),
|
|
|
|
.BPPredWrongE(BPPredWrongE),
|
|
|
|
.BPPredDirWrongE(BPPredDirWrongE),
|
|
|
|
.BTBPredPCWrongE(BTBPredPCWrongE),
|
|
|
|
.RASPredPCWrongE(RASPredPCWrongE),
|
|
|
|
.BPPredClassNonCFIWrongE(BPPredClassNonCFIWrongE));
|
2021-04-26 19:27:42 +00:00
|
|
|
end else begin : bpred
|
|
|
|
assign BPPredPCF = {`XLEN{1'b0}};
|
|
|
|
assign SelBPPredF = 1'b0;
|
|
|
|
assign BPPredWrongE = PCSrcE;
|
|
|
|
assign BPPredDirWrongE = 1'b0;
|
|
|
|
assign BTBPredPCWrongE = 1'b0;
|
|
|
|
assign RASPredPCWrongE = 1'b0;
|
2021-05-03 13:56:45 +00:00
|
|
|
assign BPPredClassNonCFIWrongE = 1'b0;
|
2021-04-26 19:27:42 +00:00
|
|
|
end
|
|
|
|
endgenerate
|
2021-12-15 20:10:45 +00:00
|
|
|
// The true correct target is IEUAdrE if PCSrcE is 1 else it is the fall through PCLinkE.
|
|
|
|
assign PCCorrectE = PCSrcE ? IEUAdrE : PCLinkE;
|
2021-02-18 04:19:17 +00:00
|
|
|
|
2021-01-19 01:16:53 +00:00
|
|
|
// pcadder
|
|
|
|
// add 2 or 4 to the PC, based on whether the instruction is 16 bits or 32
|
2021-01-23 15:48:12 +00:00
|
|
|
assign PCPlusUpperF = PCF[`XLEN-1:2] + 1; // add 4 to PC
|
2021-01-19 01:16:53 +00:00
|
|
|
// choose PC+2 or PC+4
|
|
|
|
always_comb
|
|
|
|
if (CompressedF) // add 2
|
|
|
|
if (PCF[1]) PCPlus2or4F = {PCPlusUpperF, 2'b00};
|
2021-01-23 15:48:12 +00:00
|
|
|
else PCPlus2or4F = {PCF[`XLEN-1:2], 2'b10};
|
2021-01-19 01:16:53 +00:00
|
|
|
else PCPlus2or4F = {PCPlusUpperF, PCF[1:0]}; // add 4
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-01-28 03:49:47 +00:00
|
|
|
// Decode stage pipeline register and logic
|
|
|
|
flopenrc #(`XLEN) PCDReg(clk, reset, FlushD, ~StallD, PCF, PCD);
|
|
|
|
|
2021-01-28 05:22:05 +00:00
|
|
|
// expand 16-bit compressed instructions to 32 bits
|
2021-12-02 18:32:35 +00:00
|
|
|
|
|
|
|
decompress decomp(.InstrRawD, .InstrD, .IllegalCompInstrD);
|
2021-01-28 03:49:47 +00:00
|
|
|
assign IllegalIEUInstrFaultD = IllegalBaseInstrFaultD | IllegalCompInstrD; // illegal if bad 32 or 16-bit instr
|
|
|
|
// *** combine these with others in better way, including M, F
|
|
|
|
|
2021-03-04 15:23:35 +00:00
|
|
|
|
|
|
|
// the branch predictor needs a compact decoding of the instruction class.
|
|
|
|
// *** consider adding in the alternate return address x5 for returns.
|
2021-03-30 18:57:40 +00:00
|
|
|
assign InstrClassD[4] = (InstrD[6:0] & 7'h77) == 7'h67 && (InstrD[11:07] & 5'h1B) == 5'h01; // jal(r) must link to ra or r5
|
2021-05-24 18:41:14 +00:00
|
|
|
assign InstrClassD[3] = InstrD[6:0] == 7'h67 && (InstrD[19:15] & 5'h1B) == 5'h01; // return must return to ra or r5
|
|
|
|
assign InstrClassD[2] = InstrD[6:0] == 7'h67 && (InstrD[19:15] & 5'h1B) != 5'h01 && (InstrD[11:7] & 5'h1B) != 5'h01; // jump register, but not return
|
2021-05-24 17:37:16 +00:00
|
|
|
assign InstrClassD[1] = InstrD[6:0] == 7'h6F && (InstrD[11:7] & 5'h1B) != 5'h01; // jump, RD != x1 or x5
|
2021-03-04 15:23:35 +00:00
|
|
|
assign InstrClassD[0] = InstrD[6:0] == 7'h63; // branch
|
|
|
|
|
2021-01-15 04:37:51 +00:00
|
|
|
// Misaligned PC logic
|
|
|
|
|
|
|
|
generate
|
|
|
|
if (`C_SUPPORTED) // C supports compressed instructions on halfword boundaries
|
|
|
|
assign misaligned = PCNextF[0];
|
|
|
|
else // instructions must be on word boundaries
|
|
|
|
assign misaligned = |PCNextF[1:0];
|
|
|
|
endgenerate
|
|
|
|
|
|
|
|
// pipeline misaligned faults to M stage
|
|
|
|
assign BranchMisalignedFaultE = misaligned & PCSrcE; // E-stage (Branch/Jump) misaligned
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenr #(1) InstrMisalginedReg(clk, reset, ~StallM, BranchMisalignedFaultE, BranchMisalignedFaultM);
|
2021-06-23 20:13:56 +00:00
|
|
|
// *** Ross Thompson. Check InstrMisalignedAdrM as I believe it is the same as PCF. Should be able to remove.
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenr #(`XLEN) InstrMisalignedAdrReg(clk, reset, ~StallM, PCNextF, InstrMisalignedAdrM);
|
2021-01-15 04:37:51 +00:00
|
|
|
assign TrapMisalignedFaultM = misaligned & PrivilegedChangePCM;
|
|
|
|
assign InstrMisalignedFaultM = BranchMisalignedFaultM; // | TrapMisalignedFaultM; *** put this back in without causing a cyclic path
|
|
|
|
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenr #(32) InstrEReg(clk, reset, ~StallE, FlushE ? nop : InstrD, InstrE);
|
|
|
|
flopenr #(32) InstrMReg(clk, reset, ~StallM, FlushM ? nop : InstrE, InstrM);
|
|
|
|
flopenr #(`XLEN) PCEReg(clk, reset, ~StallE, PCD, PCE);
|
|
|
|
flopenr #(`XLEN) PCMReg(clk, reset, ~StallM, PCE, PCM);
|
2021-01-28 05:22:05 +00:00
|
|
|
|
2021-03-30 18:57:40 +00:00
|
|
|
flopenrc #(5) InstrClassRegE(.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.reset(reset),
|
|
|
|
.en(~StallE),
|
|
|
|
.clear(FlushE),
|
|
|
|
.d(InstrClassD),
|
|
|
|
.q(InstrClassE));
|
2021-03-04 15:23:35 +00:00
|
|
|
|
2021-03-30 18:57:40 +00:00
|
|
|
flopenrc #(5) InstrClassRegM(.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.reset(reset),
|
|
|
|
.en(~StallM),
|
|
|
|
.clear(FlushM),
|
|
|
|
.d(InstrClassE),
|
|
|
|
.q(InstrClassM));
|
2021-03-23 18:25:51 +00:00
|
|
|
|
2021-03-31 16:54:02 +00:00
|
|
|
flopenrc #(4) BPPredWrongRegM(.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.reset(reset),
|
|
|
|
.en(~StallM),
|
|
|
|
.clear(FlushM),
|
|
|
|
.d({BPPredDirWrongE, BTBPredPCWrongE, RASPredPCWrongE, BPPredClassNonCFIWrongE}),
|
|
|
|
.q({BPPredDirWrongM, BTBPredPCWrongM, RASPredPCWrongM, BPPredClassNonCFIWrongM}));
|
2021-03-23 18:25:51 +00:00
|
|
|
|
2021-01-29 02:40:48 +00:00
|
|
|
// seems like there should be a lower-cost way of doing this PC+2 or PC+4 for JAL.
|
|
|
|
// either have ALU compute PC+2/4 and feed into ALUResult input of ResultMux or
|
|
|
|
// have dedicated adder in Mem stage based on PCM + 2 or 4
|
|
|
|
// *** redo this
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenr #(`XLEN) PCPDReg(clk, reset, ~StallD, PCPlus2or4F, PCLinkD);
|
|
|
|
flopenr #(`XLEN) PCPEReg(clk, reset, ~StallE, PCLinkD, PCLinkE);
|
2021-01-15 04:37:51 +00:00
|
|
|
endmodule
|
|
|
|
|