public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Tsukasa OI <research_trasio@irq.a4lg.com>
To: Tsukasa OI <research_trasio@irq.a4lg.com>
Cc: binutils@sourceware.org
Subject: [REVIEW ONLY 3/3] TEST: Add instantiation script on CSR allocation
Date: Tue, 29 Nov 2022 01:23:59 +0000	[thread overview]
Message-ID: <73828cb4ccf8c03275b6af7e42872d661dea267f.1669684988.git.research_trasio@irq.a4lg.com> (raw)
In-Reply-To: <cover.1669684988.git.research_trasio@irq.a4lg.com>

From: Tsukasa OI <research_trasio@irq.a4lg.com>

---
 instantiate-zisslpcfi.sh | 127 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)
 create mode 100755 instantiate-zisslpcfi.sh

diff --git a/instantiate-zisslpcfi.sh b/instantiate-zisslpcfi.sh
new file mode 100755
index 000000000000..a6bb0dfd763b
--- /dev/null
+++ b/instantiate-zisslpcfi.sh
@@ -0,0 +1,127 @@
+#! /bin/bash
+# SPDX-License-Identifier: CC0-1.0
+# Author: Tsukasa OI <research_trasio@irq.a4lg.com>
+# Year: 2022
+
+check_csr_addr ()
+{
+	ADDR="$1"
+	case "$ADDR" in
+	0x* | 0X*)
+		ADDR="${ADDR#??}"
+		;;
+	esac
+	case "$ADDR" in
+	[0-9a-fA-F])
+		ADDR=00$ADDR
+		;;
+	[0-9a-fA-F][0-9a-fA-F])
+		ADDR=0$ADDR
+		;;
+	[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])
+		;;
+	*)
+		echo "ERROR: \`$1' is not a valid CSR address for \`$2'." 1>&2
+		exit 1
+		;;
+	esac
+	ADDR=$(echo $ADDR | tr A-F a-f)
+	printf %s $ADDR
+	return 0
+}
+
+canonicalize_hex ()
+{
+	ADDR=$1
+	while :
+	do
+		case $ADDR in
+		0)
+			break
+			;;
+		0?*)
+			ADDR=${ADDR#0}
+			;;
+		*)
+			break
+			;;
+		esac
+	done
+	printf 0x%s $ADDR
+}
+
+dwarf_regnum ()
+{
+	echo -n $(($1 + 4096))
+}
+
+dwarf_offset ()
+{
+	echo -n $(($1 * 4))
+}
+
+test_path ()
+{
+	if test '!' -f "$1"
+	then
+		echo "ERROR: file \`$1' is not found." 1>&2
+		exit 1
+	fi
+}
+
+CSRS=(
+	lplr
+	ssp
+)
+
+if test $# -ne ${#CSRS[@]}
+then
+	ERRMSG="usage: $0"
+	for CSR in ${CSRS[@]}
+	do
+		CSR_UPPER=$(echo $CSR | tr a-z A-Z)
+		ERRMSG="$ERRMSG ADDR_${CSR_UPPER}"
+	done
+	echo "$ERRMSG" 1>&2
+	exit 1
+fi
+
+PRIV_VERSIONS="1p9p1 1p10 1p11 1p12"
+
+test_path include/opcode/riscv-opc.h
+for V in $PRIV_VERSIONS
+do
+	test_path gas/testsuite/gas/riscv/csr-version-$V.d
+done
+test_path gas/testsuite/gas/riscv/csr-dw-regnums.s
+test_path gas/testsuite/gas/riscv/csr-dw-regnums.d
+
+do_csr_instantiation ()
+{
+	CSR="$1"
+	CSR_UPPER=$(echo $CSR | tr a-z A-Z)
+	ADDR=$(check_csr_addr "$2" $CSR)
+	HEXC=$(canonicalize_hex $ADDR)
+	DWREG=$(dwarf_regnum $HEXC)
+	DWOFF=$(dwarf_offset $HEXC)
+	ORIG_ADDR=$(grep "a0,${CSR}\$" gas/testsuite/gas/riscv/csr-version-1p12.d | head -n 1 | sed 's/.*+\([0-9a-f]\{3\}\)02573.*/\1/')
+	sed -i "s/^#define CSR_${CSR_UPPER} .*/#define CSR_${CSR_UPPER} $HEXC/" include/opcode/riscv-opc.h
+	for V in $PRIV_VERSIONS
+	do
+		sed -i "s/+${ORIG_ADDR}\\(02573\\|59073\\)/+${ADDR}\\1/" gas/testsuite/gas/riscv/csr-version-$V.d
+	done
+	sed -i "s/\\.cfi_offset ${CSR}, .*/.cfi_offset ${CSR}, ${DWOFF}/" gas/testsuite/gas/riscv/csr-dw-regnums.s
+	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
+}
+
+for CSR in ${CSRS[@]}
+do
+	do_csr_instantiation $CSR "$1"
+	shift
+done
+
+if test -f "$0"
+then
+	rm -f "$0"
+fi
+exit 0
-- 
2.38.1


      parent reply	other threads:[~2022-11-29  1:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29  1:23 [REVIEW ONLY 0/3] UNRATIFIED RISC-V: Add 'Zisslpcfi' extension and its TENTATIVE CSRs Tsukasa OI
2022-11-29  1:23 ` [REVIEW ONLY 1/3] RISC-V: Add "XUN@S" operand type Tsukasa OI
2022-11-29  3:01   ` Palmer Dabbelt
2022-11-29  1:23 ` [REVIEW ONLY 2/3] UNRATIFIED RISC-V: Add 'Zisslpcfi' extension and its TENTATIVE CSRs Tsukasa OI
2022-11-29  1:23 ` Tsukasa OI [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73828cb4ccf8c03275b6af7e42872d661dea267f.1669684988.git.research_trasio@irq.a4lg.com \
    --to=research_trasio@irq.a4lg.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).