1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
module IF ( input wire i_clk, input wire i_rst_n,
input wire i_pc_we, input wire[31:0] i_pc_wdata,
input wire i_pipe_stop,
output wire[31:0] o_ibus_addr, input wire[31:0] i_ibus_data, output reg o_ibus_req, input wire i_ibus_rsp,
output wire[31:0] o_iaddr,
output wire[31:0] o_idata
);
reg[31:0] pc;
initial begin pc = 32'h0;
o_ibus_req = 0; end
wire valid = i_ibus_rsp & (~i_pipe_stop) ;
always @(posedge i_clk or negedge i_rst_n) begin
if(i_rst_n == `rst)begin pc <= 32'h0; o_ibus_req <= 0; end else if(valid)begin pc <= (i_pc_we) ? i_pc_wdata : (pc+4);
end else if(i_pipe_stop) begin
end
o_ibus_req <= 1; end
assign o_iaddr = pc;
assign o_ibus_addr = pc;
assign o_idata = (i_ibus_rsp & (~i_pc_we)) ? i_ibus_data : `inst_nop;
endmodule
module IF_ID ( input wire i_clk, input wire i_rst_n,
input wire i_pipe_stop, input wire i_pipe_flush,
input wire[31:0] i_iaddr, input wire[31:0] i_idata,
output wire[31:0] o_iaddr, output wire[31:0] o_idata
);
wire en = (~i_pipe_stop | i_pipe_flush);
reg[31:0] iaddr,idata;
initial begin iaddr<=0; idata<=0; end
assign o_iaddr = (i_pipe_flush == `en) ? 32'h0 : iaddr; assign o_idata = (i_pipe_flush == `en) ? `inst_nop : idata;
always @(posedge i_clk or negedge i_rst_n) begin if(i_rst_n == `rst)begin iaddr <= 32'b0; idata <= `inst_nop; end else if(en == `en)begin
iaddr <= i_iaddr;
idata <= i_idata; end end
endmodule
|