Skip to content

Commit d3a44c2

Browse files
committed
Sync to V3.00.004
0 parents  commit d3a44c2

File tree

7,070 files changed

+2317477
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,070 files changed

+2317477
-0
lines changed

Document/CMSIS.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<title>Redirect to the CMSIS main page after 0 seconds</title>
5+
<meta http-equiv="refresh" content="0; URL=../Library/CMSIS/Documentation/General/html/index.html">
6+
<meta name="keywords" content="automatic redirection">
7+
</head>
8+
9+
<body>
10+
11+
If the automatic redirection is failing, click <a href="../Library/CMSIS/Documentation/General/html/index.html">open CMSIS Documentation</a>.
12+
13+
</body>
14+
</html>
18.4 MB
Binary file not shown.
270 KB
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2013-2016 ARM Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the License); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* ----------------------------------------------------------------------
19+
*
20+
* $Date: 15. October 2016
21+
* $Revision: 1.1.0
22+
*
23+
* Project: TrustZone for ARMv8-M
24+
* Title: Code template for secure main function
25+
*
26+
*---------------------------------------------------------------------------*/
27+
28+
/* Use CMSE intrinsics */
29+
#include <arm_cmse.h>
30+
31+
#include "RTE_Components.h"
32+
#include CMSIS_device_header
33+
34+
/* TZ_START_NS: Start address of non-secure application */
35+
#ifndef TZ_START_NS
36+
#define TZ_START_NS (0x200000U)
37+
#endif
38+
39+
/* typedef for non-secure callback functions */
40+
typedef void (*funcptr_void) (void) __attribute__((cmse_nonsecure_call));
41+
42+
/* Secure main() */
43+
int main(void) {
44+
funcptr_void NonSecure_ResetHandler;
45+
46+
/* Add user setup code for secure part here*/
47+
48+
/* Set non-secure main stack (MSP_NS) */
49+
__TZ_set_MSP_NS(*((uint32_t *)(TZ_START_NS)));
50+
51+
/* Get non-secure reset handler */
52+
NonSecure_ResetHandler = (funcptr_void)(*((uint32_t *)((TZ_START_NS) + 4U)));
53+
54+
/* Start non-secure state software application */
55+
NonSecure_ResetHandler();
56+
57+
/* Non-secure software does not return, this code is not executed */
58+
while (1) {
59+
__NOP();
60+
}
61+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
* Copyright (c) 2015-2016 ARM Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the License); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* ----------------------------------------------------------------------------
19+
*
20+
* $Date: 15. October 2016
21+
* $Revision: 1.1.0
22+
*
23+
* Project: TrustZone for ARMv8-M
24+
* Title: Context Management for ARMv8-M TrustZone - Sample implementation
25+
*
26+
*---------------------------------------------------------------------------*/
27+
28+
#include "RTE_Components.h"
29+
#include CMSIS_device_header
30+
#include "tz_context.h"
31+
32+
/// Number of process slots (threads may call secure library code)
33+
#ifndef TZ_PROCESS_STACK_SLOTS
34+
#define TZ_PROCESS_STACK_SLOTS 8U
35+
#endif
36+
37+
/// Stack size of the secure library code
38+
#ifndef TZ_PROCESS_STACK_SIZE
39+
#define TZ_PROCESS_STACK_SIZE 256U
40+
#endif
41+
42+
typedef struct {
43+
uint32_t sp_top; // stack space top
44+
uint32_t sp_limit; // stack space limit
45+
uint32_t sp; // current stack pointer
46+
} stack_info_t;
47+
48+
static stack_info_t ProcessStackInfo [TZ_PROCESS_STACK_SLOTS];
49+
static uint64_t ProcessStackMemory[TZ_PROCESS_STACK_SLOTS][TZ_PROCESS_STACK_SIZE/8U];
50+
static uint32_t ProcessStackFreeSlot = 0xFFFFFFFFU;
51+
52+
53+
/// Initialize secure context memory system
54+
/// \return execution status (1: success, 0: error)
55+
__attribute__((cmse_nonsecure_entry))
56+
uint32_t TZ_InitContextSystem_S (void) {
57+
uint32_t n;
58+
59+
if (__get_IPSR() == 0U) {
60+
return 0U; // Thread Mode
61+
}
62+
63+
for (n = 0U; n < TZ_PROCESS_STACK_SLOTS; n++) {
64+
ProcessStackInfo[n].sp = 0U;
65+
ProcessStackInfo[n].sp_limit = (uint32_t)&ProcessStackMemory[n];
66+
ProcessStackInfo[n].sp_top = (uint32_t)&ProcessStackMemory[n] + TZ_PROCESS_STACK_SIZE;
67+
*((uint32_t *)ProcessStackMemory[n]) = n + 1U;
68+
}
69+
*((uint32_t *)ProcessStackMemory[--n]) = 0xFFFFFFFFU;
70+
71+
ProcessStackFreeSlot = 0U;
72+
73+
// Default process stack pointer and stack limit
74+
__set_PSPLIM((uint32_t)ProcessStackMemory);
75+
__set_PSP ((uint32_t)ProcessStackMemory);
76+
77+
// Privileged Thread Mode using PSP
78+
__set_CONTROL(0x02U);
79+
80+
return 1U; // Success
81+
}
82+
83+
84+
/// Allocate context memory for calling secure software modules in TrustZone
85+
/// \param[in] module identifies software modules called from non-secure mode
86+
/// \return value != 0 id TrustZone memory slot identifier
87+
/// \return value 0 no memory available or internal error
88+
__attribute__((cmse_nonsecure_entry))
89+
TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module) {
90+
uint32_t slot;
91+
92+
(void)module; // Ignore (fixed Stack size)
93+
94+
if (__get_IPSR() == 0U) {
95+
return 0U; // Thread Mode
96+
}
97+
98+
if (ProcessStackFreeSlot == 0xFFFFFFFFU) {
99+
return 0U; // No slot available
100+
}
101+
102+
slot = ProcessStackFreeSlot;
103+
ProcessStackFreeSlot = *((uint32_t *)ProcessStackMemory[slot]);
104+
105+
ProcessStackInfo[slot].sp = ProcessStackInfo[slot].sp_top;
106+
107+
return (slot + 1U);
108+
}
109+
110+
111+
/// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S
112+
/// \param[in] id TrustZone memory slot identifier
113+
/// \return execution status (1: success, 0: error)
114+
__attribute__((cmse_nonsecure_entry))
115+
uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id) {
116+
uint32_t slot;
117+
118+
if (__get_IPSR() == 0U) {
119+
return 0U; // Thread Mode
120+
}
121+
122+
if ((id == 0U) || (id > TZ_PROCESS_STACK_SLOTS)) {
123+
return 0U; // Invalid ID
124+
}
125+
126+
slot = id - 1U;
127+
128+
if (ProcessStackInfo[slot].sp == 0U) {
129+
return 0U; // Inactive slot
130+
}
131+
ProcessStackInfo[slot].sp = 0U;
132+
133+
*((uint32_t *)ProcessStackMemory[slot]) = ProcessStackFreeSlot;
134+
ProcessStackFreeSlot = slot;
135+
136+
return 1U; // Success
137+
}
138+
139+
140+
/// Load secure context (called on RTOS thread context switch)
141+
/// \param[in] id TrustZone memory slot identifier
142+
/// \return execution status (1: success, 0: error)
143+
__attribute__((cmse_nonsecure_entry))
144+
uint32_t TZ_LoadContext_S (TZ_MemoryId_t id) {
145+
uint32_t slot;
146+
147+
if ((__get_IPSR() == 0U) || ((__get_CONTROL() & 2U) == 0U)) {
148+
return 0U; // Thread Mode or using Main Stack for threads
149+
}
150+
151+
if ((id == 0U) || (id > TZ_PROCESS_STACK_SLOTS)) {
152+
return 0U; // Invalid ID
153+
}
154+
155+
slot = id - 1U;
156+
157+
if (ProcessStackInfo[slot].sp == 0U) {
158+
return 0U; // Inactive slot
159+
}
160+
161+
// Setup process stack pointer and stack limit
162+
__set_PSPLIM(ProcessStackInfo[slot].sp_limit);
163+
__set_PSP (ProcessStackInfo[slot].sp);
164+
165+
return 1U; // Success
166+
}
167+
168+
169+
/// Store secure context (called on RTOS thread context switch)
170+
/// \param[in] id TrustZone memory slot identifier
171+
/// \return execution status (1: success, 0: error)
172+
__attribute__((cmse_nonsecure_entry))
173+
uint32_t TZ_StoreContext_S (TZ_MemoryId_t id) {
174+
uint32_t slot;
175+
uint32_t sp;
176+
177+
if ((__get_IPSR() == 0U) || ((__get_CONTROL() & 2U) == 0U)) {
178+
return 0U; // Thread Mode or using Main Stack for threads
179+
}
180+
181+
if ((id == 0U) || (id > TZ_PROCESS_STACK_SLOTS)) {
182+
return 0U; // Invalid ID
183+
}
184+
185+
slot = id - 1U;
186+
187+
if (ProcessStackInfo[slot].sp == 0U) {
188+
return 0U; // Inactive slot
189+
}
190+
191+
sp = __get_PSP();
192+
if ((sp < ProcessStackInfo[slot].sp_limit) ||
193+
(sp > ProcessStackInfo[slot].sp_top)) {
194+
return 0U; // SP out of range
195+
}
196+
ProcessStackInfo[slot].sp = sp;
197+
198+
// Default process stack pointer and stack limit
199+
__set_PSPLIM((uint32_t)ProcessStackMemory);
200+
__set_PSP ((uint32_t)ProcessStackMemory);
201+
202+
return 1U; // Success
203+
}

0 commit comments

Comments
 (0)