Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft Extension: Ssqosid #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bfd/elfxx-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 },
Expand Down
4 changes: 4 additions & 0 deletions gas/config/tc-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions gas/testsuite/gas/riscv/csr-dw-regnums.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gas/testsuite/gas/riscv/csr-dw-regnums.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gas/testsuite/gas/riscv/csr-version-1p10.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gas/testsuite/gas/riscv/csr-version-1p10.l
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gas/testsuite/gas/riscv/csr-version-1p11.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gas/testsuite/gas/riscv/csr-version-1p11.l
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gas/testsuite/gas/riscv/csr-version-1p12.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gas/testsuite/gas/riscv/csr-version-1p12.l
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gas/testsuite/gas/riscv/csr-version-1p9p1.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gas/testsuite/gas/riscv/csr-version-1p9p1.l
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions gas/testsuite/gas/riscv/csr.s
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@
csr mhpmevent30h
csr mhpmevent31h

# Ssqosid extension
csr sqoscfg

# Sstc extension
csr stimecmp
csr stimecmph
Expand Down
4 changes: 4 additions & 0 deletions include/opcode/riscv-opc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
126 changes: 126 additions & 0 deletions instantiate-ssqosid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#! /bin/bash
# SPDX-License-Identifier: CC0-1.0
# Author: Tsukasa OI <[email protected]>
# 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