platform: common: Panic in fault handlers

Call TF-M core panic handling when ARM exception faults has occured.
This will call into either a halt or reset handling depending on the
configuration.

Change-Id: I6d08313c84b823202d74ad8ce8a65f2c85176fb7
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
diff --git a/platform/ext/common/faults.c b/platform/ext/common/faults.c
index 8c15a84..d9f1595 100644
--- a/platform/ext/common/faults.c
+++ b/platform/ext/common/faults.c
@@ -6,57 +6,99 @@
  */
 #include "cmsis.h"
 #include "exception_info.h"
+#include "utilities.h"
 
-__attribute__((naked)) void HardFault_Handler(void)
+void C_HardFault_Handler(void)
 {
-    EXCEPTION_INFO(EXCEPTION_TYPE_HARDFAULT);
-
     /* A HardFault may indicate corruption of secure state, so it is essential
      * that Non-secure code does not regain control after one is raised.
      * Returning from this exception could allow a pending NS exception to be
      * taken, so the current solution is not to return.
      */
-    __ASM volatile("b    .");
+    tfm_core_panic();
+}
+
+__attribute__((naked)) void HardFault_Handler(void)
+{
+    EXCEPTION_INFO(EXCEPTION_TYPE_HARDFAULT);
+
+    __ASM volatile(
+        "bl        C_HardFault_Handler     \n"
+        "b         .                       \n"
+    );
+}
+
+void C_MemManage_Handler(void)
+{
+    /* A MemManage fault may indicate corruption of secure state, so it is
+     * essential that Non-secure code does not regain control after one is
+     * raised. Returning from this exception could allow a pending NS exception
+     * to be taken, so the current solution is to panic.
+     */
+    tfm_core_panic();
 }
 
 __attribute__((naked)) void MemManage_Handler(void)
 {
     EXCEPTION_INFO(EXCEPTION_TYPE_MEMFAULT);
 
-    /* A MemManage fault may indicate corruption of secure state, so it is
-     * essential that Non-secure code does not regain control after one is
-     * raised. Returning from this exception could allow a pending NS exception
-     * to be taken, so the current solution is not to return.
+    __ASM volatile(
+        "bl        C_MemManage_Handler     \n"
+        "b         .                       \n"
+    );
+}
+
+void C_BusFault_Handler(void)
+{
+    /* A BusFault may indicate corruption of secure state, so it is essential
+     * that Non-secure code does not regain control after one is raised.
+     * Returning from this exception could allow a pending NS exception to be
+     * taken, so the current solution is to panic.
      */
-    __ASM volatile("b    .");
+    tfm_core_panic();
 }
 
 __attribute__((naked)) void BusFault_Handler(void)
 {
     EXCEPTION_INFO(EXCEPTION_TYPE_BUSFAULT);
 
-    /* A BusFault may indicate corruption of secure state, so it is essential
+    __ASM volatile(
+        "bl        C_BusFault_Handler      \n"
+        "b         .                       \n"
+    );
+}
+
+void C_SecureFault_Handler(void)
+{
+    /* A SecureFault may indicate corruption of secure state, so it is essential
      * that Non-secure code does not regain control after one is raised.
      * Returning from this exception could allow a pending NS exception to be
-     * taken, so the current solution is not to return.
+     * taken, so the current solution is to panic.
      */
-    __ASM volatile("b    .");
+    tfm_core_panic();
 }
 
 __attribute__((naked)) void SecureFault_Handler(void)
 {
     EXCEPTION_INFO(EXCEPTION_TYPE_SECUREFAULT);
 
-    /* A SecureFault may indicate corruption of secure state, so it is essential
-     * that Non-secure code does not regain control after one is raised.
-     * Returning from this exception could allow a pending NS exception to be
-     * taken, so the current solution is not to return.
-     */
-    __ASM volatile("b    .");
+    __ASM volatile(
+        "bl        C_SecureFault_Handler   \n"
+        "b         .                       \n"
+    );
+}
+
+void C_UsageFault_Handler(void)
+{
+    tfm_core_panic();
 }
 
 __attribute__((naked)) void UsageFault_Handler(void)
 {
     EXCEPTION_INFO(EXCEPTION_TYPE_USAGEFAULT);
-    __ASM volatile("b    .");
+
+    __ASM volatile(
+        "bl        C_UsageFault_Handler   \n"
+        "b         .                      \n"
+    );
 }