diff mbox series

[U-Boot,v2,07/29] riscv: add Kconfig entries for the code model

Message ID 20181030125553.5230-8-lukas.auer@aisec.fraunhofer.de
State Superseded
Delegated to: Andes
Headers show
Series General fixes / cleanup for RISC-V and improvements to qemu-riscv | expand

Commit Message

Lukas Auer Oct. 30, 2018, 12:55 p.m. UTC
RISC-V has two code models, medium low (medlow) and medium any (medany).
Medlow limits addressable memory to a single 2 GiB range between the
absolute addresses -2 GiB and +2 GiB. Medany limits addressable memory
to any single 2 GiB address range.
By default, medlow is selected on 32-bit systems and medany on 64-bit
systems. This matches the configuration in Linux.

The -mcmodel compiler flag is selected according to the Kconfig
configuration.

Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
---

Changes in v2:
- Change ISA string construction, as suggested by Bin Meng

 arch/riscv/Kconfig  | 19 +++++++++++++++++++
 arch/riscv/Makefile |  9 ++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

Comments

Bin Meng Oct. 31, 2018, 2:13 a.m. UTC | #1
Hi Lukas,

On Tue, Oct 30, 2018 at 8:57 PM Lukas Auer
<lukas.auer@aisec.fraunhofer.de> wrote:
>
> RISC-V has two code models, medium low (medlow) and medium any (medany).
> Medlow limits addressable memory to a single 2 GiB range between the
> absolute addresses -2 GiB and +2 GiB. Medany limits addressable memory
> to any single 2 GiB address range.
> By default, medlow is selected on 32-bit systems and medany on 64-bit
> systems. This matches the configuration in Linux.
>
> The -mcmodel compiler flag is selected according to the Kconfig
> configuration.
>
> Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
> ---
>
> Changes in v2:
> - Change ISA string construction, as suggested by Bin Meng
>
>  arch/riscv/Kconfig  | 19 +++++++++++++++++++
>  arch/riscv/Makefile |  9 ++++++++-
>  2 files changed, 27 insertions(+), 1 deletion(-)
>

I had a further look at this, and I suspect we should stick to medlow
for U-Boot, even for 64-bit. As U-Boot will be only running within the
low 4GB memory space even for 64-bit. Adding medany seems unnecessary.

Regards,
Bin
Lukas Auer Oct. 31, 2018, 3:01 p.m. UTC | #2
Hi Bin,

On Wed, 2018-10-31 at 10:13 +0800, Bin Meng wrote:
> Hi Lukas,
> 
> On Tue, Oct 30, 2018 at 8:57 PM Lukas Auer
> <lukas.auer@aisec.fraunhofer.de> wrote:
> > 
> > RISC-V has two code models, medium low (medlow) and medium any
> > (medany).
> > Medlow limits addressable memory to a single 2 GiB range between
> > the
> > absolute addresses -2 GiB and +2 GiB. Medany limits addressable
> > memory
> > to any single 2 GiB address range.
> > By default, medlow is selected on 32-bit systems and medany on 64-
> > bit
> > systems. This matches the configuration in Linux.
> > 
> > The -mcmodel compiler flag is selected according to the Kconfig
> > configuration.
> > 
> > Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
> > ---
> > 
> > Changes in v2:
> > - Change ISA string construction, as suggested by Bin Meng
> > 
> >  arch/riscv/Kconfig  | 19 +++++++++++++++++++
> >  arch/riscv/Makefile |  9 ++++++++-
> >  2 files changed, 27 insertions(+), 1 deletion(-)
> > 
> 
> I had a further look at this, and I suspect we should stick to medlow
> for U-Boot, even for 64-bit. As U-Boot will be only running within
> the
> low 4GB memory space even for 64-bit. Adding medany seems
> unnecessary.
> 
> Regards,
> Bin

You are right, however I think it's actually because U-Boot is compiled
as a position independent binary. U-Boot can be relocated above what's
addressable with 32-bit if the memory is large enough. This should
cause issues with medlow.
I suspects that's the reason, but I am not entirely sure. What do you
think?

Thanks,
Lukas
Bin Meng Nov. 13, 2018, 7:34 a.m. UTC | #3
Hi Lukas,

On Wed, Oct 31, 2018 at 11:01 PM Auer, Lukas
<lukas.auer@aisec.fraunhofer.de> wrote:
>
> Hi Bin,
>
> On Wed, 2018-10-31 at 10:13 +0800, Bin Meng wrote:
> > Hi Lukas,
> >
> > On Tue, Oct 30, 2018 at 8:57 PM Lukas Auer
> > <lukas.auer@aisec.fraunhofer.de> wrote:
> > >
> > > RISC-V has two code models, medium low (medlow) and medium any
> > > (medany).
> > > Medlow limits addressable memory to a single 2 GiB range between
> > > the
> > > absolute addresses -2 GiB and +2 GiB. Medany limits addressable
> > > memory
> > > to any single 2 GiB address range.
> > > By default, medlow is selected on 32-bit systems and medany on 64-
> > > bit
> > > systems. This matches the configuration in Linux.
> > >
> > > The -mcmodel compiler flag is selected according to the Kconfig
> > > configuration.
> > >
> > > Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
> > > ---
> > >
> > > Changes in v2:
> > > - Change ISA string construction, as suggested by Bin Meng
> > >
> > >  arch/riscv/Kconfig  | 19 +++++++++++++++++++
> > >  arch/riscv/Makefile |  9 ++++++++-
> > >  2 files changed, 27 insertions(+), 1 deletion(-)
> > >
> >
> > I had a further look at this, and I suspect we should stick to medlow
> > for U-Boot, even for 64-bit. As U-Boot will be only running within
> > the
> > low 4GB memory space even for 64-bit. Adding medany seems
> > unnecessary.
> >
> > Regards,
> > Bin
>
> You are right, however I think it's actually because U-Boot is compiled
> as a position independent binary. U-Boot can be relocated above what's
> addressable with 32-bit if the memory is large enough. This should
> cause issues with medlow.
> I suspects that's the reason, but I am not entirely sure. What do you
> think?

Sorry I missed this email. I just found in your v3 this patch was
dropped. I think this is still needed to explicitly pass the code
model to the compiler. I believe we only need change to:

+choice
+       prompt "Code Model"
+       default CMODEL_MEDLOW

I can include the modified patch in my upcoming series.

Regards,
Bin
Lukas Auer Nov. 13, 2018, 10:20 a.m. UTC | #4
Hi Bin,

On Tue, 2018-11-13 at 15:34 +0800, Bin Meng wrote:
> Hi Lukas,
> 
> On Wed, Oct 31, 2018 at 11:01 PM Auer, Lukas
> <lukas.auer@aisec.fraunhofer.de> wrote:
> > 
> > Hi Bin,
> > 
> > On Wed, 2018-10-31 at 10:13 +0800, Bin Meng wrote:
> > > Hi Lukas,
> > > 
> > > On Tue, Oct 30, 2018 at 8:57 PM Lukas Auer
> > > <lukas.auer@aisec.fraunhofer.de> wrote:
> > > > 
> > > > RISC-V has two code models, medium low (medlow) and medium any
> > > > (medany).
> > > > Medlow limits addressable memory to a single 2 GiB range
> > > > between
> > > > the
> > > > absolute addresses -2 GiB and +2 GiB. Medany limits addressable
> > > > memory
> > > > to any single 2 GiB address range.
> > > > By default, medlow is selected on 32-bit systems and medany on
> > > > 64-
> > > > bit
> > > > systems. This matches the configuration in Linux.
> > > > 
> > > > The -mcmodel compiler flag is selected according to the Kconfig
> > > > configuration.
> > > > 
> > > > Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
> > > > ---
> > > > 
> > > > Changes in v2:
> > > > - Change ISA string construction, as suggested by Bin Meng
> > > > 
> > > >  arch/riscv/Kconfig  | 19 +++++++++++++++++++
> > > >  arch/riscv/Makefile |  9 ++++++++-
> > > >  2 files changed, 27 insertions(+), 1 deletion(-)
> > > > 
> > > 
> > > I had a further look at this, and I suspect we should stick to
> > > medlow
> > > for U-Boot, even for 64-bit. As U-Boot will be only running
> > > within
> > > the
> > > low 4GB memory space even for 64-bit. Adding medany seems
> > > unnecessary.
> > > 
> > > Regards,
> > > Bin
> > 
> > You are right, however I think it's actually because U-Boot is
> > compiled
> > as a position independent binary. U-Boot can be relocated above
> > what's
> > addressable with 32-bit if the memory is large enough. This should
> > cause issues with medlow.
> > I suspects that's the reason, but I am not entirely sure. What do
> > you
> > think?
> 
> Sorry I missed this email. I just found in your v3 this patch was
> dropped. I think this is still needed to explicitly pass the code
> model to the compiler. I believe we only need change to:
> 
> +choice
> +       prompt "Code Model"
> +       default CMODEL_MEDLOW
> 
> I can include the modified patch in my upcoming series.
> 
> Regards,
> Bin

Ok, I miss-understood that. Sounds good, thanks!

Lukas
diff mbox series

Patch

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 0de77a75d7..371921b412 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -38,6 +38,25 @@  config ARCH_RV64I
 
 endchoice
 
+choice
+	prompt "Code Model"
+	default CMODEL_MEDLOW if 32BIT
+	default CMODEL_MEDANY if 64BIT
+
+config CMODEL_MEDLOW
+	bool "medium low code model"
+	help
+	  U-Boot and its statically defined symbols must lie within a single 2 GiB
+	  address range and must lie between absolute addresses -2 GiB and +2 GiB.
+
+config CMODEL_MEDANY
+	bool "medium any code model"
+	help
+	  U-Boot and its statically defined symbols must be within any single 2 GiB
+	  address range.
+
+endchoice
+
 config RISCV_ISA_C
 	bool "Emit compressed instructions"
 	default y
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 55d7c6550e..0b80eb8d86 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -17,8 +17,15 @@  endif
 ifeq ($(CONFIG_RISCV_ISA_C),y)
 	ARCH_C = c
 endif
+ifeq ($(CONFIG_CMODEL_MEDLOW),y)
+	CMODEL = medlow
+endif
+ifeq ($(CONFIG_CMODEL_MEDANY),y)
+	CMODEL = medany
+endif
 
-ARCH_FLAGS = -march=$(ARCH_BASE)$(ARCH_A)$(ARCH_C) -mabi=$(ABI)
+ARCH_FLAGS = -march=$(ARCH_BASE)$(ARCH_A)$(ARCH_C) -mabi=$(ABI) \
+	     -mcmodel=$(CMODEL)
 
 PLATFORM_CPPFLAGS	+= $(ARCH_FLAGS)
 CFLAGS_EFI		+= $(ARCH_FLAGS)