-
Notifications
You must be signed in to change notification settings - Fork 0
/
runElf.sh
executable file
·190 lines (153 loc) · 4.57 KB
/
runElf.sh
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
#!/usr/bin/env bash
# This script accepts one argument, a RISC-V binary program file
# path, and runs the program within the RISC-V processor simulator.
source common.sh
coqSim=0
haskellSim=0
verilogSim=0
interactive=""
interrupts=""
signature=""
sign_size=""
noprint=""
xlen=64
profile=""
heapdump=""
noSimSelected=1
options=$(getopt --options="hvsp:x:" --longoptions="coq-sim,haskell-sim,signature:,sign_size:,help,verbose,interactive,noprint,path:,debug,enable-ext-interrupts,xlen:,profile,heapdump,verilog-sim" -- "$@")
[ $? == 0 ] || error "Invalid command line. The command line includes one or more invalid command line parameters."
eval set -- "$options"
while true
do
case "$1" in
-h | --help)
cat <<- EOF
USAGE
-----
./runElf.sh [OPTIONS] PATH
This script reads the RISC-V binary referenced by PATH and executes
it within the RISC-V processor simulator.
OPTIONS
-------
--debug
Uses default values in place of random values (useful for when debugging against verilog)
--enable-ext-interrupts
Send random external interrupts to the processor model
--coq-sim
Runs the Coq simulator. See the doGenerate help docs for more information.
--haskell-sim
-s
Runs the haskell simulator. See the doGenerate help docs for more information.
--heapdump
Output a heap dump if an exception occurs during execution of the Haskell simulator.
Note: the simulator must have been compiled with the --profile and --heapdump flags.
-h|--help
Displays this message.
--path location
Path to the directory where the test is located.
--profile
Output a heap trace during execution of the Haskell simulator.
--sign_size size
Size of the memory to dump
--signature filename
The name of the file to dump the memory
-v|--verbose
Enables verbose output.
--verilog-sim
Run the Verilog simulator. (DEFAULT). See the doGenerate help docs for more information.
--xlen 32|64
Specifies whether or not the generator should produce a 32 or 64
bit RISC-V processor model. Default is 64.
EXAMPLES
--------
./runElf.sh -v rv32ui-p-and
Simulates the rv32ui-p-and test suite program in the RISC-V
processor simulator.
AUTHORS
-------
Murali Vijayaraghavan
Larry Lee
Evan Marzion
EOF
exit 0;;
--coq-sim)
coqSim=1
noSimSelected=0
shift;;
-v|--verbose)
verbose=1
shift;;
-p|--path)
path=$2
shift 2;;
--interactive)
interactive="--interactive"
shift;;
--haskell-sim)
haskellSim=1
noSimSelected=0
shift;;
--profile)
profile="+RTS -p -RTS"
shift;;
--heapdump)
heapdump="+RTS -xc -RTS"
shift;;
--debug)
debug="--debug"
shift;;
--noprint)
noprint="--noprint"
shift;;
--enable-ext-interrupts)
interrupts="--enable-ext-interrupts"
shift;;
--signature)
signaturev=$2
signature=signature@$2
shift 2;;
--sign_size)
sign_sizev=$2
sign_size=sign_size@$2
shift 2;;
-x|--xlen)
xlen=$2
shift 2;;
--verilog-sim)
verilogSim=1
noSimSelected=0
shift;;
--)
shift
break;;
esac
done
shift $((OPTIND - 1))
[[ -z "$path" ]] && error "Invalid command line. The PATH argument is missing."
base=$(basename $path)
if [[ $haskellSim == 1 ]]
then
dump=haskelldump
else
if [[ $coqSim == 1 ]]
then
dump=coqdump
else
dump=verilogdump
fi
fi
mkdir -p $dump
binfile=$dump/$base.bin
hexfile=$dump/$base.hex
execute "riscv64-unknown-elf-objcopy -O binary $path $binfile"
execute "hexdump -v -e '16/1 \"%02x \" \"\n\"' $binfile > $hexfile"
tohost_addr=$(riscv64-unknown-elf-readelf -a $path | grep '[^\.]\<tohost\>' | awk '{print $2}')
tohost_address=$((0x$tohost_addr - 0x80000000))
tohost_address=$(printf "%x" $tohost_address)
notice "Running $base"
[[ $verilogSim == 1 || $noSimSelected == 1 ]] && execute "time ./models/model$xlen/obj_dir/Vsystem +sign_size=$sign_sizev +signature=$signaturev +testfile=$hexfile +boot_rom=boot_ROM_RV${xlen}.hex +tohost_address=$tohost_address > $dump/$base.out"
[[ $haskellSim == 1 ]] && execute "time ./HaskellGen/HaskellSim boot_rom=boot_ROM_RV${xlen}.hex $interactive $noprint testfile=$hexfile tohost_address:$tohost_address xlen@${xlen} $signature $sign_size $debug $interrupts $profile $heapdump > $dump/$base.out"
[[ $coqSim == 1 ]] && execute "time ./HaskellGen/CoqSim boot_rom=boot_ROM_RV${xlen}.hex $interactive $noprint testfile=$hexfile tohost_address:$tohost_address xlen@${xlen} $signature $sign_size $debug $interrupts > $dump/$base.out"
execute "time $cmd"
result=$?
exit $result