|
|
@@ -0,0 +1,66 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
|
|
|
+ *
|
|
|
+ * SPDX-License-Identifier: Apache-2.0
|
|
|
+ *
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the License); you may
|
|
|
+ * not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
|
|
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ *
|
|
|
+ * ----------------------------------------------------------------------
|
|
|
+ *
|
|
|
+ * main_s.c Code template for secure main function
|
|
|
+ *
|
|
|
+ * Version 1.0
|
|
|
+ * Initial Release
|
|
|
+ *---------------------------------------------------------------------------*/
|
|
|
+
|
|
|
+/* Use CMSE intrinsics */
|
|
|
+#include <arm_cmse.h>
|
|
|
+
|
|
|
+/* TZ_START_NS: Start address of non-secure application */
|
|
|
+#if !(defined (TZ_START__NS))
|
|
|
+ #define TZ_START_NS (0x200000U)
|
|
|
+#endif
|
|
|
+
|
|
|
+/* Generate BLXNS instruction */
|
|
|
+void NonSecure_Start (uint32_t addr);
|
|
|
+
|
|
|
+void NonSecure_Start (uint32_t addr) {
|
|
|
+ __ASM volatile ("MOV r0, %0\n\t"
|
|
|
+ "BLXNS r0\n\t" : : "r" (addr));
|
|
|
+}
|
|
|
+
|
|
|
+/* main function does not take arguments */
|
|
|
+#if !defined(__MICROLIB) && defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
|
+__asm(" .global __ARM_use_no_argv\n");
|
|
|
+#endif
|
|
|
+
|
|
|
+/* Secure main() */
|
|
|
+int main(void) {
|
|
|
+ volatile uint32_t NonSecure_ResetHandler;
|
|
|
+
|
|
|
+ /* Add user setup code for secure part here*/
|
|
|
+
|
|
|
+ /* Set non-secure main stack (MSP_NS) */
|
|
|
+ __TZ_set_MSP_NS(*((uint32_t *) (TZ_START_NS)));
|
|
|
+
|
|
|
+ /* Set non-secure main stack (MSP_NS) */
|
|
|
+ NonSecure_ResetHandler = cmse_nsfptr_create(*((uint32_t *)((TZ_START_NS) + 4u)));
|
|
|
+
|
|
|
+ /* Start non-secure state software application */
|
|
|
+ NonSecure_Start(NonSecure_ResetHandler);
|
|
|
+
|
|
|
+ /* Non-secure software does not return, this code is not executed */
|
|
|
+ while (1) {
|
|
|
+ __NOP( ) ;
|
|
|
+ }
|
|
|
+}
|