From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id 0FB1538532E4 for ; Tue, 29 Nov 2022 02:39:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0FB1538532E4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dabbelt.com Received: by mail-pj1-x102a.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so15954726pjs.4 for ; Mon, 28 Nov 2022 18:39:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=YyV8IaYV6Q5E7XKv6Mzucb1gOxxIefE8tW7fchgIpns=; b=Iia6SeKbIxVdHIGpKAzbAO0h11A+t7s9AqCiT0Wu+vtKN7cPkWJxJ+mmqy0wSQu01N F+h7lNooLVgpWtCFxZWYcrVvmSIgkwQ2xaVz2ELrOzjhP52aGf4RdRlsAXKdf3vbithX JNeJcbA1KjgMOPexJtT0AnQWGbRn8YveCT6O1rIaXWWl/xqrkgfpzQH04P+85beu1vPC SIyW7nMa3Cghi1JEKlNM6WeO7Zt8cbr0xaa1L0KF5g/ms3B94+gc8VxTE+6Sy95sZwEb stwmoohaGen5JcwSb22o1ihIfl9pDEz9FQOee4Ia13bJGI9GDSEeNEfJzDRyA58HYTg+ wrJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YyV8IaYV6Q5E7XKv6Mzucb1gOxxIefE8tW7fchgIpns=; b=knme404Wmn/jy8X3eIpQNg3OrgM2gnqsI0Km4Lb3OaMJ5NH+94RbkxQ52V160yCJom Sw3WodHT1/9Cpi/q+hjHYaWK7AQuiiQJuxUKkg3PWpLqKcIYvY1abVrJQo+jmb+aTt1E +XhTMVXCwyLyU7WgFiJ+pW4oMDrxDT5zpU2w9wNxmLWaOCKeH2IqOpyWACmvBCkPAczs rn52h7onjVxVnoAgTVI16XxJDw9cs6jYUEBk6Du19olmrpZTgthTILQmE5b5/QSnTYjX MyIuXZz+ecdg+S0FCzao7j9Iwimi4ndreEGtyf2ar6IQJadku4XX+KmnXTJ8QmTcmL8/ cGTA== X-Gm-Message-State: ANoB5pk4PUkrRezPMH/TuTELWq+47zInchG4JuCDckeE6IXM6nPtsh8c vgnwyyxKtdlzCtlf1azA8a0SvDXMPCfXhg== X-Google-Smtp-Source: AA0mqf7ZRWngOyf+/PoGCuHIDYS/qBcZaDxdgF68024VYHwBZz9bencboFqVVBst3GblKFhPFm8Xfg== X-Received: by 2002:a17:90b:1942:b0:219:42d8:bd3a with SMTP id nk2-20020a17090b194200b0021942d8bd3amr5024132pjb.177.1669689574584; Mon, 28 Nov 2022 18:39:34 -0800 (PST) Received: from localhost ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id p7-20020a170902780700b00174c1855cd9sm9408683pll.267.2022.11.28.18.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 18:39:34 -0800 (PST) Date: Mon, 28 Nov 2022 18:39:34 -0800 (PST) X-Google-Original-Date: Mon, 28 Nov 2022 18:39:26 PST (-0800) Subject: Re: [REVIEW ONLY 2/2] TEST: Add instantiation script on CSR allocation In-Reply-To: <01990896-e81c-be50-85df-0dbf1bb9732b@irq.a4lg.com> CC: binutils@sourceware.org From: Palmer Dabbelt To: research_trasio@irq.a4lg.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Mon, 28 Nov 2022 18:32:05 PST (-0800), research_trasio@irq.a4lg.com wrote: > On 2022/11/29 11:22, Palmer Dabbelt wrote: >> On Mon, 28 Nov 2022 17:20:58 PST (-0800), binutils@sourceware.org wrote: >>> From: Tsukasa OI >>> >>> --- >>>  instantiate-sspmp.sh | 130 +++++++++++++++++++++++++++++++++++++++++++ >>>  1 file changed, 130 insertions(+) >>>  create mode 100755 instantiate-sspmp.sh >> >> It's not clear to me what you're trying to do here. > > It will not be a part of GNU Binutils. > > Because 'Sspmp' CSRs don't have CSR numbers assigned, I assigned numbers > in the "custom" CSR range. Once we determined the real number, we can > replace all related files in GNU Binutils just by running this script. > > e.g. > ./instantiate-sspmp.sh 0x1a0 0x1b0 0x1f0 0x1f1 > if real CSR numbers are assigned as follows: > - (hypothetical) spmpcfg0 == 0x1a0 > - (hypothetical) spmpaddr0 == 0x1b0 > - (hypothetical) spmpswitch0 == 0x1f0 > - (hypothetical) spmpswitch1 == 0x1f1 > > If someone tests this extension, it's possible that they assign their > CSR numbers. I attached this script for this reason. It also applies > to 'Zisslpcfi' and (not yet submitted) 'Zjpm' extension proposals. OK, that makes sense. Maybe just include in the commit message that it's for example only? > > Thanks, > Tsukasa > >> >>> >>> diff --git a/instantiate-sspmp.sh b/instantiate-sspmp.sh >>> new file mode 100755 >>> index 000000000000..23b6a2f554e6 >>> --- /dev/null >>> +++ b/instantiate-sspmp.sh >>> @@ -0,0 +1,130 @@ >>> +#! /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 >>> +} >>> + >>> +if test $# -ne 4 >>> +then >>> +    ERRMSG="usage: $0 ADDR_SPMPCFG0 ADDR_SPMPADDR0 ADDR_SPMPSWITCH0 >>> ADDR_SPMPSWITCH1" >>> +    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 >>> +} >>> + >>> +ADDR=$(check_csr_addr "$1" spmpcfg0) >>> +NADDR=$((0x$ADDR)) >>> +for N in $(seq 0 15) >>> +do >>> +    ADDR_N=$(printf %03x $(($NADDR + $N))) >>> +    do_csr_instantiation spmpcfg$N $ADDR_N >>> +done >>> + >>> +ADDR=$(check_csr_addr "$2" spmpaddr0) >>> +NADDR=$((0x$ADDR)) >>> +for N in $(seq 0 63) >>> +do >>> +    ADDR_N=$(printf %03x $(($NADDR + $N))) >>> +    do_csr_instantiation spmpaddr$N $ADDR_N >>> +done >>> + >>> +do_csr_instantiation spmpswitch0 "$3" >>> +do_csr_instantiation spmpswitch1 "$4" >>> + >>> +if test -f "$0" >>> +then >>> +    rm -f "$0" >>> +fi >>> +exit 0 >>