diff options
author | Jeenu Viswambharan <jeenu.viswambharan@arm.com> | 2018-02-16 11:54:24 +0000 |
---|---|---|
committer | Jeenu Viswambharan <jeenu.viswambharan@arm.com> | 2018-06-21 16:15:23 +0100 |
commit | e7b9473e1591d4ab375a95ebbb9256adfe9d4670 (patch) | |
tree | 97e17803652b72586ae0e099e6e367f534dea2e5 /include | |
parent | 2ccfcb2ea555eb86122e7780010cc50fcee08f54 (diff) | |
download | platform_external_arm-trusted-firmware-e7b9473e1591d4ab375a95ebbb9256adfe9d4670.tar.gz platform_external_arm-trusted-firmware-e7b9473e1591d4ab375a95ebbb9256adfe9d4670.tar.bz2 platform_external_arm-trusted-firmware-e7b9473e1591d4ab375a95ebbb9256adfe9d4670.zip |
BL31: Introduce jump primitives
This patch introduces setjmp() and ongjmp() primitives to enable
standard setjmp/longjmp style execution. Both APIs parameters take a
pointer to struct jmpbuf type, which hosts CPU registers saved/restored
during jump.
As per the standard usage:
- setjmp() return 0 when a jump is setup; and a non-zero value when
returning from jump.
- The caller of setjmp() must not return, or otherwise update stack
pointer since.
Change-Id: I4af1d32e490cfa547979631b762b4cba188d0551
Signed-off-by: Jeenu Viswambharan <jeenu.viswambharan@arm.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/lib/aarch64/setjmp.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/include/lib/aarch64/setjmp.h b/include/lib/aarch64/setjmp.h new file mode 100644 index 000000000..c65810d82 --- /dev/null +++ b/include/lib/aarch64/setjmp.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef __JMP_H__ +#define __JMP_H__ + +#define JMP_CTX_X19 0x0 +#define JMP_CTX_X21 0x10 +#define JMP_CTX_X23 0x20 +#define JMP_CTX_X25 0x30 +#define JMP_CTX_X27 0x40 +#define JMP_CTX_X29 0x50 +#define JMP_CTX_SP 0x60 +#define JMP_CTX_END 0x70 + +#define JMP_SIZE (JMP_CTX_END >> 3) + +#ifndef __ASSEMBLY__ + +#include <stdint.h> + +/* Jump buffer hosting x18 - x30 and sp_el0 registers */ +struct jmpbuf { + uint64_t buf[JMP_SIZE]; +} __aligned(16); + + +/* + * Set a jump point, and populate the jump buffer with context information so + * that longjmp() can jump later. The caller must adhere to the following + * conditions: + * + * - After calling this function, the stack must not be shrunk. The contents of + * the stack must not be changed either. + * + * - If the caller were to 'return', the buffer must be considered invalid, and + * must not be used with longjmp(). + * + * The caller will observe this function returning at two distinct + * circumstances, each with different return values: + * + * - Zero, when the buffer is setup; + * + * - Non-zero, when a call to longjmp() is made (presumably by one of the + * callee functions) with the same jump buffer. + */ +int setjmp(struct jmpbuf *buf); + +/* + * Reset execution to a jump point, and restore context information according to + * the jump buffer populated by setjmp(). + */ +void longjmp(struct jmpbuf *buf); + +#endif /* __ASSEMBLY__ */ +#endif /* __JMP_H__ */ |