This repository has been archived by the owner on May 15, 2024. It is now read-only.
forked from chipsalliance/riscv-dv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iss_sim
executable file
·191 lines (170 loc) · 4.84 KB
/
iss_sim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Environment variable for the path of RISC-V GCC toolchain
# You can install the toolchain from https://github.com/riscv/riscv-gcc
# RISCV_TOOLCHAIN="XXX"
# GCC compile options
ABI="lp64"
ISA="rv64imc"
DATE=`date +%Y-%m-%d`
# Instruction set simulator
ISS="spike" # other options: ovpsim, all
# riscv-ovpsim options
OVPSIM_VARIANT="RV64GC"
# Binary of RISC-V ovpsim ISS
# https://github.com/riscv/riscv-ovpsim
RISCV_OVPSIM="${OVPSIM_PATH}/riscvOVPsim.exe"
# Directory of assemble tests
SRC_DIR="./out_${DATE}/asm_tests"
# Assembly test file name
TEST=""
# Regression report file name
REPORT="$SRC_DIR/regression_report.log"
# Clean the result of the previous runs
CLEAN=1
if [[ -z $RISCV_TOOLCHAIN ]]; then
echo "ERROR: Please define RISCV_TOOLCHAIN environment variable first"
exit 1
fi
# Process command line options
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-iss)
ISS="$2"
shift
;;
-dir)
SRC_DIR="$2"
shift
;;
-toolchain)
RISCV_TOOLCHAIN="$2"
shift
;;
-isa)
ISA="$2"
shift
;;
-abi)
ABI="$2"
shift
;;
-test)
TEST="$2"
shift
;;
-report)
REPORT="$2"
shift
;;
-noclean)
CLEAN=0
shift
;;
*)
echo "unknown option $1"
return
;;
esac
shift
done
RISCV_GCC="$RISCV_TOOLCHAIN/bin/riscv64-unknown-elf-gcc"
RISCV_OBJCOPY="$RISCV_TOOLCHAIN/bin/riscv64-unknown-elf-objcopy"
RISCV_SPIKE="$RISCV_TOOLCHAIN/bin/spike"
mkdir -p "$SRC_DIR"
# If the test is specified through "-test" option, run a single test rather
# than all tests under SRC_DIR.
if [[ $TEST == "" ]]; then
find "$SRC_DIR" -name "*.S" > "$SRC_DIR/asm_test_list"
else
echo "$TEST" > "$SRC_DIR/asm_test_list"
fi
if [[ $ISA =~ 32 ]]; then
OVPSIM_VARIANT="RV32GC"
fi
# Clean up previous running result
if [[ $CLEAN == 1 ]]; then
rm -rf "$REPORT"
if [[ "$ISS" == "spike" ]] || [[ "$ISS" == "all" ]]; then
rm -rf "$SRC_DIR/spike_sim"
fi
if [[ "$ISS" == "ovpsim" ]] || [[ "$ISS" == "all" ]]; then
rm -rf "$SRC_DIR/riscv_ovpsim"
fi
fi
# GCC compile
while read asm_test; do
# Generate binary for RTL simulation
SRC="$asm_test"
OBJFILE="$asm_test.o"
BINFILE="$asm_test.bin"
GCC_CMD="$RISCV_GCC -march=$ISA -mabi=$ABI -static -mcmodel=medany \
-fvisibility=hidden -nostdlib \
-nostartfiles -I$RISCV_TESTS/env/p \
-Tscripts/link.ld $SRC -o $OBJFILE"
echo "riscv_gcc compiling : $SRC"
$($GCC_CMD)
echo "Convert $OBJFILE to $BINFILE"
# Convert the ELF to plain binary
# You can load this binary to your RTL simulation
"$RISCV_OBJCOPY" -O binary "$OBJFILE" "$BINFILE"
done <"$SRC_DIR/asm_test_list"
if [[ "$ISS" == "ovpsim" ]] || [[ "$ISS" == "all" ]]; then
mkdir -p "$SRC_DIR/riscv_ovpsim"
fi
if [[ "$ISS" == "spike" ]] || [[ "$ISS" == "all" ]]; then
mkdir -p "$SRC_DIR/spike_sim"
fi
# Run ISS simulation
while read asm_test; do
ELF="${asm_test}.o"
TEST_NAME=$(echo "$ELF" | sed 's/^.*\///g')
# Spike sim
if [[ "$ISS" == "spike" ]] || [[ "$ISS" == "all" ]]; then
echo "Running spike: $TEST_NAME"
SPIKE_LOG="$SRC_DIR/spike_sim/$TEST_NAME.log"
SPIKE_CMD="timeout 60s $RISCV_SPIKE --isa=$ISA -l $ELF &> $SPIKE_LOG"
$($SPIKE_CMD &> $SPIKE_LOG)
fi
# riscv_ovpsim sim
if [[ "$ISS" == "ovpsim" ]] || [[ "$ISS" == "all" ]]; then
if [[ -z $OVPSIM_PATH ]]; then
echo "ERROR: Please define OVPSIM_PATH environment variable first"
exit 1
fi
OVPSIM_LOG="$SRC_DIR/riscv_ovpsim/$TEST_NAME.log"
echo "Running ovpsim: $TEST_NAME"
RISCV_OVPSIM_CMD="$RISCV_OVPSIM --variant $OVPSIM_VARIANT \
--override riscvOVPsim/cpu/PMP_registers=0 \
--override riscvOVPsim/cpu/simulateexceptions=T \
--trace --tracechange --traceshowicount --program $ELF \
--finishafter 500000"
$($RISCV_OVPSIM_CMD &> $OVPSIM_LOG)
fi
if [[ "$ISS" == "all" ]]; then
echo "Rerun command: ./iss_sim -test $asm_test -iss all" >> "$REPORT"
echo "spike : $SPIKE_LOG" >> "$REPORT"
echo "ovpsim : $OVPSIM_LOG" >> "$REPORT"
./iss_cmp "$SPIKE_LOG" "$OVPSIM_LOG" "$REPORT"
tail -1 "$REPORT"
echo "" >> "$REPORT"
fi
done <"$SRC_DIR/asm_test_list"
if [[ "$ISS" == "all" ]]; then
echo "Full regression report is saved to $REPORT"
cat "$REPORT"
fi