From patchwork Tue Nov 29 01:23:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 27018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp57628wrr; Mon, 28 Nov 2022 17:28:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6yjCgdefWBBD85eRKjK1E2km9g0YPwdfVedaCYAUh1VDNzWK3a0tVju23xxNEYL/DEBiVX X-Received: by 2002:a17:906:3ad6:b0:7ae:40b7:7fbe with SMTP id z22-20020a1709063ad600b007ae40b77fbemr44280476ejd.371.1669685292660; Mon, 28 Nov 2022 17:28:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669685292; cv=none; d=google.com; s=arc-20160816; b=nLvWrXjQUS+AhynaVmoNBBzMy32VE7Zb4SekbiQzODWZzO//9ae2r8C32Mk99dCQYI lK6bVG7E7OEPstzLnyF7SCcgeHxYASSe3ROl+a0AFAH5RE8PR4pguWo++7mePnsH9lkR dJUE7G/ePIRLbY06K5EjbsD+i4qAVj17egqZA5gq+kq3rm+iZYPOXFgmIpCeNKzTmkMd ebYWS/6+VsF30luf56AmsKu6FrMB1WrifMf9vkF64UhdDnn1N9yVGIuLvcOEd9wBL0rd 4LasnDvTOycTeMuICCLdw03LknrErYjO1drAWZIeshO4B49oFTsJpuj1lkJRnVRDDq7Q SgIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=UByC+I3v3y5SMspeqABkF/WfYMTmEqc3Xua09V7fMXc=; b=Ava09RPRpqOsUsalZ3pacwnXX4Q+f5Jni/BTkG9XyWamoHO/DdXW9emn1h2d49n8rP 6ORnpdDTIM+hqUuOyVKMOaO7XFZomjH3DYkddVty9UsxTkSl/HNkRUkGCXNBZMhGXIJk vkjxw3hSrLuUD0gzPtePkLYp21VulF9HCFuendcCMvxjPpX+0AxITmRO1IDlXdYIXI18 J+pAzSasi7Sz14g5LIcdp2bSu43+aA9E4EV+GAPVAY7ak+00DY/SUc0sZQvxrdllZdSF Bv91c+U0TrREg6YFYVElqiGPnr5NmgAGDX2kAPIW0O2OrY6nnpF2LYVWR8tPg0Ae6yo1 PU0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=x9D6AGqm; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cw9-20020a170906478900b007c080a3f372si1355144ejc.363.2022.11.28.17.28.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 17:28:12 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=x9D6AGqm; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8EAB38518AE for ; Tue, 29 Nov 2022 01:26:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8EAB38518AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669685187; bh=UByC+I3v3y5SMspeqABkF/WfYMTmEqc3Xua09V7fMXc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=x9D6AGqmwsKqeXGxhaYCYA4Gr2SGjIjha8XzY9G5NqnrlQF/NV5Wu9w6lwsKCzDJ3 Dvgxpsw521VyAGY8CIKZAwhJTmpFTNhwMN187YKtmIlj96LpamvOxn40UOe7dF7sPG ZetgRL8zHm2iXvFrAau6bSrj6PugS9brDRbpW7ag= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id F09C63832D00 for ; Tue, 29 Nov 2022 01:24:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F09C63832D00 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 5E4BF300089; Tue, 29 Nov 2022 01:24:32 +0000 (UTC) To: Tsukasa OI 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 Message-Id: <73828cb4ccf8c03275b6af7e42872d661dea267f.1669684988.git.research_trasio@irq.a4lg.com> In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750791925847690831?= X-GMAIL-MSGID: =?utf-8?q?1750791925847690831?= From: Tsukasa OI --- 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 +# 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