picorv32/testbench_wb.v

147 lines
3.4 KiB
Coq
Raw Permalink Normal View History

`timescale 1 ns / 1 ps
module picorv32_wrapper #(
2023-01-10 15:44:16 +08:00
parameter VERBOSE = 0
) (
2023-01-17 16:09:28 +08:00
input clk,
input rst,
2023-01-10 15:44:16 +08:00
output trap,
input [1024:0] hex_file
);
2023-01-10 15:44:16 +08:00
wire exit;
reg [15:0] count_cycle = 0;
2023-01-17 16:09:28 +08:00
always @(posedge clk) count_cycle <= !rst ? count_cycle + 1 : 0;
2023-01-10 15:44:16 +08:00
wire [31:0] wb_m2s_adr;
wire [31:0] wb_m2s_dat;
wire [3:0] wb_m2s_sel;
wire wb_m2s_we;
wire wb_m2s_cyc;
wire wb_m2s_stb;
wire [31:0] wb_s2m_dat;
wire wb_s2m_ack;
picorv32_wb #() uut (
.trap(trap),
.exit(exit),
2023-01-17 16:09:28 +08:00
.clk(clk),
.rst(rst)
2023-01-10 15:44:16 +08:00
);
initial begin
$readmemh(hex_file, uut.memory);
$display("HEX File : %s", hex_file);
2023-01-10 15:44:16 +08:00
end
integer cycle_counter;
2023-01-17 16:09:28 +08:00
always @(posedge clk) begin
cycle_counter <= !rst ? cycle_counter + 1 : 0;
if (!rst && trap) begin
2023-01-10 15:44:16 +08:00
$display("TRAP after %1d clock cycles", cycle_counter);
if (exit) begin
$display("ALL TESTS PASSED.");
$finish;
end else begin
$display("ERROR!");
if ($test$plusargs("noerror")) $finish;
$stop;
end
end
end
endmodule
2023-01-10 15:43:08 +08:00
2023-01-10 15:44:16 +08:00
module picorv32_wb #(
) (
output trap,
output reg exit,
2023-01-17 16:09:28 +08:00
input rst,
input clk
2023-01-10 15:43:08 +08:00
);
2023-01-10 15:44:16 +08:00
wire mem_la_read;
wire mem_la_write;
wire [31:0] mem_la_addr;
wire [31:0] mem_la_wdata;
reg [31:0] mem_la_rdata;
2023-01-10 15:44:16 +08:00
wire [ 3:0] mem_la_wstrb;
wire resetn;
initial exit = 0;
2023-01-17 16:09:28 +08:00
assign resetn = ~rst;
2023-01-10 15:44:16 +08:00
picorv32 #(
.PROGADDR_RESET(32'h0000_0000),
.STACKADDR(32'h0004_0000)
2023-01-10 15:44:16 +08:00
) picorv32_core (
.clk (clk),
.resetn(resetn),
.trap (trap),
.mem_la_read (mem_la_read),
.mem_la_write(mem_la_write),
.mem_la_addr (mem_la_addr),
.mem_la_wdata(mem_la_wdata),
.mem_la_rdata(mem_la_rdata),
2023-01-17 20:59:02 +08:00
.mem_la_wstrb(mem_la_wstrb)
2023-01-10 15:44:16 +08:00
);
reg [7:0] memory[0:256*1024-1];
2023-01-13 16:11:36 +08:00
integer fconsole, fif;
2023-01-13 15:44:41 +08:00
initial begin
fconsole = $fopen("console.log", "w");
2023-01-13 16:11:36 +08:00
fif = $fopen("if.log", "w");
2023-01-13 15:44:41 +08:00
end
2023-01-10 15:44:16 +08:00
always @(posedge clk) begin
mem_la_rdata[7:0] <= mem_la_read ? memory[mem_la_addr+0] : 'bx;
mem_la_rdata[15:8] <= mem_la_read ? memory[mem_la_addr+1] : 'bx;
mem_la_rdata[23:16] <= mem_la_read ? memory[mem_la_addr+2] : 'bx;
mem_la_rdata[31:24] <= mem_la_read ? memory[mem_la_addr+3] : 'bx;
2023-01-10 15:44:16 +08:00
if (mem_la_write) begin
case (mem_la_addr)
32'h1000_0000: begin
2023-01-13 15:44:41 +08:00
$fwrite(fconsole, "%c", mem_la_wdata);
2023-01-10 15:44:16 +08:00
end
32'h2000_0000: begin
if (mem_la_wdata[31:0] == 123456789) exit = 1;
end
default: begin
if (mem_la_wstrb[0]) memory[mem_la_addr+0] <= mem_la_wdata[7:0];
if (mem_la_wstrb[1]) memory[mem_la_addr+1] <= mem_la_wdata[15:8];
if (mem_la_wstrb[2]) memory[mem_la_addr+2] <= mem_la_wdata[23:16];
if (mem_la_wstrb[3]) memory[mem_la_addr+3] <= mem_la_wdata[31:24];
end
endcase
end
end
2023-01-13 16:11:36 +08:00
2023-01-17 20:59:02 +08:00
// always @(posedge clk) begin
// if (fetch_next) begin
// if (&dbg_insn_opcode[1:0])
// $fwrite(
// fif,
// "DECODE: 0x%08x 0x%08x %-0s\n",
// dbg_insn_addr,
// dbg_insn_opcode,
// dbg_ascii_instr ? dbg_ascii_instr : "UNKNOWN"
// );
// else
// $fwrite(
// fif,
// "DECODE: 0x%08x 0x%04x %-0s\n",
// dbg_insn_addr,
// dbg_insn_opcode[15:0],
// dbg_ascii_instr ? dbg_ascii_instr : "UNKNOWN"
// );
// end
// end
2023-01-13 16:11:36 +08:00
2023-01-10 15:43:08 +08:00
endmodule