Jeenu Viswambharan | 2de8153 | 2018-02-16 11:54:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef __JMP_H__ |
| 8 | #define __JMP_H__ |
| 9 | |
| 10 | #define JMP_CTX_X19 0x0 |
| 11 | #define JMP_CTX_X21 0x10 |
| 12 | #define JMP_CTX_X23 0x20 |
| 13 | #define JMP_CTX_X25 0x30 |
| 14 | #define JMP_CTX_X27 0x40 |
| 15 | #define JMP_CTX_X29 0x50 |
| 16 | #define JMP_CTX_SP 0x60 |
| 17 | #define JMP_CTX_END 0x70 |
| 18 | |
| 19 | #define JMP_SIZE (JMP_CTX_END >> 3) |
| 20 | |
| 21 | #ifndef __ASSEMBLY__ |
| 22 | |
| 23 | #include <stdint.h> |
| 24 | |
| 25 | /* Jump buffer hosting x18 - x30 and sp_el0 registers */ |
| 26 | struct jmpbuf { |
| 27 | uint64_t buf[JMP_SIZE]; |
| 28 | } __aligned(16); |
| 29 | |
| 30 | |
| 31 | /* |
| 32 | * Set a jump point, and populate the jump buffer with context information so |
| 33 | * that longjmp() can jump later. The caller must adhere to the following |
| 34 | * conditions: |
| 35 | * |
| 36 | * - After calling this function, the stack must not be shrunk. The contents of |
| 37 | * the stack must not be changed either. |
| 38 | * |
| 39 | * - If the caller were to 'return', the buffer must be considered invalid, and |
| 40 | * must not be used with longjmp(). |
| 41 | * |
| 42 | * The caller will observe this function returning at two distinct |
| 43 | * circumstances, each with different return values: |
| 44 | * |
| 45 | * - Zero, when the buffer is setup; |
| 46 | * |
| 47 | * - Non-zero, when a call to longjmp() is made (presumably by one of the |
| 48 | * callee functions) with the same jump buffer. |
| 49 | */ |
| 50 | int setjmp(struct jmpbuf *buf); |
| 51 | |
| 52 | /* |
| 53 | * Reset execution to a jump point, and restore context information according to |
| 54 | * the jump buffer populated by setjmp(). |
| 55 | */ |
| 56 | void longjmp(struct jmpbuf *buf); |
| 57 | |
| 58 | #endif /* __ASSEMBLY__ */ |
| 59 | #endif /* __JMP_H__ */ |