arm: add initjmp()
authorJerome Forissier <jerome.forissier@linaro.org>
Fri, 18 Apr 2025 14:09:30 +0000 (16:09 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 23 Apr 2025 19:19:44 +0000 (13:19 -0600)
Implement initjmp() for Arm. a non-standard extension to setjmp()/
longjmp() allowing to initialize a jump buffer with a function pointer
and a stack pointer. This will be useful to later introduce threads.
With this new function it becomes possible to longjmp() to a particular
function pointer (rather than to a point previously reached during
program execution as is the case with setjmp()), and with a custom stack.
Both things are needed to spin off a new thread. Then the usual
setjmp()/longjmp() pair is enough to save and restore a context, i.e.,
switch thread.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
arch/Kconfig
arch/arm/lib/setjmp.S
arch/arm/lib/setjmp_aarch64.S

index 14111ca..7a3141e 100644 (file)
@@ -95,6 +95,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
index 2f041ae..81bef57 100644 (file)
@@ -34,3 +34,15 @@ ENTRY(longjmp)
        ret  lr
 ENDPROC(longjmp)
 .popsection
+
+.pushsection .text.initjmp, "ax"
+ENTRY(initjmp)
+       stm  a1, {v1-v8}
+       /* a2: entry point address, a3: stack base, a4: stack size */
+       add  a3, a3, a4
+       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
index 1b8d000..01193cc 100644 (file)
@@ -39,3 +39,13 @@ ENTRY(longjmp)
        ret
 ENDPROC(longjmp)
 .popsection
+
+.pushsection .text.initjmp, "ax"
+ENTRY(initjmp)
+       /* x1: entry point address, x2: stack base, x3: stack size */
+       add x2, x2, x3
+       stp x1, x2, [x0,#88]
+       mov  x0, #0
+       ret
+ENDPROC(initjmp)
+.popsection