SPM: Abstract NS configurations

Move configure_ns_code() operations into "Trustzone NS Agent" for the
IPC model. For the library model, move it into the library "main.c"
as a static function.

This abstraction leaves Trustzone specific operations to the Trustzone
NS Agent. The NS Agent thread entry keeps in assembly to accurately
control the stack usage.

Signed-off-by: Summer Qin <summer.qin@arm.com>
Change-Id: I25c3075627a418a1bc2f2f376d3eca6ddbc7aae0
diff --git a/secure_fw/spm/cmsis_func/main.c b/secure_fw/spm/cmsis_func/main.c
index 1a44ebc..b08a0d4 100644
--- a/secure_fw/spm/cmsis_func/main.c
+++ b/secure_fw/spm/cmsis_func/main.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -14,7 +14,6 @@
 #include "tfm_hal_platform.h"
 #include "tfm_hal_isolation.h"
 #include "tfm_irq_list.h"
-#include "tfm_nspm.h"
 #include "tfm_spm_hal.h"
 #include "tfm_spm_log.h"
 #include "tfm_version.h"
@@ -39,6 +38,25 @@
 REGION_DECLARE(Image$$, ARM_LIB_STACK,  $$ZI$$Limit)[];
 REGION_DECLARE(Image$$, ER_INITIAL_PSP,  $$ZI$$Limit)[];
 
+static void configure_ns_code(void)
+{
+    /* SCB_NS.VTOR points to the Non-secure vector table base address */
+    SCB_NS->VTOR = tfm_spm_hal_get_ns_VTOR();
+
+    /* Setups Main stack pointer of the non-secure code */
+    uint32_t ns_msp = tfm_spm_hal_get_ns_MSP();
+
+    __TZ_set_MSP_NS(ns_msp);
+
+    /* Get the address of non-secure code entry point to jump there */
+    uint32_t entry_ptr = tfm_spm_hal_get_ns_entry_point();
+
+    /* Clears LSB of the function address to indicate the function-call
+     * will perform the switch from secure to non-secure
+     */
+    ns_entry = (nsfptr_t)cmse_nsfptr_create(entry_ptr);
+}
+
 static fih_int tfm_core_init(void)
 {
     size_t i;