From b7e1c8f5ab24645b8ace4c6be4bbf56b6bc6c009 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sun, 11 Sep 2022 13:00:35 +0000 Subject: [PATCH 1/2] UNRATIFIED RISC-V: Add 'Ssqosid' extension and its TENTATIVE CSRs [DO NOT MERGE] Until the 'Ssqosid' extension is frozen/ratified and the final version number is determined, this patch should not be merged upstream. This commit uses version 0.1 as the placeholder, not version 0.0.0 in the latest PDF documentation (since 0.0 is invalid). This commit adds QoS registration interface for S-mode ('Ssqosid' extension) support based on the specification: ***Draft Note*** Because CSR addresse is not fixed yet, this commit uses tentative addresse (a part of custom CSR space). bfd/ChangeLog: * elfxx-riscv.c (riscv_implicit_subsets): Add implications to 'Zicsr'. (riscv_supported_std_s_ext): Add 'Ssqosid' extension to valid 'S' extension list. gas/ChangeLog: * config/tc-riscv.c (enum riscv_csr_class): Add CSR class for the 'Ssqosid' extension. (riscv_csr_address): Add handling for new CSR class. * testsuite/gas/riscv/csr-dw-regnums.d: Add new CSR. * testsuite/gas/riscv/csr-dw-regnums.s: Likewise. * testsuite/gas/riscv/csr.s: Add new CSR. * testsuite/gas/riscv/csr-version-1p9p1.d: Likewise. * testsuite/gas/riscv/csr-version-1p9p1.l: Likewise. * testsuite/gas/riscv/csr-version-1p10.d: Likewise. * testsuite/gas/riscv/csr-version-1p10.l: Likewise. * testsuite/gas/riscv/csr-version-1p11.d: Likewise. * testsuite/gas/riscv/csr-version-1p11.l: Likewise. * testsuite/gas/riscv/csr-version-1p12.d: Likewise. * testsuite/gas/riscv/csr-version-1p12.l: Likewise. include/ChangeLog: * opcode/riscv-opc.h (CSR_SQOSCFG): New. --- bfd/elfxx-riscv.c | 2 ++ gas/config/tc-riscv.c | 4 ++++ gas/testsuite/gas/riscv/csr-dw-regnums.d | 1 + gas/testsuite/gas/riscv/csr-dw-regnums.s | 2 ++ gas/testsuite/gas/riscv/csr-version-1p10.d | 2 ++ gas/testsuite/gas/riscv/csr-version-1p10.l | 4 ++++ gas/testsuite/gas/riscv/csr-version-1p11.d | 2 ++ gas/testsuite/gas/riscv/csr-version-1p11.l | 4 ++++ gas/testsuite/gas/riscv/csr-version-1p12.d | 2 ++ gas/testsuite/gas/riscv/csr-version-1p12.l | 4 ++++ gas/testsuite/gas/riscv/csr-version-1p9p1.d | 2 ++ gas/testsuite/gas/riscv/csr-version-1p9p1.l | 4 ++++ gas/testsuite/gas/riscv/csr.s | 3 +++ include/opcode/riscv-opc.h | 4 ++++ 14 files changed, 40 insertions(+) diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index c070394a366..adbfb3de685 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -1188,6 +1188,7 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] = {"smepmp", "zicsr", check_implicit_always}, {"ssaia", "zicsr", check_implicit_always}, {"sscofpmf", "zicsr", check_implicit_always}, + {"ssqosid", "zicsr", check_implicit_always}, {"ssstateen", "zicsr", check_implicit_always}, {"sstc", "zicsr", check_implicit_always}, {"svadu", "zicsr", check_implicit_always}, @@ -1335,6 +1336,7 @@ static struct riscv_supported_ext riscv_supported_std_s_ext[] = {"smstateen", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"ssaia", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"sscofpmf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"ssqosid", ISA_SPEC_CLASS_DRAFT, 0, 1, 0 }, {"ssstateen", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"sstc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"svadu", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 5759d3a5fc4..456aad7e61a 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -82,6 +82,7 @@ enum riscv_csr_class CSR_CLASS_SSAIA_AND_H, /* Ssaia with H */ CSR_CLASS_SSAIA_32, /* Ssaia, rv32 only */ CSR_CLASS_SSAIA_AND_H_32, /* Ssaia with H, rv32 only */ + CSR_CLASS_SSQOSID, /* Ssqosid */ CSR_CLASS_SSSTATEEN, /* S[ms]stateen only */ CSR_CLASS_SSSTATEEN_AND_H, /* S[ms]stateen only (with H) */ CSR_CLASS_SSSTATEEN_AND_H_32, /* S[ms]stateen RV32 only (with H) */ @@ -1077,6 +1078,9 @@ riscv_csr_address (const char *csr_name, || csr_class == CSR_CLASS_SSAIA_AND_H_32); extension = "ssaia"; break; + case CSR_CLASS_SSQOSID: + extension = "ssqosid"; + break; case CSR_CLASS_SSSTATEEN_AND_H_32: is_rv32_only = true; /* Fall through. */ diff --git a/gas/testsuite/gas/riscv/csr-dw-regnums.d b/gas/testsuite/gas/riscv/csr-dw-regnums.d index cabb7c71918..fb98931e0a1 100644 --- a/gas/testsuite/gas/riscv/csr-dw-regnums.d +++ b/gas/testsuite/gas/riscv/csr-dw-regnums.d @@ -399,6 +399,7 @@ Contents of the .* section: DW_CFA_offset_extended_sf: r5949 \(mhpmevent29h\) at cfa\+7412 DW_CFA_offset_extended_sf: r5950 \(mhpmevent30h\) at cfa\+7416 DW_CFA_offset_extended_sf: r5951 \(mhpmevent31h\) at cfa\+7420 + DW_CFA_offset_extended_sf: r5568 \(sqoscfg\) at cfa\+5888 DW_CFA_offset_extended_sf: r4429 \(stimecmp\) at cfa\+1332 DW_CFA_offset_extended_sf: r4445 \(stimecmph\) at cfa\+1396 DW_CFA_offset_extended_sf: r4685 \(vstimecmp\) at cfa\+2356 diff --git a/gas/testsuite/gas/riscv/csr-dw-regnums.s b/gas/testsuite/gas/riscv/csr-dw-regnums.s index 428d0770779..ab35bb3ea09 100644 --- a/gas/testsuite/gas/riscv/csr-dw-regnums.s +++ b/gas/testsuite/gas/riscv/csr-dw-regnums.s @@ -400,6 +400,8 @@ _start: .cfi_offset mhpmevent29h, 7412 .cfi_offset mhpmevent30h, 7416 .cfi_offset mhpmevent31h, 7420 + # Ssqosid extension + .cfi_offset sqoscfg, 5888 # Sstc extension .cfi_offset stimecmp, 1332 .cfi_offset stimecmph, 1396 diff --git a/gas/testsuite/gas/riscv/csr-version-1p10.d b/gas/testsuite/gas/riscv/csr-version-1p10.d index dbdc077adac..707c4bbf0ec 100644 --- a/gas/testsuite/gas/riscv/csr-version-1p10.d +++ b/gas/testsuite/gas/riscv/csr-version-1p10.d @@ -773,6 +773,8 @@ Disassembly of section .text: [ ]+[0-9a-f]+:[ ]+73e59073[ ]+csrw[ ]+mhpmevent30h,a1 [ ]+[0-9a-f]+:[ ]+73f02573[ ]+csrr[ ]+a0,mhpmevent31h [ ]+[0-9a-f]+:[ ]+73f59073[ ]+csrw[ ]+mhpmevent31h,a1 +[ ]+[0-9a-f]+:[ ]+5c002573[ ]+csrr[ ]+a0,sqoscfg +[ ]+[0-9a-f]+:[ ]+5c059073[ ]+csrw[ ]+sqoscfg,a1 [ ]+[0-9a-f]+:[ ]+14d02573[ ]+csrr[ ]+a0,stimecmp [ ]+[0-9a-f]+:[ ]+14d59073[ ]+csrw[ ]+stimecmp,a1 [ ]+[0-9a-f]+:[ ]+15d02573[ ]+csrr[ ]+a0,stimecmph diff --git a/gas/testsuite/gas/riscv/csr-version-1p10.l b/gas/testsuite/gas/riscv/csr-version-1p10.l index 054179a416d..f166024b0d5 100644 --- a/gas/testsuite/gas/riscv/csr-version-1p10.l +++ b/gas/testsuite/gas/riscv/csr-version-1p10.l @@ -1479,6 +1479,10 @@ .*Info: macro .* .*Warning: invalid CSR `mhpmevent31h', needs `sscofpmf' extension .*Info: macro .* +.*Warning: invalid CSR `sqoscfg', needs `ssqosid' extension +.*Info: macro .* +.*Warning: invalid CSR `sqoscfg', needs `ssqosid' extension +.*Info: macro .* .*Warning: invalid CSR `stimecmp', needs `sstc' extension .*Info: macro .* .*Warning: invalid CSR `stimecmp', needs `sstc' extension diff --git a/gas/testsuite/gas/riscv/csr-version-1p11.d b/gas/testsuite/gas/riscv/csr-version-1p11.d index 7ba88b6d1d5..1519aed1eee 100644 --- a/gas/testsuite/gas/riscv/csr-version-1p11.d +++ b/gas/testsuite/gas/riscv/csr-version-1p11.d @@ -773,6 +773,8 @@ Disassembly of section .text: [ ]+[0-9a-f]+:[ ]+73e59073[ ]+csrw[ ]+mhpmevent30h,a1 [ ]+[0-9a-f]+:[ ]+73f02573[ ]+csrr[ ]+a0,mhpmevent31h [ ]+[0-9a-f]+:[ ]+73f59073[ ]+csrw[ ]+mhpmevent31h,a1 +[ ]+[0-9a-f]+:[ ]+5c002573[ ]+csrr[ ]+a0,sqoscfg +[ ]+[0-9a-f]+:[ ]+5c059073[ ]+csrw[ ]+sqoscfg,a1 [ ]+[0-9a-f]+:[ ]+14d02573[ ]+csrr[ ]+a0,stimecmp [ ]+[0-9a-f]+:[ ]+14d59073[ ]+csrw[ ]+stimecmp,a1 [ ]+[0-9a-f]+:[ ]+15d02573[ ]+csrr[ ]+a0,stimecmph diff --git a/gas/testsuite/gas/riscv/csr-version-1p11.l b/gas/testsuite/gas/riscv/csr-version-1p11.l index cc365f1df41..95ef602557d 100644 --- a/gas/testsuite/gas/riscv/csr-version-1p11.l +++ b/gas/testsuite/gas/riscv/csr-version-1p11.l @@ -1475,6 +1475,10 @@ .*Info: macro .* .*Warning: invalid CSR `mhpmevent31h', needs `sscofpmf' extension .*Info: macro .* +.*Warning: invalid CSR `sqoscfg', needs `ssqosid' extension +.*Info: macro .* +.*Warning: invalid CSR `sqoscfg', needs `ssqosid' extension +.*Info: macro .* .*Warning: invalid CSR `stimecmp', needs `sstc' extension .*Info: macro .* .*Warning: invalid CSR `stimecmp', needs `sstc' extension diff --git a/gas/testsuite/gas/riscv/csr-version-1p12.d b/gas/testsuite/gas/riscv/csr-version-1p12.d index 677820b9526..45b373ce6d4 100644 --- a/gas/testsuite/gas/riscv/csr-version-1p12.d +++ b/gas/testsuite/gas/riscv/csr-version-1p12.d @@ -773,6 +773,8 @@ Disassembly of section .text: [ ]+[0-9a-f]+:[ ]+73e59073[ ]+csrw[ ]+mhpmevent30h,a1 [ ]+[0-9a-f]+:[ ]+73f02573[ ]+csrr[ ]+a0,mhpmevent31h [ ]+[0-9a-f]+:[ ]+73f59073[ ]+csrw[ ]+mhpmevent31h,a1 +[ ]+[0-9a-f]+:[ ]+5c002573[ ]+csrr[ ]+a0,sqoscfg +[ ]+[0-9a-f]+:[ ]+5c059073[ ]+csrw[ ]+sqoscfg,a1 [ ]+[0-9a-f]+:[ ]+14d02573[ ]+csrr[ ]+a0,stimecmp [ ]+[0-9a-f]+:[ ]+14d59073[ ]+csrw[ ]+stimecmp,a1 [ ]+[0-9a-f]+:[ ]+15d02573[ ]+csrr[ ]+a0,stimecmph diff --git a/gas/testsuite/gas/riscv/csr-version-1p12.l b/gas/testsuite/gas/riscv/csr-version-1p12.l index 7a7f5f717c5..4b0937d6726 100644 --- a/gas/testsuite/gas/riscv/csr-version-1p12.l +++ b/gas/testsuite/gas/riscv/csr-version-1p12.l @@ -1199,6 +1199,10 @@ .*Info: macro .* .*Warning: invalid CSR `mhpmevent31h', needs `sscofpmf' extension .*Info: macro .* +.*Warning: invalid CSR `sqoscfg', needs `ssqosid' extension +.*Info: macro .* +.*Warning: invalid CSR `sqoscfg', needs `ssqosid' extension +.*Info: macro .* .*Warning: invalid CSR `stimecmp', needs `sstc' extension .*Info: macro .* .*Warning: invalid CSR `stimecmp', needs `sstc' extension diff --git a/gas/testsuite/gas/riscv/csr-version-1p9p1.d b/gas/testsuite/gas/riscv/csr-version-1p9p1.d index f4d2b04ca6a..eb46e3cddb0 100644 --- a/gas/testsuite/gas/riscv/csr-version-1p9p1.d +++ b/gas/testsuite/gas/riscv/csr-version-1p9p1.d @@ -773,6 +773,8 @@ Disassembly of section .text: [ ]+[0-9a-f]+:[ ]+73e59073[ ]+csrw[ ]+mhpmevent30h,a1 [ ]+[0-9a-f]+:[ ]+73f02573[ ]+csrr[ ]+a0,mhpmevent31h [ ]+[0-9a-f]+:[ ]+73f59073[ ]+csrw[ ]+mhpmevent31h,a1 +[ ]+[0-9a-f]+:[ ]+5c002573[ ]+csrr[ ]+a0,sqoscfg +[ ]+[0-9a-f]+:[ ]+5c059073[ ]+csrw[ ]+sqoscfg,a1 [ ]+[0-9a-f]+:[ ]+14d02573[ ]+csrr[ ]+a0,stimecmp [ ]+[0-9a-f]+:[ ]+14d59073[ ]+csrw[ ]+stimecmp,a1 [ ]+[0-9a-f]+:[ ]+15d02573[ ]+csrr[ ]+a0,stimecmph diff --git a/gas/testsuite/gas/riscv/csr-version-1p9p1.l b/gas/testsuite/gas/riscv/csr-version-1p9p1.l index 7fcd73ab7dd..767220827b2 100644 --- a/gas/testsuite/gas/riscv/csr-version-1p9p1.l +++ b/gas/testsuite/gas/riscv/csr-version-1p9p1.l @@ -1595,6 +1595,10 @@ .*Info: macro .* .*Warning: invalid CSR `mhpmevent31h', needs `sscofpmf' extension .*Info: macro .* +.*Warning: invalid CSR `sqoscfg', needs `ssqosid' extension +.*Info: macro .* +.*Warning: invalid CSR `sqoscfg', needs `ssqosid' extension +.*Info: macro .* .*Warning: invalid CSR `stimecmp', needs `sstc' extension .*Info: macro .* .*Warning: invalid CSR `stimecmp', needs `sstc' extension diff --git a/gas/testsuite/gas/riscv/csr.s b/gas/testsuite/gas/riscv/csr.s index 3d8da5488a0..0f9ef17f72c 100644 --- a/gas/testsuite/gas/riscv/csr.s +++ b/gas/testsuite/gas/riscv/csr.s @@ -433,6 +433,9 @@ csr mhpmevent30h csr mhpmevent31h + # Ssqosid extension + csr sqoscfg + # Sstc extension csr stimecmp csr stimecmph diff --git a/include/opcode/riscv-opc.h b/include/opcode/riscv-opc.h index 375483500e2..8b94be6460f 100644 --- a/include/opcode/riscv-opc.h +++ b/include/opcode/riscv-opc.h @@ -2957,6 +2957,8 @@ #define CSR_MHPMEVENT29H 0x73d #define CSR_MHPMEVENT30H 0x73e #define CSR_MHPMEVENT31H 0x73f +/* Ssqosid extension. */ +#define CSR_SQOSCFG 0x5c0 /* TENTATIVELY use custom CSR address. */ /* Sstc extension */ #define CSR_STIMECMP 0x14d #define CSR_STIMECMPH 0x15d @@ -3948,6 +3950,8 @@ DECLARE_CSR(mhpmevent28h, CSR_MHPMEVENT28H, CSR_CLASS_SSCOFPMF_32, PRIV_SPEC_CLA DECLARE_CSR(mhpmevent29h, CSR_MHPMEVENT29H, CSR_CLASS_SSCOFPMF_32, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) DECLARE_CSR(mhpmevent30h, CSR_MHPMEVENT30H, CSR_CLASS_SSCOFPMF_32, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) DECLARE_CSR(mhpmevent31h, CSR_MHPMEVENT31H, CSR_CLASS_SSCOFPMF_32, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) +/* Ssqosid extension. */ +DECLARE_CSR(sqoscfg, CSR_SQOSCFG, CSR_CLASS_SSQOSID, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) /* Sstc extension */ DECLARE_CSR(stimecmp, CSR_STIMECMP, CSR_CLASS_SSTC, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) DECLARE_CSR(stimecmph, CSR_STIMECMPH, CSR_CLASS_SSTC_32, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) From 628b1b67384246f09b1aa8eff140d3bfef734f08 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Tue, 25 Oct 2022 09:08:09 +0000 Subject: [PATCH 2/2] TEST: Add instantiation script on CSR allocation **DEVELOPMENT ENVIRONMENT ONLY** The attached script can be used to replace related source files when the CSR addresse of "sqoscfg" (now tentative) is determined. Usage (when "sqoscfg" is allocated to 0x5ad): ./instantiate-ssqosid.sh 0x5ad --- instantiate-ssqosid.sh | 126 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 instantiate-ssqosid.sh diff --git a/instantiate-ssqosid.sh b/instantiate-ssqosid.sh new file mode 100755 index 00000000000..b90f3ebdbcc --- /dev/null +++ b/instantiate-ssqosid.sh @@ -0,0 +1,126 @@ +#! /bin/bash +# SPDX-License-Identifier: CC0-1.0 +# Author: Tsukasa OI +# Year: 2023 + +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=( + sqoscfg +) + +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