diff mbox

[v1,15/16] target-arm: Add IRQ and FIQ routing to EL2 and 3

Message ID 1401434911-26992-16-git-send-email-edgar.iglesias@gmail.com
State New
Headers show

Commit Message

Edgar E. Iglesias May 30, 2014, 7:28 a.m. UTC
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 target-arm/cpu.h    | 10 ++++++++++
 target-arm/helper.c | 16 ++++++++++++++++
 2 files changed, 26 insertions(+)

Comments

Alex Bennée June 3, 2014, 10:47 a.m. UTC | #1
Edgar E. Iglesias writes:

> From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
>
> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
> ---
>  target-arm/cpu.h    | 10 ++++++++++
>  target-arm/helper.c | 16 ++++++++++++++++
>  2 files changed, 26 insertions(+)
>
> diff --git a/target-arm/cpu.h b/target-arm/cpu.h
> index b3631f2..d15e8d2 100644
> --- a/target-arm/cpu.h
> +++ b/target-arm/cpu.h
> @@ -1133,6 +1133,8 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
>      CPUARMState *env = cs->env_ptr;
>      unsigned int cur_el = arm_current_pl(env);
>      unsigned int target_el = arm_excp_target_el(cs, excp_idx);
> +    /* FIXME: Use actual secure state.  */
> +    bool secure = false;

Again FIXME?

>  
>      /* Don't take exceptions if they target a lower EL.  */
>      if (cur_el > target_el) {
> @@ -1141,8 +1143,16 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
>  
>      switch (excp_idx) {
>      case EXCP_FIQ:
> +        if (!secure && cur_el < 2 && target_el == 2
> +            && (env->cp15.hcr_el2 & HCR_FMO)) {
> +            return true;
> +        }
>          return !(env->daif & PSTATE_F);
>      case EXCP_IRQ:
> +        if (!secure && cur_el < 2 && target_el == 2
> +            && (env->cp15.hcr_el2 & HCR_IMO)) {
> +            return true;
> +        }
>          return ((IS_M(env) && env->regs[15] < 0xfffffff0)
>                              || !(env->daif & PSTATE_I));

Hmm identical but subtly different tests may cause later trip ups.

> diff --git a/target-arm/helper.c b/target-arm/helper.c
> index 35091ea..649476b 100644
> --- a/target-arm/helper.c
> +++ b/target-arm/helper.c
> @@ -3304,6 +3304,22 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx)
>              target_el = 2;
>          }
>          break;
> +    case EXCP_IRQ:
> +        if (!secure && (env->cp15.hcr_el2 & HCR_IMO)) {
> +            target_el = 2;
> +        }
> +        if (env->cp15.scr_el3 & SCR_IRQ) {
> +            target_el = 3;
> +        }
> +        break;
> +    case EXCP_FIQ:
> +        if (!secure && (env->cp15.hcr_el2 & HCR_FMO)) {
> +            target_el = 2;
> +        }
> +        if (env->cp15.scr_el3 & SCR_FIQ) {
> +            target_el = 3;
> +        }
> +        break;

I wonder if it's possible to make the common logic more common while
keeping the differences?

>      }
>      return target_el;
>  }
diff mbox

Patch

diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index b3631f2..d15e8d2 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -1133,6 +1133,8 @@  static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
     CPUARMState *env = cs->env_ptr;
     unsigned int cur_el = arm_current_pl(env);
     unsigned int target_el = arm_excp_target_el(cs, excp_idx);
+    /* FIXME: Use actual secure state.  */
+    bool secure = false;
 
     /* Don't take exceptions if they target a lower EL.  */
     if (cur_el > target_el) {
@@ -1141,8 +1143,16 @@  static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
 
     switch (excp_idx) {
     case EXCP_FIQ:
+        if (!secure && cur_el < 2 && target_el == 2
+            && (env->cp15.hcr_el2 & HCR_FMO)) {
+            return true;
+        }
         return !(env->daif & PSTATE_F);
     case EXCP_IRQ:
+        if (!secure && cur_el < 2 && target_el == 2
+            && (env->cp15.hcr_el2 & HCR_IMO)) {
+            return true;
+        }
         return ((IS_M(env) && env->regs[15] < 0xfffffff0)
                             || !(env->daif & PSTATE_I));
     default:
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 35091ea..649476b 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -3304,6 +3304,22 @@  unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx)
             target_el = 2;
         }
         break;
+    case EXCP_IRQ:
+        if (!secure && (env->cp15.hcr_el2 & HCR_IMO)) {
+            target_el = 2;
+        }
+        if (env->cp15.scr_el3 & SCR_IRQ) {
+            target_el = 3;
+        }
+        break;
+    case EXCP_FIQ:
+        if (!secure && (env->cp15.hcr_el2 & HCR_FMO)) {
+            target_el = 2;
+        }
+        if (env->cp15.scr_el3 & SCR_FIQ) {
+            target_el = 3;
+        }
+        break;
     }
     return target_el;
 }