2 * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * ----------------------------------------------------------------------
20 * main_s.c Code template for secure main function
24 *---------------------------------------------------------------------------*/
26 /* Use CMSE intrinsics */
29 #include "RTE_Components.h"
30 #include CMSIS_device_header
32 /* TZ_START_NS: Start address of non-secure application */
34 #define TZ_START_NS (0x200000U)
37 /* Default process stack size */
38 #ifndef PROCESS_STACK_SIZE
39 #define PROCESS_STACK_SIZE 256U
42 /* Default process stack */
43 static uint64_t ProcessStack[PROCESS_STACK_SIZE/8U];
45 /* Generate BLXNS instruction */
46 void NonSecure_Start (uint32_t addr) __attribute__((always_inline));
47 void NonSecure_Start (uint32_t addr) {
48 __ASM volatile ("blxns %[addr]" : : [addr] "l" (addr));
54 volatile uint32_t NonSecure_ResetHandler;
56 /* Add user setup code for secure part here*/
58 /* Set non-secure main stack (MSP_NS) */
59 __TZ_set_MSP_NS(*((uint32_t *)(TZ_START_NS)));
61 /* Set default PSP, PSPLIM and privileged Thread Mode using PSP */
62 __set_PSPLIM((uint32_t)ProcessStack);
63 __set_PSP ((uint32_t)ProcessStack + PROCESS_STACK_SIZE);
66 /* Get non-secure reset hanlder */
67 NonSecure_ResetHandler = cmse_nsfptr_create(*((uint32_t *)((TZ_START_NS) + 4U)));
69 /* Start non-secure state software application */
70 NonSecure_Start(NonSecure_ResetHandler);
72 /* Non-secure software does not return, this code is not executed */