Skip to content

Commit e27fb3e

Browse files
CyrilKoepaulsc96
andauthored
target/sim: Add VCS simulation flow (#163)
* vip: Various fixes for VCS, bump AXI * cheshire_pkg: Replace parameter by variables inside function * vcs: Add first version of vcs scripts * ci: Add vcs to CI * sim: Some cleanup * docs: Document simulation using VCS * Bender.yml: Update to newest AXI version * make: Use Bender flags variable for VCS compile script --------- Co-authored-by: Paul Scheffler <paulsc@iis.ee.ethz.ch>
1 parent 709355b commit e27fb3e

8 files changed

Lines changed: 127 additions & 28 deletions

File tree

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ target/sim/vsim/transcript
3838
target/sim/vsim/vsim.wlf
3939
target/sim/vsim/work/
4040

41+
# VCS generated files
42+
target/sim/vcs/compile.*.sh
43+
target/sim/vcs/*.log
44+
target/sim/vcs/AN.DB
45+
target/sim/vcs/simv*
46+
target/sim/vcs/csrc
47+
target/sim/vcs/ucli.key
48+
target/sim/vcs/work*
49+
target/sim/vcs/vc_hdrs.h
50+
4151
# Xilinx generated files
4252
target/xilinx/build
4353
target/xilinx/out

Bender.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ packages:
1515
- apb
1616
- register_interface
1717
axi:
18-
revision: ac5deb3ff086aa34b168f392c051e92603d6c0e2
19-
version: 0.39.2
18+
revision: 39f5f2d51c5e524f6fc5cf8b6e901f7dcc5622d7
19+
version: 0.39.6
2020
source:
2121
Git: https://github.com/pulp-platform/axi.git
2222
dependencies:

Bender.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ package:
1313

1414
dependencies:
1515
apb_uart: { git: "https://github.com/pulp-platform/apb_uart.git", version: 0.2.1 }
16-
axi: { git: "https://github.com/pulp-platform/axi.git", version: 0.39.2 }
16+
axi: { git: "https://github.com/pulp-platform/axi.git", version: 0.39.6 }
1717
axi_llc: { git: "https://github.com/pulp-platform/axi_llc.git", version: 0.2.1 }
1818
axi_riscv_atomics: { git: "https://github.com/pulp-platform/axi_riscv_atomics.git", version: 0.8.2 }
1919
axi_rt: { git: "https://github.com/pulp-platform/axi_rt.git", version: 0.0.0-alpha.9 }

cheshire.mk

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
# Paul Scheffler <paulsc@iis.ee.ethz.ch>
88

99
BENDER ?= bender
10+
VLOGAN ?= vlogan
1011

1112
# Caution: Questasim requires this to point to the *actual* compiler install path
1213
CXX_PATH := $(shell which $(CXX))
1314

14-
VLOG_ARGS ?= -suppress 2583 -suppress 13314 -timescale 1ns/1ps
15+
VLOG_ARGS ?= -suppress 2583 -suppress 13314 -timescale 1ns/1ps
16+
VLOGAN_ARGS ?= -kdb -nc -assert svaext +v2k -timescale=1ns/1ps
1517

1618
# Common Bender flags for Cheshire RTL
1719
CHS_BENDER_RTL_FLAGS ?= -t rtl -t cva6 -t cv64a6_imafdcsclic_sv39
@@ -61,7 +63,7 @@ chs-clean-deps:
6163
######################
6264

6365
CHS_NONFREE_REMOTE ?= git@iis-git.ee.ethz.ch:pulp-restricted/cheshire-nonfree.git
64-
CHS_NONFREE_COMMIT ?= 99e58ec
66+
CHS_NONFREE_COMMIT ?= 99aa8d9
6567

6668
CHS_PHONY += chs-nonfree-init
6769
chs-nonfree-init:
@@ -149,6 +151,10 @@ $(CHS_ROOT)/target/sim/vsim/compile.cheshire_soc.tcl: $(CHS_ROOT)/Bender.yml
149151
$(BENDER) script vsim -t sim -t test $(CHS_BENDER_RTL_FLAGS) --vlog-arg="$(VLOG_ARGS)" > $@
150152
echo 'vlog "$(realpath $(CHS_ROOT))/target/sim/src/elfloader.cpp" -ccflags "-std=c++11" -cpppath "$(CXX_PATH)"' >> $@
151153

154+
$(CHS_ROOT)/target/sim/vcs/compile.cheshire_soc.sh: $(CHS_ROOT)/Bender.yml
155+
$(BENDER) script vcs -t sim -t test $(CHS_BENDER_RTL_FLAGS) --vlog-arg="$(VLOGAN_ARGS)" --vlogan-bin="$(VLOGAN)" > $@
156+
chmod +x $@
157+
152158
.PRECIOUS: $(CHS_ROOT)/target/sim/models
153159
$(CHS_ROOT)/target/sim/models:
154160
mkdir -p $@
@@ -167,6 +173,7 @@ $(CHS_ROOT)/target/sim/models/24FC1025.v: $(CHS_ROOT)/Bender.yml | $(CHS_ROOT)/t
167173
CHS_SIM_ALL += $(CHS_ROOT)/target/sim/models/s25fs512s.v
168174
CHS_SIM_ALL += $(CHS_ROOT)/target/sim/models/24FC1025.v
169175
CHS_SIM_ALL += $(CHS_ROOT)/target/sim/vsim/compile.cheshire_soc.tcl
176+
CHS_SIM_ALL += $(CHS_ROOT)/target/sim/vcs/compile.cheshire_soc.sh
170177

171178
###########
172179
# DRAMSys #

docs/tg/sim.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This page describes how to simulate Cheshire to *execute baremetal programs*. Pl
55
We currently provide working setups for:
66

77
- Questa Advanced Simulator (QuestaSim) `>= 2022.3`
8+
- VCS `>= 2024.09`
89

910
We plan on supporting more simulators in the future. If your situation requires it, simulating Cheshire on other setups should be straightforward.
1011

@@ -21,21 +22,21 @@ We provide a SystemVerilog testbench for `cheshire_soc` running baremetal progra
2122

2223
Preloading boot modes expect an ELF executable to be passed through `BINARY`, while autonomous boot modes expect a disk image (GPT formatted or raw code) to be passed through `IMAGE`. For more information on how to build software for Cheshire and its boot process, see [Software Stack](../um/sw.md).
2324

24-
The `SELCFG` environment variable selects the Cheshire configuration used in simulations. Possible configurations are specified in the `tb_cheshire_pkg` package. If not set or set to `0`, the default configuration is selected.
25+
The `SELCFG` variable selects the Cheshire configuration used in simulations. Possible configurations are specified in the `tb_cheshire_pkg` package. If not set or set to `0`, the default configuration is selected.
2526

2627
| `SELCFG` | Configuration in (`tb_cheshire_pkg`) |
2728
| -------- | ----------------------------------------- |
2829
| 0 | Default configuration from `cheshire_pkg` |
2930
| 1 | AXI-RT-enabled configuration |
3031
| 2 | CLIC-enabled configuration |
3132

32-
The `USE_DRAMSYS` environment variable controls whether simulations are linked against and use DRAMSys for DRAM simulation. Note that before starting a simulation using DRAMSys, it must be built with `make chs-dramsys-all` first.
33+
The `USE_DRAMSYS` variable controls whether simulations are linked against and use DRAMSys for DRAM simulation. Note that before starting a simulation using DRAMSys, it must be built with `make chs-dramsys-all` first.
3334

3435
For simulation of Cheshire in other designs, we provide the module `cheshire_vip` encapsulating all verification IPs and their interfaces. For details, see [Verifying Cheshire In-System](integr.md#verifying-cheshire-in-system).
3536

3637
## QuestaSim
3738

38-
After building Cheshire, start QuestaSim in `target/sim/vsim` and run:
39+
Variables are read from QuestaSim's Tcl environment. After building Cheshire, start QuestaSim in `target/sim/vsim` and run:
3940

4041
```tcl
4142
# Preload `helloworld.spm.elf` through serial link
@@ -52,3 +53,22 @@ run -all
5253
```
5354

5455
The design needs to be recompiled only when hardware is changed. The simulation can be restarted by re-sourcing `start.cheshire_soc.tcl`, allowing binary (or image) and load method changes beforehand.
56+
57+
## VCS
58+
59+
Variables are read from your shell environment. After building Cheshire, start a POSIX-compliant shell in `target/sim/vcs` and run:
60+
61+
```sh
62+
# Preload `helloworld.spm.elf` through serial link
63+
export BINARY="../../../sw/tests/helloworld.spm.elf"
64+
export BOOTMODE=0
65+
export PRELMODE=1
66+
67+
# Compile design
68+
./compile.cheshire_soc.sh
69+
70+
# Start and run simulation
71+
./start.cheshire_soc.sh
72+
```
73+
74+
The design needs to be recompiled only when hardware is changed. The simulation can be run repeatedly using `start.cheshire_soc.sh`, allowing binary (or image) and load method changes beforehand.

hw/cheshire_pkg.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ package cheshire_pkg;
463463

464464
// Choose static colocation of IDs based on how heavily used and/or critical they are
465465
function automatic cva6_id_map_t gen_cva6_id_map(cheshire_cfg_t cfg);
466-
localparam int unsigned DefaultMapEntry[2] = '{0, 0};
466+
int unsigned DefaultMapEntry[2] = '{0, 0};
467467
case (cfg.AxiMstIdWidth)
468468
// Provide exclusive ID to I-cache to prevent fetch blocking
469469
1: return '{'{Cva6IdBypMmu, 0}, '{Cva6IdBypLoad, 0}, '{Cva6IdBypAccel, 0}, '{Cva6IdBypStore, 0},

target/sim/src/vip_cheshire_soc.sv

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
228228
assign jtag.tdo = jtag_tdo;
229229

230230
initial begin
231-
@(negedge rst_n);
231+
wait (!rst_n);
232232
jtag_dbg.reset_master();
233233
end
234234

@@ -469,6 +469,7 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
469469
initial begin
470470
static byte_bt uart_read_buf [$];
471471
byte_bt bite;
472+
string line;
472473
wait_for_reset();
473474
forever begin
474475
uart_read_byte(bite);
@@ -477,7 +478,8 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
477478
uart_boot_ena = 0;
478479
end else if (bite == "\n") begin
479480
if (uart_read_buf.size() > 0) begin
480-
$display("[UART] %s", {>>8{uart_read_buf}});
481+
line = {>>8{uart_read_buf}};
482+
$display("[UART] %s", line);
481483
uart_read_buf.delete();
482484
end else begin
483485
$display("[UART]");
@@ -648,7 +650,7 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
648650
.AXI_DATA_WIDTH ( DutCfg.AxiDataWidth ),
649651
.AXI_ID_WIDTH ( DutCfg.AxiMstIdWidth ),
650652
.AXI_USER_WIDTH ( DutCfg.AxiUserWidth )
651-
) slink_mst_ext(), slink_mst_vip(), slink_mst();
653+
) slink_mst_ext(), slink_mst_vip(), slink_mst(), slink_slv_mux[1:0]();
652654

653655
AXI_BUS #(
654656
.AXI_ADDR_WIDTH ( DutCfg.AddrWidth ),
@@ -666,6 +668,9 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
666668
.clk_i ( clk )
667669
);
668670

671+
`AXI_ASSIGN (slink_slv_mux[0], slink_mst_ext)
672+
`AXI_ASSIGN (slink_slv_mux[1], slink_mst_vip)
673+
669674
// Multiplex internal and external AXI requests
670675
axi_mux_intf #(
671676
.SLV_AXI_ID_WIDTH ( DutCfg.AxiMstIdWidth ),
@@ -678,8 +683,8 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
678683
.clk_i ( clk ),
679684
.rst_ni ( rst_n ),
680685
.test_i ( test_mode ),
681-
.slv ( '{slink_mst_vip, slink_mst_ext} ),
682-
.mst ( slink_mst_mux )
686+
.slv ( slink_slv_mux ),
687+
.mst ( slink_mst_mux )
683688
);
684689

685690
// Serialize away added AXI index bits
@@ -785,7 +790,7 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
785790
slink_axi_driver_t slink_axi_driver = new (slink_mst_vip_dv);
786791

787792
initial begin
788-
@(negedge rst_n);
793+
wait (!rst_n);
789794
slink_axi_driver.reset_master();
790795
end
791796

@@ -951,20 +956,20 @@ endmodule
951956

952957
module vip_cheshire_soc_tristate import cheshire_pkg::*; (
953958
// I2C pad IO
954-
output logic i2c_sda_i,
955-
input logic i2c_sda_o,
956-
input logic i2c_sda_en,
957-
output logic i2c_scl_i,
958-
input logic i2c_scl_o,
959-
input logic i2c_scl_en,
959+
output wire i2c_sda_i,
960+
input wire i2c_sda_o,
961+
input wire i2c_sda_en,
962+
output wire i2c_scl_i,
963+
input wire i2c_scl_o,
964+
input wire i2c_scl_en,
960965
// SPI host pad IO
961-
input logic spih_sck_o,
962-
input logic spih_sck_en,
963-
input logic [SpihNumCs-1:0] spih_csb_o,
964-
input logic [SpihNumCs-1:0] spih_csb_en,
965-
output logic [ 3:0] spih_sd_i,
966-
input logic [ 3:0] spih_sd_o,
967-
input logic [ 3:0] spih_sd_en,
966+
input wire spih_sck_o,
967+
input wire spih_sck_en,
968+
input wire [SpihNumCs-1:0] spih_csb_o,
969+
input wire [SpihNumCs-1:0] spih_csb_en,
970+
output wire [ 3:0] spih_sd_i,
971+
input wire [ 3:0] spih_sd_o,
972+
input wire [ 3:0] spih_sd_en,
968973
// I2C wires
969974
inout wire i2c_sda,
970975
inout wire i2c_scl,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# #!/usr/bin/env bash
2+
# Copyright 2022 ETH Zurich and University of Bologna.
3+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Cyril Koenig <cykoenig@iis.ee.ethz.ch>
7+
8+
TESTBENCH=tb_cheshire_soc
9+
10+
# Set full path to c++ compiler.
11+
if [ -z "${CXX_PATH}" ]; then
12+
if [ -z "${CXX}" ]; then
13+
CXX="g++"
14+
fi
15+
CXX_PATH=`which ${CXX}`
16+
fi
17+
18+
# Set default VCS binary
19+
[[ -z "${VERDI_VERSION}" ]] && VERDI_VERSION=""
20+
[[ -z "${VCS_VERSION}" ]] && VCS_VERSION=""
21+
[[ -z "${VCS_BIN}" ]] && VCS_BIN="${VCS_VERSION} vcs"
22+
23+
flags="-full64 -kdb "
24+
# Set default to fast simulation flags.
25+
if [ -z "${VCSARGS}" ]; then
26+
# Use -debug_access+all for waveform debugging
27+
flags+="-O2 -debug_access=r -debug_region=1,${TESTBENCH} "
28+
fi
29+
30+
flags+="-cpp ${CXX_PATH} "
31+
[[ -n "${SELCFG}" ]] && flags+="-pvalue+SelectedCfg=${SELCFG} "
32+
33+
pargs=""
34+
[[ -n "${BOOTMODE}" ]] && pargs+="+BOOTMODE=${BOOTMODE} "
35+
[[ -n "${PRELMODE}" ]] && pargs+="+PRELMODE=${PRELMODE} "
36+
[[ -n "${BINARY}" ]] && pargs+="+BINARY=${BINARY} "
37+
[[ -n "${IMAGE}" ]] && pargs+="+IMAGE=${IMAGE} "
38+
39+
# DRAMSys
40+
if [ -n "${USE_DRAMSYS}" ]; then
41+
flags+="-pvalue UseDramSys=${USE_DRAMSYS} "
42+
if [[ "${USE_DRAMSYS}" == 1 ]]; then
43+
DRAMSYS_ROOT="../dramsys"
44+
DRAMSYS_LIB="${DRAMSYS_ROOT}/build/lib"
45+
pargs+="+DRAMSYS_RES=${DRAMSYS_ROOT}/configs "
46+
pargs+="-sv_lib ${DRAMSYS_LIB}/libDRAMSys_Simulator "
47+
fi
48+
fi
49+
50+
COLOR_NC='\e[0m'
51+
COLOR_BLUE='\e[0;34m'
52+
53+
${VCS_BIN} ${flags} ../src/elfloader.cpp ${TESTBENCH} | tee elaborate.log
54+
55+
# Start simulation
56+
printf ${COLOR_BLUE}"${VCS_VERSION} ${VERDI_VERSION} ./simv ${pargs}"${COLOR_NC}"\n"
57+
${VCS_VERSION} ${VERDI_VERSION} ./simv ${pargs} | tee simulate.log

0 commit comments

Comments
 (0)