platform: nordic_nrf: Don't hang in IRQs by default

The current default IRQ handler will hang forever. It is bad practice
to hang forever in production.

Instead we now print the exception information and then panic. Which
will either reboot or hang forever depending on the configuration.

It is bad practice to for the default IRQ handler to be triggered at
all and it should indicate a configuration error.

Change-Id: Ifd3a67ac2276fa8d7ceec29482f8cec02b3cac54
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
diff --git a/platform/ext/target/nordic_nrf/common/core/startup.c b/platform/ext/target/nordic_nrf/common/core/startup.c
index e51400d..d347613 100644
--- a/platform/ext/target/nordic_nrf/common/core/startup.c
+++ b/platform/ext/target/nordic_nrf/common/core/startup.c
@@ -12,6 +12,27 @@
 
 #include "startup.h"
 
+#if !(defined(DOMAIN_NS) || defined(BL2))
+#include "utilities.h"
+#endif
+
+void default_irq_handler(void)
+{
+	/*
+	 * This file is used by the TF-M build system. Usually in the
+	 * secure domain (tfm_s.elf), but also for vanilla BL2 and for
+	 * testing purposes in the non-secure domain (tfm_ns.elf).
+	 *
+	 * When used in vanilla BL2 or the non-secure domain we do not
+	 * have tfm_core_panic so we loop forever instead.
+	 */
+#if defined(DOMAIN_NS) || defined(BL2)
+	while(1);
+#else
+	tfm_core_panic();
+#endif
+}
+
 /*----------------------------------------------------------------------------
   Reset Handler called on controller reset
  *----------------------------------------------------------------------------*/
diff --git a/platform/ext/target/nordic_nrf/common/core/startup.h b/platform/ext/target/nordic_nrf/common/core/startup.h
index 873361d..0afa58a 100644
--- a/platform/ext/target/nordic_nrf/common/core/startup.h
+++ b/platform/ext/target/nordic_nrf/common/core/startup.h
@@ -28,6 +28,12 @@
 
 __NO_RETURN void Reset_Handler(void);
 
+/*
+ * The default irq handler is used as a backup in case of
+ * misconfiguration.
+ */
+void default_irq_handler(void);
+
 extern const VECTOR_TABLE_Type __VECTOR_TABLE[];
 
 #endif /* __STARTUP_H__ */
diff --git a/platform/ext/target/nordic_nrf/common/nrf5340/gcc/startup_nrf5340.c b/platform/ext/target/nordic_nrf/common/nrf5340/gcc/startup_nrf5340.c
index 83a4c36..cae5dac 100644
--- a/platform/ext/target/nordic_nrf/common/nrf5340/gcc/startup_nrf5340.c
+++ b/platform/ext/target/nordic_nrf/common/nrf5340/gcc/startup_nrf5340.c
@@ -27,9 +27,15 @@
 #include "hw_init.h"
 #endif
 #include "startup.h"
+#include "exception_info.h"
 
 __NO_RETURN __attribute__((naked)) void default_tfm_IRQHandler(void) {
-    while(1);
+	EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+
+	__ASM volatile(
+        "BL        default_irq_handler     \n"
+        "B         .                       \n"
+    );
 }
 
 DEFAULT_IRQ_HANDLER(NMI_Handler)
diff --git a/platform/ext/target/nordic_nrf/common/nrf91/gcc/startup_nrf91.c b/platform/ext/target/nordic_nrf/common/nrf91/gcc/startup_nrf91.c
index 71a6b79..581e1c4 100644
--- a/platform/ext/target/nordic_nrf/common/nrf91/gcc/startup_nrf91.c
+++ b/platform/ext/target/nordic_nrf/common/nrf91/gcc/startup_nrf91.c
@@ -24,9 +24,15 @@
 #include "cmsis.h"
 #include "hw_init.h"
 #include "startup.h"
+#include "exception_info.h"
 
 __NO_RETURN __attribute__((naked)) void default_tfm_IRQHandler(void) {
-    while(1);
+	EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+
+	__ASM volatile(
+        "BL        default_irq_handler     \n"
+        "B         .                       \n"
+    );
 }
 
 DEFAULT_IRQ_HANDLER(NMI_Handler)