App: Add SVC call for registering client ID

Add an SVC call that calls the NS client ID registering veneer.
Also call that veneer at the beginning of the app threads' main
function.

Change-Id: I06c46529967ed66ef4f63ee6ba96513c0815b64d
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 86641ac..2be76fd 100755
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -45,7 +45,9 @@
 	"${APP_DIR}/os_wrapper_rtx.c"
 	"${INTERFACE_DIR}/src/tfm_sst_api.c"
 	"${INTERFACE_DIR}/src/tfm_audit_api.c"
+	"${INTERFACE_DIR}/src/tfm_nspm_svc_handler.c"
 	"${INTERFACE_DIR}/src/tfm_id_mngr_dummy.c"
+	"${INTERFACE_DIR}/src/tfm_nspm_api.c"
 	"${INTERFACE_DIR}/src/tfm_ns_lock_rtx.c"
 	)
 
diff --git a/app/main_ns.c b/app/main_ns.c
index f1ffc19..c3ba83b 100644
--- a/app/main_ns.c
+++ b/app/main_ns.c
@@ -13,6 +13,7 @@
 #include "tfm_api.h"
 #include "cmsis_os2.h"
 #include "tfm_integ_test.h"
+#include "tfm_ns_svc.h"
 #include "tfm_ns_lock.h"
 #ifdef TEST_FRAMEWORK_NS
 #include "test/framework/test_framework_integ_test.h"
@@ -24,6 +25,29 @@
 /* For UART the CMSIS driver is used */
 extern ARM_DRIVER_USART NS_DRIVER_STDIO;
 
+/**
+ * \brief Modified table template for user defined SVC functions
+ *
+ * \details RTX has a weak definition of osRtxUserSVC, which
+ *          is overridden here
+ */
+extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
+       void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
+  (void *)USER_SVC_COUNT,
+
+#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
+
+    /* SVC API for Services */
+    LIST_SVC_NSPM
+
+#undef X
+
+/*
+ * (void *)user_function1,
+ *  ...
+ */
+};
+
 /* Struct FILE is implemented in stdio.h. Used to redirect printf to
  * NS_DRIVER_STDIO
  */
diff --git a/app/tfm_integ_test.c b/app/tfm_integ_test.c
index e7b518a..0707737 100644
--- a/app/tfm_integ_test.c
+++ b/app/tfm_integ_test.c
@@ -13,6 +13,7 @@
 #include "cmsis.h"
 #include "tfm_api.h"
 #include "cmsis_os2.h"
+#include "tfm_nspm_api.h"
 
 #include "tfm_integ_test.h"
 #include "test/framework/test_framework_integ_test.h"
@@ -218,6 +219,8 @@
     osThreadState_t thread_pri_state;
     uint32_t idx;
 
+    tfm_nspm_register_client_id();
+
     thread_id_pri = *((osThreadId_t *)argument);
 
     /* go to sleep */
@@ -249,6 +252,8 @@
 __attribute__((noreturn))
 static void pri_task(void *argument)
 {
+    tfm_nspm_register_client_id();
+
     /* go to sleep */
     osDelay(100U);
 
@@ -275,6 +280,8 @@
     struct tfm_ns_lock_options ns_lock_opt_pri =
                                   {.use_ns_lock=true, .timeout=osWaitForever};
 
+    tfm_nspm_register_client_id();
+
     test_type = *((enum test_type *)argument);
 
     if (test_type == TEST_TYPE_1) {