RISC-V: Support the read-only CSR checking.
authorNelson Chu <nelson.chu@sifive.com>
Wed, 12 Feb 2020 10:18:51 +0000 (02:18 -0800)
committerJim Wilson <jimw@sifive.com>
Fri, 21 Feb 2020 00:49:09 +0000 (16:49 -0800)
commit54b2aec10df9ad032184c556ec9cc3f611a91830
treeb8a42a4500cd3a7faf247ab0ef07789ab2b4628f
parent2ca89224b1ce2cf170bb891b211bede4f6eda473
RISC-V: Support the read-only CSR checking.

CSRRW and CSRRWI always write CSR.  CSRRS, CSRRC, CSRRSI and CSRRCI write CSR
when RS1 isn't zero.  The CSR is read only if the [11:10] bits of CSR address
is 0x3.  The read-only CSR can not be written by the CSR instructions.

gas/
* config/tc-riscv.c (riscv_ip): New boolean insn_with_csr to indicate
we are assembling instruction with CSR.  Call riscv_csr_read_only_check
after parsing all arguments.
(enum csr_insn_type): New enum is used to classify the CSR instruction.
(riscv_csr_insn_type, riscv_csr_read_only_check): New functions.  These
are used to check if we write a read-only CSR by the CSR instruction.

* testsuite/gas/riscv/priv-reg-fail-read-only-01.s: New testcase.  Test
all CSR for the read-only CSR checking.
* testsuite/gas/riscv/priv-reg-fail-read-only-01.d: Likewise.
* testsuite/gas/riscv/priv-reg-fail-read-only-01.l: Likewise.
* testsuite/gas/riscv/priv-reg-fail-read-only-02.s: New testcase.  Test
all CSR instructions for the read-only CSR checking.
* testsuite/gas/riscv/priv-reg-fail-read-only-02.d: Likewise.
* testsuite/gas/riscv/priv-reg-fail-read-only-02.l: Likewise.
gas/ChangeLog
gas/config/tc-riscv.c
gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.d [new file with mode: 0644]
gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.l [new file with mode: 0644]
gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.s [new file with mode: 0644]
gas/testsuite/gas/riscv/priv-reg-fail-read-only-02.d [new file with mode: 0644]
gas/testsuite/gas/riscv/priv-reg-fail-read-only-02.l [new file with mode: 0644]
gas/testsuite/gas/riscv/priv-reg-fail-read-only-02.s [new file with mode: 0644]