AdaCore / Ada_Drivers_Library

Ada source code and complete sample GNAT projects for selected bare-board platforms supported by GNAT.
BSD 3-Clause "New" or "Revised" License
236 stars 141 forks source link

RISC-V requires "zicsr" ISA extension to build with FSF GNAT 12.1.1 #411

Closed rod-chapman closed 1 year ago

rod-chapman commented 2 years ago

A recent change in GNU binutils (see https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/aE1ZeHHCYf4) means that the RISC-V "performance counter" registers are now in a specific ISA extension called "zicsr". This change is shipping with the FSF GNAT 12.1.1 in Alire, so the build of Ada_Drivers_Library for the HiFive_revb (for example) fails. The project files needs to be updated to select "-march=rv32imac_zicsr" for all units, or (more generally) to add "_zicsr" to the end of the "-march" option for units that require the CSRR instructions.

rod-chapman commented 2 years ago

It may also be possible to directly insert an assembler directive in the generated code for the packages that require the CSRR and CSRW instructions. I think you need to add .option arch,+zicsr

near the top of the generated .s file. Can this be done with package Machine_Code?

Details in the RISC-V specific section of the most recent GNU as manual.

rod-chapman commented 2 years ago

For reference, my local changes to SPARKNaCl to get GNAT 12.1.1 working are here: https://github.com/rod-chapman/SPARKNaCl/pull/28

Fabien-Chouteau commented 2 years ago

.option arch,+zicsr in inlined machine code would be the best option in my opinion. Did you try it?

rod-chapman commented 2 years ago

Yes... but I couldn't work out the exact syntax required...

See https://sourceware.org/binutils/docs/as/RISC_002dV_002dDirectives.html#RISC_002dV_002dDirectives

Fabien-Chouteau commented 2 years ago

Might be because we don't have the latest binutils: https://github.com/enjoy-digital/litex/commit/91d79ae1daec8ca46a2d359bed37cfe5176f29d9

I will build a toolchain with the latest and try again.

Fabien-Chouteau commented 2 years ago

Confirmed, I started build for a new release of the toolchains with binutils 2.38.

rod-chapman commented 2 years ago

OK... let me know when it's ready (and how to get it) and I will give it a try...

rod-chapman commented 2 years ago

Reading the ISA spec more carefully, I think you actually should generate

.option push .option arch,+zicsr # do stuff with CSRs or whatever... .option pop

so that the existing state of the "arch" setting is saved and restored properly.

rod-chapman commented 1 year ago

The SPARKNaCl performance test program now seems to build OK with the new GNAT 12.1.2 with no modification to the assembly language component(s), so looking good.

Fabien-Chouteau commented 1 year ago

Without the .option arch,+zicsr?

Thanks for the update,

rod-chapman commented 1 year ago

Yes... my sources (see SPARKNaCl/perf/csrs.s) are unmodified and it builds OK...