2017-12-01 23:30:33 +00:00
|
|
|
`ifndef RV32_FETCH
|
|
|
|
|
`define RV32_FETCH
|
|
|
|
|
|
2017-11-30 22:30:49 +00:00
|
|
|
module rv32_fetch (
|
2017-12-01 18:45:47 +00:00
|
|
|
input clk,
|
2017-11-30 22:30:49 +00:00
|
|
|
|
2017-12-03 17:55:39 +00:00
|
|
|
/* control in (from mem) */
|
2017-12-02 15:23:12 +00:00
|
|
|
input branch_taken_in,
|
|
|
|
|
|
2017-12-03 17:55:39 +00:00
|
|
|
/* data in (from mem) */
|
2017-12-02 15:23:12 +00:00
|
|
|
input [31:0] branch_pc_in,
|
|
|
|
|
|
2017-11-30 22:30:49 +00:00
|
|
|
/* data out */
|
2017-12-01 18:45:47 +00:00
|
|
|
output [31:0] pc_out,
|
|
|
|
|
output [31:0] instr_out
|
2017-11-30 22:30:49 +00:00
|
|
|
);
|
|
|
|
|
logic [31:0] instr_mem [255:0];
|
2017-12-02 15:23:12 +00:00
|
|
|
logic [31:0] next_pc;
|
|
|
|
|
|
|
|
|
|
logic [31:0] pc = branch_taken_in ? branch_pc_in : next_pc;
|
2017-11-30 22:30:49 +00:00
|
|
|
|
2017-12-02 17:17:26 +00:00
|
|
|
initial
|
|
|
|
|
$readmemh("progmem_syn.hex", instr_mem);
|
|
|
|
|
|
2017-11-30 22:30:49 +00:00
|
|
|
always_ff @(posedge clk) begin
|
|
|
|
|
instr_out <= instr_mem[pc[31:2]];
|
2017-12-02 15:23:12 +00:00
|
|
|
next_pc <= pc + 4;
|
2017-11-30 22:30:49 +00:00
|
|
|
pc_out <= pc;
|
|
|
|
|
end
|
|
|
|
|
endmodule
|
2017-12-01 23:30:33 +00:00
|
|
|
|
|
|
|
|
`endif
|