arch-arm: Allow EL2 trapping of secure AA32 instructions

With the introduction of FEAT_SEL2 we should allow trapping
to EL2 in secure mode. This is already implemented for AArch64
EL1. With this patch we are extending it to AArch32

Change-Id: I3551a93af7db0b1d2bdf0935c3a29e39e8db55f8
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/53266
Reviewed-by: Richard Cooper <richard.cooper@arm.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/arch/arm/utility.cc b/src/arch/arm/utility.cc
index 3cc4b43..d24f470 100644
--- a/src/arch/arm/utility.cc
+++ b/src/arch/arm/utility.cc
@@ -519,14 +519,12 @@
     uint32_t opc2;
     bool trap_to_hyp = false;
 
-    const CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
     const HCR hcr = tc->readMiscReg(MISCREG_HCR);
-    const SCR scr = tc->readMiscReg(MISCREG_SCR);
     const HDCR hdcr = tc->readMiscReg(MISCREG_HDCR);
     const HSTR hstr = tc->readMiscReg(MISCREG_HSTR);
     const HCPTR hcptr = tc->readMiscReg(MISCREG_HCPTR);
 
-    if (!inSecureState(scr, cpsr) && (cpsr.mode != MODE_HYP)) {
+    if (EL2Enabled(tc) && (currEL(tc) < EL2)) {
         mcrMrcIssExtract(iss, is_read, crm, rt, crn, opc1, opc2);
         trap_to_hyp  = ((uint32_t) hstr) & (1 << crn);
         trap_to_hyp |= hdcr.tpm  && (crn == 9) && (crm >= 12);
@@ -674,8 +672,6 @@
     uint32_t opc1;
     uint32_t opc2;
 
-    const CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
-    const SCR scr = tc->readMiscReg(MISCREG_SCR);
     const HCR hcr = tc->readMiscReg(MISCREG_HCR);
     const HDCR hdcr = tc->readMiscReg(MISCREG_HDCR);
     const HSTR hstr = tc->readMiscReg(MISCREG_HSTR);
@@ -683,7 +679,7 @@
 
     bool trap_to_hyp = false;
 
-    if (!inSecureState(scr, cpsr) && (cpsr.mode != MODE_HYP)) {
+    if (EL2Enabled(tc) && (currEL(tc) < EL2)) {
         mcrMrcIssExtract(iss, is_read, crm, rt, crn, opc1, opc2);
         inform("trap check M:%x N:%x 1:%x 2:%x hdcr %x, hcptr %x, hstr %x\n",
                 crm, crn, opc1, opc2, hdcr, hcptr, hstr);
@@ -743,12 +739,10 @@
     bool is_read;
     bool trap_to_hyp = false;
 
-    const CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
     const HCR hcr = tc->readMiscReg(MISCREG_HCR);
-    const SCR scr = tc->readMiscReg(MISCREG_SCR);
     const HSTR hstr = tc->readMiscReg(MISCREG_HSTR);
 
-    if (!inSecureState(scr, cpsr) && (cpsr.mode != MODE_HYP)) {
+    if (EL2Enabled(tc) && (currEL(tc) < EL2)) {
         // This is technically the wrong function, but we can re-use it for
         // the moment because we only need one field, which overlaps with the
         // mcrmrc layout