Skip to content

Commit ac3b65c

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 addresses of "spmpcfg*", "spmpaddr*" and "spmpswitch[01]" (now tentative) are determined. Note that this script accepts the CSR addresses of "spmpcfg0" and "spmpaddr0", assuming subsequent entries are consecutive.
1 parent 4b97caa commit ac3b65c

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

instantiate-sspmp.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
if test $# -ne 4
73+
then
74+
ERRMSG="usage: $0 ADDR_SPMPCFG0 ADDR_SPMPADDR0 ADDR_SPMPSWITCH0 ADDR_SPMPSWITCH1"
75+
echo "$ERRMSG" 1>&2
76+
exit 1
77+
fi
78+
79+
PRIV_VERSIONS="1p9p1 1p10 1p11 1p12"
80+
81+
test_path include/opcode/riscv-opc.h
82+
for V in $PRIV_VERSIONS
83+
do
84+
test_path gas/testsuite/gas/riscv/csr-version-$V.d
85+
done
86+
test_path gas/testsuite/gas/riscv/csr-dw-regnums.s
87+
test_path gas/testsuite/gas/riscv/csr-dw-regnums.d
88+
89+
do_csr_instantiation ()
90+
{
91+
CSR="$1"
92+
CSR_UPPER=$(echo $CSR | tr a-z A-Z)
93+
ADDR=$(check_csr_addr "$2" $CSR)
94+
HEXC=$(canonicalize_hex $ADDR)
95+
DWREG=$(dwarf_regnum $HEXC)
96+
DWOFF=$(dwarf_offset $HEXC)
97+
ORIG_ADDR=$(grep "a0,${CSR}\$" gas/testsuite/gas/riscv/csr-version-1p12.d | head -n 1 | sed 's/.*+\([0-9a-f]\{3\}\)02573.*/\1/')
98+
sed -i "s/^#define CSR_${CSR_UPPER} .*/#define CSR_${CSR_UPPER} $HEXC/" include/opcode/riscv-opc.h
99+
for V in $PRIV_VERSIONS
100+
do
101+
sed -i "s/+${ORIG_ADDR}\\(02573\\|59073\\)/+${ADDR}\\1/" gas/testsuite/gas/riscv/csr-version-$V.d
102+
done
103+
sed -i "s/\\.cfi_offset ${CSR}, .*/.cfi_offset ${CSR}, ${DWOFF}/" gas/testsuite/gas/riscv/csr-dw-regnums.s
104+
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
105+
}
106+
107+
ADDR=$(check_csr_addr "$1" spmpcfg0)
108+
NADDR=$((0x$ADDR))
109+
for N in $(seq 0 15)
110+
do
111+
ADDR_N=$(printf %03x $(($NADDR + $N)))
112+
do_csr_instantiation spmpcfg$N $ADDR_N
113+
done
114+
115+
ADDR=$(check_csr_addr "$2" spmpaddr0)
116+
NADDR=$((0x$ADDR))
117+
for N in $(seq 0 63)
118+
do
119+
ADDR_N=$(printf %03x $(($NADDR + $N)))
120+
do_csr_instantiation spmpaddr$N $ADDR_N
121+
done
122+
123+
do_csr_instantiation spmpswitch0 "$3"
124+
do_csr_instantiation spmpswitch1 "$4"
125+
126+
if test -f "$0"
127+
then
128+
rm -f "$0"
129+
fi
130+
exit 0

0 commit comments

Comments
 (0)