From cb04e919abb6b392ec20e930420a93c45fa30dca Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Fri, 16 Feb 2018 14:47:42 -0500 Subject: [PATCH] target-arm: implement arm_debug_target_el() Implement debug exception routing according to ARM ARM D2.3.1 Pseudocode description of routing debug exceptions. Backports commit 81669b8b81eb450d7b89ee5fdd57bdb73d87022d from qemu --- qemu/target-arm/cpu.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/qemu/target-arm/cpu.h b/qemu/target-arm/cpu.h index 63beab05..cccb2cc4 100644 --- a/qemu/target-arm/cpu.h +++ b/qemu/target-arm/cpu.h @@ -1725,7 +1725,22 @@ static inline int cpu_mmu_index(CPUARMState *env, bool ifetch) */ static inline int arm_debug_target_el(CPUARMState *env) { - return 1; + bool secure = arm_is_secure(env); + bool route_to_el2 = false; + + if (arm_feature(env, ARM_FEATURE_EL2) && !secure) { + route_to_el2 = env->cp15.hcr_el2 & HCR_TGE || + env->cp15.mdcr_el2 & (1 << 8); + } + + if (route_to_el2) { + return 2; + } else if (arm_feature(env, ARM_FEATURE_EL3) && + !arm_el_is_aa64(env, 3) && secure) { + return 3; + } else { + return 1; + } } static inline bool aa64_generate_debug_exceptions(CPUARMState *env)