Mistake on this page?
Report an issue in GitHub or email us
secure_utilities.h
1 /*
2  * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __SECURE_UTILITIES_H__
9 #define __SECURE_UTILITIES_H__
10 
11 #include <stdio.h>
12 #include "cmsis_compiler.h"
13 #include "tfm_svc.h"
14 
15 #define EXC_RETURN_INDICATOR (0xF << 28)
16 #define EXC_RETURN_SECURITY_STACK_STATUS_MASK (0x3 << 5)
17 #define EXC_RETURN_SECURE_STACK (1 << 6)
18 #define EXC_RETURN_FPU_FRAME_BASIC (1 << 4)
19 #define EXC_RETURN_MODE_THREAD (1 << 3)
20 #define EXC_RETURN_STACK_PROCESS (1 << 2)
21 #define EXC_RETURN_EXC_SECURE (1)
22 
23 #define EXC_NUM_THREAD_MODE (0)
24 #define EXC_NUM_SVCALL (11)
25 #define EXC_NUM_PENDSV (14)
26 #define EXC_NUM_SYSTICK (15)
27 
28 #define printf(...)
29 
30 /* Disable NS exceptions by setting NS PRIMASK to 1 */
31 #define TFM_NS_EXC_DISABLE() __TZ_set_PRIMASK_NS(1)
32 /* Enable NS exceptions by setting NS PRIMASK to 0 */
33 #define TFM_NS_EXC_ENABLE() __TZ_set_PRIMASK_NS(0)
34 
36  uint32_t R0;
37  uint32_t R1;
38  uint32_t R2;
39  uint32_t R3;
40  uint32_t R12;
41  uint32_t LR;
42  uint32_t RetAddr;
43  uint32_t XPSR;
44 };
45 
46 #ifdef TFM_CORE_DEBUG
47 #define LOG_MSG_HDLR(MSG) printf("[Sec Handler] %s\r\n", MSG)
48 #else
49 /* FixMe: redirect to secure log area */
50 #define LOG_MSG_HDLR(MSG) printf("[Sec Handler] %s\r\n", MSG)
51 #endif
52 
53 #define LOG_MSG_THR(MSG) \
54  __ASM volatile("MOV r0, %0\n" \
55  "SVC %1\n" \
56  : : "r" (MSG), "I" (TFM_SVC_PRINT))
57 
58 #define LOG_MSG(MSG) \
59  do { \
60  if (__get_active_exc_num()) { \
61  LOG_MSG_HDLR(MSG); \
62  } else { \
63  LOG_MSG_THR(MSG); \
64  } \
65  } while (0)
66 
67 #ifdef TFM_CORE_DEBUG
68 #define ERROR_MSG(MSG) printf("[Sec Error] %s\r\n", MSG)
69 #else
70 /* FixMe: redirect to secure log area */
71 #define ERROR_MSG(MSG) printf("[Sec Error] %s\r\n", MSG)
72 #endif
73 
74 /**
75  * \brief Get Link Register
76  * \details Returns the value of the Link Register (LR)
77  * \return LR value
78  */
79 
80 __attribute__ ((always_inline)) __STATIC_INLINE uint32_t __get_LR(void)
81 {
82  register uint32_t result;
83 
84  __ASM volatile ("MOV %0, LR\n" : "=r" (result));
85  return result;
86 }
87 
88 __attribute__ ((always_inline))
89 __STATIC_INLINE uint32_t __get_active_exc_num(void)
90 {
91  IPSR_Type IPSR;
92 
93  /* if non-zero, exception is active. NOT banked S/NS */
94  IPSR.w = __get_IPSR();
95  return IPSR.b.ISR;
96 }
97 
98 __attribute__ ((always_inline))
99 __STATIC_INLINE void __set_CONTROL_SPSEL(uint32_t SPSEL)
100 {
101  CONTROL_Type ctrl;
102 
103  ctrl.w = __get_CONTROL();
104  ctrl.b.SPSEL = SPSEL;
105  __set_CONTROL(ctrl.w);
106  __ISB();
107 }
108 
109 #endif /* __SECURE_UTILITIES_H__ */
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.