To allow use of global_variable_offset() from common PBL code, move the definition into a new <asm/reloc.h> header. At current time, it's expected that PBL enabled platforms define at least get_runtime_offset() there. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- arch/riscv/include/asm/barebox-riscv.h | 7 +------ arch/riscv/include/asm/reloc.h | 15 +++++++++++++++ include/asm-generic/reloc.h | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 arch/riscv/include/asm/reloc.h create mode 100644 include/asm-generic/reloc.h diff --git a/arch/riscv/include/asm/barebox-riscv.h b/arch/riscv/include/asm/barebox-riscv.h index 5c87d37c9eb8..db6ff0ea7131 100644 --- a/arch/riscv/include/asm/barebox-riscv.h +++ b/arch/riscv/include/asm/barebox-riscv.h @@ -21,12 +21,7 @@ #include <asm/barebox-riscv-head.h> #include <asm/system.h> #include <asm/cache.h> - -unsigned long get_runtime_offset(void); - -void setup_c(void); -void relocate_to_current_adr(void); -void relocate_to_adr(unsigned long target); +#include <asm/reloc.h> void __noreturn __naked barebox_riscv_entry(unsigned long membase, unsigned long memsize, void *boarddata, unsigned int flags); diff --git a/arch/riscv/include/asm/reloc.h b/arch/riscv/include/asm/reloc.h new file mode 100644 index 000000000000..9a59326cad27 --- /dev/null +++ b/arch/riscv/include/asm/reloc.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _ASM_RELOC_H_ +#define _ASM_RELOC_H_ + +unsigned long get_runtime_offset(void); + +void relocate_to_current_adr(void); +void relocate_to_adr(unsigned long target); + +void setup_c(void); + +#include <asm-generic/reloc.h> + +#endif /* _BAREBOX_RISCV_H_ */ diff --git a/include/asm-generic/reloc.h b/include/asm-generic/reloc.h new file mode 100644 index 000000000000..90459371ebe8 --- /dev/null +++ b/include/asm-generic/reloc.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _ASM_GENERIC_RELOC_H_ +#define _ASM_GENERIC_RELOC_H_ + +#ifndef global_variable_offset +#define global_variable_offset() get_runtime_offset() +#endif + +#endif -- 2.30.2
Like done for RISC-V, move declaration of the relocation functions into asm/reloc.h Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- arch/arm/include/asm/barebox-arm.h | 29 +-------------------- arch/arm/include/asm/reloc.h | 42 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 arch/arm/include/asm/reloc.h diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h index 8795c89d515b..d901cb10013d 100644 --- a/arch/arm/include/asm/barebox-arm.h +++ b/arch/arm/include/asm/barebox-arm.h @@ -20,6 +20,7 @@ #include <asm/barebox-arm-head.h> #include <asm/common.h> #include <asm/sections.h> +#include <asm/reloc.h> /* * We have a 4GiB address space split into 1MiB sections, with each @@ -27,34 +28,6 @@ */ #define ARM_TTB_SIZE (SZ_4G / SZ_1M * sizeof(u32)) -unsigned long get_runtime_offset(void); - -/* global_variable_offset() - Access global variables when not running at link address - * - * Get the offset of global variables when not running at the address we are - * linked at. - */ -static inline unsigned long global_variable_offset(void) -{ -#ifdef CONFIG_CPU_V8 - unsigned long text; - - __asm__ __volatile__( - "adr %0, _text\n" - : "=r" (text) - : - : "memory"); - return text - (unsigned long)_text; -#else - return get_runtime_offset(); -#endif -} - -void setup_c(void); -void pbl_barebox_break(void); -void relocate_to_current_adr(void); -void relocate_to_adr(unsigned long target); -void relocate_to_adr_full(unsigned long target); void __noreturn barebox_arm_entry(unsigned long membase, unsigned long memsize, void *boarddata); struct barebox_arm_boarddata { diff --git a/arch/arm/include/asm/reloc.h b/arch/arm/include/asm/reloc.h new file mode 100644 index 000000000000..0002c96c014c --- /dev/null +++ b/arch/arm/include/asm/reloc.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _ASM_RELOC_H_ +#define _ASM_RELOC_H_ + +#include <asm/sections.h> + +unsigned long get_runtime_offset(void); + +/* global_variable_offset() - Access global variables when not running at link address + * + * Get the offset of global variables when not running at the address we are + * linked at. + */ +static inline unsigned long global_variable_offset(void) +{ +#ifdef CONFIG_CPU_V8 + unsigned long text; + + __asm__ __volatile__( + "adr %0, _text\n" + : "=r" (text) + : + : "memory"); + return text - (unsigned long)_text; +#else + return get_runtime_offset(); +#endif +} +#define global_variable_offset() global_variable_offset() + +void relocate_to_current_adr(void); +void relocate_to_adr(unsigned long target); +void relocate_to_adr_full(unsigned long target); + +void pbl_barebox_break(void); + +void setup_c(void); + +#include <asm-generic/reloc.h> + +#endif -- 2.30.2
MIPS' relocation setup differs from ARM and RISC-V, but as it always happen within assembly, we can assume C code to always be relocated, which allows a trivial implementation of get_runtime_offset(). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- arch/mips/include/asm/reloc.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 arch/mips/include/asm/reloc.h diff --git a/arch/mips/include/asm/reloc.h b/arch/mips/include/asm/reloc.h new file mode 100644 index 000000000000..adffd6f1c7ef --- /dev/null +++ b/arch/mips/include/asm/reloc.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _ASM_RELOC_H_ +#define _ASM_RELOC_H_ + +static inline unsigned long get_runtime_offset(void) +{ + /* On MIPS, we always relocate before jumping into C */ + return 0; +} + +#include <asm-generic/reloc.h> + +#endif -- 2.30.2
On Fri, Aug 05, 2022 at 09:42:35AM +0200, Ahmad Fatoum wrote: > To allow use of global_variable_offset() from common PBL code, > move the definition into a new <asm/reloc.h> header. > At current time, it's expected that PBL enabled platforms define > at least get_runtime_offset() there. > > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > --- > arch/riscv/include/asm/barebox-riscv.h | 7 +------ > arch/riscv/include/asm/reloc.h | 15 +++++++++++++++ > include/asm-generic/reloc.h | 10 ++++++++++ > 3 files changed, 26 insertions(+), 6 deletions(-) > create mode 100644 arch/riscv/include/asm/reloc.h > create mode 100644 include/asm-generic/reloc.h Applied, thanks Sascha > > diff --git a/arch/riscv/include/asm/barebox-riscv.h b/arch/riscv/include/asm/barebox-riscv.h > index 5c87d37c9eb8..db6ff0ea7131 100644 > --- a/arch/riscv/include/asm/barebox-riscv.h > +++ b/arch/riscv/include/asm/barebox-riscv.h > @@ -21,12 +21,7 @@ > #include <asm/barebox-riscv-head.h> > #include <asm/system.h> > #include <asm/cache.h> > - > -unsigned long get_runtime_offset(void); > - > -void setup_c(void); > -void relocate_to_current_adr(void); > -void relocate_to_adr(unsigned long target); > +#include <asm/reloc.h> > > void __noreturn __naked barebox_riscv_entry(unsigned long membase, unsigned long memsize, > void *boarddata, unsigned int flags); > diff --git a/arch/riscv/include/asm/reloc.h b/arch/riscv/include/asm/reloc.h > new file mode 100644 > index 000000000000..9a59326cad27 > --- /dev/null > +++ b/arch/riscv/include/asm/reloc.h > @@ -0,0 +1,15 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > + > +#ifndef _ASM_RELOC_H_ > +#define _ASM_RELOC_H_ > + > +unsigned long get_runtime_offset(void); > + > +void relocate_to_current_adr(void); > +void relocate_to_adr(unsigned long target); > + > +void setup_c(void); > + > +#include <asm-generic/reloc.h> > + > +#endif /* _BAREBOX_RISCV_H_ */ > diff --git a/include/asm-generic/reloc.h b/include/asm-generic/reloc.h > new file mode 100644 > index 000000000000..90459371ebe8 > --- /dev/null > +++ b/include/asm-generic/reloc.h > @@ -0,0 +1,10 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > + > +#ifndef _ASM_GENERIC_RELOC_H_ > +#define _ASM_GENERIC_RELOC_H_ > + > +#ifndef global_variable_offset > +#define global_variable_offset() get_runtime_offset() > +#endif > + > +#endif > -- > 2.30.2 > > > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |