]> begriffs open source - cmsis/blob - CMSIS/Core/Template/ARMv8-M/main_s.c
removed AC6.6 compiler work-around
[cmsis] / CMSIS / Core / Template / ARMv8-M / main_s.c
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  * http://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  * main_s.c      Code template for secure main function 
21  *
22  * Version 1.0
23  *    Initial Release
24  *---------------------------------------------------------------------------*/
25  
26 /* Use CMSE intrinsics */
27 #include <arm_cmse.h>
28  
29 #include "RTE_Components.h"
30 #include CMSIS_device_header
31  
32 /* TZ_START_NS: Start address of non-secure application */
33 #ifndef TZ_START_NS
34 #define TZ_START_NS (0x200000U)
35 #endif
36  
37 /* Default process stack size */
38 #ifndef PROCESS_STACK_SIZE
39 #define PROCESS_STACK_SIZE 256U
40 #endif
41  
42 /* Default process stack */
43 static uint64_t ProcessStack[PROCESS_STACK_SIZE/8U];
44  
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));
49 }
50  
51  
52 /* Secure main() */
53 int main(void) {
54   volatile uint32_t NonSecure_ResetHandler;
55  
56   /* Add user setup code for secure part here*/
57  
58   /* Set non-secure main stack (MSP_NS) */
59   __TZ_set_MSP_NS(*((uint32_t *)(TZ_START_NS)));
60
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);
64   __set_CONTROL(0x02U);
65  
66   /* Get non-secure reset hanlder */
67   NonSecure_ResetHandler = cmse_nsfptr_create(*((uint32_t *)((TZ_START_NS) + 4U)));
68  
69   /* Start non-secure state software application */
70   NonSecure_Start(NonSecure_ResetHandler);
71  
72   /* Non-secure software does not return, this code is not executed */
73   while (1) {
74     __NOP();
75   }
76 }