riscv: add initjmp()
authorJerome Forissier <jerome.forissier@linaro.org>
Fri, 18 Apr 2025 14:09:31 +0000 (16:09 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 23 Apr 2025 19:19:44 +0000 (13:19 -0600)
Implement initjmp() for RISC-V, 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>
arch/Kconfig
arch/riscv/lib/setjmp.S

index 7a3141e..aa60c5f 100644 (file)
@@ -153,6 +153,7 @@ config RISCV
        bool "RISC-V architecture"
        select CREATE_ARCH_SYMLINK
        select HAVE_SETJMP
+       select HAVE_INITJMP
        select SUPPORT_ACPI
        select SUPPORT_LITTLE_ENDIAN
        select SUPPORT_OF_CONTROL
index 99d6195..9e1f3d5 100644 (file)
@@ -59,3 +59,14 @@ ENTRY(longjmp)
        ret
 ENDPROC(longjmp)
 .popsection
+
+.pushsection .text.initjmp, "ax"
+ENTRY(initjmp)
+       /* a1: entry point address, a2: stack base, a3: stack size */
+       add a2, a2, a3
+       STORE_IDX(a1, 12)
+       STORE_IDX(a2, 13)
+       li  a0, 0
+       ret
+ENDPROC(initjmp)
+.popsection