TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 #ifndef __TFM_ARCH_H__
8 #define __TFM_ARCH_H__
9 
10 /* This header file collects the architecture related operations. */
11 
12 #include <stddef.h>
13 #include <inttypes.h>
14 #include "tfm_hal_device_header.h"
15 #include "cmsis_compiler.h"
16 
17 #if defined(__ARM_ARCH_8_1M_MAIN__) || \
18  defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8M_BASE__)
19 #include "tfm_arch_v8m.h"
20 #elif defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_7M__) || \
21  defined(__ARM_ARCH_7EM__)
22 #include "tfm_arch_v6m_v7m.h"
23 #else
24 #error "Unsupported ARM Architecture."
25 #endif
26 
27 #define XPSR_T32 0x01000000
28 
29 /* General core state context */
31  uint32_t r0;
32  uint32_t r1;
33  uint32_t r2;
34  uint32_t r3;
35  uint32_t r12;
36  uint32_t lr;
37  uint32_t ra;
38  uint32_t xpsr;
39 };
40 
41 #define TFM_STATE_RET_VAL(ctx) (((struct tfm_state_context_t *)((ctx)->sp))->r0)
42 
43 __attribute__ ((always_inline))
44 __STATIC_INLINE void tfm_arch_trigger_pendsv(void)
45 {
46  SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
47 }
48 
54 #if !defined ( __ICCARM__ )
55 __attribute__ ((always_inline)) __STATIC_INLINE uint32_t __get_LR(void)
56 {
57  register uint32_t result;
58 
59  __ASM volatile ("MOV %0, LR\n" : "=r" (result));
60  return result;
61 }
62 #endif
63 
64 __attribute__ ((always_inline))
65 __STATIC_INLINE uint32_t __get_active_exc_num(void)
66 {
67  IPSR_Type IPSR;
68 
69  /* if non-zero, exception is active. NOT banked S/NS */
70  IPSR.w = __get_IPSR();
71  return IPSR.b.ISR;
72 }
73 
74 __attribute__ ((always_inline))
75 __STATIC_INLINE void __set_CONTROL_SPSEL(uint32_t SPSEL)
76 {
77  CONTROL_Type ctrl;
78 
79  ctrl.w = __get_CONTROL();
80  ctrl.b.SPSEL = SPSEL;
81  __set_CONTROL(ctrl.w);
82  __ISB();
83 }
84 
85 /*
86  * Initialize CPU architecture specific thread context extension
87  */
88 void tfm_arch_init_actx(struct tfm_arch_ctx_t *p_actx,
89  uint32_t sp, uint32_t sp_limit);
90 
91 /*
92  * Set secure exceptions priority
93  */
95 
100 
101 /*
102  * Clear float point status.
103  */
104 void tfm_arch_clear_fp_status(void);
105 
106 void tfm_arch_init_context(struct tfm_arch_ctx_t *p_actx,
107  void *param, uintptr_t pfn,
108  uintptr_t stk_btm, uintptr_t stk_top);
109 #endif
void tfm_arch_configure_coprocessors(void)
Configure coprocessors.
Definition: arch.c:271
void tfm_arch_clear_fp_status(void)
void tfm_arch_init_actx(struct tfm_arch_ctx_t *p_actx, uint32_t sp, uint32_t sp_limit)
__STATIC_INLINE uint32_t __get_active_exc_num(void)
Definition: tfm_arch.h:65
__STATIC_INLINE void __set_CONTROL_SPSEL(uint32_t SPSEL)
Definition: tfm_arch.h:75
void tfm_arch_set_secure_exception_priorities(void)
void tfm_arch_init_context(struct tfm_arch_ctx_t *p_actx, void *param, uintptr_t pfn, uintptr_t stk_btm, uintptr_t stk_top)
Definition: tfm_arch.c:57
__STATIC_INLINE uint32_t __get_LR(void)
Get Link Register.
Definition: tfm_arch.h:55
__STATIC_INLINE void tfm_arch_trigger_pendsv(void)
Definition: tfm_arch.h:44