Skip to content

Commit e91f66b

Browse files
committed
TEST: Add instantiation script on CSR allocation
**DEVELOPMENT ENVIRONMENT ONLY** The attached script can be used to replace related source files when the CSR address of "ssp" (now tentative) is determined. Usage (when "ssp" is allocated to 0x0ad): ./instantiate-zicfiss.sh 0x0ad
1 parent ef5161e commit e91f66b

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

instantiate-zicfiss.sh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#! /bin/bash
2+
# SPDX-License-Identifier: CC0-1.0
3+
# Author: Tsukasa OI <[email protected]>
4+
# Year: 2023
5+
6+
check_csr_addr ()
7+
{
8+
ADDR="$1"
9+
case "$ADDR" in
10+
0x* | 0X*)
11+
ADDR="${ADDR#??}"
12+
;;
13+
esac
14+
case "$ADDR" in
15+
[0-9a-fA-F])
16+
ADDR=00$ADDR
17+
;;
18+
[0-9a-fA-F][0-9a-fA-F])
19+
ADDR=0$ADDR
20+
;;
21+
[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])
22+
;;
23+
*)
24+
echo "ERROR: \`$1' is not a valid CSR address for \`$2'." 1>&2
25+
exit 1
26+
;;
27+
esac
28+
ADDR=$(echo $ADDR | tr A-F a-f)
29+
printf %s $ADDR
30+
return 0
31+
}
32+
33+
canonicalize_hex ()
34+
{
35+
ADDR=$1
36+
while :
37+
do
38+
case $ADDR in
39+
0)
40+
break
41+
;;
42+
0?*)
43+
ADDR=${ADDR#0}
44+
;;
45+
*)
46+
break
47+
;;
48+
esac
49+
done
50+
printf 0x%s $ADDR
51+
}
52+
53+
dwarf_regnum ()
54+
{
55+
echo -n $(($1 + 4096))
56+
}
57+
58+
dwarf_offset ()
59+
{
60+
echo -n $(($1 * 4))
61+
}
62+
63+
test_path ()
64+
{
65+
if test '!' -f "$1"
66+
then
67+
echo "ERROR: file \`$1' is not found." 1>&2
68+
exit 1
69+
fi
70+
}
71+
72+
CSRS=(
73+
ssp
74+
)
75+
76+
if test $# -ne ${#CSRS[@]}
77+
then
78+
ERRMSG="usage: $0"
79+
for CSR in ${CSRS[@]}
80+
do
81+
CSR_UPPER=$(echo $CSR | tr a-z A-Z)
82+
ERRMSG="$ERRMSG ADDR_${CSR_UPPER}"
83+
done
84+
echo "$ERRMSG" 1>&2
85+
exit 1
86+
fi
87+
88+
PRIV_VERSIONS="1p9p1 1p10 1p11 1p12"
89+
90+
test_path include/opcode/riscv-opc.h
91+
for V in $PRIV_VERSIONS
92+
do
93+
test_path gas/testsuite/gas/riscv/csr-version-$V.d
94+
done
95+
test_path gas/testsuite/gas/riscv/csr-dw-regnums.s
96+
test_path gas/testsuite/gas/riscv/csr-dw-regnums.d
97+
98+
do_csr_instantiation ()
99+
{
100+
CSR="$1"
101+
CSR_UPPER=$(echo $CSR | tr a-z A-Z)
102+
ADDR=$(check_csr_addr "$2" $CSR)
103+
HEXC=$(canonicalize_hex $ADDR)
104+
DWREG=$(dwarf_regnum $HEXC)
105+
DWOFF=$(dwarf_offset $HEXC)
106+
ORIG_ADDR=$(grep "a0,${CSR}\$" gas/testsuite/gas/riscv/csr-version-1p12.d | head -n 1 | sed 's/.*+\([0-9a-f]\{3\}\)02573.*/\1/')
107+
sed -i "s/^#define CSR_${CSR_UPPER} .*/#define CSR_${CSR_UPPER} $HEXC/" include/opcode/riscv-opc.h
108+
for V in $PRIV_VERSIONS
109+
do
110+
sed -i "s/+${ORIG_ADDR}\\(02573\\|59073\\)/+${ADDR}\\1/" gas/testsuite/gas/riscv/csr-version-$V.d
111+
done
112+
sed -i "s/\\.cfi_offset ${CSR}, .*/.cfi_offset ${CSR}, ${DWOFF}/" gas/testsuite/gas/riscv/csr-dw-regnums.s
113+
sed -i "s/DW_CFA_offset_extended_sf: r[0-9]\\+ \\\\(${CSR}\\\\) at cfa\\\\+[0-9]\\+/DW_CFA_offset_extended_sf: r${DWREG} \\\\(${CSR}\\\\) at cfa\\\\+${DWOFF}/" gas/testsuite/gas/riscv/csr-dw-regnums.d
114+
}
115+
116+
for CSR in ${CSRS[@]}
117+
do
118+
do_csr_instantiation $CSR "$1"
119+
shift
120+
done
121+
122+
if test -f "$0"
123+
then
124+
rm -f "$0"
125+
fi
126+
exit 0

0 commit comments

Comments
 (0)