test(el3-runtime): check DIT is retained on exception

Add a test to check that the PSTATE bits not set in the
Aarch64.TakeException but set to a default when taking an exception to
EL3 are maintained after an exception and that changes in TSP do not
effect the PSTATE in TFTF and vice versa.

Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: Id4d625c7e9cbb565ac236f844274319cc02c2335
diff --git a/include/common/test_helpers.h b/include/common/test_helpers.h
index 0881f00..74b71a7 100644
--- a/include/common/test_helpers.h
+++ b/include/common/test_helpers.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -90,6 +90,15 @@
 		}								\
 	} while (0)
 
+#define SKIP_TEST_IF_DIT_NOT_SUPPORTED()					\
+	do {									\
+		if (!is_armv8_4_dit_present()) {				\
+			tftf_testcase_printf(					\
+				"DIT not supported\n");				\
+			return TEST_RESULT_SKIPPED;				\
+		}								\
+	} while (0)
+
 #define SKIP_TEST_IF_PAUTH_NOT_SUPPORTED()					\
 	do {									\
 		if (!is_armv8_3_pauth_present()) {				\
diff --git a/include/lib/aarch32/arch_features.h b/include/lib/aarch32/arch_features.h
index 1addc44..3c6a338 100644
--- a/include/lib/aarch32/arch_features.h
+++ b/include/lib/aarch32/arch_features.h
@@ -42,6 +42,12 @@
 		ID_DFR0_TRACEFILT_SUPPORTED;
 }
 
+static inline bool is_armv8_4_dit_present(void)
+{
+	return ((read_id_pfr0() >> ID_PFR0_DIT_SHIFT) &
+		ID_PFR0_DIT_MASK) != 0;
+}
+
 static inline bool get_armv8_0_sys_reg_trace_support(void)
 {
 	return ((read_id_dfr0() >> ID_DFR0_COPTRC_SHIFT) &
diff --git a/include/lib/aarch32/arch_helpers.h b/include/lib/aarch32/arch_helpers.h
index 6e1097d..aca3952 100644
--- a/include/lib/aarch32/arch_helpers.h
+++ b/include/lib/aarch32/arch_helpers.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2016-2022, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -422,6 +422,9 @@
 #define read_daif()		read_cpsr()
 #define write_daif(flags)	write_cpsr(flags)
 
+#define read_dit()		read_cpsr()
+#define write_dit(flags)	write_cpsr(flags)
+
 #define read_cnthp_cval_el2()	read64_cnthp_cval_el2()
 #define write_cnthp_cval_el2(v)	write64_cnthp_cval_el2(v)
 
diff --git a/include/runtime_services/secure_el1_payloads/tsp.h b/include/runtime_services/secure_el1_payloads/tsp.h
index 87ee6f7..19db911 100644
--- a/include/runtime_services/secure_el1_payloads/tsp.h
+++ b/include/runtime_services/secure_el1_payloads/tsp.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -32,6 +32,7 @@
 #define TSP_MUL		0x2002
 #define TSP_DIV		0x2003
 #define TSP_HANDLE_SEL1_INTR_AND_RETURN	0x2004
+#define TSP_CHECK_DIT	0x2005
 
 /*
  * Identify a TSP service from function ID filtering the last 16 bits from the