diff mbox series

[v2,02/14] arm: add initjmp()

Message ID bba48e537696016b94faa69a20f998256b060685.1740499185.git.jerome.forissier@linaro.org
State New
Headers show
Series Uthreads | expand

Commit Message

Jerome Forissier Feb. 25, 2025, 4:34 p.m. UTC
Implement initjmp() for Arm.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 arch/Kconfig                  |  1 +
 arch/arm/include/asm/setjmp.h |  1 +
 arch/arm/lib/setjmp.S         | 11 +++++++++++
 arch/arm/lib/setjmp_aarch64.S |  9 +++++++++
 4 files changed, 22 insertions(+)

Comments

Ilias Apalodimas Feb. 28, 2025, 12:01 p.m. UTC | #1
On Tue, 25 Feb 2025 at 18:35, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> Implement initjmp() for Arm.
>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> ---
>  arch/Kconfig                  |  1 +
>  arch/arm/include/asm/setjmp.h |  1 +
>  arch/arm/lib/setjmp.S         | 11 +++++++++++
>  arch/arm/lib/setjmp_aarch64.S |  9 +++++++++
>  4 files changed, 22 insertions(+)
>
> diff --git a/arch/Kconfig b/arch/Kconfig
> index 8d5b54031b3..57695fada8d 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -94,6 +94,7 @@ config ARC
>  config ARM
>         bool "ARM architecture"
>         select HAVE_SETJMP
> +       select HAVE_INITJMP
>         select ARCH_SUPPORTS_LTO
>         select CREATE_ARCH_SYMLINK
>         select HAVE_PRIVATE_LIBGCC if !ARM64
> diff --git a/arch/arm/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h
> index 662bec86321..1ad5b500f2a 100644
> --- a/arch/arm/include/asm/setjmp.h
> +++ b/arch/arm/include/asm/setjmp.h
> @@ -23,5 +23,6 @@ typedef struct jmp_buf_data jmp_buf[1];
>
>  int setjmp(jmp_buf jmp);
>  void longjmp(jmp_buf jmp, int ret);
> +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
>
>  #endif /* _SETJMP_H_ */
> diff --git a/arch/arm/lib/setjmp.S b/arch/arm/lib/setjmp.S
> index 2f041aeef01..320ddea85f9 100644
> --- a/arch/arm/lib/setjmp.S
> +++ b/arch/arm/lib/setjmp.S
> @@ -34,3 +34,14 @@ ENTRY(longjmp)
>         ret  lr
>  ENDPROC(longjmp)
>  .popsection
> +
> +.pushsection .text.initjmp, "ax"
> +ENTRY(initjmp)
> +       stm  a1, {v1-v8}
> +       /* a2: entry point address, a3: stack top */
> +       str  a3, [a1, #32]  /* where setjmp would save sp */
> +       str  a2, [a1, #36]  /* where setjmp would save lr */
> +       mov  a1, #0
> +       ret  lr
> +ENDPROC(initjmp)
> +.popsection
> diff --git a/arch/arm/lib/setjmp_aarch64.S b/arch/arm/lib/setjmp_aarch64.S
> index 1b8d000eb48..074320d25fb 100644
> --- a/arch/arm/lib/setjmp_aarch64.S
> +++ b/arch/arm/lib/setjmp_aarch64.S
> @@ -39,3 +39,12 @@ ENTRY(longjmp)
>         ret
>  ENDPROC(longjmp)
>  .popsection
> +
> +.pushsection .text.initjmp, "ax"
> +ENTRY(initjmp)
> +       /* x1: entry point address, x2: stack top */
> +       stp x1, x2, [x0,#88]
> +       mov  x0, #0
> +       ret
> +ENDPROC(initjmp)
> +.popsection
> --
> 2.43.0
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Heinrich Schuchardt Feb. 28, 2025, 1:05 p.m. UTC | #2
On 25.02.25 17:34, Jerome Forissier wrote:
> Implement initjmp() for Arm.
>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> ---
>   arch/Kconfig                  |  1 +
>   arch/arm/include/asm/setjmp.h |  1 +
>   arch/arm/lib/setjmp.S         | 11 +++++++++++
>   arch/arm/lib/setjmp_aarch64.S |  9 +++++++++
>   4 files changed, 22 insertions(+)
>
> diff --git a/arch/Kconfig b/arch/Kconfig
> index 8d5b54031b3..57695fada8d 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -94,6 +94,7 @@ config ARC
>   config ARM
>   	bool "ARM architecture"
>   	select HAVE_SETJMP
> +	select HAVE_INITJMP
>   	select ARCH_SUPPORTS_LTO
>   	select CREATE_ARCH_SYMLINK
>   	select HAVE_PRIVATE_LIBGCC if !ARM64
> diff --git a/arch/arm/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h
> index 662bec86321..1ad5b500f2a 100644
> --- a/arch/arm/include/asm/setjmp.h
> +++ b/arch/arm/include/asm/setjmp.h
> @@ -23,5 +23,6 @@ typedef struct jmp_buf_data jmp_buf[1];
>
>   int setjmp(jmp_buf jmp);
>   void longjmp(jmp_buf jmp, int ret);
> +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);

As this is not a standard function we cannot expect developers to know
what it does and how to use it.

Please, provide Sphinx style documentation with the necessary information.

Best regards

Heinrich

>
>   #endif /* _SETJMP_H_ */
> diff --git a/arch/arm/lib/setjmp.S b/arch/arm/lib/setjmp.S
> index 2f041aeef01..320ddea85f9 100644
> --- a/arch/arm/lib/setjmp.S
> +++ b/arch/arm/lib/setjmp.S
> @@ -34,3 +34,14 @@ ENTRY(longjmp)
>   	ret  lr
>   ENDPROC(longjmp)
>   .popsection
> +
> +.pushsection .text.initjmp, "ax"
> +ENTRY(initjmp)
> +	stm  a1, {v1-v8}
> +	/* a2: entry point address, a3: stack top */
> +	str  a3, [a1, #32]  /* where setjmp would save sp */
> +	str  a2, [a1, #36]  /* where setjmp would save lr */
> +	mov  a1, #0
> +	ret  lr
> +ENDPROC(initjmp)
> +.popsection
> diff --git a/arch/arm/lib/setjmp_aarch64.S b/arch/arm/lib/setjmp_aarch64.S
> index 1b8d000eb48..074320d25fb 100644
> --- a/arch/arm/lib/setjmp_aarch64.S
> +++ b/arch/arm/lib/setjmp_aarch64.S
> @@ -39,3 +39,12 @@ ENTRY(longjmp)
>   	ret
>   ENDPROC(longjmp)
>   .popsection
> +
> +.pushsection .text.initjmp, "ax"
> +ENTRY(initjmp)
> +	/* x1: entry point address, x2: stack top */
> +	stp x1, x2, [x0,#88]
> +	mov  x0, #0
> +	ret
> +ENDPROC(initjmp)
> +.popsection
Jerome Forissier Feb. 28, 2025, 1:21 p.m. UTC | #3
On 2/28/25 14:05, Heinrich Schuchardt wrote:
> On 25.02.25 17:34, Jerome Forissier wrote:
>> Implement initjmp() for Arm.
>>
>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
>> ---
>>   arch/Kconfig                  |  1 +
>>   arch/arm/include/asm/setjmp.h |  1 +
>>   arch/arm/lib/setjmp.S         | 11 +++++++++++
>>   arch/arm/lib/setjmp_aarch64.S |  9 +++++++++
>>   4 files changed, 22 insertions(+)
>>
>> diff --git a/arch/Kconfig b/arch/Kconfig
>> index 8d5b54031b3..57695fada8d 100644
>> --- a/arch/Kconfig
>> +++ b/arch/Kconfig
>> @@ -94,6 +94,7 @@ config ARC
>>   config ARM
>>       bool "ARM architecture"
>>       select HAVE_SETJMP
>> +    select HAVE_INITJMP
>>       select ARCH_SUPPORTS_LTO
>>       select CREATE_ARCH_SYMLINK
>>       select HAVE_PRIVATE_LIBGCC if !ARM64
>> diff --git a/arch/arm/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h
>> index 662bec86321..1ad5b500f2a 100644
>> --- a/arch/arm/include/asm/setjmp.h
>> +++ b/arch/arm/include/asm/setjmp.h
>> @@ -23,5 +23,6 @@ typedef struct jmp_buf_data jmp_buf[1];
>>
>>   int setjmp(jmp_buf jmp);
>>   void longjmp(jmp_buf jmp, int ret);
>> +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
> 
> As this is not a standard function we cannot expect developers to know
> what it does and how to use it.
> 
> Please, provide Sphinx style documentation with the necessary information.

I agree on principle, but if I add documentation here then I should add the
same for all architectures. That being said the prototypes are already
duplicated so maybe consolidation is a question for another time.  I will
add Shpinx style doc to all 3 commits "{arm,riscv,sandbox}: add initjmp()".

As for usage, I think the best documentation is test/lib/initjmp.c added
by "test: lib: add initjmp() test".

Thanks,
Heinrich Schuchardt Feb. 28, 2025, 1:28 p.m. UTC | #4
On 28.02.25 14:21, Jerome Forissier wrote:
>
>
> On 2/28/25 14:05, Heinrich Schuchardt wrote:
>> On 25.02.25 17:34, Jerome Forissier wrote:
>>> Implement initjmp() for Arm.
>>>
>>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
>>> ---
>>>    arch/Kconfig                  |  1 +
>>>    arch/arm/include/asm/setjmp.h |  1 +
>>>    arch/arm/lib/setjmp.S         | 11 +++++++++++
>>>    arch/arm/lib/setjmp_aarch64.S |  9 +++++++++
>>>    4 files changed, 22 insertions(+)
>>>
>>> diff --git a/arch/Kconfig b/arch/Kconfig
>>> index 8d5b54031b3..57695fada8d 100644
>>> --- a/arch/Kconfig
>>> +++ b/arch/Kconfig
>>> @@ -94,6 +94,7 @@ config ARC
>>>    config ARM
>>>        bool "ARM architecture"
>>>        select HAVE_SETJMP
>>> +    select HAVE_INITJMP
>>>        select ARCH_SUPPORTS_LTO
>>>        select CREATE_ARCH_SYMLINK
>>>        select HAVE_PRIVATE_LIBGCC if !ARM64
>>> diff --git a/arch/arm/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h
>>> index 662bec86321..1ad5b500f2a 100644
>>> --- a/arch/arm/include/asm/setjmp.h
>>> +++ b/arch/arm/include/asm/setjmp.h
>>> @@ -23,5 +23,6 @@ typedef struct jmp_buf_data jmp_buf[1];
>>>
>>>    int setjmp(jmp_buf jmp);
>>>    void longjmp(jmp_buf jmp, int ret);
>>> +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
>>
>> As this is not a standard function we cannot expect developers to know
>> what it does and how to use it.
>>
>> Please, provide Sphinx style documentation with the necessary information.
>
> I agree on principle, but if I add documentation here then I should add the
> same for all architectures. That being said the prototypes are already
> duplicated so maybe consolidation is a question for another time.  I will
> add Shpinx style doc to all 3 commits "{arm,riscv,sandbox}: add initjmp()".

Yes, this was not designed correctly:

We should move setjmp.h to include/asm-generic and include an
architecture specific setjmp_bits.h from there.

setjmp_bits.h would provide the struct jmp_buf_data definition.

>
> As for usage, I think the best documentation is test/lib/initjmp.c added
> by "test: lib: add initjmp() test".

Example code is valuable but does not replace documentation.

Best regards

Heinrich
Jerome Forissier Feb. 28, 2025, 2:16 p.m. UTC | #5
On 2/28/25 14:28, Heinrich Schuchardt wrote:
> On 28.02.25 14:21, Jerome Forissier wrote:
>>
>>
>> On 2/28/25 14:05, Heinrich Schuchardt wrote:
>>> On 25.02.25 17:34, Jerome Forissier wrote:
>>>> Implement initjmp() for Arm.
>>>>
>>>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
>>>> ---
>>>>    arch/Kconfig                  |  1 +
>>>>    arch/arm/include/asm/setjmp.h |  1 +
>>>>    arch/arm/lib/setjmp.S         | 11 +++++++++++
>>>>    arch/arm/lib/setjmp_aarch64.S |  9 +++++++++
>>>>    4 files changed, 22 insertions(+)
>>>>
>>>> diff --git a/arch/Kconfig b/arch/Kconfig
>>>> index 8d5b54031b3..57695fada8d 100644
>>>> --- a/arch/Kconfig
>>>> +++ b/arch/Kconfig
>>>> @@ -94,6 +94,7 @@ config ARC
>>>>    config ARM
>>>>        bool "ARM architecture"
>>>>        select HAVE_SETJMP
>>>> +    select HAVE_INITJMP
>>>>        select ARCH_SUPPORTS_LTO
>>>>        select CREATE_ARCH_SYMLINK
>>>>        select HAVE_PRIVATE_LIBGCC if !ARM64
>>>> diff --git a/arch/arm/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h
>>>> index 662bec86321..1ad5b500f2a 100644
>>>> --- a/arch/arm/include/asm/setjmp.h
>>>> +++ b/arch/arm/include/asm/setjmp.h
>>>> @@ -23,5 +23,6 @@ typedef struct jmp_buf_data jmp_buf[1];
>>>>
>>>>    int setjmp(jmp_buf jmp);
>>>>    void longjmp(jmp_buf jmp, int ret);
>>>> +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
>>>
>>> As this is not a standard function we cannot expect developers to know
>>> what it does and how to use it.
>>>
>>> Please, provide Sphinx style documentation with the necessary information.
>>
>> I agree on principle, but if I add documentation here then I should add the
>> same for all architectures. That being said the prototypes are already
>> duplicated so maybe consolidation is a question for another time.  I will
>> add Shpinx style doc to all 3 commits "{arm,riscv,sandbox}: add initjmp()".
> 
> Yes, this was not designed correctly:
> 
> We should move setjmp.h to include/asm-generic and include an
> architecture specific setjmp_bits.h from there.
> 
> setjmp_bits.h would provide the struct jmp_buf_data definition.

Makes sense. I'll rework in v3.

> 
>>
>> As for usage, I think the best documentation is test/lib/initjmp.c added
>> by "test: lib: add initjmp() test".
> 
> Example code is valuable but does not replace documentation.

Should I provide a stripped-down example in the Sphinx doc? Or do you have
another location in mind? (doc/develop/initjmp.rst?).

Thanks,
Tom Rini Feb. 28, 2025, 5:54 p.m. UTC | #6
On Fri, Feb 28, 2025 at 03:16:37PM +0100, Jerome Forissier wrote:
> 
> 
> On 2/28/25 14:28, Heinrich Schuchardt wrote:
> > On 28.02.25 14:21, Jerome Forissier wrote:
> >>
> >>
> >> On 2/28/25 14:05, Heinrich Schuchardt wrote:
> >>> On 25.02.25 17:34, Jerome Forissier wrote:
> >>>> Implement initjmp() for Arm.
> >>>>
> >>>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> >>>> ---
> >>>>    arch/Kconfig                  |  1 +
> >>>>    arch/arm/include/asm/setjmp.h |  1 +
> >>>>    arch/arm/lib/setjmp.S         | 11 +++++++++++
> >>>>    arch/arm/lib/setjmp_aarch64.S |  9 +++++++++
> >>>>    4 files changed, 22 insertions(+)
> >>>>
> >>>> diff --git a/arch/Kconfig b/arch/Kconfig
> >>>> index 8d5b54031b3..57695fada8d 100644
> >>>> --- a/arch/Kconfig
> >>>> +++ b/arch/Kconfig
> >>>> @@ -94,6 +94,7 @@ config ARC
> >>>>    config ARM
> >>>>        bool "ARM architecture"
> >>>>        select HAVE_SETJMP
> >>>> +    select HAVE_INITJMP
> >>>>        select ARCH_SUPPORTS_LTO
> >>>>        select CREATE_ARCH_SYMLINK
> >>>>        select HAVE_PRIVATE_LIBGCC if !ARM64
> >>>> diff --git a/arch/arm/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h
> >>>> index 662bec86321..1ad5b500f2a 100644
> >>>> --- a/arch/arm/include/asm/setjmp.h
> >>>> +++ b/arch/arm/include/asm/setjmp.h
> >>>> @@ -23,5 +23,6 @@ typedef struct jmp_buf_data jmp_buf[1];
> >>>>
> >>>>    int setjmp(jmp_buf jmp);
> >>>>    void longjmp(jmp_buf jmp, int ret);
> >>>> +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
> >>>
> >>> As this is not a standard function we cannot expect developers to know
> >>> what it does and how to use it.
> >>>
> >>> Please, provide Sphinx style documentation with the necessary information.
> >>
> >> I agree on principle, but if I add documentation here then I should add the
> >> same for all architectures. That being said the prototypes are already
> >> duplicated so maybe consolidation is a question for another time.  I will
> >> add Shpinx style doc to all 3 commits "{arm,riscv,sandbox}: add initjmp()".
> > 
> > Yes, this was not designed correctly:
> > 
> > We should move setjmp.h to include/asm-generic and include an
> > architecture specific setjmp_bits.h from there.
> > 
> > setjmp_bits.h would provide the struct jmp_buf_data definition.
> 
> Makes sense. I'll rework in v3.
> 
> > 
> >>
> >> As for usage, I think the best documentation is test/lib/initjmp.c added
> >> by "test: lib: add initjmp() test".
> > 
> > Example code is valuable but does not replace documentation.
> 
> Should I provide a stripped-down example in the Sphinx doc? Or do you have
> another location in mind? (doc/develop/initjmp.rst?).

We should have doc/api/initjmp.rst and if test/lib/initjmp.c is
commented correctly / well enough it can be referenced in the rST via
'.. kernel-doc::test/lib/initjmp.c' I think.
diff mbox series

Patch

diff --git a/arch/Kconfig b/arch/Kconfig
index 8d5b54031b3..57695fada8d 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -94,6 +94,7 @@  config ARC
 config ARM
 	bool "ARM architecture"
 	select HAVE_SETJMP
+	select HAVE_INITJMP
 	select ARCH_SUPPORTS_LTO
 	select CREATE_ARCH_SYMLINK
 	select HAVE_PRIVATE_LIBGCC if !ARM64
diff --git a/arch/arm/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h
index 662bec86321..1ad5b500f2a 100644
--- a/arch/arm/include/asm/setjmp.h
+++ b/arch/arm/include/asm/setjmp.h
@@ -23,5 +23,6 @@  typedef struct jmp_buf_data jmp_buf[1];
 
 int setjmp(jmp_buf jmp);
 void longjmp(jmp_buf jmp, int ret);
+int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
 
 #endif /* _SETJMP_H_ */
diff --git a/arch/arm/lib/setjmp.S b/arch/arm/lib/setjmp.S
index 2f041aeef01..320ddea85f9 100644
--- a/arch/arm/lib/setjmp.S
+++ b/arch/arm/lib/setjmp.S
@@ -34,3 +34,14 @@  ENTRY(longjmp)
 	ret  lr
 ENDPROC(longjmp)
 .popsection
+
+.pushsection .text.initjmp, "ax"
+ENTRY(initjmp)
+	stm  a1, {v1-v8}
+	/* a2: entry point address, a3: stack top */
+	str  a3, [a1, #32]  /* where setjmp would save sp */
+	str  a2, [a1, #36]  /* where setjmp would save lr */
+	mov  a1, #0
+	ret  lr
+ENDPROC(initjmp)
+.popsection
diff --git a/arch/arm/lib/setjmp_aarch64.S b/arch/arm/lib/setjmp_aarch64.S
index 1b8d000eb48..074320d25fb 100644
--- a/arch/arm/lib/setjmp_aarch64.S
+++ b/arch/arm/lib/setjmp_aarch64.S
@@ -39,3 +39,12 @@  ENTRY(longjmp)
 	ret
 ENDPROC(longjmp)
 .popsection
+
+.pushsection .text.initjmp, "ax"
+ENTRY(initjmp)
+	/* x1: entry point address, x2: stack top */
+	stp x1, x2, [x0,#88]
+	mov  x0, #0
+	ret
+ENDPROC(initjmp)
+.popsection