xref: /optee_os/lib/libutils/isoc/include/setjmp.h (revision acf0775432668c5f5b027c7851cc40823835968f)
11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-3-Clause */
20c81fcd6SJens Wiklander /*
30c81fcd6SJens Wiklander  * Copyright (c) 1994-2009  Red Hat, Inc.
40c81fcd6SJens Wiklander  * Copyright (c) 2016, Linaro Limited
5*acf07754SMarouene Boubakri  * Copyright 2022-2023 NXP
60c81fcd6SJens Wiklander  * All rights reserved.
70c81fcd6SJens Wiklander  *
80c81fcd6SJens Wiklander  * Redistribution and use in source and binary forms, with or without
90c81fcd6SJens Wiklander  * modification, are permitted provided that the following conditions are met:
100c81fcd6SJens Wiklander  *
110c81fcd6SJens Wiklander  * 1. Redistributions of source code must retain the above copyright notice,
120c81fcd6SJens Wiklander  * this list of conditions and the following disclaimer.
130c81fcd6SJens Wiklander  *
140c81fcd6SJens Wiklander  * 2. Redistributions in binary form must reproduce the above copyright notice,
150c81fcd6SJens Wiklander  * this list of conditions and the following disclaimer in the documentation
160c81fcd6SJens Wiklander  * and/or other materials provided with the distribution.
170c81fcd6SJens Wiklander  *
180c81fcd6SJens Wiklander  * 3. Neither the name of the copyright holder nor the names of its
190c81fcd6SJens Wiklander  * contributors may be used to endorse or promote products derived from this
200c81fcd6SJens Wiklander  * software without specific prior written permission.
210c81fcd6SJens Wiklander  *
220c81fcd6SJens Wiklander  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
230c81fcd6SJens Wiklander  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
240c81fcd6SJens Wiklander  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
250c81fcd6SJens Wiklander  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
260c81fcd6SJens Wiklander  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
270c81fcd6SJens Wiklander  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
280c81fcd6SJens Wiklander  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
290c81fcd6SJens Wiklander  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
300c81fcd6SJens Wiklander  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
310c81fcd6SJens Wiklander  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
320c81fcd6SJens Wiklander  * POSSIBILITY OF SUCH DAMAGE.
330c81fcd6SJens Wiklander  */
340c81fcd6SJens Wiklander 
350c81fcd6SJens Wiklander #ifndef __SETJMP_H
360c81fcd6SJens Wiklander #define __SETJMP_H
370c81fcd6SJens Wiklander 
38f88850d4SJerome Forissier #include <compiler.h>
39f88850d4SJerome Forissier 
402fa93c74SJens Wiklander #if defined(ARM32)
410c81fcd6SJens Wiklander /*
420c81fcd6SJens Wiklander  * All callee preserved registers:
430c81fcd6SJens Wiklander  * v1 - v7, fp, ip, sp, lr, f4, f5, f6, f7
44c96d7091SSumit Garg  * One additional 32-bit value used in case ftrace
45c96d7091SSumit Garg  * is enabled to restore ftrace return stack.
460c81fcd6SJens Wiklander  */
47c96d7091SSumit Garg #define _JBLEN 24
482fa93c74SJens Wiklander #define _JBTYPE int
490c81fcd6SJens Wiklander #endif
500c81fcd6SJens Wiklander 
512fa93c74SJens Wiklander #if defined(ARM64)
520c81fcd6SJens Wiklander #define _JBLEN 22
530c81fcd6SJens Wiklander #define _JBTYPE long long
540c81fcd6SJens Wiklander #endif
55*acf07754SMarouene Boubakri /*
56*acf07754SMarouene Boubakri  * Callee preserved registers:
57*acf07754SMarouene Boubakri  * s0-s11, ra, sp
58*acf07754SMarouene Boubakri  */
59*acf07754SMarouene Boubakri #if defined(RV64) || defined(RV32)
60*acf07754SMarouene Boubakri #define _JBLEN 14
61*acf07754SMarouene Boubakri #define _JBTYPE unsigned long
62*acf07754SMarouene Boubakri #endif
630c81fcd6SJens Wiklander 
640c81fcd6SJens Wiklander #ifdef _JBLEN
650c81fcd6SJens Wiklander typedef	_JBTYPE jmp_buf[_JBLEN];
660c81fcd6SJens Wiklander #endif
670c81fcd6SJens Wiklander 
68f88850d4SJerome Forissier void __noreturn longjmp(jmp_buf env, int val);
690c81fcd6SJens Wiklander int setjmp(jmp_buf env);
700c81fcd6SJens Wiklander 
71099918f6SSumit Garg #ifdef CFG_FTRACE_SUPPORT
729d6ac097SSumit Garg void ftrace_longjmp(unsigned int *ret_idx);
739d6ac097SSumit Garg void ftrace_setjmp(unsigned int *ret_idx);
749d6ac097SSumit Garg #endif
759d6ac097SSumit Garg 
760c81fcd6SJens Wiklander #endif /*__SETJMP_H*/
77