[0/4] RISC-V: Support more rigorous check for CSR, and update them to spec 1.12.

Message ID 1574667612-17925-1-git-send-email-nelson.chu@sifive.com
Headers show
Series
  • RISC-V: Support more rigorous check for CSR, and update them to spec 1.12.
Related show

Message

Nelson Chu Nov. 25, 2019, 7:40 a.m.
According to the riscv privilege spec, CSR have some restrictions when we use
them.  Some of CSR are only valid when the specific extension is set.  Some of
CSR are read-only CSR, and we have no write access for them.  These for patches
are used to support more rigorous check for CSR, and the currently supported
checks are shown as follows:

* The ISA-dependent CSR checking
  - The CSR are only valid when the f extension is set.
  - The CSR are only valid for the rv32.

* The read-only CSR checking
  - CSRRW and CSRRWI always write CSR.  CSRRS, CSRRC, CSRRSI and CSRRCI write
    CSR when RS1 isn't zero.  We can not write the read-ony CSR by these CSR
    instructions.

For now, consider the CSR checking will cause some backwards incompatibilities,
we disable the CSR checking by default, and support two new .options
(.option csrcheck/nocsrcheck) and two new GAS options (-mcsrcheck/-mno-csrcheck)
to enbale/disable CSR checking if user need.

The previous patches are a lot hard to read, so I re-send them by the
git-send-email again.  These four patches are almost same as the previous
version.  But there are two places that are different.  One is that I remove
the redundant source files of testsuite in the second patch (priv-reg-fail-fext.s
and priv-reg-fail-rv32-only.s), and add one new testsuite for the CSR read-only
checking in the third patch (priv-reg-fail-readonly-01).  Another is that the
previous third patch has an error in the riscv_csr_read_only_check (readonly).
I have fixed it in the newest patch.

Thanks and regards
Nelson

Comments

Cui, Lili via Binutils Dec. 2, 2019, 11:16 p.m. | #1
On Sun, 24 Nov 2019 23:40:08 PST (-0800), nelson.chu@sifive.com wrote:
>

> According to the riscv privilege spec, CSR have some restrictions when we use

> them.  Some of CSR are only valid when the specific extension is set.  Some of

> CSR are read-only CSR, and we have no write access for them.  These for patches

> are used to support more rigorous check for CSR, and the currently supported

> checks are shown as follows:

>

> * The ISA-dependent CSR checking

>   - The CSR are only valid when the f extension is set.

>   - The CSR are only valid for the rv32.

>

> * The read-only CSR checking

>   - CSRRW and CSRRWI always write CSR.  CSRRS, CSRRC, CSRRSI and CSRRCI write

>     CSR when RS1 isn't zero.  We can not write the read-ony CSR by these CSR

>     instructions.

>

> For now, consider the CSR checking will cause some backwards incompatibilities,

> we disable the CSR checking by default, and support two new .options

> (.option csrcheck/nocsrcheck) and two new GAS options (-mcsrcheck/-mno-csrcheck)

> to enbale/disable CSR checking if user need.

>

> The previous patches are a lot hard to read, so I re-send them by the

> git-send-email again.  These four patches are almost same as the previous

> version.  But there are two places that are different.  One is that I remove

> the redundant source files of testsuite in the second patch (priv-reg-fail-fext.s

> and priv-reg-fail-rv32-only.s), and add one new testsuite for the CSR read-only

> checking in the third patch (priv-reg-fail-readonly-01).  Another is that the

> previous third patch has an error in the riscv_csr_read_only_check (readonly).

> I have fixed it in the newest patch.


Looks like this has a conflict with the recent GDB changes to allow CSRs in
debug info and the patch set no longer applies.  Do you mind re-spinning it?
Nelson Chu Dec. 2, 2019, 11:36 p.m. | #2
Ok, I will fix this ASAP :)

從我的iPhone傳送

> Palmer Dabbelt <palmerdabbelt@google.com> 於 2019年12月3日 上午7:16 寫道:

> 

> On Sun, 24 Nov 2019 23:40:08 PST (-0800), nelson.chu@sifive.com wrote:

>> 

>> According to the riscv privilege spec, CSR have some restrictions when we use

>> them.  Some of CSR are only valid when the specific extension is set.  Some of

>> CSR are read-only CSR, and we have no write access for them.  These for patches

>> are used to support more rigorous check for CSR, and the currently supported

>> checks are shown as follows:

>> 

>> * The ISA-dependent CSR checking

>>  - The CSR are only valid when the f extension is set.

>>  - The CSR are only valid for the rv32.

>> 

>> * The read-only CSR checking

>>  - CSRRW and CSRRWI always write CSR.  CSRRS, CSRRC, CSRRSI and CSRRCI write

>>    CSR when RS1 isn't zero.  We can not write the read-ony CSR by these CSR

>>    instructions.

>> 

>> For now, consider the CSR checking will cause some backwards incompatibilities,

>> we disable the CSR checking by default, and support two new .options

>> (.option csrcheck/nocsrcheck) and two new GAS options (-mcsrcheck/-mno-csrcheck)

>> to enbale/disable CSR checking if user need.

>> 

>> The previous patches are a lot hard to read, so I re-send them by the

>> git-send-email again.  These four patches are almost same as the previous

>> version.  But there are two places that are different.  One is that I remove

>> the redundant source files of testsuite in the second patch (priv-reg-fail-fext.s

>> and priv-reg-fail-rv32-only.s), and add one new testsuite for the CSR read-only

>> checking in the third patch (priv-reg-fail-readonly-01).  Another is that the

>> previous third patch has an error in the riscv_csr_read_only_check (readonly).

>> I have fixed it in the newest patch.

> 

> Looks like this has a conflict with the recent GDB changes to allow CSRs in

> debug info and the patch set no longer applies.  Do you mind re-spinning it?
Nelson Chu Dec. 3, 2019, 7:38 a.m. | #3
Dear binutils,

I update the serious of patches for the CSR checking since the recent GDB
changes.  Please see the details as follows:

* [PATCH v2 1/4] RISC-V: Update the CSR to privilege spec 1.12.
Upadte the testsuite/gas/riscv/csr-dw-regnums since the CSR are updated.

* [PATCH v2 2/4] RISC-V: Support the ISA-dependent CSR checking.
Upadte the binutils/dwarf.c since the DECLARE_CSR is changed.

* [PATCH v2 3/4] RISC-V: Support the read-only CSR checking.
Same as the previous one.

* [PATCH v2 4/4] RISC-V: Disable the CSR checking by default.
Same as the previous one.


Thanks and Regards
Nelson