Cactus: tidy message loop and commands definitions

Creating specific header and source file for the message loop code,
separating it from the definition of test commands. Thus message loop
won't be included in tftf target.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Ieb0c4b0bf56ed0cbbf3323cac57dd9d9b37fae92
diff --git a/include/runtime_services/cactus_message_loop.h b/include/runtime_services/cactus_message_loop.h
new file mode 100644
index 0000000..d69e77c
--- /dev/null
+++ b/include/runtime_services/cactus_message_loop.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <ffa_helpers.h>
+#include <spm_common.h>
+
+/**
+ * Pairs a command id with a function call, to handle the command ID.
+ */
+struct cactus_cmd_handler {
+	const uint64_t id;
+	smc_ret_values (*fn)(const smc_ret_values *args,
+			     struct mailbox_buffers *mb);
+};
+
+/**
+ * Helper to create the name of a handler function.
+ */
+#define CACTUS_HANDLER_FN_NAME(name) cactus_##name##_handler
+
+/**
+ * Define handler's function signature.
+ */
+#define CACTUS_HANDLER_FN(name)						\
+	static smc_ret_values CACTUS_HANDLER_FN_NAME(name)(		\
+		const smc_ret_values *args, struct mailbox_buffers *mb)
+
+/**
+ * Helper to define Cactus command handler, and pair it with a command ID.
+ * It also creates a table with this information, to be traversed by
+ * 'cactus_handle_cmd' function.
+ */
+#define CACTUS_CMD_HANDLER(name, ID)					\
+	CACTUS_HANDLER_FN(name);					\
+	struct cactus_cmd_handler name __section(".cactus_handler") = {	\
+		.id = ID, .fn = CACTUS_HANDLER_FN_NAME(name),		\
+	};								\
+	CACTUS_HANDLER_FN(name)
+
+bool cactus_handle_cmd(smc_ret_values *cmd_args, smc_ret_values *ret,
+		       struct mailbox_buffers *mb);
diff --git a/include/runtime_services/cactus_test_cmds.h b/include/runtime_services/cactus_test_cmds.h
index c65816f..246f4f9 100644
--- a/include/runtime_services/cactus_test_cmds.h
+++ b/include/runtime_services/cactus_test_cmds.h
@@ -7,9 +7,7 @@
 #ifndef CACTUS_TEST_CMDS
 #define CACTUS_TEST_CMDS
 
-#include <debug.h>
 #include <ffa_helpers.h>
-#include <spm_common.h>
 
 /**
  * Success and error return to be sent over a msg response.
@@ -102,11 +100,6 @@
 	return (uint32_t) ret.ret4;
 }
 
-#define PRINT_CMD(smc_ret)						\
-	VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n",	 		\
-		smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, 		\
-		smc_ret.ret6, smc_ret.ret7)
-
 /**
  * With this test command the sender transmits a 64-bit value that it then
  * expects to receive on the respective command response.
@@ -256,40 +249,4 @@
 			       0);
 }
 
-/**
- * Pairs a command id with a function call, to handle the command ID.
- */
-struct cactus_cmd_handler {
-	const uint64_t id;
-	smc_ret_values (*fn)(const smc_ret_values *args,
-			     struct mailbox_buffers *mb);
-};
-
-/**
- * Helper to create the name of a handler function.
- */
-#define CACTUS_HANDLER_FN_NAME(name) cactus_##name##_handler
-
-/**
- * Define handler's function signature.
- */
-#define CACTUS_HANDLER_FN(name)						\
-	static smc_ret_values CACTUS_HANDLER_FN_NAME(name)(		\
-		const smc_ret_values *args, struct mailbox_buffers *mb)
-
-/**
- * Helper to define Cactus command handler, and pair it with a command ID.
- * It also creates a table with this information, to be traversed by
- * 'cactus_handle_cmd' function.
- */
-#define CACTUS_CMD_HANDLER(name, ID)					\
-	CACTUS_HANDLER_FN(name);					\
-	struct cactus_cmd_handler name __section(".cactus_handler") = {	\
-		.id = ID, .fn = CACTUS_HANDLER_FN_NAME(name),		\
-	};								\
-	CACTUS_HANDLER_FN(name)
-
-bool cactus_handle_cmd(smc_ret_values *cmd_args, smc_ret_values *ret,
-		       struct mailbox_buffers *mb);
-
 #endif
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index 31ac990..08b824c 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -40,8 +40,8 @@
 		sp_helpers.c				\
 	)						\
 	$(addprefix spm/cactus/cactus_tests/,		\
+		cactus_message_loop.c			\
 		cactus_test_cpu_features.c		\
-		cactus_test_cmds.c			\
 		cactus_test_direct_messaging.c		\
 		cactus_test_ffa.c 			\
 		cactus_test_memory_sharing.c		\
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index 650f06d..7e3f40b 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -8,8 +8,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <cactus_message_loop.h>
 #include <cactus_platform_def.h>
-#include <cactus_test_cmds.h>
 #include <drivers/arm/pl011.h>
 #include <drivers/console.h>
 #include <lib/aarch64/arch_helpers.h>
@@ -74,8 +74,6 @@
 			break;
 		}
 
-		PRINT_CMD(ffa_ret);
-
 		if (!cactus_handle_cmd(&ffa_ret, &ffa_ret, mb)) {
 			break;
 		}
diff --git a/spm/cactus/cactus_tests/cactus_test_cmds.c b/spm/cactus/cactus_tests/cactus_message_loop.c
similarity index 80%
rename from spm/cactus/cactus_tests/cactus_test_cmds.c
rename to spm/cactus/cactus_tests/cactus_message_loop.c
index e13e40d..11207dc 100644
--- a/spm/cactus/cactus_tests/cactus_test_cmds.c
+++ b/spm/cactus/cactus_tests/cactus_message_loop.c
@@ -4,8 +4,11 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
+#include "cactus_message_loop.h"
 #include "cactus_test_cmds.h"
 #include <ffa_helpers.h>
+#include <debug.h>
+
 
 /**
  * Begin and end of command handler table, respectively. Both symbols defined by
@@ -14,6 +17,11 @@
 extern struct cactus_cmd_handler cactus_cmd_handler_begin[];
 extern struct cactus_cmd_handler cactus_cmd_handler_end[];
 
+#define PRINT_CMD(smc_ret)						\
+	VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n",	 		\
+		smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, 		\
+		smc_ret.ret6, smc_ret.ret7)
+
 /**
  * Traverses command table from section ".cactus_handler", searches for a
  * registered command and invokes the respective handler.
@@ -28,6 +36,8 @@
 		return false;
 	}
 
+	PRINT_CMD((*cmd_args));
+
 	in_cmd = cactus_get_cmd(*cmd_args);
 
 	for (struct cactus_cmd_handler *it_cmd = cactus_cmd_handler_begin;
@@ -39,6 +49,7 @@
 		}
 	}
 
+	ERROR("Unhandled test command!\n");
 	*ret = cactus_error_resp(ffa_dir_msg_dest(*cmd_args),
 				 ffa_dir_msg_source(*cmd_args),
 				 CACTUS_ERROR_UNHANDLED);
diff --git a/spm/cactus/cactus_tests/cactus_test_cpu_features.c b/spm/cactus/cactus_tests/cactus_test_cpu_features.c
index d39bdc4..7bf6e83 100644
--- a/spm/cactus/cactus_tests/cactus_test_cpu_features.c
+++ b/spm/cactus/cactus_tests/cactus_test_cpu_features.c
@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
+#include "cactus_message_loop.h"
 #include "cactus_test_cmds.h"
 #include "spm_common.h"
 
diff --git a/spm/cactus/cactus_tests/cactus_test_direct_messaging.c b/spm/cactus/cactus_tests/cactus_test_direct_messaging.c
index 31324b6..a59cfa2 100644
--- a/spm/cactus/cactus_tests/cactus_test_direct_messaging.c
+++ b/spm/cactus/cactus_tests/cactus_test_direct_messaging.c
@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
+#include "cactus_message_loop.h"
 #include "cactus_test_cmds.h"
 #include <debug.h>
 #include <ffa_helpers.h>
diff --git a/spm/cactus/cactus_tests/cactus_test_memory_sharing.c b/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
index f7d9235..e7bce50 100644
--- a/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
+++ b/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
@@ -5,8 +5,10 @@
  */
 
 #include <cactus_def.h>
+#include "cactus_message_loop.h"
 #include "cactus_test_cmds.h"
 #include "cactus_tests.h"
+#include <debug.h>
 #include <ffa_helpers.h>
 #include <sp_helpers.h>
 #include <xlat_tables_defs.h>