Skip to content

Commit

Permalink
Introduce width parameter
Browse files Browse the repository at this point in the history
Expose the width (or W internally) parameter to set the SERV
datapath width.

Note: Only width=1 is function at this time.
  • Loading branch information
olofk committed Oct 5, 2024
1 parent 1c5d44e commit 5d296c5
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 51 deletions.
2 changes: 2 additions & 0 deletions bench/servant_sim.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module servant_sim

parameter memfile = "";
parameter memsize = 8192;
parameter width = 1;
parameter with_csr = 1;
parameter compressed = 0;
parameter align = compressed;
Expand All @@ -22,6 +23,7 @@ module servant_sim
servant
#(.memfile (memfile),
.memsize (memsize),
.width (width),
.sim (1),
.with_csr (with_csr),
.compress (compressed[0:0]),
Expand Down
8 changes: 7 additions & 1 deletion bench/servant_tb.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ module servant_tb;

parameter memfile = "hello_uart.hex";
parameter memsize = 8192;
parameter width = 1;
parameter with_csr = 1;

localparam baud_rate =
(width == 4) ? 57600*3 :
57600;

reg wb_clk = 1'b0;
reg wb_rst = 1'b1;

Expand All @@ -15,11 +20,12 @@ module servant_tb;

vlog_tb_utils vtu();

uart_decoder #(57600) uart_decoder (q);
uart_decoder #(baud_rate) uart_decoder (q);

servant_sim
#(.memfile (memfile),
.memsize (memsize),
.width (width),
.with_csr (with_csr))
dut
(.wb_clk (wb_clk),
Expand Down
6 changes: 2 additions & 4 deletions data/verilator_waiver.vlt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
`verilator_config
// Bits [1:0] in i_wb_rdt are not used at all
lint_off -rule UNUSED -file "*/serv_top.v" -lines 179
lint_off -rule UNUSED -file "*/serv_top.v" -lines 181

//Some bits in the instruction word are not used in serv_decode but it's easier
//to just send in the whole word than picking out bits
lint_off -rule UNUSED -file "*/serv_decode.v" -lines 8

lint_off -rule UNUSED -file "*/serv_top.v" -lines 177

//Some variables are only used when we connect an Extension with serv_decode
lint_off -rule UNUSED -file "*/serv_top.v" -lines 67
lint_off -rule UNUSED -file "*/serv_top.v" -lines 69


17 changes: 10 additions & 7 deletions rtl/serv_rf_top.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module serv_rf_top
*/
parameter RESET_STRATEGY = "MINI",
parameter WITH_CSR = 1,
parameter RF_WIDTH = 2,
parameter W = 1,
parameter RF_WIDTH = W * 2,
parameter RF_L2D = $clog2((32+(WITH_CSR*4))*32/RF_WIDTH))
(
input wire clk,
Expand Down Expand Up @@ -86,13 +87,13 @@ module serv_rf_top
wire [4+WITH_CSR:0] wreg1;
wire wen0;
wire wen1;
wire wdata0;
wire wdata1;
wire [W-1:0] wdata0;
wire [W-1:0] wdata1;
wire [4+WITH_CSR:0] rreg0;
wire [4+WITH_CSR:0] rreg1;
wire rf_ready;
wire rdata0;
wire rdata1;
wire [W-1:0] rdata0;
wire [W-1:0] rdata1;

wire [RF_L2D-1:0] waddr;
wire [RF_WIDTH-1:0] wdata;
Expand All @@ -104,7 +105,8 @@ module serv_rf_top
serv_rf_ram_if
#(.width (RF_WIDTH),
.reset_strategy (RESET_STRATEGY),
.csr_regs (CSR_REGS))
.csr_regs (CSR_REGS),
.W(W))
rf_ram_if
(.i_clk (clk),
.i_rst (i_rst),
Expand Down Expand Up @@ -147,7 +149,8 @@ module serv_rf_top
.WITH_CSR (WITH_CSR),
.MDU(MDU),
.COMPRESSED(COMPRESSED),
.ALIGN(ALIGN))
.ALIGN(ALIGN),
.W(W))
cpu
(
.clk (clk),
Expand Down
68 changes: 37 additions & 31 deletions rtl/serv_top.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module serv_top
#(parameter WITH_CSR = 1,
parameter W = 1,
parameter B = W-1,
parameter PRE_REGISTER = 1,
parameter RESET_STRATEGY = "MINI",
parameter RESET_PC = 32'd0,
Expand Down Expand Up @@ -43,12 +45,12 @@ module serv_top
output wire [4+WITH_CSR:0] o_wreg1,
output wire o_wen0,
output wire o_wen1,
output wire o_wdata0,
output wire o_wdata1,
output wire [B:0] o_wdata0,
output wire [B:0] o_wdata1,
output wire [4+WITH_CSR:0] o_rreg0,
output wire [4+WITH_CSR:0] o_rreg1,
input wire i_rdata0,
input wire i_rdata1,
input wire [B:0] i_rdata0,
input wire [B:0] i_rdata1,

output wire [31:0] o_ibus_adr,
output wire o_ibus_cyc,
Expand Down Expand Up @@ -92,18 +94,18 @@ module serv_top
wire rd_alu_en;
wire rd_csr_en;
wire rd_mem_en;
wire ctrl_rd;
wire alu_rd;
wire mem_rd;
wire csr_rd;
wire [B:0] ctrl_rd;
wire [B:0] alu_rd;
wire [B:0] mem_rd;
wire [B:0] csr_rd;
wire mtval_pc;

wire ctrl_pc_en;
wire jump;
wire jal_or_jalr;
wire utype;
wire mret;
wire imm;
wire [B:0] imm;
wire trap;
wire pc_rel;
wire iscomp;
Expand All @@ -127,8 +129,8 @@ module serv_top
wire bufreg_rs1_en;
wire bufreg_imm_en;
wire bufreg_clr_lsb;
wire bufreg_q;
wire bufreg2_q;
wire [B:0] bufreg_q;
wire [B:0] bufreg2_q;
wire [31:0] dbus_rdt;
wire dbus_ack;

Expand All @@ -139,11 +141,11 @@ module serv_top
wire alu_cmp;
wire [2:0] alu_rd_sel;

wire rs1;
wire rs2;
wire [B:0] rs1;
wire [B:0] rs2;
wire rd_en;

wire op_b;
wire [B:0] op_b;
wire op_b_sel;

wire mem_signed;
Expand All @@ -156,20 +158,20 @@ module serv_top

wire mem_misalign;

wire bad_pc;
wire [B:0] bad_pc;

wire csr_mstatus_en;
wire csr_mie_en;
wire csr_mcause_en;
wire [1:0] csr_source;
wire csr_imm;
wire [B:0] csr_imm;
wire csr_d_sel;
wire csr_en;
wire [1:0] csr_addr;
wire csr_pc;
wire [B:0] csr_pc;
wire csr_imm_en;
wire csr_in;
wire rf_csr_out;
wire [B:0] csr_in;
wire [B:0] rf_csr_out;
wire dbus_en;

wire new_irq;
Expand Down Expand Up @@ -226,7 +228,8 @@ module serv_top
#(.RESET_STRATEGY (RESET_STRATEGY),
.WITH_CSR (WITH_CSR[0:0]),
.MDU(MDU),
.ALIGN(ALIGN))
.ALIGN(ALIGN),
.W(W))
state
(
.i_clk (clk),
Expand Down Expand Up @@ -420,7 +423,8 @@ module serv_top
serv_ctrl
#(.RESET_PC (RESET_PC),
.RESET_STRATEGY (RESET_STRATEGY),
.WITH_CSR (WITH_CSR))
.WITH_CSR (WITH_CSR),
.W (W))
ctrl
(
.clk (clk),
Expand All @@ -447,7 +451,7 @@ module serv_top
//External
.o_ibus_adr (wb_ibus_adr));

serv_alu alu
serv_alu #(.W (W)) alu
(
.clk (clk),
//State
Expand All @@ -467,7 +471,7 @@ module serv_top
.o_rd (alu_rd));

serv_rf_if
#(.WITH_CSR (WITH_CSR))
#(.WITH_CSR (WITH_CSR), .W(W))
rf_if
(//RF interface
.i_cnt_en (cnt_en),
Expand All @@ -485,7 +489,7 @@ module serv_top
//Trap interface
.i_trap (trap),
.i_mret (mret),
.i_mepc (wb_ibus_adr[0]),
.i_mepc (wb_ibus_adr[B:0]),
.i_mtval_pc (mtval_pc),
.i_bufreg_q (bufreg_q),
.i_bad_pc (bad_pc),
Expand Down Expand Up @@ -516,7 +520,8 @@ module serv_top
.o_csr (rf_csr_out));

serv_mem_if
#(.WITH_CSR (WITH_CSR[0:0]))
#(.WITH_CSR (WITH_CSR[0:0]),
.W (W))
mem_if
(
.i_clk (clk),
Expand All @@ -539,7 +544,8 @@ module serv_top
generate
if (|WITH_CSR) begin : gen_csr
serv_csr
#(.RESET_STRATEGY (RESET_STRATEGY))
#(.RESET_STRATEGY (RESET_STRATEGY),
.W(W))
csr
(
.i_clk (clk),
Expand Down Expand Up @@ -574,8 +580,8 @@ module serv_top
.i_rs1 (rs1),
.o_q (csr_rd));
end else begin : gen_no_csr
assign csr_in = 1'b0;
assign csr_rd = 1'b0;
assign csr_in = {W{1'b0}};
assign csr_rd = {W{1'b0}};
assign new_irq = 1'b0;
end
endgenerate
Expand All @@ -597,7 +603,7 @@ module serv_top

/* Store data written to rd */
if (o_wen0)
rvfi_rd_wdata <= {o_wdata0,rvfi_rd_wdata[31:1]};
rvfi_rd_wdata <= {o_wdata0,rvfi_rd_wdata[31:W]};

if (cnt_done & ctrl_pc_en) begin
rvfi_pc_rdata <= pc;
Expand Down Expand Up @@ -626,8 +632,8 @@ module serv_top
rvfi_rd_addr <= rd_addr;
end
if (rs_en) begin
rvfi_rs1_rdata <= {!immdec_en[1] & rs1,rvfi_rs1_rdata[31:1]};
rvfi_rs2_rdata <= {!immdec_en[2] & rs2,rvfi_rs2_rdata[31:1]};
rvfi_rs1_rdata <= {(!immdec_en[1] ? rs1 : {W{1'b0}}),rvfi_rs1_rdata[31:W]};
rvfi_rs2_rdata <= {(!immdec_en[2] ? rs2 : {W{1'b0}}),rvfi_rs2_rdata[31:W]};
end

if (i_dbus_ack) begin
Expand Down
7 changes: 7 additions & 0 deletions servant.core
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ targets:
filesets : [soc, servant_tb]
parameters :
- RISCV_FORMAL
- width
- "mdu? (MDU=1)"
- SERV_CLEAR_RAM=true
- firmware
Expand Down Expand Up @@ -649,6 +650,7 @@ targets:
- uart_baudrate
- vcd
- vcd_start
- width
- compressed
- align
- with_csr=1
Expand Down Expand Up @@ -744,6 +746,11 @@ parameters:
description : Delay start of VCD dumping until the specified time
paramtype : plusarg

width:
datatype : int
description : Interal datapath width (1=SERV, 4=QERV)
paramtype : vlogparam

with_csr:
datatype : int
description : Enable/Disable CSR support
Expand Down
7 changes: 4 additions & 3 deletions servant/servant.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module servant
parameter memfile = "zephyr_hello.hex";
parameter memsize = 8192;
parameter reset_strategy = "MINI";
parameter width = 1;
parameter sim = 0;
parameter with_csr = 1;
parameter [0:0] compress = 0;
Expand All @@ -23,7 +24,7 @@ module servant
localparam aw = $clog2(memsize);
localparam csr_regs = with_csr*4;

localparam rf_width = 2;
localparam rf_width = width * 2;
localparam rf_l2d = $clog2((32+csr_regs)*32/rf_width);

wire timer_irq;
Expand Down Expand Up @@ -133,7 +134,7 @@ module servant
.o_rdata (rf_rdata));

servile
#(.rf_width (rf_width),
#(.width (width),
.sim (sim[0]),
.with_c (compress[0]),
.with_csr (with_csr[0]),
Expand All @@ -159,7 +160,7 @@ module servant
.o_wb_ext_stb (wb_ext_stb),
.i_wb_ext_rdt (wb_ext_rdt),
.i_wb_ext_ack (wb_ext_ack),

.o_rf_waddr (rf_waddr),
.o_rf_wdata (rf_wdata),
.o_rf_wen (rf_wen),
Expand Down
Loading

0 comments on commit 5d296c5

Please sign in to comment.