mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-08-17 12:46:59 +02:00
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>
52 lines
1.0 KiB
ArmAsm
52 lines
1.0 KiB
ArmAsm
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
/*
|
|
* (C) 2017 Theobroma Systems Design und Consulting GmbH
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include <asm/macro.h>
|
|
#include <linux/linkage.h>
|
|
|
|
.pushsection .text.setjmp, "ax"
|
|
ENTRY(setjmp)
|
|
/* Preserve all callee-saved registers and the SP */
|
|
stp x19, x20, [x0,#0]
|
|
stp x21, x22, [x0,#16]
|
|
stp x23, x24, [x0,#32]
|
|
stp x25, x26, [x0,#48]
|
|
stp x27, x28, [x0,#64]
|
|
stp x29, x30, [x0,#80]
|
|
mov x2, sp
|
|
str x2, [x0, #96]
|
|
mov x0, #0
|
|
ret
|
|
ENDPROC(setjmp)
|
|
.popsection
|
|
|
|
.pushsection .text.longjmp, "ax"
|
|
ENTRY(longjmp)
|
|
ldp x19, x20, [x0,#0]
|
|
ldp x21, x22, [x0,#16]
|
|
ldp x23, x24, [x0,#32]
|
|
ldp x25, x26, [x0,#48]
|
|
ldp x27, x28, [x0,#64]
|
|
ldp x29, x30, [x0,#80]
|
|
ldr x2, [x0,#96]
|
|
mov sp, x2
|
|
/* Move the return value in place, but return 1 if passed 0. */
|
|
adds x0, xzr, x1
|
|
csinc x0, x0, xzr, ne
|
|
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
|