target-arm: A64: Emulate the SMC insn
Quoted 42 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 1 + target-arm/helper-a64.c | 1 + target-arm/helper.c | 6 ++++++ target-arm/helper.h | 1 + target-arm/internals.h | 6 ++++++ target-arm/op_helper.c | 11 +++++++++++ target-arm/translate-a64.c | 10 ++++++++++ 7 files changed, 36 insertions(+)target-arm/cpu.h +1
-0@@ -52,6 +52,7 @@#define EXCP_KERNEL_TRAP 9/* Jumped to kernel code page. */ #define EXCP_STREX 10#define EXCP_HVC 11/* HyperVisor Call */ +#define EXCP_SMC 12/* Secure Monitor Call */ #define ARMV7M_EXCP_RESET 1#define ARMV7M_EXCP_NMI 2target-arm/helper-a64.c +1
-0@@ -476,6 +476,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs)case EXCP_UDEF :case EXCP_SWI :case EXCP_HVC : +case EXCP_SMC : env->cp15.esr_el[new_el] = env->exception.syndrome;break ;case EXCP_IRQ :target-arm/helper.c +0
-0
target-arm/helper.c unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx) · line 3303
Quoted 6 lines
target-arm/helper.c +3
-0@@ -3298,6 +3298,12 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx)case EXCP_HVC : target_el =MAX (target_el,2 );break ; +case EXCP_SMC : + target_el =3 ; +if (env->cp15.hcr_el2 &HCR_TSC ) {
The HCR.TSC routing of SMC to EL2 only applies in NS EL1 mode, will fix for v2 as:
case EXCP_SMC:
target_el = 3;
if (!secure && cur_el == 1 && (env->cp15.hcr_el2 & HCR_TSC)) {
target_el = 2;
}
break;Quoted 88 lines
target-arm/helper.c +3
-0+ target_el =2 ; + } +break ; }return target_el; }target-arm/helper.h +1
-0@@ -51,6 +51,7 @@ DEF_HELPER_3(exception_with_syndrome, void, env, i32, i32) DEF_HELPER_1(wfi, void, env) DEF_HELPER_1(wfe, void, env) DEF_HELPER_2(hvc, void, env, i32) +DEF_HELPER_2(smc, void, env, i32) DEF_HELPER_3(cpsr_write, void, env, i32, i32)DEF_HELPER_1 (cpsr_read, i32, env)target-arm/internals.h +6
-0@@ -54,6 +54,7 @@ static const char * const excnames[] = { [EXCP_KERNEL_TRAP] = "QEMU intercept of kernel commpage", [EXCP_STREX] = "QEMU intercept of STREX", [EXCP_HVC] = "Hypervisor Call", + [EXCP_SMC] = "Secure Monitor Call", };static inline void arm_log_exception (int idx)@@ -210,6 +211,11 @@ static inline uint32_t syn_aa64_hvc(uint32_t imm16)return (EC_AA64_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); } +static inline uint32_t syn_aa64_smc (uint32_t imm16) +{ +return (EC_AA64_SMC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); +} +static inline uint32_t syn_aa32_svc (uint32_t imm16,bool is_thumb) {return (EC_AA32_SVC <<ARM_EL_EC_SHIFT ) | (imm16 &0xffff )target-arm/op_helper.c +11
-0@@ -405,6 +405,17 @@ void HELPER(hvc)(CPUARMState *env, uint32_t syndrome)raise_exception (env,EXCP_HVC ); } +void HELPER (smc )(CPUARMState *env,uint32_t syndrome) +{ +/* We've already checked that EL3 exists at translation time. */ +if (env->cp15.scr_el3 &SCR_SMD ) { + env->exception.syndrome =syn_uncategorized (); +raise_exception (env,EXCP_UDEF ); + } + env->exception.syndrome = syndrome; +raise_exception (env,EXCP_SMC ); +} +void HELPER (exception_return )(CPUARMState *env) {int cur_el =arm_current_pl (env);target-arm/translate-a64.c +10
-0@@ -1451,6 +1451,16 @@ static void disas_exc(DisasContext *s, uint32_t insn)gen_helper_hvc (cpu_env, tmp);tcg_temp_free_i32 (tmp);break ; +case 3 : +if (!arm_dc_feature (s,ARM_FEATURE_EL3 ) || s->current_pl ==0 ) { +unallocated_encoding (s); +break ; + } + tmp =tcg_const_i32 (syn_aa64_smc (imm16)); +gen_a64_set_pc_im (s->pc); +gen_helper_smc (cpu_env, tmp); +tcg_temp_free_i32 (tmp); +break ;default :unallocated_encoding (s);break ;Signature · 1 line
1.8.3.2
Alex Bennée
Reviewed-byRe: [Qemu-devel] [PATCH v1 01/16] target-arm: A64: Break out aarch64_save/restore_sp
In reply to a message not in the archiveQuoted 27 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Break out code to save/restore AArch64 SP into functions.
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/internals.h | 29 ++++++++++++++++++++--------- target-arm/kvm64.c | 13 +++---------- target-arm/op_helper.c | 6 +----- 3 files changed, 24 insertions(+), 24 deletions(-)target-arm/internals.h +8
-0@@ -105,6 +105,24 @@ enum arm_fprounding {int arm_rmode_to_sf (int rmode); +static inline void aarch64_save_sp (CPUARMState *env,int el) +{ +if (env->pstate &PSTATE_SP ) { + env->sp_el[el] = env->xregs[31 ]; + }else { + env->sp_el[0 ] = env->xregs[31 ]; + } +}
target-arm/internals.h enum arm_fprounding { · line 125
Quoted 10 lines
target-arm/internals.h +10
-0+ +static inline void aarch64_restore_sp (CPUARMState *env,int el) +{ +if (env->pstate &PSTATE_SP ) { + env->xregs[31 ] = env->sp_el[el]; + }else { + env->xregs[31 ] = env->sp_el[0 ]; + } +} +
Just a note to say I'm currently looking at rationalising env->pstate/env->uncached_cpsr and the various access functions. However conveniently this moves everything to one place so I approve ;-)
Quoted 71 lines
target-arm/internals.h +2
-9static inline void update_spsel (CPUARMState *env,uint32_t imm) {unsigned int cur_el =arm_current_pl (env);@@ -114,21 +132,14 @@ static inline void update_spsel(CPUARMState *env, uint32_t imm)if (!((imm ^ env->pstate) &PSTATE_SP )) {return ; } +aarch64_save_sp (env, cur_el); env->pstate =deposit32 (env->pstate,0 ,1 , imm);/* We rely on illegal updates to SPsel from EL0 to get trapped * at translation time. */ assert (cur_el >=1 && cur_el <=3 ); -if (env->pstate &PSTATE_SP ) { -/* Switch from using SP_EL0 to using SP_ELx */ - env->sp_el[0 ] = env->xregs[31 ]; - env->xregs[31 ] = env->sp_el[cur_el]; - }else { -/* Switch from SP_EL0 to SP_ELx */ - env->sp_el[cur_el] = env->xregs[31 ]; - env->xregs[31 ] = env->sp_el[0 ]; - } +aarch64_restore_sp (env, cur_el); }/* Valid Syndrome Register EC field values */ target-arm/kvm64.c +3
-10@@ -21,6 +21,7 @@#include "sysemu/kvm.h" #include "kvm_arm.h" #include "cpu.h" +#include "internals.h" #include "hw/arm/arm.h" static inline void set_feature (uint64_t *features,int feature)@@ -124,11 +125,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)/* KVM puts SP_EL0 in regs.sp and SP_EL1 in regs.sp_el1. On the * QEMU side we keep the current SP in xregs[31] as well. */ -if (env->pstate &PSTATE_SP ) { - env->sp_el[1 ] = env->xregs[31 ]; - }else { - env->sp_el[0 ] = env->xregs[31 ]; - } +aarch64_save_sp (env,1 ); reg.id =AARCH64_CORE_REG (regs.sp); reg.addr = (uintptr_t ) &env->sp_el[0 ];@@ -227,11 +224,7 @@ int kvm_arch_get_registers(CPUState *cs)/* KVM puts SP_EL0 in regs.sp and SP_EL1 in regs.sp_el1. On the * QEMU side we keep the current SP in xregs[31] as well. */ -if (env->pstate &PSTATE_SP ) { - env->xregs[31 ] = env->sp_el[1 ]; - }else { - env->xregs[31 ] = env->sp_el[0 ]; - } +aarch64_restore_sp (env,1 ); reg.id =AARCH64_CORE_REG (regs.pc); reg.addr = (uintptr_t ) &env->pc;target-arm/op_helper.c +0
-0@@ -391,11 +391,7 @@ void HELPER(exception_return)(CPUARMState *env)uint32_t spsr = env->banked_spsr[spsr_idx];
target-arm/op_helper.c void HELPER(exception_return)(CPUARMState *env) · line 396
Quoted 10 lines
target-arm/op_helper.c +1
-5int new_el, i; -if (env->pstate &PSTATE_SP ) { - env->sp_el[cur_el] = env->xregs[31 ]; - }else { - env->sp_el[0 ] = env->xregs[31 ]; - } +aarch64_save_sp (env, cur_el); env->exclusive_addr =-1 ;
Signature · 1 line
Alex Bennée
Alex Bennée
Reviewed-byRe: [Qemu-devel] [PATCH v1 02/16] target-arm: A64: Respect SPSEL in ERET SP restore
In reply to a message not in the archiveQuoted 12 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/op_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-arm/op_helper.c +0
-0
target-arm/op_helper.c void HELPER(exception_return)(CPUARMState *env) · line 430
Quoted 7 lines
target-arm/op_helper.c +1
-1@@ -425,7 +425,7 @@ void HELPER(exception_return)(CPUARMState *env) } env->aarch64 =1 ;pstate_write (env, spsr); - env->xregs[31 ] = env->sp_el[new_el]; +aarch64_restore_sp (env, new_el); env->pc = env->elr_el[cur_el]; }
It might be worth putting the Aarch64 ARM reference next to the aarch64_ functions to make it easier to find in future.
Signature · 1 line
Alex Bennée
Alex Bennée
Reviewed-byRe: [Qemu-devel] [PATCH v1 03/16] target-arm: A64: Respect SPSEL when taking exceptions
In reply to a message not in the archiveQuoted 22 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/helper-a64.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target-arm/helper-a64.c +1
-2@@ -489,8 +489,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs)if (is_a64 (env)) { env->banked_spsr[aarch64_banked_spsr_index (1 )] =pstate_read (env); - env->sp_el[arm_current_pl (env)] = env->xregs[31 ]; - env->xregs[31 ] = env->sp_el[1 ]; +aarch64_save_sp (env,arm_current_pl (env)); env->elr_el[1 ] = env->pc; }else { env->banked_spsr[0 ] =cpsr_read (env);
target-arm/helper-a64.c void aarch64_cpu_do_interrupt(CPUState *cs) · line 513
Quoted 7 lines
target-arm/helper-a64.c +1
-0@@ -508,6 +507,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs)pstate_write (env,PSTATE_DAIF | PSTATE_MODE_EL1h); env->aarch64 =1 ; +aarch64_restore_sp (env,1 ); env->pc = addr; cs->interrupt_request |=CPU_INTERRUPT_EXITTB ;
Signature · 1 line
Alex Bennée
Quoted 116 lines · Edgar E. Iglesias
Quoted 1 line · Greg Bellows
On 30 May 2014 02:28, Edgar E. Iglesias <[email protected]>
Quoted 80 lines · wrote:
Quoted 80 lines
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 1 + target-arm/helper-a64.c | 1 + target-arm/helper.c | 6 ++++++ target-arm/helper.h | 1 + target-arm/internals.h | 6 ++++++ target-arm/op_helper.c | 11 +++++++++++ target-arm/translate-a64.c | 10 ++++++++++ 7 files changed, 36 insertions(+)target-arm/cpu.h +1
-0@@ -52,6 +52,7 @@#define EXCP_KERNEL_TRAP 9/* Jumped to kernel code page. */ #define EXCP_STREX 10#define EXCP_HVC 11/* HyperVisor Call */ +#define EXCP_SMC 12/* Secure Monitor Call */ #define ARMV7M_EXCP_RESET 1#define ARMV7M_EXCP_NMI 2target-arm/helper-a64.c +1
-0@@ -476,6 +476,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs)case EXCP_UDEF :case EXCP_SWI :case EXCP_HVC : +case EXCP_SMC : env->cp15.esr_el[new_el] = env->exception.syndrome;break ;case EXCP_IRQ :target-arm/helper.c +6
-0@@ -3298,6 +3298,12 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx)case EXCP_HVC : target_el =MAX (target_el,2 );break ; +case EXCP_SMC : + target_el =3 ; +if (env->cp15.hcr_el2 &HCR_TSC ) { + target_el =2 ; + } +break ; }return target_el;}
target-arm/helper.h +1
-0@@ -51,6 +51,7 @@ DEF_HELPER_3(exception_with_syndrome, void, env, i32, i32) DEF_HELPER_1(wfi, void, env) DEF_HELPER_1(wfe, void, env) DEF_HELPER_2(hvc, void, env, i32) +DEF_HELPER_2(smc, void, env, i32) DEF_HELPER_3(cpsr_write, void, env, i32, i32)
DEF_HELPER_1(cpsr_read, i32, env)target-arm/internals.h +1
-0@@ -54,6 +54,7 @@ static const char * const excnames[] = { [EXCP_KERNEL_TRAP] = "QEMU intercept of kernel commpage", [EXCP_STREX] = "QEMU intercept of STREX", [EXCP_HVC] = "Hypervisor Call", + [EXCP_SMC] = "Secure Monitor Call", };Quoted 2 lines
target-arm/internals.h static inline uint32_t syn_aa64_hvc(uint32_t
Quoted 2 lines
target-arm/internals.h +0
-0static inline void arm_log_exception (int idx)@@ -210,6 +211,11 @@ static inline uint32_t syn_aa64_hvc(uint32_timm16)
Quoted 4 lines
Quoted 4 lines
target-arm/internals.h +0
-0return (EC_AA64_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); }Quoted 14 lines
target-arm/op_helper.c void HELPER(hvc)(CPUARMState *env, uint32_t
Quoted 14 lines
target-arm/internals.h +5
-0+static inline uint32_t syn_aa64_smc (uint32_t imm16) +{ +return (EC_AA64_SMC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); +} +static inline uint32_t syn_aa32_svc (uint32_t imm16,bool is_thumb){ return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff)target-arm/op_helper.c +0
-0@@ -405,6 +405,17 @@ void HELPER(hvc)(CPUARMState *env, uint32_tsyndrome)
Quoted 11 lines
target-arm/op_helper.c void HELPER(hvc)(CPUARMState *env, uint32_t · line 412
Quoted 8 lines
target-arm/op_helper.c +4
-0raise_exception (env,EXCP_HVC ); } +void HELPER (smc )(CPUARMState *env,uint32_t syndrome) +{ +/* We've already checked that EL3 exists at translation time. */ +if (env->cp15.scr_el3 &SCR_SMD ) {In ARMv7 isn't this is this only a valid check if the virtualization extension is present? If so, should we be checking for the virt
Quoted 9 lines
extension
Quoted 1 line
on AArch32 prior to raising undefined?
My understanding is that on AArch32 SCR.SMD only applies
to NS mode and only if HCR.TSC=0 (always the case if EL2 does not exist but can also be zero even if EL2 exists).
So it's not dependant on virtual extensions/EL2 non-existance? Am I missing something?
I'm not sure how we handle this as the ARMv7 spec states the following for the SCD bit:
"*SCD, bit[7], when implementation includes the Virtualization Extensions*"
This is not worded the same in the ARMv8 spec, possibly because the extensions are assumed to always be present? The QQMU code still supports the notion of features in which case sometimes are extensions.
Quoted 4 lines
I'm not adding AArch32 SMC here but am happy to try to get it right in preparation for the AArch32 support.
Sure, I suspect that Fabian's commits on top of yours will close any AArch32 gaps.
Quoted 7 lines
The patch misses that the HCR.TSC routing of SMC to EL2 takes priority over SMD for NS EL1. For AArch32, I need to check for non-secure state aswell. I'll update those for v2.
Need to run a few tests but I'm considering something along these lines:
Quoted 9 lines
void HELPER(smc)(CPUARMState *env,
uint32_tsyndrome){ int cur_el = arm_current_pl(env); /* FIXME: Use real secure state. */ bool secure = false; bool smd = env->cp15.scr_el3 & SCR_SMD; /* On AArch32, SMD only applies to NS mode. */ bool udef = is_a64(env) ? smd : !secure && smd;
Is it possible to get in here at EL0? A quick check, did not turn up a check for this in the code calling this helper, but I may have missed it.
Quoted 61 lines
/* In NS EL1, HCR controlled routing to EL2 has priority over SMD. */ if (!secure && cur_el == 1 && (env->cp15.hcr_el2 & HCR_TSC)) { udef = false; } /* We've already checked that EL3 exists at translation time. */ if (udef) { env->exception.syndrome = syn_uncategorized(); raise_exception(env, EXCP_UDEF); } env->exception.syndrome = syndrome; raise_exception(env, EXCP_SMC); }Thanks for the comments,
EdgarQuoted 15 lines
Quoted 15 lines
target-arm/op_helper.c +7
-0+ env->exception.syndrome =syn_uncategorized (); +raise_exception (env,EXCP_UDEF ); + } + env->exception.syndrome = syndrome; +raise_exception (env,EXCP_SMC ); +} +void HELPER (exception_return )(CPUARMState *env) {int cur_el = arm_current_pl(env);target-arm/translate-a64.c +0
-1--- a/target-arm/translate-a64.cQuoted 8 lines
target-arm/translate-a64.c static void disas_exc(DisasContext *s, uint32_t · line 1456
Quoted 8 lines
+++
b/target-arm/translate-a64.ctarget-arm/translate-a64.c +2
-0@@ -1451,6 +1451,16 @@ static void disas_exc(DisasContext *s, uint32_t insn)gen_helper_hvc (cpu_env ,tmp );tcg_temp_free_i32 (tmp);break ; +case 3 : + if (!arm_dc_feature(s, ARM_FEATURE_EL3) || s->current_pl==
Quoted 16 lines
Quoted 16 lines
target-arm/translate-a64.c +8
-00) { +unallocated_encoding (s); +break ; + } + tmp =tcg_const_i32 (syn_aa64_smc (imm16)); +gen_a64_set_pc_im (s->pc); +gen_helper_smc (cpu_env, tmp); +tcg_temp_free_i32 (tmp); +break ;default :unallocated_encoding(s); break;--
1.8.3.2
Re: [Qemu-devel] [PATCH v1 04/16] target-arm: Make far_el1 an array
In reply to a message not in the archiveQuoted 31 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
No functional change.
Prepares for future additions of the EL2 and 3 versions of this reg.Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.c | 2 +- target-arm/cpu.h | 2 +- target-arm/helper-a64.c | 4 ++-- target-arm/helper.c | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-)target-arm/cpu.c +1
-1@@ -446,7 +446,7 @@ static void arm1026_initfn(Object *obj)ARMCPRegInfo ifar = { .name ="IFAR" , .cp =15 , .crn =6 , .crm =0 , .opc1 =0 , .opc2 =1 , .access =PL1_RW , - .fieldoffset =offsetofhigh32 (CPUARMState, cp15.far_el1), + .fieldoffset =offsetofhigh32 (CPUARMState, cp15.far_el[1 ]), .resetvalue =0 };define_one_arm_cp_reg (cpu, &ifar);target-arm/cpu.h +0
-0
target-arm/cpu.h typedef struct CPUARMState { · line 190
Quoted 5 lines
target-arm/cpu.h +1
-1@@ -187,7 +187,7 @@ typedef struct CPUARMState {uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[2 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ -uint64_t far_el1;/* Fault address registers. */ +uint64_t far_el[2 ];/* Fault address registers. */
If there are EL1, 2 and 3 versions shouldn't this be [3]?
Quoted 10 lines
target-arm/cpu.h +0
-0uint64_t par_el1;/* Translation result. */ uint32_t c9_insn;/* Cache lockdown registers. */ uint32_t c9_data;target-arm/helper-a64.c +0
-0@@ -465,13 +465,13 @@ void aarch64_cpu_do_interrupt(CPUState *cs) }
target-arm/helper-a64.c void aarch64_cpu_do_interrupt(CPUState *cs) · line 474
Quoted 10 lines
target-arm/helper-a64.c +2
-2env->cp15.esr_el[1 ] = env->exception.syndrome; - env->cp15.far_el1 = env->exception.vaddress; + env->cp15.far_el[1 ] = env->exception.vaddress;switch (cs->exception_index) {case EXCP_PREFETCH_ABORT :case EXCP_DATA_ABORT :qemu_log_mask (CPU_LOG_INT ,"...with FAR 0x%" PRIx64"\n" , - env->cp15.far_el1); + env->cp15.far_el[1 ]);
As there is no FAR_EL0 shouldn't this be the first in the array (ie. 0?)
Quoted 47 lines
target-arm/helper-a64.c +0
-0break ;case EXCP_BKPT :case EXCP_UDEF :target-arm/helper.c +6
-6@@ -521,7 +521,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { .access = PL0_W, .type = ARM_CP_NOP }, { .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 2, .access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el1), + .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el[1]), .resetvalue = 0, },/* Watchpoint Fault Address Register : should actually only be present * for 1136, 1176, 11MPCore. @@ -1505,7 +1505,7 @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = {/* 64-bit FAR; this entry also gives us the AArch32 DFAR */ { .name = "FAR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el1), + .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[1]), .resetvalue = 0, }, REGINFO_SENTINEL };@@ -3414,8 +3414,8 @@ void arm_cpu_do_interrupt(CPUState *cs)/* Fall through to prefetch abort. */ case EXCP_PREFETCH_ABORT : env->cp15.ifsr_el2 = env->exception.fsr; - env->cp15.far_el1 =deposit64 (env->cp15.far_el1,32 ,32 , - env->exception.vaddress); + env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],32 ,32 , + env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with IFSR 0x%x IFAR 0x%x\n" , env->cp15.ifsr_el2, (uint32_t )env->exception.vaddress); new_mode =ARM_CPU_MODE_ABT ;@@ -3425,8 +3425,8 @@ void arm_cpu_do_interrupt(CPUState *cs)break ;case EXCP_DATA_ABORT : env->cp15.esr_el[1 ] = env->exception.fsr; - env->cp15.far_el1 =deposit64 (env->cp15.far_el1,0 ,32 , - env->exception.vaddress); + env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],0 ,32 , + env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with DFSR 0x%x DFAR 0x%x\n" , (uint32_t )env->cp15.esr_el[1 ], (uint32_t )env->exception.vaddress);
Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 06/16] target-arm: Add FAR_EL2 and 3
In reply to a message not in the archiveQuoted 13 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 2 +- target-arm/helper.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)target-arm/cpu.h +0
-0
target-arm/cpu.h typedef struct CPUARMState { · line 190
Quoted 5 lines
target-arm/cpu.h +1
-1@@ -187,7 +187,7 @@ typedef struct CPUARMState {uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[4 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ -uint64_t far_el[2 ];/* Fault address registers. */ +uint64_t far_el[4 ];/* Fault address registers. */
Ahh my confusion from earlier is now clear. Perhaps the two commits should be merged?
Quoted 27 lines
target-arm/cpu.h +0
-0uint64_t par_el1;/* Translation result. */ uint32_t c9_insn;/* Cache lockdown registers. */ uint32_t c9_data;target-arm/helper.c +6
-0@@ -2120,6 +2120,9 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = { .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 4, .crn = 5, .crm = 2, .opc2 = 1, .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[2]) }, + { .name = "FAR_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 6, .crm = 0, .opc2 = 0, + .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[2]) }, { .name = "SPSR_EL2", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 4, .crn = 4, .crm = 0, .opc2 = 0,@@ -2142,6 +2145,9 @@ static const ARMCPRegInfo v8_el3_cp_reginfo[] = { .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 6, .crn = 5, .crm = 2, .opc2 = 1, .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[3]) }, + { .name = "FAR_EL3", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 6, .crn = 6, .crm = 0, .opc2 = 0, + .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[3]) }, { .name = "SPSR_EL3", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 6, .crn = 4, .crm = 0, .opc2 = 0,
Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 07/16] target-arm: Add HCR_EL2
In reply to a message not in the archiveQuoted 47 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 35 +++++++++++++++++++++++++++++++++++ target-arm/helper.c | 27 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)target-arm/cpu.h +24
-0@@ -184,6 +184,7 @@ typedef struct CPUARMState {MPU write buffer control. */ uint32_t pmsav5_data_ap;/* PMSAv5 MPU data access permissions */ uint32_t pmsav5_insn_ap;/* PMSAv5 MPU insn access permissions */ +uint64_t hcr_el2;/* Hypervisor configuration register */ uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[4 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ @@ -526,6 +527,40 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) } } +#define HCR_VM (1ULL << 0) +#define HCR_SWIO (1ULL << 1) +#define HCR_PTW (1ULL << 2) +#define HCR_FMO (1ULL << 3) +#define HCR_IMO (1ULL << 4) +#define HCR_AMO (1ULL << 5) +#define HCR_VF (1ULL << 6) +#define HCR_VI (1ULL << 7) +#define HCR_VSE (1ULL << 8) +#define HCR_FB (1ULL << 9) +#define HCR_DC (1ULL << 12) +#define HCR_TWI (1ULL << 13) +#define HCR_TWE (1ULL << 14) +#define HCR_TID0 (1ULL << 15) +#define HCR_TID1 (1ULL << 16) +#define HCR_TID2 (1ULL << 17) +#define HCR_TID3 (1ULL << 18) +#define HCR_TSC (1ULL << 19) +#define HCR_TIDCP (1ULL << 20) +#define HCR_TACR (1ULL << 21) +#define HCR_TSW (1ULL << 22) +#define HCR_TPC (1ULL << 23) +#define HCR_TPU (1ULL << 24)
target-arm/cpu.h static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) · line 562
Quoted 10 lines
target-arm/cpu.h +10
-0+#define HCR_TTLB (1ULL << 25) +#define HCR_TVM (1ULL << 26) +#define HCR_TGE (1ULL << 27) +#define HCR_TDZ (1ULL << 28) +#define HCR_HCD (1ULL << 29) +#define HCR_TRVM (1ULL << 30) +#define HCR_RW (1ULL << 31) +#define HCR_CD (1ULL << 32) +#define HCR_ID (1ULL << 33) +#define HCR_RES0_MASK ((1ULL << 34) - 1)
Hmm isn't that actually HCR_MASK? I would expect the mask for the RES0 bits to be ~((1ULL << 34) - 1) but it's not actually used for that hence the name confusion.
Quoted 46 lines
target-arm/cpu.h +1
-0+/* Return the current FPSCR value. */ uint32_t vfp_get_fpscr (CPUARMState *env);void vfp_set_fpscr (CPUARMState *env,uint32_t val);target-arm/helper.c +27
-0@@ -2107,10 +2107,37 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 0, .opc2 = 0, .access = PL2_RW, .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore }, + { .name = "HCR_EL2", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_MIGRATE, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 0, + .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore }, REGINFO_SENTINEL }; +static void hcr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) +{ +ARMCPU *cpu =arm_env_get_cpu (env); +uint64_t res0_mask =HCR_RES0_MASK ; + +if (!arm_feature (env,ARM_FEATURE_EL3 )) { + res0_mask &= ~HCR_HCD ; + } + +/* Clear RES0 bits. */ + value &= res0_mask; + +if ((raw_read (env, ri) ^ value) &HCR_VM ) { +/* Flush the TLB when turning VM on/off. */ +tlb_flush (CPU (cpu),1 ); + } +raw_write (env, ri, value); +} +static const ARMCPRegInfo v8_el2_cp_reginfo[] = { + { .name ="HCR_EL2" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =4 , .crn =1 , .crm =1 , .opc2 =0 , + .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.hcr_el2), + .writefn = hcr_write }, { .name ="ELR_EL2" , .state =ARM_CP_STATE_AA64 , .type =ARM_CP_NO_MIGRATE , .opc0 =3 , .opc1 =4 , .crn =4 , .crm =0 , .opc2 =1 ,
Signature · 1 line
Alex Bennée
Alex Bennée
Reviewed-byRe: [Qemu-devel] [PATCH v1 08/16] target-arm: Add SCR_EL3
In reply to a message not in the archiveQuoted 27 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 15 +++++++++++++++ target-arm/helper.c | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+)target-arm/cpu.h +4
-0@@ -185,6 +185,7 @@ typedef struct CPUARMState {uint32_t pmsav5_data_ap;/* PMSAv5 MPU data access permissions */ uint32_t pmsav5_insn_ap;/* PMSAv5 MPU insn access permissions */ uint64_t hcr_el2;/* Hypervisor configuration register */ +uint32_t scr_el3;/* Secure configuration register. */ uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[4 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ @@ -561,6 +562,20 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)#define HCR_ID (1ULL << 33)#define HCR_RES0_MASK ((1ULL << 34) - 1) +#define SCR_NS (1U << 0) +#define SCR_IRQ (1U << 1) +#define SCR_FIQ (1U << 2)
target-arm/cpu.h static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) · line 577
Quoted 10 lines
target-arm/cpu.h +10
-0+#define SCR_EA (1U << 3) +#define SCR_SMD (1U << 7) +#define SCR_HCE (1U << 8) +#define SCR_SIF (1U << 9) +#define SCR_RW (1U << 10) +#define SCR_ST (1U << 11) +#define SCR_TWI (1U << 12) +#define SCR_TWE (1U << 13) +#define SCR_RES1_MASK (3U << 4) +#define SCR_RES0_MASK (0x3fff & ~SCR_RES1_MASK)
Again I have similar cognitive dissonance with the naming of the mask otherwise:
Quoted 41 lines
target-arm/cpu.h +1
-0+/* Return the current FPSCR value. */ uint32_t vfp_get_fpscr (CPUARMState *env);void vfp_set_fpscr (CPUARMState *env,uint32_t val);target-arm/helper.c +20
-0@@ -2162,6 +2162,22 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {REGINFO_SENTINEL }; +static void scr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) +{ +uint32_t res0_mask =SCR_RES0_MASK ; + +if (!arm_feature (env,ARM_FEATURE_EL2 )) { + res0_mask &= ~SCR_HCE ; + } + +/* Set RES1 bits. */ + value |=SCR_RES1_MASK ; + +/* Clear RES0 bits. */ + value &= res0_mask; +raw_write (env, ri, value); +} +static const ARMCPRegInfo v8_el3_cp_reginfo[] = { { .name ="ELR_EL3" , .state =ARM_CP_STATE_AA64 , .type =ARM_CP_NO_MIGRATE ,@@ -2184,6 +2200,10 @@ static const ARMCPRegInfo v8_el3_cp_reginfo[] = { .access = PL3_RW, .writefn = vbar_write, .fieldoffset = offsetof(CPUARMState, cp15.vbar_el[3]), .resetvalue = 0 }, + { .name = "SCR_EL3", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 1, .opc2 = 0, + .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.scr_el3), + .writefn = scr_write }, REGINFO_SENTINEL };
Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 10/16] target-arm: Break out exception masking to a separate func
In reply to a message not in the archiveQuoted 41 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- cpu-exec.c | 5 ++--- target-arm/cpu.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-)cpu-exec.c +2
-3@@ -478,7 +478,7 @@ int cpu_exec(CPUArchState *env) }#elif defined(TARGET_ARM)if (interrupt_request &CPU_INTERRUPT_FIQ - && !(env->daif &PSTATE_F )) { + &&arm_excp_unmasked (cpu,EXCP_FIQ )) { cpu->exception_index =EXCP_FIQ ; cc->do_interrupt (cpu); next_tb =0 ;@@ -493,8 +493,7 @@ int cpu_exec(CPUArchState *env)We avoid this by disabling interrupts when pc contains a magic address. */ if (interrupt_request &CPU_INTERRUPT_HARD - && ((IS_M (env) && env->regs[15 ] <0xfffffff0 ) - || !(env->daif &PSTATE_I ))) { + &&arm_excp_unmasked (cpu,EXCP_IRQ )) { cpu->exception_index =EXCP_IRQ ; cc->do_interrupt (cpu); next_tb =0 ;target-arm/cpu.h +2
-0@@ -1130,6 +1130,22 @@ bool write_cpustate_to_list(ARMCPU *cpu);# define TARGET_VIRT_ADDR_SPACE_BITS 32#endif +static inline bool arm_excp_unmasked (CPUState *cs,unsigned int excp_idx) +{
target-arm/cpu.h bool write_cpustate_to_list(ARMCPU *cpu); · line 1144
Quoted 10 lines
target-arm/cpu.h +10
-0+CPUARMState *env = cs->env_ptr; + +switch (excp_idx) { +case EXCP_FIQ : +return !(env->daif &PSTATE_F ); +case EXCP_IRQ : +return ((IS_M (env) && env->regs[15 ] <0xfffffff0 ) + || !(env->daif &PSTATE_I )); +default : +assert (0 );
g_assert_not_reached() is clearer about the intent here.
Quoted 7 lines
target-arm/cpu.h +4
-0+break ; + } +} +static inline CPUARMState *cpu_init (const char *cpu_model) {ARMCPU *cpu =cpu_arm_init (cpu_model);
Signature · 1 line
Alex Bennée
Alex Bennée
Reviewed-byRe: [Qemu-devel] [PATCH v1 12/16] target-arm: A64: Correct updates to FAR and ESR on exceptions
In reply to a message not in the archiveQuoted 24 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Not all exception types update both FAR and ESR.
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/helper-a64.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)target-arm/helper-a64.c +1
-3@@ -466,18 +466,16 @@ void aarch64_cpu_do_interrupt(CPUState *cs) env->exception.syndrome); } - env->cp15.esr_el[new_el] = env->exception.syndrome; - env->cp15.far_el[new_el] = env->exception.vaddress; -switch (cs->exception_index) {case EXCP_PREFETCH_ABORT :case EXCP_DATA_ABORT : + env->cp15.far_el[new_el] = env->exception.vaddress;
target-arm/helper-a64.c void aarch64_cpu_do_interrupt(CPUState *cs) · line 481
Quoted 10 lines
target-arm/helper-a64.c +1
-1qemu_log_mask (CPU_LOG_INT ,"...with FAR 0x%" PRIx64"\n" , env->cp15.far_el[new_el]); -break ;case EXCP_BKPT :case EXCP_UDEF :case EXCP_SWI : + env->cp15.esr_el[new_el] = env->exception.syndrome;break ;case EXCP_IRQ : addr +=0x80 ;
Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 13/16] target-arm: A64: Emulate the HVC insn
In reply to a message not in the archiveQuoted 26 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 7 ++----- target-arm/helper-a64.c | 1 + target-arm/helper.c | 39 +++++++++++++++++++++++++++++++++++++++ target-arm/helper.h | 1 + target-arm/internals.h | 6 ++++++ target-arm/op_helper.c | 21 +++++++++++++++++++++ target-arm/translate-a64.c | 21 ++++++++++++++++----- 7 files changed, 86 insertions(+), 10 deletions(-)target-arm/cpu.h +1
-0@@ -51,6 +51,7 @@#define EXCP_EXCEPTION_EXIT 8/* Return from v7M exception. */ #define EXCP_KERNEL_TRAP 9/* Jumped to kernel code page. */ #define EXCP_STREX 10 +#define EXCP_HVC 11/* HyperVisor Call */ #define ARMV7M_EXCP_RESET 1#define ARMV7M_EXCP_NMI 2
target-arm/cpu.h static inline bool arm_el_is_aa64(CPUARMState *env, int el) · line 719
Quoted 9 lines
target-arm/cpu.h +1
-5@@ -715,11 +716,7 @@ static inline bool arm_el_is_aa64(CPUARMState *env, int el) }void arm_cpu_list (FILE *f,fprintf_function cpu_fprintf); -static inline unsigned int arm_excp_target_el (CPUState *cs, -unsigned int excp_idx) -{ -return 1 ; -} +unsigned int arm_excp_target_el (CPUState *cs,unsigned int excp_idx);
If the earlier commit had added this in the final place to start with the functional diff would be clearer (although it's easy to eyeball in this case).
Quoted 36 lines
target-arm/cpu.h +0
-0/* Interface between CPU and Interrupt controller. */ void armv7m_nvic_set_pending (void *opaque,int irq);target-arm/helper-a64.c +1
-0@@ -475,6 +475,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs)case EXCP_BKPT :case EXCP_UDEF :case EXCP_SWI : +case EXCP_HVC : env->cp15.esr_el[new_el] = env->exception.syndrome;break ;case EXCP_IRQ :target-arm/helper.c +6
-0@@ -3208,6 +3208,11 @@ uint32_t HELPER(get_r13_banked)(CPUARMState *env, uint32_t mode) return 0; } +unsigned int arm_excp_target_el (CPUState *cs,unsigned int excp_idx) +{ +return 1 ; +} +#else /* Map CPU modes onto saved register banks. */ @@ -3263,6 +3268,40 @@ void switch_mode(CPUARMState *env, int mode) env->spsr = env->banked_spsr[i]; } +/*
target-arm/helper.c void switch_mode(CPUARMState *env, int mode) · line 3281
Quoted 10 lines
target-arm/helper.c +10
-0+* Determine the target EL for a given exception type. +*/ +unsigned int arm_excp_target_el (CPUState *cs,unsigned int excp_idx) +{ +CPUARMState *env = cs->env_ptr; +unsigned int cur_el =arm_current_pl (env); +unsigned int target_el =1 ; +bool route_to_el2 = false; +/* FIXME: Use actual secure state. */ +bool secure = false;
Should this be here?
<snip>
target-arm/helper.c static inline uint32_t syn_aa64_svc(uint32_t imm16) · line 211
Quoted 9 lines
target-arm/helper.c +4
-0static inline void arm_log_exception (int idx)@@ -204,6 +205,11 @@ static inline uint32_t syn_aa64_svc(uint32_t imm16)return (EC_AA64_SVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); } +static inline uint32_t syn_aa64_hvc (uint32_t imm16) +{ +return (EC_AA64_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); +}
The mask seems superfluous (as it is for arm_log_exception)
Quoted 74 lines
target-arm/helper.c +1
-0+static inline uint32_t syn_aa32_svc (uint32_t imm16,bool is_thumb) {return (EC_AA32_SVC <<ARM_EL_EC_SHIFT ) | (imm16 &0xffff )target-arm/op_helper.c +21
-0@@ -384,6 +384,27 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm) } } +void HELPER (hvc )(CPUARMState *env,uint32_t syndrome) +{ +bool udef; + +/* We've already checked that EL2 exists at translation time. +* EL3.HCE has priority over EL2.HCD. +*/ +if (arm_feature (env,ARM_FEATURE_EL3 )) { + udef = !(env->cp15.scr_el3 &SCR_HCE ); + }else { + udef = env->cp15.hcr_el2 &HCR_HCD ; + } + +if (udef) { + env->exception.syndrome =syn_uncategorized (); +raise_exception (env,EXCP_UDEF ); + } + env->exception.syndrome = syndrome; +raise_exception (env,EXCP_HVC ); +} +void HELPER (exception_return )(CPUARMState *env) {int cur_el =arm_current_pl (env);target-arm/translate-a64.c +16
-5@@ -1433,17 +1433,28 @@ static void disas_exc(DisasContext *s, uint32_t insn)int opc =extract32 (insn,21 ,3 );int op2_ll =extract32 (insn,0 ,5 );int imm16 =extract32 (insn,5 ,16 ); +TCGv_i32 tmp;switch (opc) {case 0 : -/* SVC, HVC, SMC; since we don't support the Virtualization -* or TrustZone extensions these all UNDEF except SVC. -*/ -if (op2_ll !=1 ) { +switch (op2_ll) { +case 1 : +gen_exception_insn (s,0 ,EXCP_SWI ,syn_aa64_svc (imm16)); +break ; +case 2 : +if (!arm_dc_feature (s,ARM_FEATURE_EL2 ) || s->current_pl ==0 ) { +unallocated_encoding (s); +break ; + } + tmp =tcg_const_i32 (syn_aa64_hvc (imm16)); +gen_a64_set_pc_im (s->pc); +gen_helper_hvc (cpu_env, tmp); +tcg_temp_free_i32 (tmp); +break ; +default :unallocated_encoding (s);break ; } -gen_exception_insn (s,0 ,EXCP_SWI ,syn_aa64_svc (imm16));break ;case 1 :if (op2_ll !=0 ) {
Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 15/16] target-arm: Add IRQ and FIQ routing to EL2 and 3
In reply to a message not in the archiveQuoted 13 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 10 ++++++++++ target-arm/helper.c | 16 ++++++++++++++++ 2 files changed, 26 insertions(+)target-arm/cpu.h +0
-0
target-arm/cpu.h static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx) · line 1137
Quoted 5 lines
target-arm/cpu.h +2
-0@@ -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?
Quoted 9 lines
target-arm/cpu.h +2
-0/* 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 )) {
target-arm/cpu.h static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx) · line 1157
Quoted 10 lines
target-arm/cpu.h +6
-0+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.
Quoted 14 lines
target-arm/helper.c +6
-0@@ -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 ;
target-arm/helper.c unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx) · line 3322
Quoted 10 lines
target-arm/helper.c +10
-0+ } +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?
Quoted 3 lines
target-arm/helper.c +0
-0}return target_el; }
Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 04/16] target-arm: Make far_el1 an array
In reply to Alex BennéeQuoted 34 lines · Alex Bennée
Quoted 18 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
No functional change.
Prepares for future additions of the EL2 and 3 versions of this reg.Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.c | 2 +- target-arm/cpu.h | 2 +- target-arm/helper-a64.c | 4 ++-- target-arm/helper.c | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-)target-arm/cpu.c +0
-0target-arm/cpu.c static void arm1026_initfn(Object *obj) · line 447
Quoted 2 lines
target-arm/cpu.c +0
-0@@ -446,7 +446,7 @@ static void arm1026_initfn(Object *obj)ARMCPRegInfo ifar = { .name ="IFAR" , .cp =15 , .crn =6 , .crm =0 , .opc1 =0 ,.opc2 = 1,
Quoted 10 lines
target-arm/cpu.c +1
-1.access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el1), + .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el[1]), .resetvalue = 0 };define_one_arm_cp_reg (cpu, &ifar);target-arm/cpu.h +0
-0
Quoted 10 lines
target-arm/cpu.h typedef struct CPUARMState { · line 190
Quoted 6 lines
target-arm/cpu.h +1
-1@@ -187,7 +187,7 @@ typedef struct CPUARMState {uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[2 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ -uint64_t far_el1;/* Fault address registers. */ +uint64_t far_el[2 ];/* Fault address registers. */ If there are EL1, 2 and 3 versions shouldn't this be [3]?
Or [4]? Even if we don't use all the EL slots, it would make for more readable and consistent code if we kept the indices consistent with the level value. Otherwise, as we discussed previously, we end up with different numbering schemes depending on the register.
Quoted 14 lines
Quoted 14 lines
target-arm/cpu.h +0
-0uint64_t par_el1;/* Translation result. */ uint32_t c9_insn;/* Cache lockdown registers. */ uint32_t c9_data;target-arm/helper-a64.c +1
-1@@ -465,13 +465,13 @@ void aarch64_cpu_do_interrupt(CPUState *cs) } env->cp15.esr_el[1 ] = env->exception.syndrome; - env->cp15.far_el1 = env->exception.vaddress; + env->cp15.far_el[1 ] = env->exception.vaddress;
Quoted 9 lines
target-arm/helper-a64.c void aarch64_cpu_do_interrupt(CPUState *cs) · line 474
Quoted 6 lines
target-arm/helper-a64.c +1
-1switch (cs->exception_index) {case EXCP_PREFETCH_ABORT :case EXCP_DATA_ABORT :qemu_log_mask (CPU_LOG_INT ,"...with FAR 0x%" PRIx64"\n" , - env->cp15.far_el1); + env->cp15.far_el[1 ]);As there is no
FAR_EL0shouldn't this be the first in the array (ie. 0?)
See above comment.
Quoted 57 lines
target-arm/helper.c static const ARMCPRegInfo v6_cp_reginfo[] = { · line 522
Quoted 11 lines
target-arm/helper-a64.c +0
-0break ;case EXCP_BKPT :case EXCP_UDEF :target-arm/helper.c +0
-0@@ -521,7 +521,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { .access = PL0_W, .type = ARM_CP_NOP }, { .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 =2,
target-arm/helper.c static const ARMCPRegInfo v6_cp_reginfo[] = { · line 526
Quoted 5 lines
target-arm/helper.c +1
-1.access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el1), + .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el[1]), .resetvalue = 0, },/* Watchpoint Fault Address Register : should actually only be present
target-arm/helper.c static const ARMCPRegInfo vmsa_cp_reginfo[] = { · line 1508
Quoted 6 lines
target-arm/helper.c +0
-1* for 1136, 1176, 11MPCore. @@ -1505,7 +1505,7 @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = {/* 64-bit FAR; this entry also gives us the AArch32 DFAR */ { .name = "FAR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState,cp15.far_el1),
target-arm/helper.c static const ARMCPRegInfo vmsa_cp_reginfo[] = { · line 1508
Quoted 1 line
target-arm/helper.c +1
-0+ .access = PL1_RW, .fieldoffset = offsetof(CPUARMState,cp15.far_el[1]),
target-arm/helper.c void arm_cpu_do_interrupt(CPUState *cs) · line 3420
Quoted 13 lines
target-arm/helper.c +2
-2.resetvalue = 0, }, REGINFO_SENTINEL };@@ -3414,8 +3414,8 @@ void arm_cpu_do_interrupt(CPUState *cs)/* Fall through to prefetch abort. */ case EXCP_PREFETCH_ABORT : env->cp15.ifsr_el2 = env->exception.fsr; - env->cp15.far_el1 =deposit64 (env->cp15.far_el1,32 ,32 , - env->exception.vaddress); + env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],32 ,32 , + env->exception.vaddress); qemu_log_mask(CPU_LOG_INT, "...with IFSR 0x%x IFAR 0x%x\n", env->cp15.ifsr_el2,(uint32_t)env->exception.vaddress);
target-arm/helper.c void arm_cpu_do_interrupt(CPUState *cs) · line 3432
Quoted 12 lines
target-arm/helper.c +2
-2new_mode =ARM_CPU_MODE_ABT ;@@ -3425,8 +3425,8 @@ void arm_cpu_do_interrupt(CPUState *cs)break ;case EXCP_DATA_ABORT : env->cp15.esr_el[1 ] = env->exception.fsr; - env->cp15.far_el1 =deposit64 (env->cp15.far_el1,0 ,32 , - env->exception.vaddress); + env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],0 ,32 , + env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with DFSR 0x%x DFAR 0x%x\n" , (uint32_t )env->cp15.esr_el[1 ], (uint32_t )env->exception.vaddress);--
Alex Bennée
Re: [Qemu-devel] [PATCH v1 04/16] target-arm: Make far_el1 an array
Quoted 46 lines · Greg Bellows
Quoted 34 lines · Alex Bennée
Quoted 18 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
No functional change.
Prepares for future additions of the EL2 and 3 versions of this reg.Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.c | 2 +- target-arm/cpu.h | 2 +- target-arm/helper-a64.c | 4 ++-- target-arm/helper.c | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-)target-arm/cpu.c +0
-0target-arm/cpu.c static void arm1026_initfn(Object *obj) · line 447
Quoted 2 lines
target-arm/cpu.c +0
-0@@ -446,7 +446,7 @@ static void arm1026_initfn(Object *obj)ARMCPRegInfo ifar = { .name ="IFAR" , .cp =15 , .crn =6 , .crm =0 , .opc1 =0 ,.opc2 = 1,
Quoted 10 lines
target-arm/cpu.c +1
-1.access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el1), + .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el[1]), .resetvalue = 0 };define_one_arm_cp_reg (cpu, &ifar);target-arm/cpu.h +0
-0Quoted 10 lines
target-arm/cpu.h typedef struct CPUARMState { · line 190
Quoted 6 lines
target-arm/cpu.h +1
-1@@ -187,7 +187,7 @@ typedef struct CPUARMState {uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[2 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ -uint64_t far_el1;/* Fault address registers. */ +uint64_t far_el[2 ];/* Fault address registers. */ If there are EL1, 2 and 3 versions shouldn't this be [3]?
Quoted 4 lines
Or [4]? Even if we don't use all the EL slots, it would make for more readable and consistent code if we kept the indices consistent with the level value. Otherwise, as we discussed previously, we end up with different numbering schemes depending on the register.
Makes sense although it would be nice to mark the unused ones somehow for debugging.
Quoted 86 lines
Quoted 16 lines
Quoted 16 lines
target-arm/cpu.h +0
-0uint64_t par_el1;/* Translation result. */ uint32_t c9_insn;/* Cache lockdown registers. */ uint32_t c9_data;target-arm/helper-a64.c +1
-1@@ -465,13 +465,13 @@ void aarch64_cpu_do_interrupt(CPUState *cs) } env->cp15.esr_el[1 ] = env->exception.syndrome; - env->cp15.far_el1 = env->exception.vaddress; + env->cp15.far_el[1 ] = env->exception.vaddress;Quoted 9 lines
target-arm/helper-a64.c void aarch64_cpu_do_interrupt(CPUState *cs) · line 474
Quoted 6 lines
target-arm/helper-a64.c +1
-1switch (cs->exception_index) {case EXCP_PREFETCH_ABORT :case EXCP_DATA_ABORT :qemu_log_mask (CPU_LOG_INT ,"...with FAR 0x%" PRIx64"\n" , - env->cp15.far_el1); + env->cp15.far_el[1 ]);As there is no
FAR_EL0shouldn't this be the first in the array (ie. 0?)See above comment.
Quoted 57 lines
target-arm/helper.c static const ARMCPRegInfo v6_cp_reginfo[] = { · line 522
Quoted 11 lines
target-arm/helper-a64.c +0
-0break ;case EXCP_BKPT :case EXCP_UDEF :target-arm/helper.c +0
-0@@ -521,7 +521,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { .access = PL0_W, .type = ARM_CP_NOP }, { .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 =2,
target-arm/helper.c static const ARMCPRegInfo v6_cp_reginfo[] = { · line 526
Quoted 5 lines
target-arm/helper.c +1
-1.access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el1), + .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el[1]), .resetvalue = 0, },/* Watchpoint Fault Address Register : should actually only be present
target-arm/helper.c static const ARMCPRegInfo vmsa_cp_reginfo[] = { · line 1508
Quoted 6 lines
target-arm/helper.c +0
-1* for 1136, 1176, 11MPCore. @@ -1505,7 +1505,7 @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = {/* 64-bit FAR; this entry also gives us the AArch32 DFAR */ { .name = "FAR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState,cp15.far_el1),
target-arm/helper.c static const ARMCPRegInfo vmsa_cp_reginfo[] = { · line 1508
Quoted 1 line
target-arm/helper.c +1
-0+ .access = PL1_RW, .fieldoffset = offsetof(CPUARMState,cp15.far_el[1]),
target-arm/helper.c void arm_cpu_do_interrupt(CPUState *cs) · line 3420
Quoted 13 lines
target-arm/helper.c +2
-2.resetvalue = 0, }, REGINFO_SENTINEL };@@ -3414,8 +3414,8 @@ void arm_cpu_do_interrupt(CPUState *cs)/* Fall through to prefetch abort. */ case EXCP_PREFETCH_ABORT : env->cp15.ifsr_el2 = env->exception.fsr; - env->cp15.far_el1 =deposit64 (env->cp15.far_el1,32 ,32 , - env->exception.vaddress); + env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],32 ,32 , + env->exception.vaddress); qemu_log_mask(CPU_LOG_INT, "...with IFSR 0x%x IFAR 0x%x\n", env->cp15.ifsr_el2,(uint32_t)env->exception.vaddress);
target-arm/helper.c void arm_cpu_do_interrupt(CPUState *cs) · line 3432
Quoted 12 lines
target-arm/helper.c +2
-2new_mode =ARM_CPU_MODE_ABT ;@@ -3425,8 +3425,8 @@ void arm_cpu_do_interrupt(CPUState *cs)break ;case EXCP_DATA_ABORT : env->cp15.esr_el[1 ] = env->exception.fsr; - env->cp15.far_el1 =deposit64 (env->cp15.far_el1,0 ,32 , - env->exception.vaddress); + env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],0 ,32 , + env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with DFSR 0x%x DFAR 0x%x\n" , (uint32_t )env->cp15.esr_el[1 ], (uint32_t )env->exception.vaddress);--
Alex Bennée
Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 04/16] target-arm: Make far_el1 an array
Probably simple enough just to check that the value is always zero as I believe that is what they are likely initialized to. Perhaps during reset?
Quoted 149 lines · Alex Bennée
Quoted 26 lines · Greg Bellows
Quoted 24 lines · Alex Bennée
Quoted 18 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
No functional change.
Prepares for future additions of the EL2 and 3 versions of this reg.Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.c | 2 +- target-arm/cpu.h | 2 +- target-arm/helper-a64.c | 4 ++-- target-arm/helper.c | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-)target-arm/cpu.c +0
-0target-arm/cpu.c static void arm1026_initfn(Object *obj) · line 447
Quoted 2 lines
target-arm/cpu.c +0
-0@@ -446,7 +446,7 @@ static void arm1026_initfn(Object *obj)ARMCPRegInfo ifar = { .name ="IFAR" , .cp =15 , .crn =6 , .crm =0 , .opc1 =0 ,.opc2 = 1,
Quoted 3 lines
Quoted 3 lines
target-arm/cpu.c static void arm1026_initfn(Object *obj) · line 449
Quoted 3 lines
target-arm/cpu.c +1
-1.access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el1), + .fieldoffset = offsetofhigh32(CPUARMState,cp15.far_el[1]),
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
target-arm/cpu.c +0
-0.resetvalue = 0 };define_one_arm_cp_reg (cpu, &ifar);target-arm/cpu.h +0
-0Quoted 10 lines
target-arm/cpu.h typedef struct CPUARMState { · line 190
Quoted 6 lines
target-arm/cpu.h +1
-1@@ -187,7 +187,7 @@ typedef struct CPUARMState {uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[2 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ -uint64_t far_el1;/* Fault address registers. */ +uint64_t far_el[2 ];/* Fault address registers. */ If there are EL1, 2 and 3 versions shouldn't this be [3]?
Quoted 4 lines
Or [4]? Even if we don't use all the EL slots, it would make for more readable and consistent code if we kept the indices consistent with the level value. Otherwise, as we discussed previously, we end up with different numbering schemes depending on the register.
Makes sense although it would be nice to mark the unused ones somehow for debugging.
Quoted 30 lines
Quoted 16 lines
Quoted 16 lines
target-arm/cpu.h +0
-0uint64_t par_el1;/* Translation result. */ uint32_t c9_insn;/* Cache lockdown registers. */ uint32_t c9_data;target-arm/helper-a64.c +1
-1@@ -465,13 +465,13 @@ void aarch64_cpu_do_interrupt(CPUState *cs) } env->cp15.esr_el[1 ] = env->exception.syndrome; - env->cp15.far_el1 = env->exception.vaddress; + env->cp15.far_el[1 ] = env->exception.vaddress;Quoted 9 lines
target-arm/helper-a64.c void aarch64_cpu_do_interrupt(CPUState *cs) · line 474
Quoted 6 lines
target-arm/helper-a64.c +1
-1switch (cs->exception_index) {case EXCP_PREFETCH_ABORT :case EXCP_DATA_ABORT :qemu_log_mask (CPU_LOG_INT ,"...with FAR 0x%" PRIx64"\n" , - env->cp15.far_el1); + env->cp15.far_el[1 ]);As there is no
FAR_EL0shouldn't this be the first in the array (ie. 0?)See above comment.
Quoted 1 line
Quoted 10 lines
Quoted 10 lines
target-arm/helper.c static const ARMCPRegInfo v6_cp_reginfo[] = { · line 522
Quoted 10 lines
target-arm/helper-a64.c +0
-0break ;case EXCP_BKPT :case EXCP_UDEF :target-arm/helper.c +0
-0@@ -521,7 +521,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { .access = PL0_W, .type = ARM_CP_NOP }, { .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2=
Quoted 30 lines
Quoted 30 lines
2,
target-arm/helper.c static const ARMCPRegInfo v6_cp_reginfo[] = { · line 526
Quoted 5 lines
target-arm/helper.c +1
-1.access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el1), + .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el[1]), .resetvalue = 0, },/* Watchpoint Fault Address Register : should actually only be present
target-arm/helper.c static const ARMCPRegInfo vmsa_cp_reginfo[] = { · line 1508
Quoted 6 lines
target-arm/helper.c +0
-1* for 1136, 1176, 11MPCore. @@ -1505,7 +1505,7 @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = {/* 64-bit FAR; this entry also gives us the AArch32 DFAR */ { .name = "FAR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState,cp15.far_el1),
target-arm/helper.c static const ARMCPRegInfo vmsa_cp_reginfo[] = { · line 1508
Quoted 1 line
target-arm/helper.c +1
-0+ .access = PL1_RW, .fieldoffset = offsetof(CPUARMState,cp15.far_el[1]),
target-arm/helper.c void arm_cpu_do_interrupt(CPUState *cs) · line 3420
Quoted 13 lines
target-arm/helper.c +2
-2.resetvalue = 0, }, REGINFO_SENTINEL };@@ -3414,8 +3414,8 @@ void arm_cpu_do_interrupt(CPUState *cs)/* Fall through to prefetch abort. */ case EXCP_PREFETCH_ABORT : env->cp15.ifsr_el2 = env->exception.fsr; - env->cp15.far_el1 =deposit64 (env->cp15.far_el1,32 ,32 , - env->exception.vaddress); + env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],32 ,32 , + env->exception.vaddress); qemu_log_mask(CPU_LOG_INT, "...with IFSR 0x%x IFAR 0x%x\n", env->cp15.ifsr_el2,(uint32_t)env->exception.vaddress);
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
target-arm/helper.c +0
-2new_mode =ARM_CPU_MODE_ABT ;@@ -3425,8 +3425,8 @@ void arm_cpu_do_interrupt(CPUState *cs)break ;case EXCP_DATA_ABORT : env->cp15.esr_el[1 ] = env->exception.fsr; - env->cp15.far_el1 =deposit64 (env->cp15.far_el1,0 ,32 , - env->exception.vaddress);Quoted 9 lines
target-arm/helper.c void arm_cpu_do_interrupt(CPUState *cs) · line 3432
Quoted 5 lines
target-arm/helper.c +2
-0+ env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],0 ,32 , + env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with DFSR 0x%x DFAR 0x%x\n" , (uint32_t )env->cp15.esr_el[1 ], (uint32_t )env->exception.vaddress);--
Alex Bennée--
Alex Bennée
Quoted 131 lines · Greg Bellows
Quoted 116 lines · Edgar E. Iglesias
Quoted 1 line · Greg Bellows
On 30 May 2014 02:28, Edgar E. Iglesias <[email protected]>
Quoted 80 lines · wrote:
Quoted 80 lines
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 1 + target-arm/helper-a64.c | 1 + target-arm/helper.c | 6 ++++++ target-arm/helper.h | 1 + target-arm/internals.h | 6 ++++++ target-arm/op_helper.c | 11 +++++++++++ target-arm/translate-a64.c | 10 ++++++++++ 7 files changed, 36 insertions(+)target-arm/cpu.h +1
-0@@ -52,6 +52,7 @@#define EXCP_KERNEL_TRAP 9/* Jumped to kernel code page. */ #define EXCP_STREX 10#define EXCP_HVC 11/* HyperVisor Call */ +#define EXCP_SMC 12/* Secure Monitor Call */ #define ARMV7M_EXCP_RESET 1#define ARMV7M_EXCP_NMI 2target-arm/helper-a64.c +1
-0@@ -476,6 +476,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs)case EXCP_UDEF :case EXCP_SWI :case EXCP_HVC : +case EXCP_SMC : env->cp15.esr_el[new_el] = env->exception.syndrome;break ;case EXCP_IRQ :target-arm/helper.c +6
-0@@ -3298,6 +3298,12 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx)case EXCP_HVC : target_el =MAX (target_el,2 );break ; +case EXCP_SMC : + target_el =3 ; +if (env->cp15.hcr_el2 &HCR_TSC ) { + target_el =2 ; + } +break ; }return target_el;}
target-arm/helper.h +1
-0@@ -51,6 +51,7 @@ DEF_HELPER_3(exception_with_syndrome, void, env, i32, i32) DEF_HELPER_1(wfi, void, env) DEF_HELPER_1(wfe, void, env) DEF_HELPER_2(hvc, void, env, i32) +DEF_HELPER_2(smc, void, env, i32) DEF_HELPER_3(cpsr_write, void, env, i32, i32)
DEF_HELPER_1(cpsr_read, i32, env)target-arm/internals.h +1
-0@@ -54,6 +54,7 @@ static const char * const excnames[] = { [EXCP_KERNEL_TRAP] = "QEMU intercept of kernel commpage", [EXCP_STREX] = "QEMU intercept of STREX", [EXCP_HVC] = "Hypervisor Call", + [EXCP_SMC] = "Secure Monitor Call", };Quoted 2 lines
target-arm/internals.h static inline uint32_t syn_aa64_hvc(uint32_t
Quoted 2 lines
target-arm/internals.h +0
-0static inline void arm_log_exception (int idx)@@ -210,6 +211,11 @@ static inline uint32_t syn_aa64_hvc(uint32_timm16)
Quoted 4 lines
Quoted 4 lines
target-arm/internals.h +0
-0return (EC_AA64_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); }Quoted 14 lines
target-arm/op_helper.c void HELPER(hvc)(CPUARMState *env, uint32_t
Quoted 14 lines
target-arm/internals.h +5
-0+static inline uint32_t syn_aa64_smc (uint32_t imm16) +{ +return (EC_AA64_SMC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); +} +static inline uint32_t syn_aa32_svc (uint32_t imm16,bool is_thumb){ return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff)target-arm/op_helper.c +0
-0@@ -405,6 +405,17 @@ void HELPER(hvc)(CPUARMState *env, uint32_tsyndrome)
Quoted 11 lines
target-arm/op_helper.c void HELPER(hvc)(CPUARMState *env, uint32_t · line 412
Quoted 8 lines
target-arm/op_helper.c +4
-0raise_exception (env,EXCP_HVC ); } +void HELPER (smc )(CPUARMState *env,uint32_t syndrome) +{ +/* We've already checked that EL3 exists at translation time. */ +if (env->cp15.scr_el3 &SCR_SMD ) {In ARMv7 isn't this is this only a valid check if the virtualization extension is present? If so, should we be checking for the virt
Quoted 9 lines
extension
Quoted 1 line
on AArch32 prior to raising undefined?
My understanding is that on AArch32 SCR.SMD only applies
to NS mode and only if HCR.TSC=0 (always the case if EL2 does not exist but can also be zero even if EL2 exists).
So it's not dependant on virtual extensions/EL2 non-existance? Am I missing something?I'm not sure how we handle this as the ARMv7 spec states the following for the SCD bit:
Quoted 6 lines
"*SCD, bit[7], when implementation includes the Virtualization Extensions*"
This is not worded the same in the ARMv8 spec, possibly because the extensions are assumed to always be present? The QQMU code still supports the notion of features in which case sometimes are extensions.
Hi,
This is a bit confusing. I was looking at the spec for the Cortex A15 which does not mention the virtualization condition. It does refer to the ARMv7 specs for "more" info though so I suspect we need to differentiate them. I can do that in v2.
Quoted 28 lines
Quoted 6 lines
I'm not adding AArch32 SMC here but am happy to try to get it right in preparation for the AArch32 support.
Sure, I suspect that Fabian's commits on top of yours will close any AArch32 gaps.
Quoted 7 lines
The patch misses that the HCR.TSC routing of SMC to EL2 takes priority over SMD for NS EL1. For AArch32, I need to check for non-secure state aswell. I'll update those for v2.
Need to run a few tests but I'm considering something along these lines:
Quoted 9 lines
void HELPER(smc)(CPUARMState *env,
uint32_tsyndrome){ int cur_el = arm_current_pl(env); /* FIXME: Use real secure state. */ bool secure = false; bool smd = env->cp15.scr_el3 & SCR_SMD; /* On AArch32, SMD only applies to NS mode. */ bool udef = is_a64(env) ? smd : !secure && smd;
Quoted 2 lines
Is it possible to get in here at EL0? A quick check, did not turn up a check for this in the code calling this helper, but I may have missed it.
We trap SMC from EL0 at translation time further down the patch.
Quoted 45 lines
Quoted 45 lines
/* In NS EL1, HCR controlled routing to EL2 has priority over SMD. */ if (!secure && cur_el == 1 && (env->cp15.hcr_el2 & HCR_TSC)) { udef = false; } /* We've already checked that EL3 exists at translation time. */ if (udef) { env->exception.syndrome = syn_uncategorized(); raise_exception(env, EXCP_UDEF); } env->exception.syndrome = syndrome; raise_exception(env, EXCP_SMC); }Thanks for the comments,
EdgarQuoted 15 lines
Quoted 15 lines
target-arm/op_helper.c +7
-0+ env->exception.syndrome =syn_uncategorized (); +raise_exception (env,EXCP_UDEF ); + } + env->exception.syndrome = syndrome; +raise_exception (env,EXCP_SMC ); +} +void HELPER (exception_return )(CPUARMState *env) {int cur_el = arm_current_pl(env);target-arm/translate-a64.c +0
-1--- a/target-arm/translate-a64.cQuoted 8 lines
target-arm/translate-a64.c static void disas_exc(DisasContext *s, uint32_t · line 1456
Quoted 8 lines
+++
b/target-arm/translate-a64.ctarget-arm/translate-a64.c +2
-0@@ -1451,6 +1451,16 @@ static void disas_exc(DisasContext *s, uint32_t insn)gen_helper_hvc (cpu_env ,tmp );tcg_temp_free_i32 (tmp);break ; +case 3 : + if (!arm_dc_feature(s, ARM_FEATURE_EL3) || s->current_pl==
Quoted 1 line
Quoted 1 line
Quoted 1 line
target-arm/translate-a64.c static void disas_exc(DisasContext *s, uint32_t · line 1457
Quoted 1 line
target-arm/translate-a64.c +0
-00) {
^^^^^
here
Quoted 17 lines
Quoted 17 lines
Quoted 15 lines
Quoted 15 lines
target-arm/translate-a64.c +8
-0+unallocated_encoding (s); +break ; + } + tmp =tcg_const_i32 (syn_aa64_smc (imm16)); +gen_a64_set_pc_im (s->pc); +gen_helper_smc (cpu_env, tmp); +tcg_temp_free_i32 (tmp); +break ;default :unallocated_encoding(s); break;--
1.8.3.2
Re: [Qemu-devel] [PATCH v1 06/16] target-arm: Add FAR_EL2 and 3
In reply to Alex BennéeQuoted 11 lines · Alex Bennée
Quoted 8 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 2 +- target-arm/helper.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
Quoted 13 lines
target-arm/cpu.h typedef struct CPUARMState { · line 190
Quoted 10 lines
target-arm/cpu.h +1
-1@@ -187,7 +187,7 @@ typedef struct CPUARMState {uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[4 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ -uint64_t far_el[2 ];/* Fault address registers. */ +uint64_t far_el[4 ];/* Fault address registers. */ Ahh my confusion from earlier is now clear. Perhaps the two commits should be merged?
Hi,
The point is to have a non-functional diff and then incrementally add the function to easy bisectability if something breaks. I don't have a very strong opinion though, so if people insist I can squash.
Cheers,
Edgar
Quoted 31 lines
Quoted 28 lines
target-arm/cpu.h +0
-0uint64_t par_el1;/* Translation result. */ uint32_t c9_insn;/* Cache lockdown registers. */ uint32_t c9_data;target-arm/helper.c +6
-0@@ -2120,6 +2120,9 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = { .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 4, .crn = 5, .crm = 2, .opc2 = 1, .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[2]) }, + { .name = "FAR_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 6, .crm = 0, .opc2 = 0, + .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[2]) }, { .name = "SPSR_EL2", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 4, .crn = 4, .crm = 0, .opc2 = 0,@@ -2142,6 +2145,9 @@ static const ARMCPRegInfo v8_el3_cp_reginfo[] = { .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 6, .crn = 5, .crm = 2, .opc2 = 1, .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[3]) }, + { .name = "FAR_EL3", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 6, .crn = 6, .crm = 0, .opc2 = 0, + .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[3]) }, { .name = "SPSR_EL3", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 6, .crn = 4, .crm = 0, .opc2 = 0,Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 07/16] target-arm: Add HCR_EL2
In reply to Alex BennéeQuoted 56 lines · Alex Bennée
Quoted 53 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 35 +++++++++++++++++++++++++++++++++++ target-arm/helper.c | 27 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)target-arm/cpu.h +30
-0@@ -184,6 +184,7 @@ typedef struct CPUARMState {MPU write buffer control. */ uint32_t pmsav5_data_ap;/* PMSAv5 MPU data access permissions */ uint32_t pmsav5_insn_ap;/* PMSAv5 MPU insn access permissions */ +uint64_t hcr_el2;/* Hypervisor configuration register */ uint32_t ifsr_el2;/* Fault status registers. */ uint64_t esr_el[4 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ @@ -526,6 +527,40 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) } } +#define HCR_VM (1ULL << 0) +#define HCR_SWIO (1ULL << 1) +#define HCR_PTW (1ULL << 2) +#define HCR_FMO (1ULL << 3) +#define HCR_IMO (1ULL << 4) +#define HCR_AMO (1ULL << 5) +#define HCR_VF (1ULL << 6) +#define HCR_VI (1ULL << 7) +#define HCR_VSE (1ULL << 8) +#define HCR_FB (1ULL << 9) +#define HCR_DC (1ULL << 12) +#define HCR_TWI (1ULL << 13) +#define HCR_TWE (1ULL << 14) +#define HCR_TID0 (1ULL << 15) +#define HCR_TID1 (1ULL << 16) +#define HCR_TID2 (1ULL << 17) +#define HCR_TID3 (1ULL << 18) +#define HCR_TSC (1ULL << 19) +#define HCR_TIDCP (1ULL << 20) +#define HCR_TACR (1ULL << 21) +#define HCR_TSW (1ULL << 22) +#define HCR_TPC (1ULL << 23) +#define HCR_TPU (1ULL << 24) +#define HCR_TTLB (1ULL << 25) +#define HCR_TVM (1ULL << 26) +#define HCR_TGE (1ULL << 27) +#define HCR_TDZ (1ULL << 28) +#define HCR_HCD (1ULL << 29) +#define HCR_TRVM (1ULL << 30)
Quoted 8 lines
target-arm/cpu.h static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) · line 562
Quoted 4 lines
target-arm/cpu.h +4
-0+#define HCR_RW (1ULL << 31) +#define HCR_CD (1ULL << 32) +#define HCR_ID (1ULL << 33) +#define HCR_RES0_MASK ((1ULL << 34) - 1)Hmm isn't that actually
HCR_MASK? I would expect the mask for the RES0 bits to be ~((1ULL << 34) - 1) but it's not actually used for that hence the name confusion.
I can change the name for v2, thanks.
Quoted 50 lines
Quoted 47 lines
target-arm/cpu.h +1
-0+/* Return the current FPSCR value. */ uint32_t vfp_get_fpscr (CPUARMState *env);void vfp_set_fpscr (CPUARMState *env,uint32_t val);target-arm/helper.c +27
-0@@ -2107,10 +2107,37 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 0, .opc2 = 0, .access = PL2_RW, .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore }, + { .name = "HCR_EL2", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_MIGRATE, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 0, + .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore }, REGINFO_SENTINEL }; +static void hcr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) +{ +ARMCPU *cpu =arm_env_get_cpu (env); +uint64_t res0_mask =HCR_RES0_MASK ; + +if (!arm_feature (env,ARM_FEATURE_EL3 )) { + res0_mask &= ~HCR_HCD ; + } + +/* Clear RES0 bits. */ + value &= res0_mask; + +if ((raw_read (env, ri) ^ value) &HCR_VM ) { +/* Flush the TLB when turning VM on/off. */ +tlb_flush (CPU (cpu),1 ); + } +raw_write (env, ri, value); +} +static const ARMCPRegInfo v8_el2_cp_reginfo[] = { + { .name ="HCR_EL2" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =4 , .crn =1 , .crm =1 , .opc2 =0 , + .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.hcr_el2), + .writefn = hcr_write }, { .name ="ELR_EL2" , .state =ARM_CP_STATE_AA64 , .type =ARM_CP_NO_MIGRATE , .opc0 =3 , .opc1 =4 , .crn =4 , .crm =0 , .opc2 =1 ,Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 10/16] target-arm: Break out exception masking to a separate func
In reply to Alex BennéeQuoted 42 lines · Alex Bennée
Quoted 39 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- cpu-exec.c | 5 ++--- target-arm/cpu.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-)cpu-exec.c +2
-3@@ -478,7 +478,7 @@ int cpu_exec(CPUArchState *env) }#elif defined(TARGET_ARM)if (interrupt_request &CPU_INTERRUPT_FIQ - && !(env->daif &PSTATE_F )) { + &&arm_excp_unmasked (cpu,EXCP_FIQ )) { cpu->exception_index =EXCP_FIQ ; cc->do_interrupt (cpu); next_tb =0 ;@@ -493,8 +493,7 @@ int cpu_exec(CPUArchState *env)We avoid this by disabling interrupts when pc contains a magic address. */ if (interrupt_request &CPU_INTERRUPT_HARD - && ((IS_M (env) && env->regs[15 ] <0xfffffff0 ) - || !(env->daif &PSTATE_I ))) { + &&arm_excp_unmasked (cpu,EXCP_IRQ )) { cpu->exception_index =EXCP_IRQ ; cc->do_interrupt (cpu); next_tb =0 ;target-arm/cpu.h +0
-0@@ -1130,6 +1130,22 @@ bool write_cpustate_to_list(ARMCPU *cpu);# define TARGET_VIRT_ADDR_SPACE_BITS 32#endif
Quoted 14 lines
target-arm/cpu.h bool write_cpustate_to_list(ARMCPU *cpu); · line 1144
Quoted 12 lines
target-arm/cpu.h +12
-0+static inline bool arm_excp_unmasked (CPUState *cs,unsigned int excp_idx) +{ +CPUARMState *env = cs->env_ptr; + +switch (excp_idx) { +case EXCP_FIQ : +return !(env->daif &PSTATE_F ); +case EXCP_IRQ : +return ((IS_M (env) && env->regs[15 ] <0xfffffff0 ) + || !(env->daif &PSTATE_I )); +default : +assert (0 );
g_assert_not_reached()is clearer about the intent here.
Sounds good, will change it.
Thanks,
Edgar
Quoted 11 lines
Quoted 8 lines
target-arm/cpu.h +4
-0+break ; + } +} +static inline CPUARMState *cpu_init (const char *cpu_model) {ARMCPU *cpu =cpu_arm_init (cpu_model);Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 13/16] target-arm: A64: Emulate the HVC insn
In reply to Alex BennéeQuoted 31 lines · Alex Bennée
Quoted 28 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/cpu.h | 7 ++----- target-arm/helper-a64.c | 1 + target-arm/helper.c | 39 +++++++++++++++++++++++++++++++++++++++ target-arm/helper.h | 1 + target-arm/internals.h | 6 ++++++ target-arm/op_helper.c | 21 +++++++++++++++++++++ target-arm/translate-a64.c | 21 ++++++++++++++++----- 7 files changed, 86 insertions(+), 10 deletions(-)target-arm/cpu.h +1
-0@@ -51,6 +51,7 @@#define EXCP_EXCEPTION_EXIT 8/* Return from v7M exception. */ #define EXCP_KERNEL_TRAP 9/* Jumped to kernel code page. */ #define EXCP_STREX 10 +#define EXCP_HVC 11/* HyperVisor Call */ #define ARMV7M_EXCP_RESET 1#define ARMV7M_EXCP_NMI 2@@ -715,11 +716,7 @@ static inline bool arm_el_is_aa64(CPUARMState *env, int el) }
Quoted 11 lines
target-arm/cpu.h static inline bool arm_el_is_aa64(CPUARMState *env, int el) · line 719
Quoted 7 lines
target-arm/cpu.h +1
-5void arm_cpu_list (FILE *f,fprintf_function cpu_fprintf); -static inline unsigned int arm_excp_target_el (CPUState *cs, -unsigned int excp_idx) -{ -return 1 ; -} +unsigned int arm_excp_target_el (CPUState *cs,unsigned int excp_idx);If the earlier commit had added this in the final place to start with the functional diff would be clearer (although it's easy to eyeball in this case).
Right, I can change that for v2.
Quoted 36 lines
Quoted 36 lines
target-arm/cpu.h +0
-0/* Interface between CPU and Interrupt controller. */ void armv7m_nvic_set_pending (void *opaque,int irq);target-arm/helper-a64.c +1
-0@@ -475,6 +475,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs)case EXCP_BKPT :case EXCP_UDEF :case EXCP_SWI : +case EXCP_HVC : env->cp15.esr_el[new_el] = env->exception.syndrome;break ;case EXCP_IRQ :target-arm/helper.c +5
-0@@ -3208,6 +3208,11 @@ uint32_t HELPER(get_r13_banked)(CPUARMState *env, uint32_t mode) return 0; } +unsigned int arm_excp_target_el (CPUState *cs,unsigned int excp_idx) +{ +return 1 ; +} +#else /* Map CPU modes onto saved register banks. */ @@ -3263,6 +3268,40 @@ void switch_mode(CPUARMState *env, int mode) env->spsr = env->banked_spsr[i]; }
Quoted 13 lines
target-arm/helper.c void switch_mode(CPUARMState *env, int mode) · line 3281
Quoted 11 lines
target-arm/helper.c +11
-0+/* +* Determine the target EL for a given exception type. +*/ +unsigned int arm_excp_target_el (CPUState *cs,unsigned int excp_idx) +{ +CPUARMState *env = cs->env_ptr; +unsigned int cur_el =arm_current_pl (env); +unsigned int target_el =1 ; +bool route_to_el2 = false; +/* FIXME: Use actual secure state. */ +bool secure = false;Should this be here?
I've put it there to make it easier for the TZ patches to identify the places they need to update. + it allows me to code the conditions for the exception routing (wrt S/NS).
Quoted 7 lines
<snip>
Quoted 5 lines
static inline void
arm_log_exception(int idx)target-arm/helper.c +0
-0@@ -204,6 +205,11 @@ static inline uint32_t syn_aa64_svc(uint32_t imm16)return (EC_AA64_SVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); }
Quoted 6 lines
target-arm/helper.c static inline uint32_t syn_aa64_svc(uint32_t imm16) · line 211
Quoted 4 lines
target-arm/helper.c +4
-0+static inline uint32_t syn_aa64_hvc (uint32_t imm16) +{ +return (EC_AA64_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); +}The mask seems superfluous (as it is for
arm_log_exception)
Sorry, can you clarify what you mean here? Are you refering to the imm16?
Quoted 78 lines
Quoted 75 lines
target-arm/helper.c +1
-0+static inline uint32_t syn_aa32_svc (uint32_t imm16,bool is_thumb) {return (EC_AA32_SVC <<ARM_EL_EC_SHIFT ) | (imm16 &0xffff )target-arm/op_helper.c +21
-0@@ -384,6 +384,27 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm) } } +void HELPER (hvc )(CPUARMState *env,uint32_t syndrome) +{ +bool udef; + +/* We've already checked that EL2 exists at translation time. +* EL3.HCE has priority over EL2.HCD. +*/ +if (arm_feature (env,ARM_FEATURE_EL3 )) { + udef = !(env->cp15.scr_el3 &SCR_HCE ); + }else { + udef = env->cp15.hcr_el2 &HCR_HCD ; + } + +if (udef) { + env->exception.syndrome =syn_uncategorized (); +raise_exception (env,EXCP_UDEF ); + } + env->exception.syndrome = syndrome; +raise_exception (env,EXCP_HVC ); +} +void HELPER (exception_return )(CPUARMState *env) {int cur_el =arm_current_pl (env);target-arm/translate-a64.c +16
-5@@ -1433,17 +1433,28 @@ static void disas_exc(DisasContext *s, uint32_t insn)int opc =extract32 (insn,21 ,3 );int op2_ll =extract32 (insn,0 ,5 );int imm16 =extract32 (insn,5 ,16 ); +TCGv_i32 tmp;switch (opc) {case 0 : -/* SVC, HVC, SMC; since we don't support the Virtualization -* or TrustZone extensions these all UNDEF except SVC. -*/ -if (op2_ll !=1 ) { +switch (op2_ll) { +case 1 : +gen_exception_insn (s,0 ,EXCP_SWI ,syn_aa64_svc (imm16)); +break ; +case 2 : +if (!arm_dc_feature (s,ARM_FEATURE_EL2 ) || s->current_pl ==0 ) { +unallocated_encoding (s); +break ; + } + tmp =tcg_const_i32 (syn_aa64_hvc (imm16)); +gen_a64_set_pc_im (s->pc); +gen_helper_hvc (cpu_env, tmp); +tcg_temp_free_i32 (tmp); +break ; +default :unallocated_encoding (s);break ; } -gen_exception_insn (s,0 ,EXCP_SWI ,syn_aa64_svc (imm16));break ;case 1 :if (op2_ll !=0 ) {Signature · 1 line
Alex Bennée
Re: [Qemu-devel] [PATCH v1 13/16] target-arm: A64: Emulate the HVC insn
Quoted 8 lines · Edgar E. Iglesias
Quoted 7 lines · Alex Benn�e
Quoted 5 lines · Edgar E. Iglesias
static inline void
arm_log_exception(int idx)(quoted diff) +0
-0@@ -204,6 +205,11 @@ static inline uint32_t syn_aa64_svc(uint32_t imm16) return (EC_AA64_SVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); }
Quoted 8 lines
Quoted 6 lines
Review static inline uint32_t syn_aa64_svc(uint32_t imm16) · line 211
Quoted 4 lines
(quoted diff) +4
-0+static inline uint32_t syn_aa64_hvc(uint32_t imm16) +{ + return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); +}The mask seems superfluous (as it is for
arm_log_exception)Sorry, can you clarify what you mean here? Are you refering to the imm16?
Yes the imm16. It's the result of an extract32(..,..,16) so I can't see how it wouldn't already be correctly masked.
Signature · 1 line
Alex Benn�e
Re: [Qemu-devel] [PATCH v1 06/16] target-arm: Add FAR_EL2 and 3
In reply to Edgar E. IglesiasQuoted 5 lines · Edgar E. Iglesias
Quoted 4 lines · Alex Benn�e
Edgar E. Iglesias writes:
Quoted 8 lines
Quoted 2 lines
Ahh my confusion from earlier is now clear. Perhaps the two commits should be merged?
Hi,
The point is to have a non-functional diff and then incrementally add the function to easy bisectability if something breaks. I don't have a very strong opinion though, so if people insist I can squash.
Having each commit point be buildable and testable is certainly a worthwhile goal from a bisect point of view. But for a simple no-op diff (i.e. functionaly identical, just moving a few bits around) which will then get updated with functional changes there is an argument to squash the two together.
I like this patch series because the individual patches are narrow in scope and not too big hence easier to review. I don't think squashing some of non-function + functional diffs together detracts from that nobel goal. As you say it's a judgement call.
Signature · 1 line
Alex Benn�e
Re: [Qemu-devel] [PATCH v1 13/16] target-arm: A64: Emulate the HVC insn
In reply to Alex Benn�eQuoted 18 lines · Alex Benn�e
Quoted 15 lines · Edgar E. Iglesias
Quoted 13 lines · Alex Benn?e
Review static inline uint32_t syn_aa64_svc(uint32_t imm16) · line 211
Quoted 9 lines · Edgar E. Iglesias
static inline void
arm_log_exception(int idx)(quoted diff) +4
-0@@ -204,6 +205,11 @@ static inline uint32_t syn_aa64_svc(uint32_t imm16) return (EC_AA64_SVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); } +static inline uint32_t syn_aa64_hvc(uint32_t imm16) +{ + return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); +}The mask seems superfluous (as it is for
arm_log_exception)
Quoted 4 lines
Quoted 1 line
Sorry, can you clarify what you mean here? Are you refering to the imm16?
Yes the imm16. It's the result of an
extract32(..,..,16)so I can't see how it wouldn't already be correctly masked.
Right, so my first version here had a uint16_t imm16, but I changed it to keep it consistent with the other functions. I'm happy to change things to match their use with additional patches. I'll do something for v2.
Re: [Qemu-devel] [PATCH v1 06/16] target-arm: Add FAR_EL2 and 3
In reply to Alex Benn�eQuoted 17 lines · Alex Benn�e
Quoted 5 lines · Edgar E. Iglesias
Quoted 4 lines · Alex Benn?e
Edgar E. Iglesias writes:
Quoted 8 lines
Quoted 2 lines
Ahh my confusion from earlier is now clear. Perhaps the two commits should be merged?
Hi,
The point is to have a non-functional diff and then incrementally add the function to easy bisectability if something breaks. I don't have a very strong opinion though, so if people insist I can squash.
Quoted 5 lines
Having each commit point be buildable and testable is certainly a worthwhile goal from a bisect point of view. But for a simple no-op diff (i.e. functionaly identical, just moving a few bits around) which will then get updated with functional changes there is an argument to squash the two together.
I disagree. IMO when patches include refactoring + changes, the refactoring should be done with non functional changes (as far as possible) and then followed up with small easily reviewable functional patches.
Quoted 5 lines
I like this patch series because the individual patches are narrow in scope and not too big hence easier to review. I don't think squashing some of non-function + functional diffs together detracts from that nobel goal. As you say it's a judgement call.
Re: [Qemu-devel] [PATCH v1 11/16] target-arm: Don't take interrupts targeting lower ELs
In reply to a message not in the archiveQuoted 12 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>---
target-arm/cpu.h| 7 +++++++1 file changed, 7 insertions(+)target-arm/cpu.h +0
-0
target-arm/cpu.h bool write_cpustate_to_list(ARMCPU *cpu); · line 1142
Quoted 10 lines
target-arm/cpu.h +7
-0@@ -1133,6 +1133,13 @@ bool write_cpustate_to_list(ARMCPU *cpu);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); + +/* Don't take exceptions if they target a lower EL. */ +if (cur_el > target_el) { +return false; + }
Hi Edgar
When making arm_excp_unmasked() reflect tables D1-13, D1-14, D1-15 and G1-18, G1-19 in ARM ARMv8 this should not be necessary if I am not mistaken. Cases in which target_el is lower than cur_el are marked with a P (pending) in the table. Or am I missing something interpreting the tables?
I extended your arm_excp_unmasked() and arm_excp_target_el() to reflect the behaviour shown in the tables in ARM ARMv8 and ARM ARMv7. I will send them with the TZ patches.
Best,
Fabian
Quoted 6 lines
target-arm/cpu.h +0
-0switch (excp_idx) {case EXCP_FIQ :Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v1 11/16] target-arm: Don't take interrupts targeting lower ELs
Quoted 19 lines · Aggeler Fabian
Quoted 16 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>---
target-arm/cpu.h| 7 +++++++1 file changed, 7 insertions(+)target-arm/cpu.h +1
-0@@ -1133,6 +1133,13 @@ bool write_cpustate_to_list(ARMCPU *cpu);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);
Quoted 8 lines
target-arm/cpu.h bool write_cpustate_to_list(ARMCPU *cpu); · line 1142
Quoted 6 lines
target-arm/cpu.h +6
-0+unsigned int target_el =arm_excp_target_el (cs, excp_idx); + +/* Don't take exceptions if they target a lower EL. */ +if (cur_el > target_el) { +return false; + }Hi Edgar
Hi Fabian,
Quoted 6 lines
When making
arm_excp_unmasked()reflect tables D1-13, D1-14, D1-15 and G1-18, G1-19 in ARM ARMv8 this should not be necessary if I am not mistaken. Cases in whichtarget_elis lower thancur_elare marked with a P (pending) in the table. Or am I missing something interpreting the tables?
This function is called to check if we can take a pending interrupt or exception with current CPU state. It does not clear pending exceptions. In this case, if the target_el is lower than the current EL we return false and leave the exception pending (to be taken later).
Quoted 4 lines
I extended your
arm_excp_unmasked()andarm_excp_target_el()to reflect the behaviour shown in the tables in ARM ARMv8 and ARM ARMv7. I will send them with the TZ patches.
Great, thanks.
Cheers,
Edgar
Quoted 11 lines
Best,
FabianQuoted 6 lines
target-arm/cpu.h +0
-0switch (excp_idx) {case EXCP_FIQ :Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v1 11/16] target-arm: Don't take interrupts targeting lower ELs
Quoted 38 lines · Edgar E. Iglesias
Quoted 19 lines · Aggeler Fabian
Quoted 16 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Signed-off-by Edgar E. Iglesias <[email protected]>---
target-arm/cpu.h| 7 +++++++1 file changed, 7 insertions(+)target-arm/cpu.h +1
-0@@ -1133,6 +1133,13 @@ bool write_cpustate_to_list(ARMCPU *cpu);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);Quoted 8 lines
target-arm/cpu.h bool write_cpustate_to_list(ARMCPU *cpu); · line 1142
Quoted 6 lines
target-arm/cpu.h +6
-0+unsigned int target_el =arm_excp_target_el (cs, excp_idx); + +/* Don't take exceptions if they target a lower EL. */ +if (cur_el > target_el) { +return false; + }Hi Edgar
Hi Fabian,
Quoted 6 lines
When making
arm_excp_unmasked()reflect tables D1-13, D1-14, D1-15 and G1-18, G1-19 in ARM ARMv8 this should not be necessary if I am not mistaken. Cases in whichtarget_elis lower thancur_elare marked with a P (pending) in the table. Or am I missing something interpreting the tables?
Quoted 4 lines
This function is called to check if we can take a pending interrupt or exception with current CPU state. It does not clear pending exceptions. In this case, if the
target_elis lower than the current EL we return false and leave the exception pending (to be taken later).
I know, but what I want to say is, doesn’t the table which I mentioned reflect this by marking it with a P for pending for cases where target_el would be lower than the current EL it is taken from?
So if we handle these cases in arm_excp_unmasked() we don’t need to call arm_excp_target_el() to check.
Quoted 21 lines
Quoted 5 lines
I extended your
arm_excp_unmasked()andarm_excp_target_el()to reflect the behaviour shown in the tables in ARM ARMv8 and ARM ARMv7. I will send them with the TZ patches.Great, thanks.
Cheers,
EdgarQuoted 9 lines
Best,
FabianQuoted 5 lines
target-arm/cpu.h +0
-0switch (excp_idx) {case EXCP_FIQ :Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v1 00/16] target-arm: Parts of the AArch64 EL2/3 exception model
In reply to a message not in the archiveQuoted 11 lines · Edgar E. Iglesias
This is a second round of AArch64 EL2/3 patches working on the exception model. Among other things adding HVC/SMC, interrupt routing to EL2/3 and Virtual IRQs/FIQs. The VIRQ/VFIQ support only adds the external signal delivery method.
Patch 3 is a bug fix.
Patch 14 fails checkpatch, seems like a bug in checkpatch, CC:d Blue.This conflicts slightly with the PSCI emulation patches that Rob posted. A rebase should be trivial, hooking in the PSCI emulation calls in the HVC/SMC helpers.
Sorry for letting this patchset sit in my to-review queue for so long. Patches 1-6 are good and I'm going to put them in target-arm.next. Patches 9 and 11 I've added my R-by to. Patches 7, 8, 10, 12..16 I've replied to with review comments.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v1 00/16] target-arm: Parts of the AArch64 EL2/3 exception model
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Edgar E. Iglesias
This is a second round of AArch64 EL2/3 patches working on the exception model. Among other things adding HVC/SMC, interrupt routing to EL2/3 and Virtual IRQs/FIQs. The VIRQ/VFIQ support only adds the external signal delivery method.
Patch 3 is a bug fix.
Patch 14 fails checkpatch, seems like a bug in checkpatch, CC:d Blue.
Quoted 8 lines
Quoted 3 lines
This conflicts slightly with the PSCI emulation patches that Rob posted. A rebase should be trivial, hooking in the PSCI emulation calls in the HVC/SMC helpers.
Sorry for letting this patchset sit in my to-review queue for so long. Patches 1-6 are good and I'm going to put them in target-arm.next. Patches 9 and 11 I've added my R-by to. Patches 7, 8, 10, 12..16 I've replied to with review comments.
...this reply was to the v1 cover letter, but I did review v3 :-)
thanks
-- PMM
Re: [Qemu-devel] [PATCH v1 00/16] target-arm: Parts of the AArch64 EL2/3 exception model
In reply to Peter MaydellQuoted 9 lines · Peter Maydell
Quoted 8 lines · Edgar E. Iglesias
This is a second round of AArch64 EL2/3 patches working on the exception model. Among other things adding HVC/SMC, interrupt routing to EL2/3 and Virtual IRQs/FIQs. The VIRQ/VFIQ support only adds the external signal delivery method.
Patch 3 is a bug fix.
Patch 14 fails checkpatch, seems like a bug in checkpatch, CC:d Blue.
Quoted 8 lines
Quoted 3 lines
This conflicts slightly with the PSCI emulation patches that Rob posted. A rebase should be trivial, hooking in the PSCI emulation calls in the HVC/SMC helpers.
Sorry for letting this patchset sit in my to-review queue for so long. Patches 1-6 are good and I'm going to put them in target-arm.next. Patches 9 and 11 I've added my R-by to. Patches 7, 8, 10, 12..16 I've replied to with review comments.
Thanks Peter,
I think I've addressed most of your comments, sending out v4 now.
I fixed up the PC for trapped HVC/SMC and for SMC routed to EL2 but left the exception raising as is. I'm happy to update it if you have a better idea.
Cheers,
Edgar