1 /* 2 * Copyright (c) 2024 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_ARCH_XTENSA_XTENSA_STACK_H_ 8 #define ZEPHYR_ARCH_XTENSA_XTENSA_STACK_H_ 9 10 #include <stdbool.h> 11 #include <stddef.h> 12 #include <stdint.h> 13 14 #include <xtensa_asm2_context.h> 15 16 /** 17 * @defgroup xtensa_stack_internal_apis Xtensa Stack related Internal APIs 18 * @ingroup xtensa_stack_apis 19 * @{ 20 */ 21 22 /** 23 * @brief Check if memory region is within correct stack boundaries. 24 * 25 * Check if the memory region [@a addr, (@a addr + @a sz)) is within 26 * correct stack boundaries: 27 * - Interrupt stack if servicing interrupts. 28 * - Privileged stack if in kernel mode doing syscalls. 29 * - Thread stack otherwise. 30 * 31 * @note When @ps == UINT32_MAX, it checks the whole range of stack 32 * object because we cannot get PS via frame pointer yet. 33 * 34 * @param addr Beginning address of memory region to check. 35 * @param sz Size of memory region to check. Can be zero. 36 * @param ps PS register value of interrupted context. Use UINT32_MAX if 37 * PS cannot be determined at time of call. 38 * 39 * @return True if memory region is outside stack bounds, false otherwise. 40 */ 41 bool xtensa_is_outside_stack_bounds(uintptr_t addr, size_t sz, uint32_t ps); 42 43 /** 44 * @brief Check if frame pointer is within correct stack boundaries. 45 * 46 * Check if the frame pointer and its associated BSA (base save area) are 47 * within correct stack boundaries. Use @ref xtensa_is_outside_stack_bounds 48 * to determine validity. 49 * 50 * @param frame Frame Pointer. Cannot be NULL. 51 */ 52 bool xtensa_is_frame_pointer_valid(_xtensa_irq_stack_frame_raw_t *frame); 53 54 /** 55 * @} 56 */ 57 58 #endif /* ZEPHYR_ARCH_XTENSA_XTENSA_STACK_H_ */ 59