2
2
3
3
module serv_top
4
4
#(parameter WITH_CSR = 1 ,
5
+ parameter W = 1 ,
6
+ parameter B = W- 1 ,
5
7
parameter PRE_REGISTER = 1 ,
6
8
parameter RESET_STRATEGY = "MINI" ,
7
9
parameter RESET_PC = 32'd0 ,
@@ -43,12 +45,12 @@ module serv_top
43
45
output wire [4 + WITH_CSR:0 ] o_wreg1,
44
46
output wire o_wen0,
45
47
output wire o_wen1,
46
- output wire o_wdata0,
47
- output wire o_wdata1,
48
+ output wire [B: 0 ] o_wdata0,
49
+ output wire [B: 0 ] o_wdata1,
48
50
output wire [4 + WITH_CSR:0 ] o_rreg0,
49
51
output wire [4 + WITH_CSR:0 ] o_rreg1,
50
- input wire i_rdata0,
51
- input wire i_rdata1,
52
+ input wire [B: 0 ] i_rdata0,
53
+ input wire [B: 0 ] i_rdata1,
52
54
53
55
output wire [31 :0 ] o_ibus_adr,
54
56
output wire o_ibus_cyc,
@@ -92,18 +94,18 @@ module serv_top
92
94
wire rd_alu_en;
93
95
wire rd_csr_en;
94
96
wire rd_mem_en;
95
- wire ctrl_rd;
96
- wire alu_rd;
97
- wire mem_rd;
98
- wire csr_rd;
97
+ wire [B: 0 ] ctrl_rd;
98
+ wire [B: 0 ] alu_rd;
99
+ wire [B: 0 ] mem_rd;
100
+ wire [B: 0 ] csr_rd;
99
101
wire mtval_pc;
100
102
101
103
wire ctrl_pc_en;
102
104
wire jump;
103
105
wire jal_or_jalr;
104
106
wire utype;
105
107
wire mret;
106
- wire imm;
108
+ wire [B: 0 ] imm;
107
109
wire trap;
108
110
wire pc_rel;
109
111
wire iscomp;
@@ -127,8 +129,8 @@ module serv_top
127
129
wire bufreg_rs1_en;
128
130
wire bufreg_imm_en;
129
131
wire bufreg_clr_lsb;
130
- wire bufreg_q;
131
- wire bufreg2_q;
132
+ wire [B: 0 ] bufreg_q;
133
+ wire [B: 0 ] bufreg2_q;
132
134
wire [31 :0 ] dbus_rdt;
133
135
wire dbus_ack;
134
136
@@ -139,11 +141,11 @@ module serv_top
139
141
wire alu_cmp;
140
142
wire [2 :0 ] alu_rd_sel;
141
143
142
- wire rs1;
143
- wire rs2;
144
+ wire [B: 0 ] rs1;
145
+ wire [B: 0 ] rs2;
144
146
wire rd_en;
145
147
146
- wire op_b;
148
+ wire [B: 0 ] op_b;
147
149
wire op_b_sel;
148
150
149
151
wire mem_signed;
@@ -156,20 +158,20 @@ module serv_top
156
158
157
159
wire mem_misalign;
158
160
159
- wire bad_pc;
161
+ wire [B: 0 ] bad_pc;
160
162
161
163
wire csr_mstatus_en;
162
164
wire csr_mie_en;
163
165
wire csr_mcause_en;
164
166
wire [1 :0 ] csr_source;
165
- wire csr_imm;
167
+ wire [B: 0 ] csr_imm;
166
168
wire csr_d_sel;
167
169
wire csr_en;
168
170
wire [1 :0 ] csr_addr;
169
- wire csr_pc;
171
+ wire [B: 0 ] csr_pc;
170
172
wire csr_imm_en;
171
- wire csr_in;
172
- wire rf_csr_out;
173
+ wire [B: 0 ] csr_in;
174
+ wire [B: 0 ] rf_csr_out;
173
175
wire dbus_en;
174
176
175
177
wire new_irq;
@@ -226,7 +228,8 @@ module serv_top
226
228
#(.RESET_STRATEGY (RESET_STRATEGY),
227
229
.WITH_CSR (WITH_CSR[0 :0 ]),
228
230
.MDU(MDU),
229
- .ALIGN(ALIGN))
231
+ .ALIGN(ALIGN),
232
+ .W(W))
230
233
state
231
234
(
232
235
.i_clk (clk),
@@ -420,7 +423,8 @@ module serv_top
420
423
serv_ctrl
421
424
#(.RESET_PC (RESET_PC),
422
425
.RESET_STRATEGY (RESET_STRATEGY),
423
- .WITH_CSR (WITH_CSR))
426
+ .WITH_CSR (WITH_CSR),
427
+ .W (W))
424
428
ctrl
425
429
(
426
430
.clk (clk),
@@ -447,7 +451,7 @@ module serv_top
447
451
// External
448
452
.o_ibus_adr (wb_ibus_adr));
449
453
450
- serv_alu alu
454
+ serv_alu #(.W (W)) alu
451
455
(
452
456
.clk (clk),
453
457
// State
@@ -467,7 +471,7 @@ module serv_top
467
471
.o_rd (alu_rd));
468
472
469
473
serv_rf_if
470
- #(.WITH_CSR (WITH_CSR))
474
+ #(.WITH_CSR (WITH_CSR), .W(W) )
471
475
rf_if
472
476
(// RF interface
473
477
.i_cnt_en (cnt_en),
@@ -485,7 +489,7 @@ module serv_top
485
489
// Trap interface
486
490
.i_trap (trap),
487
491
.i_mret (mret),
488
- .i_mepc (wb_ibus_adr[0 ]),
492
+ .i_mepc (wb_ibus_adr[B: 0 ]),
489
493
.i_mtval_pc (mtval_pc),
490
494
.i_bufreg_q (bufreg_q),
491
495
.i_bad_pc (bad_pc),
@@ -516,7 +520,8 @@ module serv_top
516
520
.o_csr (rf_csr_out));
517
521
518
522
serv_mem_if
519
- #(.WITH_CSR (WITH_CSR[0 :0 ]))
523
+ #(.WITH_CSR (WITH_CSR[0 :0 ]),
524
+ .W (W))
520
525
mem_if
521
526
(
522
527
.i_clk (clk),
@@ -539,7 +544,8 @@ module serv_top
539
544
generate
540
545
if (| WITH_CSR) begin : gen_csr
541
546
serv_csr
542
- #(.RESET_STRATEGY (RESET_STRATEGY))
547
+ #(.RESET_STRATEGY (RESET_STRATEGY),
548
+ .W(W))
543
549
csr
544
550
(
545
551
.i_clk (clk),
@@ -574,8 +580,8 @@ module serv_top
574
580
.i_rs1 (rs1),
575
581
.o_q (csr_rd));
576
582
end else begin : gen_no_csr
577
- assign csr_in = 1'b0 ;
578
- assign csr_rd = 1'b0 ;
583
+ assign csr_in = {W{ 1'b0 }} ;
584
+ assign csr_rd = {W{ 1'b0 }} ;
579
585
assign new_irq = 1'b0 ;
580
586
end
581
587
endgenerate
@@ -597,7 +603,7 @@ module serv_top
597
603
598
604
/* Store data written to rd */
599
605
if (o_wen0)
600
- rvfi_rd_wdata <= {o_wdata0,rvfi_rd_wdata[31 :1 ]};
606
+ rvfi_rd_wdata <= {o_wdata0,rvfi_rd_wdata[31 :W ]};
601
607
602
608
if (cnt_done & ctrl_pc_en) begin
603
609
rvfi_pc_rdata <= pc;
@@ -626,8 +632,8 @@ module serv_top
626
632
rvfi_rd_addr <= rd_addr;
627
633
end
628
634
if (rs_en) begin
629
- rvfi_rs1_rdata <= {! immdec_en[1 ] & rs1,rvfi_rs1_rdata[31 :1 ]};
630
- rvfi_rs2_rdata <= {! immdec_en[2 ] & rs2,rvfi_rs2_rdata[31 :1 ]};
635
+ rvfi_rs1_rdata <= {( ! immdec_en[1 ] ? rs1 : {W{ 1'b0 }}) ,rvfi_rs1_rdata[31 :W ]};
636
+ rvfi_rs2_rdata <= {( ! immdec_en[2 ] ? rs2 : {W{ 1'b0 }}) ,rvfi_rs2_rdata[31 :W ]};
631
637
end
632
638
633
639
if (i_dbus_ack) begin
0 commit comments