Skip to content

Dev #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ python3 cva6.py --testlist=../tests/testlist_riscv-tests-cv64a6_imafdc_sv39-p.ya

# COREV-APU FPGA Emulation

We currently provide support for the [Genesys 2 board](https://reference.digilentinc.com/reference/programmable-logic/genesys-2/reference-manual) and the [Agilex 7 Development Kit](https://www.intel.la/content/www/xl/es/products/details/fpga/development-kits/agilex/agf014.html).
We currently provide support for the [Genesys 2 board](https://reference.digilentinc.com/reference/programmable-logic/genesys-2/reference-manual) and the [Agilex 7 Development Kit](https://www.intel.la/content/www/xl/es/products/details/fpga/development-kits/agilex/agf014.html). In order the run the FPGA build scripts you will need to use Xilinx 2018.2.

- **Genesys 2**

Expand Down
2 changes: 1 addition & 1 deletion ci/install-verilator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi
VERILATOR_REPO="https://github.com/verilator/verilator.git"
VERILATOR_BRANCH="master"
# Use the release tag instead of a full SHA1 hash.
VERILATOR_HASH="v5.008"
VERILATOR_HASH="v5.028"
VERILATOR_PATCH="$ROOT/verif/regress/verilator-v5.patch"

VERILATOR_BUILD_DIR=$PWD/verilator-$VERILATOR_HASH/verilator
Expand Down
10 changes: 8 additions & 2 deletions core/csr_regfile.sv
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ module csr_regfile
// RVFI
output rvfi_probes_csr_t rvfi_csr_o,
//jvt output
output jvt_t jvt_o
output jvt_t jvt_o,
// Data endianness output
output bit endian
);

localparam logic [63:0] SMODE_STATUS_READ_MASK = ariane_pkg::smode_status_read_mask(CVA6Cfg);
Expand Down Expand Up @@ -1390,7 +1392,9 @@ module csr_regfile
mstatus_d.wpri1 = 1'b0;
mstatus_d.wpri2 = 1'b0;
mstatus_d.wpri0 = 1'b0;
mstatus_d.ube = 1'b0; // CVA6 is little-endian
// Mirror MBE
mstatus_d.sbe = mstatus_d.mbe;
mstatus_d.ube = mstatus_d.mbe;
// this register has side-effects on other registers, flush the pipeline
flush_o = 1'b1;
end
Expand Down Expand Up @@ -2535,6 +2539,8 @@ module csr_regfile
assign single_step_o = CVA6Cfg.DebugEn ? dcsr_q.step : 1'b0;
assign mcountinhibit_o = {{29 - MHPMCounterNum{1'b0}}, mcountinhibit_q};

assign endian = mstatus_q.mbe;

// sequential process
always_ff @(posedge clk_i or negedge rst_ni) begin
if (~rst_ni) begin
Expand Down
5 changes: 4 additions & 1 deletion core/cva6.sv
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ module cva6
fu_t fu;
fu_op operation;
logic [CVA6Cfg.TRANS_ID_BITS-1:0] trans_id;
logic endian;
},

localparam type fu_data_t = struct packed {
Expand Down Expand Up @@ -207,6 +208,7 @@ module cva6
logic [CVA6Cfg.DcacheIdWidth-1:0] data_id;
logic kill_req;
logic tag_valid;
logic endian;
},

localparam type dcache_req_o_t = struct packed {
Expand Down Expand Up @@ -1200,7 +1202,8 @@ module cva6
.mcountinhibit_o (mcountinhibit_csr_perf),
.jvt_o (jvt),
//RVFI
.rvfi_csr_o (rvfi_csr)
.rvfi_csr_o (rvfi_csr),
.endian (rvfi_lsu_ctrl.endian)
);

// ------------------------
Expand Down
16 changes: 16 additions & 0 deletions core/include/ariane_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ package ariane_pkg;
| riscv::SSTATUS_UPIE
| riscv::SSTATUS_SPIE
| riscv::SSTATUS_UXL
| riscv::SSTATUS_SBE
| riscv::sstatus_sd(Cfg.IS_XLEN64);
endfunction

Expand Down Expand Up @@ -815,4 +816,19 @@ package ariane_pkg;
return (n < 0) ? 0 : n;
endfunction : avoid_neg

function automatic [CVA6Cfg.XLEN-1:0] byte_swap;
input [CVA6Cfg.XLEN-1:0] data;
input int width;
input bit swap;
begin
if (!swap) begin
byte_swap = data;
end else begin
byte_swap = '0;
for (int i = 0; i < width; i += 8) begin
byte_swap[i +: 8] = data[width - 8 - i +: 8];
end
end
end
endfunction
endpackage
5 changes: 5 additions & 0 deletions core/include/riscv_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ package riscv;
localparam logic [63:0] SSTATUS_MXR = 'h00080000;
localparam logic [63:0] SSTATUS_UPIE = 'h00000010;
localparam logic [63:0] SSTATUS_UXL = 64'h0000000300000000;
localparam logic [63:0] SSTATUS_SBE = 'h1000000000;
localparam logic [63:0] SSTATUS_UBE = 'h40;
// CSR Bit Implementation Masks

function automatic logic [63:0] sstatus_sd(logic IS_XLEN64);
Expand Down Expand Up @@ -762,6 +764,9 @@ package riscv;
localparam logic [63:0] MSTATUS_TVM = 'h00100000;
localparam logic [63:0] MSTATUS_TW = 'h00200000;
localparam logic [63:0] MSTATUS_TSR = 'h00400000;
localparam logic [63:0] MSTATUS_MBE = 'h2000000000;
localparam logic [63:0] MSTATUS_SBE = 'h1000000000;
localparam logic [63:0] MSTATUS_UBE = 'h40;
function automatic logic [63:0] mstatus_uxl(logic IS_XLEN64);
return {30'h0000000, IS_XLEN64, IS_XLEN64, 32'h00000000};
endfunction
Expand Down
19 changes: 11 additions & 8 deletions core/load_unit.sv
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ module load_unit
req_port_o.kill_req = 1'b0;
req_port_o.tag_valid = 1'b0;
req_port_o.data_be = lsu_ctrl_i.be;
req_port_o.endian = lsu_ctrl_i.endian;
req_port_o.data_size = extract_transfer_size(lsu_ctrl_i.operation);
pop_ld_o = 1'b0;

Expand Down Expand Up @@ -467,9 +468,11 @@ module load_unit
// Sign Extend
// ---------------
logic [CVA6Cfg.XLEN-1:0] shifted_data;
logic [CVA6Cfg.XLEN-1:0] endian_correct_data;

// realign as needed
assign shifted_data = req_port_i.data_rdata >> {ldbuf_rdata.address_offset, 3'b000};
assign endian_correct_data = byte_swap(shifted_data, req_port_o.data_size, req_port_o.endian);

/* // result mux (leaner code, but more logic stages.
// can be used instead of the code below (in between //result mux fast) if timing is not so critical)
Expand Down Expand Up @@ -511,30 +514,30 @@ module load_unit
always_comb begin
unique case (ldbuf_rdata.operation)
ariane_pkg::LW, ariane_pkg::LWU, ariane_pkg::HLV_W, ariane_pkg::HLV_WU, ariane_pkg::HLVX_WU:
result_o = {{CVA6Cfg.XLEN - 32{rdata_sign_bit}}, shifted_data[31:0]};
result_o = {{CVA6Cfg.XLEN - 32{rdata_sign_bit}}, endian_correct_data[31:0]};
ariane_pkg::LH, ariane_pkg::LHU, ariane_pkg::HLV_H, ariane_pkg::HLV_HU, ariane_pkg::HLVX_HU:
result_o = {{CVA6Cfg.XLEN - 32 + 16{rdata_sign_bit}}, shifted_data[15:0]};
result_o = {{CVA6Cfg.XLEN - 32 + 16{rdata_sign_bit}}, endian_correct_data[15:0]};
ariane_pkg::LB, ariane_pkg::LBU, ariane_pkg::HLV_B, ariane_pkg::HLV_BU:
result_o = {{CVA6Cfg.XLEN - 32 + 24{rdata_sign_bit}}, shifted_data[7:0]};
result_o = {{CVA6Cfg.XLEN - 32 + 24{rdata_sign_bit}}, endian_correct_data[7:0]};
default: begin
// FLW, FLH and FLB have been defined here in default case to improve Code Coverage
if (CVA6Cfg.FpPresent) begin
unique case (ldbuf_rdata.operation)
ariane_pkg::FLW: begin
result_o = {{CVA6Cfg.XLEN - 32{rdata_sign_bit}}, shifted_data[31:0]};
result_o = {{CVA6Cfg.XLEN - 32{rdata_sign_bit}}, endian_correct_data[31:0]};
end
ariane_pkg::FLH: begin
result_o = {{CVA6Cfg.XLEN - 32 + 16{rdata_sign_bit}}, shifted_data[15:0]};
result_o = {{CVA6Cfg.XLEN - 32 + 16{rdata_sign_bit}}, endian_correct_data[15:0]};
end
ariane_pkg::FLB: begin
result_o = {{CVA6Cfg.XLEN - 32 + 24{rdata_sign_bit}}, shifted_data[7:0]};
result_o = {{CVA6Cfg.XLEN - 32 + 24{rdata_sign_bit}}, endian_correct_data[7:0]};
end
default: begin
result_o = shifted_data[CVA6Cfg.XLEN-1:0];
result_o = endian_correct_data[CVA6Cfg.XLEN-1:0];
end
endcase
end else begin
result_o = shifted_data[CVA6Cfg.XLEN-1:0];
result_o = endian_correct_data[CVA6Cfg.XLEN-1:0];
end
end
endcase
Expand Down
11 changes: 8 additions & 3 deletions core/store_unit.sv
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ module store_unit

logic [CVA6Cfg.TRANS_ID_BITS-1:0] trans_id_n, trans_id_q;

logic [CVA6Cfg.XLEN-1:0] endian_correct_data;

// output assignments
assign vaddr_o = lsu_ctrl_i.vaddr; // virtual address
assign hs_ld_st_inst_o = CVA6Cfg.RVH ? lsu_ctrl_i.hs_ld_st_inst : 1'b0;
Expand Down Expand Up @@ -251,9 +253,12 @@ module store_unit
always_comb begin
st_be_n = lsu_ctrl_i.be;
// don't shift the data if we are going to perform an AMO as we still need to operate on this data
st_data_n = (CVA6Cfg.RVA && instr_is_amo) ? lsu_ctrl_i.data[CVA6Cfg.XLEN-1:0] :
data_align(lsu_ctrl_i.vaddr[2:0], {{64 - CVA6Cfg.XLEN{1'b0}}, lsu_ctrl_i.data});
st_data_n = ((CVA6Cfg.RVA && instr_is_amo) ? lsu_ctrl_i.data[CVA6Cfg.XLEN-1:0] :
data_align(lsu_ctrl_i.vaddr[2:0], {{64 - CVA6Cfg.XLEN{1'b0}}, lsu_ctrl_i.data}));
st_data_size_n = extract_transfer_size(lsu_ctrl_i.operation);

assign endian_correct_data = byte_swap(st_data_n, st_data_size_n, lsu_ctrl_i.endian);

// save AMO op for next cycle
if (CVA6Cfg.RVA) begin
case (lsu_ctrl_i.operation)
Expand Down Expand Up @@ -356,7 +361,7 @@ module store_unit
end else begin
state_q <= state_d;
st_be_q <= st_be_n;
st_data_q <= st_data_n;
st_data_q <= endian_correct_data;
trans_id_q <= trans_id_n;
st_data_size_q <= st_data_size_n;
amo_op_q <= amo_op_d;
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Original Author: Jean-Roch COULON - Thales

#!/usr/bin/python3
#!/usr/bin/env python3


class Parameter:
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/define_blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Original Author: Jean-Roch COULON - Thales

#!/usr/bin/python3
#!/usr/bin/env python3


def define_blacklist(parameters):
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/parameters_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Original Author: Jean-Roch COULON - Thales

#!/usr/bin/python3
#!/usr/bin/env python3

import sys
import os
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/spec_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Original Author: Jean-Roch COULON - Thales

#!/usr/bin/python3
#!/usr/bin/env python3

import re
import sys
Expand Down
2 changes: 1 addition & 1 deletion verif/regress/install-verilator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fi
VERILATOR_REPO="https://github.com/verilator/verilator.git"
VERILATOR_BRANCH="master"
# Use the release tag instead of a full SHA1 hash.
VERILATOR_HASH="v5.008"
VERILATOR_HASH="v5.028"
VERILATOR_PATCH="$ROOT_PROJECT/verif/regress/verilator-v5.patch"

# Unset historical variable VERILATOR_ROOT as it collides with the build process.
Expand Down
4 changes: 2 additions & 2 deletions verif/sim/cva6.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ def check_spike_version():
logging.info(f"- stderr:\n\n{user_spike_stderr_string}")
# Run 'ldd' on Spike binary and print contents of stdout and stderr.
spike_ldd = subprocess.run(
"/bin/ldd $SPIKE_PATH/spike", capture_output=True, text=True, shell=True
"ldd $SPIKE_PATH/spike", capture_output=True, text=True, shell=True
)
spike_ldd_stdout = spike_ldd.stdout.strip()
spike_ldd_stderr = spike_ldd.stderr.strip()
Expand All @@ -1030,7 +1030,7 @@ def check_spike_version():


def check_verilator_version():
REQUIRED_VERILATOR_VERSION = "5.008"
REQUIRED_VERILATOR_VERSION = "5.028"

verilator_version_string = run_cmd("verilator --version")
logging.info(f"Verilator Version: {verilator_version_string.strip()}")
Expand Down