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