Hi Bo Gan,

> From: Bo Gan <ganbo...@gmail.com>
> Sent: Tuesday, May 09, 2023 9:46 AM
> To: u-boot@lists.denx.de
> Cc: Bo Gan <ganbo...@gmail.com>; Rick Jian-Zhi Chen(陳建志) 
> <r...@andestech.com>; Leo Yu-Chi Liang(梁育齊) <ycli...@andestech.com>
> Subject: [PATCH] riscv: setup per-hart stack earlier
>
> Harts need to use per-hart stack before any function call, even if that 
> function is a simple one. When the callee uses stack for register save/ 
> restore, especially RA, if nested call, concurrent access by multiple harts 
> on the same stack will cause data-race.
>
> This patch sets up SP before `board_init_f_alloc_reserve`. A side effect of 
> this is that the memory layout has changed as the following:
>
> +----------------+        +----------------+ <----- SPL_STACK/
> |  ......        |        |  hart 0 stack  |        SYS_INIT_SP_ADDR
> |  malloc_base   |        +----------------+
> +----------------+        |  hart 1 stack  |
> |  GD            |        +----------------+ If not SMP, N=1
> +----------------+        |  ......        |
> |  hart 0 stack  |        +----------------+
> +----------------+   ==>  |  hart N-1 stack|
> |  hart 1 stack  |        +----------------+
> +----------------+        |  ......        |
> |  ......        |        |  malloc_base   |
> +----------------+        +----------------+
> |  hart N-1 stack|        |  GD            |
> +----------------+        +----------------+
> |                |        |                |
>
> Signed-off-by: Bo Gan <ganbo...@gmail.com>
> Cc: Rick Chen <r...@andestech.com>
> Cc: Leo <ycli...@andestech.com>
> ---
>  arch/riscv/cpu/start.S | 37 ++++++++++++++++++++++++-------------
>  1 file changed, 24 insertions(+), 13 deletions(-)
>
> diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index 
> dad22bf..90015c2 100644
> --- a/arch/riscv/cpu/start.S
> +++ b/arch/riscv/cpu/start.S
> @@ -91,16 +91,35 @@ _start:
>   * Set stackpointer in internal/ex RAM to call board_init_f
>   */
>  call_board_init_f:
> -       li      t0, -16
>  #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
> -       li      t1, CONFIG_SPL_STACK
> +       li      t0, CONFIG_SPL_STACK
>  #else
> -       li      t1, SYS_INIT_SP_ADDR
> +       li      t0, CONFIG_SYS_INIT_SP_ADDR

It builds fail as below:

arch/riscv/cpu/start.S:97: Error: illegal operands `li
t0,CONFIG_SYS_INIT_SP_ADDR'

Thanks,
Rick

Reply via email to