test(rme): check if non SVE realm gets undefined abort

This test checks whether a non SVE realm receives undefined abort upon
accessing SVE register state or instructions.

Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Change-Id: I2785488b1344cc4d59dde75e38d9e0d6f856af61
diff --git a/realm/realm_sve.c b/realm/realm_sve.c
index 0512789..b41e23d 100644
--- a/realm/realm_sve.c
+++ b/realm/realm_sve.c
@@ -9,6 +9,7 @@
 #include <assert.h>
 #include <debug.h>
 #include <stdlib.h>
+#include <sync.h>
 #include <lib/extensions/sve.h>
 
 #include <host_realm_sve.h>
@@ -22,6 +23,8 @@
 
 static sve_vector_t rl_sve_vectors_write[SVE_NUM_VECTORS] __aligned(16);
 
+static int volatile realm_got_undef_abort;
+
 /* Returns the maximum supported VL. This test is called only by sve Realm */
 bool test_realm_sve_rdvl(void)
 {
@@ -128,3 +131,34 @@
 
 	return true;
 }
+
+static bool realm_sync_exception_handler(void)
+{
+	uint64_t esr_el1 = read_esr_el1();
+
+	if (EC_BITS(esr_el1) == EC_UNKNOWN) {
+		realm_printf("Realm: received undefined abort. "
+			     "esr_el1: 0x%llx elr_el1: 0x%llx\n",
+			     esr_el1, read_elr_el1());
+		realm_got_undef_abort++;
+	}
+
+	return true;
+}
+
+/* Check if Realm gets undefined abort when it accesses SVE functionality */
+bool test_realm_sve_undef_abort(void)
+{
+	realm_got_undef_abort = 0UL;
+
+	/* install exception handler to catch undef abort */
+	register_custom_sync_exception_handler(&realm_sync_exception_handler);
+	(void)sve_rdvl_1();
+	unregister_custom_sync_exception_handler();
+
+	if (realm_got_undef_abort == 0UL) {
+		return false;
+	}
+
+	return true;
+}