All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni via buildroot <buildroot@buildroot.org>
To: Romain Naour <romain.naour@gmail.com>
Cc: Mark Corbin <mark@dibsco.co.uk>, buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH for-next 01/11] arch/Config.in.riscv: add Zicsr and Zifencei standalone extensions
Date: Sat, 23 Jul 2022 14:39:21 +0200	[thread overview]
Message-ID: <20220723143921.1e89b49f@windsurf> (raw)
In-Reply-To: <20220529131811.481017-1-romain.naour@gmail.com>

Hello Romain,

On Sun, 29 May 2022 15:18:01 +0200
Romain Naour <romain.naour@gmail.com> wrote:

> Since gcc 12, default Riscv ISA spec version was bump to 20191213 [1].
> 
> This introduce a major incompatibility issue is the csr read/write
> (csrr*/csrw*) instructions and fence.i instruction has separated from
> the "I" extension, become two standalone extensions: Zicsr and
> Zifencei; so you might get error messages like that: unrecognized
> opcode "csrr" (or "fence.i").
> 
> Indeed, without Zifencei we can't build opensbi bootloader [3]:
> 
> opensbi-1.0/lib/sbi/sbi_tlb.c: Assembler messages:
> opensbi-1.0/lib/sbi/sbi_tlb.c:190: Error: unrecognized opcode `fence.i', extension `zifencei' required
> 
> As a workaround, opensbi build system has been patched [4] to use
> -march=rv64imafdc_zicsr_zifencei when needed.
> This workaround doesn't work in Buildroot due to the local patch
> 0001-Makefile-Don-t-specify-mabi-or-march.patch removing -march
> from CFLAGS.
> 
> Fix this issue by introducing two additional Kconfig option
> enabling Zicsr and Zifencei standalone extensions for gcc >= 12
> as recommanded by [2].
> 
> Select Zicsr and Zifencei for General purpose (G) architecture variant
> (BR2_riscv_g) since theses extentions were implicitely enabled
> previously.
> 
> [1] https://gcc.gnu.org/gcc-12/changes.html
> [2] https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/aE1ZeHHCYf4
> [3] https://github.com/riscv-software-src/opensbi/blob/v0.9/lib/sbi/sbi_tlb.c#L173
> [4] https://github.com/riscv-software-src/opensbi/commit/5d53b55aa77ffeefd4012445dfa6ad3535e1ff2c
> 
> Signed-off-by: Romain Naour <romain.naour@gmail.com>
> Cc: Mark Corbin <mark@dibsco.co.uk>

Thanks for the patch and explanation, but I'm wondering if this isn't
perhaps too complicated.


> +	select BR2_RISCV_ISA_RVZicsr if BR2_TOOLCHAIN_GCC_AT_LEAST_12
> +	select BR2_RISCV_ISA_RVZifencei if BR2_TOOLCHAIN_GCC_AT_LEAST_12

[...]

>  	help
> -	  General purpose (G) is equivalent to IMAFD.
> +	  General purpose (G) is equivalent to IMAFD
> +	  (with Zicsr and Zifencei since gcc >= 12).
>  
>  config BR2_riscv_custom
>  	bool "Custom architecture"
> @@ -63,6 +72,16 @@ config BR2_RISCV_ISA_CUSTOM_RVD
>  config BR2_RISCV_ISA_CUSTOM_RVC
>  	bool "Compressed Instructions (C)"
>  	select BR2_RISCV_ISA_RVC
> +
> +if BR2_TOOLCHAIN_GCC_AT_LEAST_12

The problem with this is that options in arch/ now depend on the gcc
version that is selected, which is something we have tried to avoid.

Do a git grep GCC_AT_LEAST in arch/, you will see that we only use
"select BR2_ARCH_NEEDS_GCC_AT_LEAST_xyz", i.e the choice of the
architecture/variant/ABI is what drives the available gcc versions.

And here you are doing exactly the opposite: it's the selected gcc
version that drives the architecture/variant/ABI options that are
available.

At this point, I don't really see the need from a Buildroot perspective
to separate icsr and ifencei from the base BR2_RISCV_ISA_RVI
instruction set.

So what I would do is exactly what OpenSBI has done in
https://github.com/riscv-software-src/opensbi/commit/5d53b55aa77ffeefd4012445dfa6ad3535e1ff2c:
when gcc >= 12 is used, we simply use -march with a _zicsr_zifencei
suffix, and that's it.

I.e something like this:

diff --git a/arch/arch.mk.riscv b/arch/arch.mk.riscv
index f3bf2b3467..d77f88dd70 100644
--- a/arch/arch.mk.riscv
+++ b/arch/arch.mk.riscv
@@ -27,4 +27,8 @@ ifeq ($(BR2_RISCV_ISA_RVC),y)
 GCC_TARGET_ARCH := $(GCC_TARGET_ARCH)c
 endif
 
+ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_12),y)
+GCC_TARGET_ARCH := $(GCC_TARGET_ARCH)_zicsr_zifencei
+endif
+
 endif

I don't think we will see RISC-V cores running Linux that support the
base I instruction, but not the csr and fence extensions... as even
OpenSBI assumes the RISC-V core supports them!

What do you think?

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2022-07-23 12:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-29 13:18 [Buildroot] [PATCH for-next 01/11] arch/Config.in.riscv: add Zicsr and Zifencei standalone extensions Romain Naour
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 02/11] configs/qemu_riscv{32, 64}_virt: kernel bump version to 5.15.43 Romain Naour
2022-07-23 12:57   ` Thomas Petazzoni via buildroot
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 03/11] package/gcc: disable libsanitizer for mips64{el} w/ n32 ABI Romain Naour
2022-07-23 12:41   ` Thomas Petazzoni via buildroot
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 04/11] package/gcc: disable libsanitizer for mips{el} and gcc > 12 Romain Naour
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 05/11] toolchain: enable libquadmath for PowerPC with VSX Romain Naour
2022-07-23 12:57   ` Thomas Petazzoni via buildroot
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 06/11] package/gcc: add missing --enable-libquadmath-support option Romain Naour
2022-07-23 12:57   ` Thomas Petazzoni via buildroot
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 07/11] package/gcc: switch to https urls for archives hashes Romain Naour
2022-07-23 12:57   ` Thomas Petazzoni via buildroot
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 08/11] package/gcc: add support for gcc 12 Romain Naour
2022-06-25  6:45   ` James Hilliard
2022-07-16 11:31     ` Romain Naour
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 09/11] arch: add BR2_ARCH_NEEDS_GCC_AT_LEAST_12 Romain Naour
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 10/11] package/gcc: switch to gcc 11.x as the default Romain Naour
2022-05-29 13:18 ` [Buildroot] [PATCH for-next 11/11] package/gcc: remove gcc 9.x Romain Naour
2022-07-23 12:39 ` Thomas Petazzoni via buildroot [this message]
2022-07-23 13:00   ` [Buildroot] [PATCH for-next 01/11] arch/Config.in.riscv: add Zicsr and Zifencei standalone extensions Romain Naour
2022-07-23 13:25     ` Thomas Petazzoni via buildroot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220723143921.1e89b49f@windsurf \
    --to=buildroot@buildroot.org \
    --cc=mark@dibsco.co.uk \
    --cc=romain.naour@gmail.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.