[PATCH 01/11] ARM: at91: sama5: switch to nonnaked entry functions

Sascha Hauer sha at pengutronix.de
Thu Dec 15 22:49:29 PST 2022


On Wed, Dec 14, 2022 at 11:58:21AM +0100, Ahmad Fatoum wrote:
> Functions were kept naked because they modify the stack pointer.
> We can hoist that up and change the board-provided entry point
> to be non-naked to be more robust in face of unexpected compiler
> optimizations.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  .../boards/microchip-ksz9477-evb/lowlevel.c    |  6 ++----
>  arch/arm/boards/sama5d27-giantboard/lowlevel.c |  4 ++--
>  arch/arm/boards/sama5d27-som1/lowlevel.c       |  4 ++--
>  arch/arm/boards/sama5d3_xplained/lowlevel.c    |  6 ++----
>  arch/arm/mach-at91/include/mach/barebox-arm.h  | 18 ++++++++++++++----
>  5 files changed, 22 insertions(+), 16 deletions(-)
> 

[...]

> diff --git a/arch/arm/mach-at91/include/mach/barebox-arm.h b/arch/arm/mach-at91/include/mach/barebox-arm.h
> index 4a65c6f8fa55..36c6abadc137 100644
> --- a/arch/arm/mach-at91/include/mach/barebox-arm.h
> +++ b/arch/arm/mach-at91/include/mach/barebox-arm.h
> @@ -3,19 +3,29 @@
>  #define AT91_BAREBOX_ARM_H_
>  
>  #include <asm/barebox-arm.h>
> +#include <asm/common.h>
> +#include <mach/sama5d3.h>
>  
> -#define SAMA5_ENTRY_FUNCTION(name, r4)						\
> +#define SAMA5_ENTRY_FUNCTION(name, stack_top, r4)				\
>  	void name (u32 r0, u32 r1, u32 r2, u32 r3);				\
>  										\
>  	static void __##name(u32);						\
>  										\
> -	void NAKED __section(.text_head_entry_##name)	name			\
> +	void __naked __section(.text_head_entry_##name)	name			\
>  				(u32 r0, u32 r1, u32 r2, u32 r3)		\
>  		{								\
>  			register u32 r4 asm("r4");				\
>  			__barebox_arm_head();					\
> +			arm_setup_stack(stack_top);				\
>  			__##name(r4);						\
>  		}								\
> -		static void NAKED noinline __##name				\
> -			(u32 r4)
> +		static void noinline __##name(u32 r4)
> +
> +/* BootROM already initialized usable stack top */
> +#define SAMA5D2_ENTRY_FUNCTION(name, r4)					\
> +	SAMA5_ENTRY_FUNCTION(name, 0, r4)

Shouldn't you pass a valid stack address here as well? Without this
change the stack pointer from the bootrom was reused in barebox, but now
it is explicitly set to 0.

Sascha

> +
> +#define SAMA5D3_ENTRY_FUNCTION(name, r4)					\
> +	SAMA5_ENTRY_FUNCTION(name, SAMA5D3_SRAM_BASE + SAMA5D3_SRAM_SIZE, r4)
> +
>  #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 |



More information about the barebox mailing list