platform: exception_info: Add getter for exception info context

Add an API, `tfm_exception_info_get_context()`, which can be used to
retrieve exception info from the exception_info module.

This option is added allow for platform specific handling logic -- for
example, saving the exception info to a non-volatile storage medium
for postmortem analysis.

Change Highlights:

  * Moved `struct exception_info_t` from `exception_info.c` to
    `exception_info.h`
  * Defined `tfm_exception_info_get_context()` which exposes access to
    the static scope `exception_info` struct from exception_info.h

Signed-off-by: Chris Coleman <chris@memfault.com>
Change-Id: I635ef2cc79bf5221300064a3a2813d504f62d46a
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
diff --git a/platform/ext/common/exception_info.c b/platform/ext/common/exception_info.c
index f4fc17c..71f7ab7 100644
--- a/platform/ext/common/exception_info.c
+++ b/platform/ext/common/exception_info.c
@@ -10,30 +10,6 @@
 /* "exception_info.h" must be the last include because of the IAR pragma */
 #include "exception_info.h"
 
-struct exception_info_t {
-    uint32_t EXC_RETURN;        /* EXC_RETURN value in LR. */
-    uint32_t MSP;               /* (Secure) MSP. */
-    uint32_t PSP;               /* (Secure) PSP. */
-    uint32_t *EXC_FRAME;        /* Exception frame on stack. */
-    uint32_t EXC_FRAME_COPY[8]; /* Copy of the basic exception frame. */
-    uint32_t xPSR;              /* Program Status Registers. */
-
-#ifdef FAULT_STATUS_PRESENT
-    uint32_t CFSR;              /* Configurable Fault Status Register. */
-    uint32_t HFSR;              /* Hard Fault Status Register. */
-    uint32_t BFAR;              /* Bus Fault address register. */
-    uint32_t BFARVALID;         /* Whether BFAR contains a valid address. */
-    uint32_t MMFAR;             /* MemManage Fault address register. */
-    uint32_t MMARVALID;         /* Whether MMFAR contains a valid address. */
-#ifdef TRUSTZONE_PRESENT
-    uint32_t SFSR;              /* SecureFault Status Register. */
-    uint32_t SFAR;              /* SecureFault Address Register. */
-    uint32_t SFARVALID;         /* Whether SFAR contains a valid address. */
-#endif
-
-#endif
-};
-
 static struct exception_info_t exception_info;
 
 /**
@@ -209,6 +185,11 @@
     dump_exception_info(stack_error, &exception_info);
 }
 
+void tfm_exception_info_get_context(struct exception_info_t *ctx)
+{
+    memcpy(ctx, &exception_info, sizeof(exception_info));
+}
+
 void store_and_dump_context(uint32_t LR_in, uint32_t MSP_in, uint32_t PSP_in,
                             uint32_t exception_type)
 {
diff --git a/platform/include/exception_info.h b/platform/include/exception_info.h
index 028120d..7c37575 100644
--- a/platform/include/exception_info.h
+++ b/platform/include/exception_info.h
@@ -39,6 +39,37 @@
  */
 #ifdef TFM_EXCEPTION_INFO_DUMP
 
+struct exception_info_t {
+    uint32_t EXC_RETURN;        /* EXC_RETURN value in LR. */
+    uint32_t MSP;               /* (Secure) MSP. */
+    uint32_t PSP;               /* (Secure) PSP. */
+    uint32_t *EXC_FRAME;        /* Exception frame on stack. */
+    uint32_t EXC_FRAME_COPY[8]; /* Copy of the basic exception frame. */
+    uint32_t xPSR;              /* Program Status Registers. */
+
+#ifdef FAULT_STATUS_PRESENT
+    uint32_t CFSR;              /* Configurable Fault Status Register. */
+    uint32_t HFSR;              /* Hard Fault Status Register. */
+    uint32_t BFAR;              /* Bus Fault address register. */
+    uint32_t BFARVALID;         /* Whether BFAR contains a valid address. */
+    uint32_t MMFAR;             /* MemManage Fault address register. */
+    uint32_t MMARVALID;         /* Whether MMFAR contains a valid address. */
+#ifdef TRUSTZONE_PRESENT
+    uint32_t SFSR;              /* SecureFault Status Register. */
+    uint32_t SFAR;              /* SecureFault Address Register. */
+    uint32_t SFARVALID;         /* Whether SFAR contains a valid address. */
+#endif
+#endif
+};
+
+/**
+ * \brief Get a pointer to the current exception_info_t context
+ *
+ * \return  A pointer to the exception_info_t context or NULL if no context
+ *          has been stored
+ */
+void tfm_exception_info_get_context(struct exception_info_t *ctx);
+
 /* Store context for an exception, then print the info.
  * Call EXCEPTION_INFO() instead of calling this directly.
  */