feat(rme): add tests for FEAT_MPAM on Realms

Signed-off-by: Javier Almansa Sobrino <javier.almansasobrino@arm.com>
Change-Id: I6e138cbf121793bdaaa3a44824c0dbff74daced1
diff --git a/realm/realm_simd.c b/realm/realm_simd.c
index 2eb3eab..0ff1710 100644
--- a/realm/realm_simd.c
+++ b/realm/realm_simd.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023, Arm Limited. All rights reserved.
+ * Copyright (c) 2023-2025, Arm Limited. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
@@ -9,9 +9,11 @@
 #include <assert.h>
 #include <debug.h>
 #include <stdlib.h>
+
 #include <sync.h>
 #include <lib/extensions/fpu.h>
 #include <lib/extensions/sve.h>
+#include <realm_helpers.h>
 
 #include <host_realm_simd.h>
 #include <host_shared_data.h>
@@ -34,8 +36,6 @@
 static fpu_cs_regs_t rl_fpu_cs_regs_write;
 static fpu_cs_regs_t rl_fpu_cs_regs_read;
 
-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)
 {
@@ -188,35 +188,17 @@
 	return rc;
 }
 
-static bool realm_sync_exception_handler(void)
-{
-	uint64_t esr_el1 = read_esr_el1();
-
-	if (EC_BITS(esr_el1) == EC_UNKNOWN) {
-		realm_printf("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;
+	realm_reset_undef_abort_count();
 
-	/* install exception handler to catch undef abort */
+	/* Install exception handler to catch undefined 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;
+	return (realm_get_undef_abort_count() != 0U);
 }
 
 /* Reads and returns the ID_AA64PFR1_EL1 and ID_AA64SMFR0_EL1 registers */
@@ -240,16 +222,12 @@
 /* Check if Realm gets undefined abort when it access SME functionality */
 bool test_realm_sme_undef_abort(void)
 {
-	realm_got_undef_abort = 0UL;
+	realm_reset_undef_abort_count();
 
-	/* install exception handler to catch undef abort */
+	/* Install exception handler to catch undefined abort */
 	register_custom_sync_exception_handler(&realm_sync_exception_handler);
 	(void)read_svcr();
 	unregister_custom_sync_exception_handler();
 
-	if (realm_got_undef_abort == 0UL) {
-		return false;
-	}
-
-	return true;
+	return (realm_get_undef_abort_count() != 0U);
 }