SPM: Use Main Stack for initialization
On reset, the Main Stack is used by default.
TF-M changes the stack to Processor Stack.
This patch remove the change to PSP in startup.s and:
- Rename the ARM_LIB_STACK to ER_INITIAL_PSP
- Rename the ARM_LIB_STACK_MSP to ARM_LIB_STACK
The renaming is to align the __main function of ARMClang where the
ARM_LIB_STACK is set to the current SP (MSP)
For Library Mode, the stacks are set to back to use PSP before entering
c code to avoid massive corresponding changes.
For FF-M implementations, this patch also:
- Seal the Main Stack before entering c code
- Manually free the Main Stack usage after initialization as the init
function does not return
Change-Id: Ie1b6f2fca1f774c4812a89fa45bb039b16fe5af0
Signed-off-by: Kevin Peng <kevin.peng@arm.com>
Co-authored-by: Summer Qin <summer.qin@arm.com>
diff --git a/secure_fw/spm/include/tfm_arch.h b/secure_fw/spm/include/tfm_arch.h
index 8a96d9f..8eb24b8 100644
--- a/secure_fw/spm/include/tfm_arch.h
+++ b/secure_fw/spm/include/tfm_arch.h
@@ -103,6 +103,13 @@
*/
void tfm_arch_clear_fp_status(void);
+/*
+ * This function is called after SPM has initialized.
+ * 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_init_context(struct tfm_arch_ctx_t *p_actx,
void *param, uintptr_t pfn,
uintptr_t stk_btm, uintptr_t stk_top);
diff --git a/secure_fw/spm/include/tfm_arch_v8m.h b/secure_fw/spm/include/tfm_arch_v8m.h
index e615c3c..a532a51 100644
--- a/secure_fw/spm/include/tfm_arch_v8m.h
+++ b/secure_fw/spm/include/tfm_arch_v8m.h
@@ -45,6 +45,8 @@
#define EXC_NUM_SVCALL (11)
#define EXC_NUM_PENDSV (14)
+#define VTOR_BASE (0xE000ED08)
+
#if defined(__ARM_ARCH_8_1M_MAIN__) || defined(__ARM_ARCH_8M_MAIN__)
struct tfm_arch_ctx_t {
uint32_t r4;
@@ -123,6 +125,16 @@
}
/**
+ * \brief Set MSP limit value.
+ *
+ * \param[in] msplim MSP limit value to be written.
+ */
+__STATIC_INLINE void tfm_arch_set_msplim(uint32_t msplim)
+{
+ __set_MSPLIM(msplim);
+}
+
+/**
* \brief Seal the thread stack.
*
* This function must be called only when the caller is using MSP.
diff --git a/secure_fw/spm/include/utilities.h b/secure_fw/spm/include/utilities.h
index f527071..aec3ea0 100644
--- a/secure_fw/spm/include/utilities.h
+++ b/secure_fw/spm/include/utilities.h
@@ -37,4 +37,8 @@
/* FixMe: Replace ERROR_MSG() in platform code with a suitable API */
#define ERROR_MSG(msg) SPMLOG_ERRMSG(msg "\r\n")
+/* Preprocessor to reference C MACRO to string in inline asm */
+#define M2S_HELPER(x) #x
+#define M2S(m) M2S_HELPER(m)
+
#endif /* __TFM_UTILS_H__ */