summaryrefslogtreecommitdiff
path: root/cactus
diff options
context:
space:
mode:
authorSandrine Bailleux <sandrine.bailleux@arm.com>2017-12-11 16:32:40 +0000
committerSandrine Bailleux <sandrine.bailleux@arm.com>2017-12-12 16:43:05 +0000
commit1d069ae099d8e2e0f7552d8715238d59b746cdf9 (patch)
treed38caad0560e458c6f6c9bf474f5a215483d08fe /cactus
parentf0153912f775b6ebaa7b18052b6d6e802a156eb6 (diff)
Cactus: Store SVC return values in a structure
Change the prototype of the cactus_svc() helper function to: u_register_t cactus_svc(svc_args *args) The arguments to pass through the SVC call must be stored in the svc_args structure. The return values of the SVC call will be stored in the same structure (overriding the input arguments). Return the first return value. It is equivalent to args.arg0 but is also provided as the return value for convenience. Modify the MM_COMMUNICATE handler to print these additional values, which in the case of an MM_COMMUNICATE call, correspond to the event context address, size and cookie. Change-Id: I78085fb1012ee834e1f82f6be1300085742a3119 Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Diffstat (limited to 'cactus')
-rw-r--r--cactus/aarch64/cactus_arch_helpers.S27
-rw-r--r--cactus/cactus_helpers.h24
-rw-r--r--cactus/cactus_main.c59
-rw-r--r--cactus/cactus_tests_memory_attributes.c20
-rw-r--r--cactus/cactus_tests_misc.c3
5 files changed, 90 insertions, 43 deletions
diff --git a/cactus/aarch64/cactus_arch_helpers.S b/cactus/aarch64/cactus_arch_helpers.S
index 2b69883..c9ca49a 100644
--- a/cactus/aarch64/cactus_arch_helpers.S
+++ b/cactus/aarch64/cactus_arch_helpers.S
@@ -9,6 +9,33 @@
.globl cactus_svc
func cactus_svc
+ /*
+ * Save the address of the svc_args structure on the stack.
+ *
+ * Although x0 contains an 8-byte value, we are allocating 16 bytes
+ * on the stack to respect the 16-byte stack-alignment.
+ */
+ str x0, [sp, #-16]!
+
+ /* Load the SVC arguments values into the appropriate registers. */
+ ldp x6, x7, [x0, #48]
+ ldp x4, x5, [x0, #32]
+ ldp x2, x3, [x0, #16]
+ ldp x0, x1, [x0, #0]
+
svc #0
+
+ /*
+ * Pop the svc_args structure address from the stack into a caller-saved
+ * register.
+ */
+ ldr x9, [sp], #16
+
+ /*
+ * The return values are stored in x0-x3, put them in the svc_args
+ * return structure.
+ */
+ stp x0, x1, [x9, #0]
+ stp x2, x3, [x9, #16]
ret
endfunc cactus_svc
diff --git a/cactus/cactus_helpers.h b/cactus/cactus_helpers.h
index f4c766c..465ced3 100644
--- a/cactus/cactus_helpers.h
+++ b/cactus/cactus_helpers.h
@@ -9,11 +9,29 @@
#include <stdint.h>
+
+typedef struct {
+ u_register_t arg0;
+ u_register_t arg1;
+ u_register_t arg2;
+ u_register_t arg3;
+ u_register_t arg4;
+ u_register_t arg5;
+ u_register_t arg6;
+ u_register_t arg7;
+} svc_args;
+
/*
- * Helper functions
+ * Trigger an SVC call.
+ *
+ * The arguments to pass through the SVC call must be stored in the svc_args
+ * structure. The return values of the SVC call will be stored in the same
+ * structure (overriding the input arguments).
+ *
+ * Return the first return value. It is equivalent to args.arg0 but is also
+ * provided as the return value for convenience.
*/
-uint64_t cactus_svc(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3,
- uint64_t x4, uint64_t x5, uint64_t x6, uint64_t x7);
+u_register_t cactus_svc(svc_args *args);
/*
* Choose a pseudo-random number within the [min,max] range (both limits are
diff --git a/cactus/cactus_main.c b/cactus/cactus_main.c
index eab80b8..bddc5a2 100644
--- a/cactus/cactus_main.c
+++ b/cactus/cactus_main.c
@@ -73,34 +73,39 @@ static void cactus_print_memory_layout(const secure_partition_boot_info_t *boot_
static __dead2 void secure_services_loop(void)
{
- int32_t event_status_code;
-
- /*
- * The first time this loop is executed corresponds to when Cactus has
- * finished initialising its run time environment and is ready to handle
- * secure service requests.
- */
- NOTICE("Cactus: Signal end of init to SPM\n");
- event_status_code = SPM_SUCCESS;
-
- while (1) {
- int32_t event_id = cactus_svc(SP_EVENT_COMPLETE_AARCH64,
- event_status_code,
- 0, 0, 0, 0, 0, 0);
-
- switch (event_id) {
- case MM_COMMUNICATE_AARCH64:
- case MM_COMMUNICATE_AARCH32:
- NOTICE("Cactus: Received MM_COMMUNICATE call\n");
- event_status_code = SPM_SUCCESS;
- break;
-
- default:
- NOTICE("Unhandled Service ID 0x%x\n", event_id);
- event_status_code = -1;
- break;
+ int32_t event_status_code;
+ svc_args svc_values = { 0 };
+
+ /*
+ * The first time this loop is executed corresponds to when Cactus has
+ * finished initialising its run time environment and is ready to handle
+ * secure service requests.
+ */
+ NOTICE("Cactus: Signal end of init to SPM\n");
+ event_status_code = SPM_SUCCESS;
+
+ while (1) {
+ svc_values.arg0 = SP_EVENT_COMPLETE_AARCH64;
+ svc_values.arg1 = event_status_code;
+ int32_t event_id = cactus_svc(&svc_values);
+
+ switch (event_id) {
+ case MM_COMMUNICATE_AARCH64:
+ case MM_COMMUNICATE_AARCH32:
+ NOTICE("Cactus: Received MM_COMMUNICATE call on CPU #%lu\n",
+ svc_values.arg3);
+ NOTICE("Cactus: Context address: %p\n", (void *) svc_values.arg1);
+ NOTICE("Cactus: Context size : %lu\n", svc_values.arg2);
+ NOTICE("Cactus: Cookie : 0x%lx\n", svc_values.arg3);
+ event_status_code = SPM_SUCCESS;
+ break;
+
+ default:
+ NOTICE("Unhandled Service ID 0x%x\n", event_id);
+ event_status_code = -1;
+ break;
+ }
}
- }
}
diff --git a/cactus/cactus_tests_memory_attributes.c b/cactus/cactus_tests_memory_attributes.c
index fae5e52..26ec0e7 100644
--- a/cactus/cactus_tests_memory_attributes.c
+++ b/cactus/cactus_tests_memory_attributes.c
@@ -49,13 +49,11 @@ static int32_t request_mem_attr_changes(uintptr_t base_address,
INFO(" Number of pages: %i\n", pages_count);
INFO(" Attributes : 0x%x\n", memory_access_controls);
- uint64_t ret = cactus_svc(SP_MEMORY_ATTRIBUTES_SET_AARCH64,
- base_address,
- pages_count,
- memory_access_controls,
- 0, 0, 0, 0);
-
- return (int32_t) ret;
+ svc_args svc_values = { SP_MEMORY_ATTRIBUTES_SET_AARCH64,
+ base_address,
+ pages_count,
+ memory_access_controls };
+ return cactus_svc(&svc_values);
}
/*
@@ -67,11 +65,9 @@ static int32_t request_get_mem_attr(uintptr_t base_address)
INFO("Requesting memory attributes\n");
INFO(" Base address : %p\n", (void *) base_address);
- uint64_t ret = cactus_svc(SP_MEMORY_ATTRIBUTES_GET_AARCH64,
- base_address,
- 0, 0, 0, 0, 0, 0);
-
- return (int32_t) ret;
+ svc_args svc_values = { SP_MEMORY_ATTRIBUTES_GET_AARCH64,
+ base_address };
+ return cactus_svc(&svc_values);
}
/*
diff --git a/cactus/cactus_tests_misc.c b/cactus/cactus_tests_misc.c
index 785c157..20c80da 100644
--- a/cactus/cactus_tests_misc.c
+++ b/cactus/cactus_tests_misc.c
@@ -28,7 +28,8 @@ void misc_tests(void)
const char *test_version = "SPM version check";
announce_test_start(test_version);
- ret = cactus_svc(SPM_VERSION_AARCH32, 0, 0, 0, 0, 0, 0, 0);
+ svc_args svc_values = { SPM_VERSION_AARCH32 };
+ ret = cactus_svc(&svc_values);
INFO("Version = 0x%x (%u.%u)\n", ret,
(ret >> 16) & 0x7FFF, ret & 0xFFFF);
expect(ret, SPM_VERSION_COMPILED);