Skip to content

Commit

Permalink
RISC-V: Imply 'Zicsr' from privileged extensions with CSRs
Browse files Browse the repository at this point in the history
'H', 'Smstateen', 'Sscofpmf' and 'Sstc' are four privileged extensions with
their CSR definitions and 'Smepmp' is a privileged extension with additional
CSR bits.

Volume II: Privileged Architecture of the RISC-V ISA Manual states that the
privileged architecture requires the 'Zicsr' extension.  However, current
GNU Binutils has no direct way whether the program has dependency to the
privileged architecture itself.

As a workaround, we should add implications from privileged extensions that
either add new CSRs, extend existing CSRs or depends on using CSRs.

This commit adds such implications for existing privileged extensions that
satisfy this condition.

gas/ChangeLog:

	* testsuite/gas/riscv/march-imply-h.d: New test, at least for 'H'.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_implicit_subsets): Add 'Zicsr'
	implicications for privileged extensions 'H', 'Smstateen',
	'Sscofpmf', 'Sstc' and 'Smepmp'.
  • Loading branch information
a4lg committed Oct 13, 2022
1 parent 927b2f4 commit 48fc7da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bfd/elfxx-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
{"g", "zicsr", check_implicit_always},
{"g", "zifencei", check_implicit_always},
{"m", "zmmul", check_implicit_always},
{"h", "zicsr", check_implicit_always},
{"q", "d", check_implicit_always},
{"v", "d", check_implicit_always},
{"v", "zve64d", check_implicit_always},
Expand Down Expand Up @@ -1096,6 +1097,10 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
{"zks", "zbkx", check_implicit_always},
{"zks", "zksed", check_implicit_always},
{"zks", "zksh", check_implicit_always},
{"smepmp", "zicsr", check_implicit_always},
{"smstateen", "zicsr", check_implicit_always},
{"sscofpmf", "zicsr", check_implicit_always},
{"sstc", "zicsr", check_implicit_always},
{NULL, NULL, NULL}
};

Expand Down
6 changes: 6 additions & 0 deletions gas/testsuite/gas/riscv/march-imply-h.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#as: -march=rv32ih -march-attr -misa-spec=20191213 -mpriv-spec=1.12
#readelf: -A
#source: empty.s
Attribute Section: riscv
File Attributes
Tag_RISCV_arch: "rv32i2p1_h1p0_zicsr2p0"

0 comments on commit 48fc7da

Please sign in to comment.