1 /* 2 * Copyright (c) 2018-2022, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 #ifndef __TFM_UTILS_H__ 8 #define __TFM_UTILS_H__ 9 10 #include <stdbool.h> 11 #include <string.h> 12 #include "tfm_spm_log.h" 13 14 /* 15 * CPU spin here. 16 * Note: this function is used to handle PROGRAMMER ERROR. 17 */ 18 void tfm_core_panic(void); 19 20 /* SPM assert */ 21 #ifndef NDEBUG 22 #define SPM_ASSERT(cond) \ 23 do { \ 24 if (!(cond)) { \ 25 SPMLOG_INFMSG("Assert:"); \ 26 SPMLOG_INFMSG(__func__); \ 27 SPMLOG_INFMSGVAL(",", __LINE__); \ 28 while (1) \ 29 ; \ 30 } \ 31 } while (0) 32 #else 33 #define SPM_ASSERT(cond) 34 #endif 35 36 /* Get container structure start address from member */ 37 #define TO_CONTAINER(ptr, type, member) \ 38 (type *)((unsigned long)(ptr) - offsetof(type, member)) 39 40 /* FixMe: Replace ERROR_MSG() in platform code with a suitable API */ 41 #define ERROR_MSG(msg) SPMLOG_ERRMSG(msg "\r\n") 42 43 /* Stringify preprocessors, no leading underscore. ('STRINGIFY') */ 44 #define STRINGIFY_EXPAND(x) #x 45 #define M2S(m) STRINGIFY_EXPAND(m) 46 47 /* Runtime memory operations forwarding */ 48 #ifndef spm_memcpy 49 #define spm_memcpy memcpy 50 #endif /* spm_memcpy */ 51 52 #ifndef spm_memset 53 #define spm_memset memset 54 #endif /* spm_memset */ 55 56 #endif /* __TFM_UTILS_H__ */ 57