1 /* 2 * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 #ifndef __TFM_UTILS_H__ 8 #define __TFM_UTILS_H__ 9 10 #include <string.h> 11 #include <stdint.h> 12 #include "tfm_log.h" 13 #include "cmsis_compiler.h" 14 15 /* 16 * CPU spin here. 17 * Note: this function is used to handle PROGRAMMER ERROR. 18 */ 19 __NO_RETURN void tfm_core_panic(void); 20 21 /* 22 * Accessor function to get the value of the spm_boundary 23 */ 24 uintptr_t get_spm_boundary(void); 25 26 /* Get container structure start address from member */ 27 #define TO_CONTAINER(ptr, type, member) \ 28 ((type *)((unsigned long)(ptr) - offsetof(type, member))) 29 30 #define ERROR_MSG(msg) ERROR_RAW(msg "\n") 31 32 /* Stringify preprocessors, no leading underscore. ('STRINGIFY') */ 33 #define STRINGIFY_EXPAND(x) #x 34 #define M2S(m) STRINGIFY_EXPAND(m) 35 36 /* Runtime memory operations forwarding */ 37 #ifndef spm_memcpy 38 #define spm_memcpy memcpy 39 #else 40 void *spm_memcpy(void *dest, const void *src, size_t n); 41 #endif /* spm_memcpy */ 42 43 #ifndef spm_memset 44 #define spm_memset memset 45 #else 46 void *spm_memset(void *s, int c, size_t n); 47 #endif /* spm_memset */ 48 49 #endif /* __TFM_UTILS_H__ */ 50