Skip to content

Commit 7e13fc3

Browse files
committed
Update google_riscv-dv to SamuelRiedel/riscv-dv@31bc39f
Update code from upstream repository https://github.com/SamuelRiedel/riscv-dv to revision 31bc39ffcf2a9920c652462671e9a549331260e7 Signed-off-by: Samuel Riedel <[email protected]>
1 parent 5645112 commit 7e13fc3

30 files changed

+1319
-76
lines changed

vendor/google_riscv-dv.lock.hjson

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright lowRISC contributors.
1+
// Copyright lowRISC contributors (OpenTitan project).
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

@@ -8,7 +8,7 @@
88
{
99
upstream:
1010
{
11-
url: https://github.com/chipsalliance/riscv-dv
12-
rev: 71666ebacd69266b1abb7cdbad5e1897ce5884e6
11+
url: https://github.com/SamuelRiedel/riscv-dv
12+
rev: 31bc39ffcf2a9920c652462671e9a549331260e7
1313
}
1414
}

vendor/google_riscv-dv/.github/workflows/build-spike.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
key: ${{ env.cache_name }}_${{ env.cache_date }}
3737
restore-keys: ${{ env.cache_name }}_
3838

39-
- name: Install prerequisities
39+
- name: Install prerequisites
4040
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
4141
run: |
4242
sudo apt -qqy update && sudo apt -qqy --no-install-recommends install \

vendor/google_riscv-dv/.github/workflows/run-tests.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ jobs:
2222
name: Prepare test types
2323
run: |
2424
python3 -m pip install pyyaml
25-
echo "tests=$(python3 .github/scripts/parse_testlist.py $RISCV_TARGET)" | tee -a $GITHUB_OUTPUT
25+
python3 .github/scripts/parse_testlist.py $RISCV_TARGET > tests.list
26+
echo "tests=$(cat tests.list)" | tee -a $GITHUB_OUTPUT
2627
- id: hash
2728
name: Prepare files' hash
2829
run: |
29-
echo "files-hash=$(sha256sum **/*.sv **/*.py **/*.yml **/*.yaml | cut -d\ -f1 | sha256sum | cut -d\ -f1)" | tee -a $GITHUB_OUTPUT
30-
30+
sha256sum **/*.sv **/*.py **/*.yaml > file.hash
31+
echo "files-hash=$(cat file.hash | cut -d\ -f1 | sha256sum | cut -d\ -f1)" | tee -a $GITHUB_OUTPUT
32+
3133
3234
generate-code:
3335
runs-on: [ self-hosted, Linux, X64, gcp-custom-runners ]
@@ -39,7 +41,7 @@ jobs:
3941
test: ${{ fromJSON(needs.generate-config.outputs.test-types) }}
4042
version: [ uvm ]
4143
include:
42-
- test: riscv_arithmetic_basic_test
44+
- test: riscv_arithmetic_basic_test
4345
version: pyflow
4446
env:
4547
GHA_EXTERNAL_DISK: additional-tools
@@ -89,9 +91,10 @@ jobs:
8991
--isa $RISCV_TARGET --mabi ilp32 --steps gen -v -o test 2>&1 | tee test/generate.log
9092
9193
- name: Upload Artifacts
92-
uses: actions/upload-artifact@v3
94+
uses: actions/upload-artifact@v4
9395
if: always()
9496
with:
97+
name: generate_code_${{ matrix.test }}_${{ matrix.version }}
9598
path: |
9699
test/asm_test/*.S
97100
@@ -116,7 +119,14 @@ jobs:
116119
- uses: actions/checkout@v4
117120

118121
- name: Install dependencies
119-
run: sudo apt-get -qqy update && sudo apt-get -qqy install gcc-riscv64-unknown-elf device-tree-compiler
122+
run: sudo apt-get -qqy update && sudo apt-get -qqy install device-tree-compiler
123+
124+
- name: Install cross-compiler
125+
shell: bash
126+
run: |
127+
echo "deb http://archive.ubuntu.com/ubuntu/ noble main universe" | sudo tee -a /etc/apt/sources.list > /dev/null
128+
sudo apt -qqy update && sudo apt -qqy --no-install-recommends install gcc-riscv64-unknown-elf
129+
riscv64-unknown-elf-gcc --version
120130
121131
- name: Setup python
122132
# python dependencies cannot be properly downloaded with new versions of python
@@ -174,9 +184,10 @@ jobs:
174184
--isa $RISCV_TARGET --mabi ilp32 --steps gcc_compile,iss_sim -v -o test 2>&1 | tee -a test/generate.log
175185
176186
- name: Upload Artifacts
177-
uses: actions/upload-artifact@v3
187+
uses: actions/upload-artifact@v4
178188
if: always()
179189
with:
190+
name: run_tests_log_${{ matrix.test }}_${{ matrix.version }}
180191
path: |
181-
test/asm_test/*.log
182192
test/*.log
193+
test/**/${{ matrix.test }}*.log

vendor/google_riscv-dv/__init__.py

Whitespace-only changes.

vendor/google_riscv-dv/run.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ def get_generator_cmd(simulator, simulator_yaml, cov, exp, debug_cmd):
124124
sys.exit(RET_FAIL)
125125

126126

127-
def parse_iss_yaml(iss, iss_yaml, isa, setting_dir, debug_cmd):
127+
def parse_iss_yaml(iss, iss_yaml, isa, priv, setting_dir, debug_cmd):
128128
"""Parse ISS YAML to get the simulation command
129129
130130
Args:
131131
iss : target ISS used to look up in ISS YAML
132132
iss_yaml : ISS configuration file in YAML format
133133
isa : ISA variant passed to the ISS
134+
priv: : privilege modes
134135
setting_dir : Generator setting directory
135136
debug_cmd : Produce the debug cmd log without running
136137
@@ -140,6 +141,9 @@ def parse_iss_yaml(iss, iss_yaml, isa, setting_dir, debug_cmd):
140141
logging.info("Processing ISS setup file : {}".format(iss_yaml))
141142
yaml_data = read_yaml(iss_yaml)
142143

144+
# Path to the "yaml" subdirectory
145+
yaml_dir = os.path.dirname(iss_yaml)
146+
143147
# Path to the "scripts" subdirectory
144148
my_path = os.path.dirname(os.path.realpath(__file__))
145149
scripts_dir = os.path.join(my_path, "scripts") # Search for matched ISS
@@ -166,7 +170,9 @@ def parse_iss_yaml(iss, iss_yaml, isa, setting_dir, debug_cmd):
166170
cmd = re.sub("\<variant\>", variant, cmd)
167171
else:
168172
cmd = re.sub("\<variant\>", isa, cmd)
173+
cmd = re.sub("\<priv\>", priv, cmd)
169174
cmd = re.sub("\<scripts_path\>", scripts_dir, cmd)
175+
cmd = re.sub("\<config_path\>", yaml_dir, cmd)
170176
return cmd
171177
logging.error("Cannot find ISS {}".format(iss))
172178
sys.exit(RET_FAIL)
@@ -442,7 +448,12 @@ def gcc_compile(test_list, output_dir, isa, mabi, opts, debug_cmd):
442448
if 'gen_opts' in test:
443449
# Disable compressed instruction
444450
if re.search('disable_compressed_instr', test['gen_opts']):
445-
test_isa = re.sub("c", "", test_isa)
451+
# Note that this substitution assumes the cannonical order
452+
# of extensions, i.e. that extensions with preceding
453+
# underscores will be provided after all letter extensions.
454+
# This assumption should hold true, as this is a
455+
# requirement enforced by e.g. gcc
456+
test_isa = re.sub(r"(rv.+?)c", r"\1", test_isa)
446457
# If march/mabi is not defined in the test gcc_opts, use the default
447458
# setting from the command line.
448459
if not re.search('march', cmd):
@@ -641,7 +652,7 @@ def run_c_from_dir(c_test_dir, iss_yaml, isa, mabi, gcc_opts, iss,
641652

642653

643654
def iss_sim(test_list, output_dir, iss_list, iss_yaml, iss_opts,
644-
isa, setting_dir, timeout_s, debug_cmd):
655+
isa, priv, setting_dir, timeout_s, debug_cmd):
645656
"""Run ISS simulation with the generated test program
646657
647658
Args:
@@ -651,13 +662,15 @@ def iss_sim(test_list, output_dir, iss_list, iss_yaml, iss_opts,
651662
iss_yaml : ISS configuration file in YAML format
652663
iss_opts : ISS command line options
653664
isa : ISA variant passed to the ISS
665+
priv : privilege modes
654666
setting_dir : Generator setting directory
655667
timeout_s : Timeout limit in seconds
656668
debug_cmd : Produce the debug cmd log without running
657669
"""
658670
for iss in iss_list.split(","):
659671
log_dir = ("{}/{}_sim".format(output_dir, iss))
660-
base_cmd = parse_iss_yaml(iss, iss_yaml, isa, setting_dir, debug_cmd)
672+
base_cmd = parse_iss_yaml(iss, iss_yaml, isa, priv, setting_dir, debug_cmd)
673+
base_cmd += iss_opts
661674
logging.info("{} sim log dir: {}".format(iss, log_dir))
662675
run_cmd_output(["mkdir", "-p", log_dir])
663676
for test in test_list:
@@ -814,6 +827,8 @@ def parse_args(cwd):
814827
command is not specified")
815828
parser.add_argument("--isa", type=str, default="",
816829
help="RISC-V ISA subset")
830+
parser.add_argument("--priv", type=str, default="m",
831+
help="RISC-V privilege modes enabled in simulation [su]")
817832
parser.add_argument("-m", "--mabi", type=str, default="",
818833
help="mabi used for compilation", dest="mabi")
819834
parser.add_argument("--gen_timeout", type=int, default=360,
@@ -936,40 +951,40 @@ def load_config(args, cwd):
936951
args.core_setting_dir = cwd + "/target/" + args.target
937952
if args.target == "rv32imc":
938953
args.mabi = "ilp32"
939-
args.isa = "rv32imc"
954+
args.isa = "rv32imc_zicsr_zifencei"
940955
elif args.target == "rv32imafdc":
941956
args.mabi = "ilp32"
942-
args.isa = "rv32imafdc"
957+
args.isa = "rv32imafdc_zicsr_zifencei"
943958
elif args.target == "rv32imc_sv32":
944959
args.mabi = "ilp32"
945-
args.isa = "rv32imc"
960+
args.isa = "rv32imc_zicsr_zifencei"
946961
elif args.target == "multi_harts":
947962
args.mabi = "ilp32"
948-
args.isa = "rv32gc"
963+
args.isa = "rv32gc_zicsr_zifencei"
949964
elif args.target == "rv32imcb":
950965
args.mabi = "ilp32"
951-
args.isa = "rv32imcb"
966+
args.isa = "rv32imcb_zicsr_zifencei"
952967
elif args.target == "rv32i":
953968
args.mabi = "ilp32"
954-
args.isa = "rv32i"
969+
args.isa = "rv32i_zicsr_zifencei"
955970
elif args.target == "rv64imc":
956971
args.mabi = "lp64"
957-
args.isa = "rv64imc"
972+
args.isa = "rv64imc_zicsr_zifencei"
958973
elif args.target == "rv64imcb":
959974
args.mabi = "lp64"
960-
args.isa = "rv64imcb"
975+
args.isa = "rv64imcb_zicsr_zifencei"
961976
elif args.target == "rv64gc":
962977
args.mabi = "lp64"
963-
args.isa = "rv64gc"
978+
args.isa = "rv64gc_zicsr_zifencei"
964979
elif args.target == "rv64gcv":
965980
args.mabi = "lp64"
966-
args.isa = "rv64gcv"
981+
args.isa = "rv64gcv_zicsr_zifencei"
967982
elif args.target == "ml":
968983
args.mabi = "lp64"
969-
args.isa = "rv64imc"
984+
args.isa = "rv64imc_zicsr_zifencei"
970985
elif args.target == "rv64imafdc":
971986
args.mabi = "lp64"
972-
args.isa = "rv64imafdc"
987+
args.isa = "rv64imafdc_zicsr_zifencei"
973988
else:
974989
sys.exit("Unsupported pre-defined target: {}".format(args.target))
975990
else:
@@ -1147,7 +1162,7 @@ def main():
11471162
if args.steps == "all" or re.match(".*iss_sim.*", args.steps):
11481163
iss_sim(matched_list, output_dir, args.iss, args.iss_yaml,
11491164
args.iss_opts,
1150-
args.isa, args.core_setting_dir, args.iss_timeout,
1165+
args.isa, args.priv, args.core_setting_dir, args.iss_timeout,
11511166
args.debug)
11521167

11531168
# Compare ISS simulation result

vendor/google_riscv-dv/scripts/instr_trace_compare.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def compare_trace_csv(csv1, csv2, name1, name2, log,
125125
instr_trace_2[trace_2_index].gpr,
126126
gpr_val_2)
127127
if gpr_state_change_2 == 1:
128+
fd.write("Mismatch[{}]:\n[{}] {} : {}\n".format(
129+
mismatch_cnt, trace_1_index, name1,trace.get_trace_string()))
128130
fd.write("{} instructions left in trace {}\n".format(
129131
len(instr_trace_2) - trace_2_index, name2))
130132
mismatch_cnt += len(instr_trace_2) - trace_2_index

vendor/google_riscv-dv/scripts/lib.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_env_var(var, debug_cmd=None):
8888
return val
8989

9090

91-
def run_cmd(cmd, timeout_s=999, exit_on_error=1, check_return_code=True,
91+
def run_cmd(cmd, timeout_s=3600, exit_on_error=1, check_return_code=True,
9292
debug_cmd=None):
9393
"""Run a command and return output
9494
@@ -103,6 +103,12 @@ def run_cmd(cmd, timeout_s=999, exit_on_error=1, check_return_code=True,
103103
debug_cmd.write(cmd)
104104
debug_cmd.write("\n\n")
105105
return
106+
def killgroup(ps):
107+
try:
108+
os.killpg(os.getpgid(ps.pid), signal.SIGTERM)
109+
except AttributeError: #killpg not available on windows
110+
ps.kill()
111+
sys.exit(130)
106112
try:
107113
ps = subprocess.Popen("exec " + cmd,
108114
shell=True,
@@ -112,21 +118,17 @@ def run_cmd(cmd, timeout_s=999, exit_on_error=1, check_return_code=True,
112118
env=os.environ,
113119
stdout=subprocess.PIPE,
114120
stderr=subprocess.STDOUT)
121+
output = ps.communicate(timeout = timeout_s)[0]
115122
except subprocess.CalledProcessError:
116123
logging.error(ps.communicate()[0])
117124
sys.exit(RET_FAIL)
118125
except KeyboardInterrupt:
119126
logging.info("\nExited Ctrl-C from user request.")
120-
sys.exit(130)
121-
try:
122-
output = ps.communicate(timeout=timeout_s)[0]
127+
killgroup(ps)
123128
except subprocess.TimeoutExpired:
124129
logging.error("Timeout[{}s]: {}".format(timeout_s, cmd))
125130
output = ""
126-
try:
127-
os.killpg(os.getpgid(ps.pid), signal.SIGTERM)
128-
except AttributeError: #killpg not available on windows
129-
ps.kill()
131+
killgroup(ps)
130132
rc = ps.returncode
131133
if rc and check_return_code and rc > 0:
132134
logging.info(output)

vendor/google_riscv-dv/scripts/renode_log_to_trace_csv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def process_renode_sim_log(log_name, csv_name):
7878
if not line:
7979
continue
8080

81+
# We've hit ecall, quit
82+
if line.startswith("ECALL:"):
83+
break
84+
8185
# Skip non-regdump
8286
if not line.startswith("REGDUMP:"):
8387
continue

vendor/google_riscv-dv/scripts/renode_wrapper.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
REPL_TEMPLATE = """
1010
memory: Memory.MappedMemory @ sysbus 0x80000000
11-
size: 0x10000
11+
size: {mem}
1212
13-
cpu: CPU.RiscV32 @ sysbus
13+
cpu: CPU.{cpu_type} @ sysbus
1414
cpuType: "{isa}"
1515
timeProvider: clint
1616
hartId: 0
17+
{priv_levels}
18+
{additional_cpu_parameters}
1719
1820
clint: IRQControllers.CoreLevelInterruptor @ sysbus 0x02000000
1921
[0,1] -> cpu@[3,7]
@@ -29,8 +31,9 @@
2931
3032
cpu MaximumBlockSize 1
3133
cpu SetHookAtBlockEnd "print('REGDUMP:' + ','.join(self.GetRegistersValues()))"
34+
cpu InstallCustomInstructionHandlerFromString "00000000000000000000000001110011" "print('ECALL:');"
3235
33-
emulation RunFor "0.000100"
36+
emulation RunFor "0.001"
3437
3538
quit
3639
"""
@@ -69,6 +72,32 @@ def main():
6972
required=True,
7073
help="ELF file to run",
7174
)
75+
parser.add_argument(
76+
"--mem-size",
77+
type=str,
78+
default="0x100000",
79+
help="Memory size",
80+
)
81+
parser.add_argument(
82+
"--cpu-type",
83+
type=str,
84+
default="Riscv32",
85+
help="Renode CPU type",
86+
)
87+
parser.add_argument(
88+
"--priv",
89+
type=str,
90+
default="",
91+
help="Supported privilege levels",
92+
)
93+
# Some CPUs might not expose these parameters as configurable
94+
# allow the testing software to ignore/override them if needed
95+
parser.add_argument(
96+
"--additional-cpu-parameters",
97+
type=str,
98+
default="allowUnalignedAccesses: true",
99+
help="Additional CPU parameters",
100+
)
72101

73102
args = parser.parse_args()
74103

@@ -77,13 +106,27 @@ def main():
77106
repl = os.path.join(tmpdir, "riscv.repl")
78107
resc = os.path.join(tmpdir, "riscv.resc")
79108

109+
priv_levels = ""
110+
if args.priv:
111+
priv_levels += "privilegeLevels: PrivilegeLevels."
112+
if "m" in args.priv:
113+
priv_levels += "Machine"
114+
if "s" in args.priv:
115+
priv_levels += "Supervisor"
116+
if "u" in args.priv:
117+
priv_levels += "User"
118+
80119
params = {
81120
"renode": args.renode,
82121
"isa": args.isa,
83122
"elf": args.elf,
84123
"repl": repl,
85124
"resc": resc,
86125
"log": args.log,
126+
"mem": args.mem_size,
127+
"cpu_type": args.cpu_type,
128+
"priv_levels": priv_levels,
129+
"additional_cpu_parameters": args.additional_cpu_parameters,
87130
}
88131

89132
# Render REPL template

0 commit comments

Comments
 (0)