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 /* Get container structure start address from member */
20 #define TO_CONTAINER(ptr, type, member) \
21     (type *)((unsigned long)(ptr) - offsetof(type, member))
22 
23 /* FixMe: Replace ERROR_MSG() in platform code with a suitable API */
24 #define ERROR_MSG(msg) SPMLOG_ERRMSG(msg "\r\n")
25 
26 /* Stringify preprocessors, no leading underscore. ('STRINGIFY') */
27 #define STRINGIFY_EXPAND(x) #x
28 #define M2S(m) STRINGIFY_EXPAND(m)
29 
30 /* Runtime memory operations forwarding */
31 #ifndef spm_memcpy
32 #define spm_memcpy memcpy
33 #else
34 void *spm_memcpy(void *dest, const void *src, size_t n);
35 #endif /* spm_memcpy */
36 
37 #ifndef spm_memset
38 #define spm_memset memset
39 #else
40 void *spm_memset(void *s, int c, size_t n);
41 #endif /* spm_memset */
42 
43 #endif /* __TFM_UTILS_H__ */
44