TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_arch.c
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 
8 #include "tfm_arch.h"
9 #include "tfm_core_utils.h"
10 #include "tfm/tfm_core_svc.h"
11 #include "tfm/tfm_spm_services.h"
12 
13 __attribute__((naked))
14 static int32_t tfm_spm_request(int32_t request_type)
15 {
16  __ASM volatile(
17  "SVC %0\n"
18  "BX lr\n"
19  : : "I" (TFM_SVC_SPM_REQUEST));
20 }
21 
23 {
24  return tfm_spm_request((int32_t)TFM_SPM_REQUEST_RESET_VOTE);
25 }
26 
27 __attribute__((naked))
28 void tfm_enable_irq(psa_signal_t irq_signal)
29 {
30  __ASM("SVC %0\n"
31  "BX LR\n"
32  : : "I" (TFM_SVC_ENABLE_IRQ));
33 }
34 
35 __attribute__((naked))
36 void tfm_disable_irq(psa_signal_t irq_signal)
37 {
38  __ASM("SVC %0\n"
39  "BX LR\n"
40  : : "I" (TFM_SVC_DISABLE_IRQ));
41 }
42 
43 static void tfm_arch_init_state_ctx(struct tfm_state_context_t *p_stat_ctx,
44  void *param, uintptr_t pfn)
45 {
46  p_stat_ctx->r0 = (uint32_t)param;
47  p_stat_ctx->ra = (uint32_t)pfn;
48  /*
49  * Prevent thread exits:
50  * Only T32 is supported, so bit[0] must be 1. Clear the bit[0] of LR to
51  * trigger a fault.
52  */
53  p_stat_ctx->lr = ((uint32_t)pfn) & (~1UL);
54  p_stat_ctx->xpsr = XPSR_T32;
55 }
56 
58  void *param, uintptr_t pfn,
59  uintptr_t stk_btm, uintptr_t stk_top)
60 {
61  /*
62  * For security consideration, set unused registers into ZERO;
63  * and only necessary registers are set here.
64  */
65  struct tfm_state_context_t *p_stat_ctx=
67 
68  /*
69  * Shift back SP to leave space for holding base context
70  * since thread is kicked off through exception return.
71  */
72  p_stat_ctx--;
73 
74  /* State context is considerate at thread start.*/
75  spm_memset(p_stat_ctx, 0, sizeof(*p_stat_ctx));
76  tfm_arch_init_state_ctx(p_stat_ctx, param, pfn);
77 
78  /* Initialize architecture context */
79  spm_memset(p_actx, 0, sizeof(*p_actx));
80  tfm_arch_init_actx(p_actx, (uint32_t)p_stat_ctx, (uint32_t)stk_btm);
81 }
void tfm_arch_init_actx(struct tfm_arch_ctx_t *p_actx, uint32_t sp, uint32_t sp_limit)
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
uint32_t psa_signal_t
Definition: service.h:50
int32_t tfm_spm_request_reset_vote(void)
Request a vote from SPM on a system reset.
Definition: tfm_arch.c:22
void * spm_memset(void *s, int c, size_t n)
Memory set function for TF-M core.
void tfm_enable_irq(psa_signal_t irq_signal)
Definition: tfm_arch.c:28
#define XPSR_T32
Definition: tfm_arch.h:27
void tfm_disable_irq(psa_signal_t irq_signal)
Definition: tfm_arch.c:36
__STATIC_INLINE uintptr_t tfm_arch_seal_thread_stack(uintptr_t stk)
Seal the thread stack.