SPM : Arch: Update MSP resetting logic

VTOR MAY NOT exist in a particular platform, skip relying
on VTOR to get MSP initial value when resetting MSP.

Change-Id: I1010ba751b1d98cfe63b3f331b48ab5a2d9c93ae
Signed-off-by: Ken Liu <Ken.Liu@arm.com>
diff --git a/secure_fw/spm/cmsis_psa/arch/tfm_arch.c b/secure_fw/spm/cmsis_psa/arch/tfm_arch.c
index b2a1e5a..297edf2 100644
--- a/secure_fw/spm/cmsis_psa/arch/tfm_arch.c
+++ b/secure_fw/spm/cmsis_psa/arch/tfm_arch.c
@@ -5,23 +5,22 @@
  *
  */
 
+#include "compiler_ext_defs.h"
+#include "security_defs.h"
 #include "tfm_arch.h"
 #include "tfm_core_utils.h"
 #include "utilities.h"
 
-__attribute__((naked)) void tfm_arch_free_msp_and_exc_ret(uint32_t exc_return)
+__naked void tfm_arch_free_msp_and_exc_ret(uint32_t msp_base,
+                                           uint32_t exc_return)
 {
     __ASM volatile(
 #if !defined(__ICCARM__)
         ".syntax unified                        \n"
 #endif
-        "mov     lr, r0                         \n"
-        "ldr     r0, ="M2S(SCB_VTOR_ADDR)"      \n" /* VTOR */
-        "ldr     r0, [r0]                       \n" /* MSP address */
-        "ldr     r0, [r0]                       \n" /* MSP */
-        "subs    r0, #8                         \n" /* Exclude stack seal */
-        "msr     msp, r0                        \n" /* Free Main Stack space */
-        "bx      lr                             \n"
+        "subs    r0, #8                         \n" /* SEAL room */
+        "msr     msp, r0                        \n"
+        "bx      r1                             \n"
     );
 }
 
diff --git a/secure_fw/spm/cmsis_psa/arch/tfm_arch_v6m_v7m.h b/secure_fw/spm/cmsis_psa/arch/tfm_arch_v6m_v7m.h
index 13c6429..4ee058d 100644
--- a/secure_fw/spm/cmsis_psa/arch/tfm_arch_v6m_v7m.h
+++ b/secure_fw/spm/cmsis_psa/arch/tfm_arch_v6m_v7m.h
@@ -38,16 +38,6 @@
 #define SCB_ICSR_ADDR                   (0xE000ED04)
 #define SCB_ICSR_PENDSVSET_BIT          (0x10000000)
 
-/*
- * Report an error at current when VTOR does not present.
- * TODO: Do not rely on VTOR to retrieve MSP initial value.
- */
-#if defined(__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
-#define SCB_VTOR_ADDR                    (0xE000ED08)
-#else
-#error "VTOR not present, check configurations."
-#endif
-
 /**
  * \brief Check whether Secure or Non-secure stack is used to restore stack
  *        frame on exception return.
diff --git a/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c b/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
index d92cffe..1a08bb9 100644
--- a/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
+++ b/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
@@ -223,7 +223,9 @@
         tfm_arch_clear_fp_status();
         exc_return = tfm_spm_init();
         /* The following call does not return */
-        tfm_arch_free_msp_and_exc_ret(exc_return);
+        tfm_arch_free_msp_and_exc_ret(
+            (uint32_t)&REGION_NAME(Image$$, ARM_LIB_STACK, $$ZI$$Limit),
+            exc_return);
         break;
     case TFM_SVC_GET_BOOT_DATA:
         tfm_core_get_boot_data_handler(svc_args);
diff --git a/secure_fw/spm/include/tfm_arch.h b/secure_fw/spm/include/tfm_arch.h
index 70b21a6..a754d5f 100644
--- a/secure_fw/spm/include/tfm_arch.h
+++ b/secure_fw/spm/include/tfm_arch.h
@@ -132,7 +132,7 @@
  * It frees the stack used by SPM initialization and do Exception Return.
  * It does not return.
  */
-void tfm_arch_free_msp_and_exc_ret(uint32_t exc_return);
+void tfm_arch_free_msp_and_exc_ret(uint32_t msp_base, uint32_t exc_return);
 
 /*
  * This function sets return value on APIs that cause scheduling, for example
diff --git a/secure_fw/spm/include/tfm_arch_v8m.h b/secure_fw/spm/include/tfm_arch_v8m.h
index 3cb4db0..e03ae8a 100644
--- a/secure_fw/spm/include/tfm_arch_v8m.h
+++ b/secure_fw/spm/include/tfm_arch_v8m.h
@@ -48,16 +48,6 @@
 #define SCB_ICSR_ADDR                    (0xE000ED04)
 #define SCB_ICSR_PENDSVSET_BIT           (0x10000000)
 
-/*
- * Shout an error at current when VTOR does not present.
- * TODO: Do not rely on VTOR to retrieve MSP initial value.
- */
-#if defined(__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
-#define SCB_VTOR_ADDR                    (0xE000ED08)
-#else
-#error "VTOR not present, check configurations."
-#endif
-
 /* Disable NS exceptions by setting NS PRIMASK to 1 */
 #define TFM_NS_EXC_DISABLE()    __TZ_set_PRIMASK_NS(1)
 /* Enable NS exceptions by setting NS PRIMASK to 0 */