Various EL3 support/cleanup patches
cover Various EL3 support/cleanup patches
This patch series is basically the remaining patches from Greg's EL3-trapping series, cleaned up by me based on review comments and on various things I noticed as I went along. (In particular it has the reworking of when we should set exception.target_el &c that I mentioned in the comments on patch 4 of Edgar's recent series, and fixes for all the bugs that making that change brings to light.) I also threw in some patches for obvious cleanup that I noticed as I was doing this.
Greg Bellows (6):
target-arm: Add exception target el infrastructure
target-arm: Extend helpers to route exceptions
target-arm: Update interrupt handling to use target EL
target-arm: Add AArch64 CPTR registers
target-arm: Extend FP checks to use an EL
target-arm: Add WFx instruction trap support
Peter Maydell (8):
target-arm: Set correct syndrome for faults on MSR DAIF*, imm
target-arm: Move setting of exception info into tlb_fill
target-arm: Set exception target EL in tlb_fill
target-arm: Make raise_exception() take syndrome and target EL
target-arm: Allow cp access functions to indicate traps to EL2 or EL3
target-arm: Make singlestate TB flags common between AArch32/64
target-arm: Move TB flags down to fill gap
target-arm: Don't halt on WFI unless we don't have any work
target-arm/cpu.c | 78 ++++++++++++++----- target-arm/cpu.h | 186 +++++++++++++++++++++++++++------------------ target-arm/helper-a64.c | 2 +- target-arm/helper.c | 128 ++++++++++++------------------- target-arm/helper.h | 2 +- target-arm/internals.h | 3 + target-arm/op_helper.c | 174 ++++++++++++++++++++++++++++++++++-------- target-arm/translate-a64.c | 48 +++++++----- target-arm/translate.c | 74 +++++++++++------- target-arm/translate.h | 17 ++++- 10 files changed, 465 insertions(+), 247 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/14 target-arm: Add exception target el infrastructure
From: Greg Bellows <[email protected]>
Add a CPU state exception target EL field that will be used for communicating the EL to which an exception should be routed.
Add a disassembly context field for tracking the EL3 architecture needed for determining the target exception EL.
Add a target EL argument to the generic exception helper for callers to specify the EL to which the exception should be routed. Extended the helper to set the newly added CPU state exception target el.
Added a function for setting the target exception EL and updated calls to helpers to call it.
Message-id: [email protected]
--- target-arm/cpu.h | 1 + target-arm/helper.h | 2 +- target-arm/op_helper.c | 3 ++- target-arm/translate-a64.c | 34 +++++++++++++++--------- target-arm/translate.c | 65 ++++++++++++++++++++++++++++++---------------- target-arm/translate.h | 15 +++++++++++ 6 files changed, 83 insertions(+), 37 deletions(-)
target-arm/cpu.h +1 -0
@@ -396,6 +396,7 @@ typedef struct CPUARMState {uint32_t syndrome;/* AArch64 format syndrome register */ uint32_t fsr;/* AArch32 format fault status register info */ uint64_t vaddress;/* virtual addr associated with exception, if any */ +uint32_t target_el;/* EL the exception should be targeted for */ /* If we implement EL2 we will also need to store information * about the intermediate physical address for stage 2 faults. */
target-arm/helper.h +1 -1
@@ -47,7 +47,7 @@ DEF_HELPER_FLAGS_2(usad8, TCG_CALL_NO_RWG_SE, i32, i32, i32)DEF_HELPER_FLAGS_3 (sel_flags,TCG_CALL_NO_RWG_SE , i32, i32, i32, i32) DEF_HELPER_2(exception_internal, void, env, i32) -DEF_HELPER_3(exception_with_syndrome, void, env, i32, i32) +DEF_HELPER_4(exception_with_syndrome, void, env, i32, i32, i32) DEF_HELPER_1(wfi, void, env) DEF_HELPER_1(wfe, void, env)DEF_HELPER_1 (pre_hvc, void, env)
target-arm/op_helper.c +2 -1
@@ -246,13 +246,14 @@ void HELPER(exception_internal)(CPUARMState *env, uint32_t excp)/* Raise an exception with the specified syndrome register value */ void HELPER (exception_with_syndrome )(CPUARMState *env,uint32_t excp, -uint32_t syndrome) +uint32_t syndrome,uint32_t target_el) {CPUState *cs =CPU (arm_env_get_cpu (env));assert (!excp_is_internal (excp)); cs->exception_index = excp; env->exception.syndrome = syndrome; + env->exception.target_el = target_el;cpu_loop_exit (cs); }
target-arm/translate-a64.c +22 -12
@@ -197,12 +197,15 @@ static void gen_exception_internal(int excp)tcg_temp_free_i32 (tcg_excp); } -static void gen_exception (int excp,uint32_t syndrome) +static void gen_exception (int excp,uint32_t syndrome,uint32_t target_el) {TCGv_i32 tcg_excp =tcg_const_i32 (excp);TCGv_i32 tcg_syn =tcg_const_i32 (syndrome); +TCGv_i32 tcg_el =tcg_const_i32 (target_el); -gen_helper_exception_with_syndrome (cpu_env, tcg_excp, tcg_syn); +gen_helper_exception_with_syndrome (cpu_env, tcg_excp, + tcg_syn, tcg_el); +tcg_temp_free_i32 (tcg_el);tcg_temp_free_i32 (tcg_syn);tcg_temp_free_i32 (tcg_excp); }
@@ -215,10 +218,10 @@ static void gen_exception_internal_insn(DisasContext *s, int offset, int excp) }static void gen_exception_insn (DisasContext *s,int offset,int excp, -uint32_t syndrome) +uint32_t syndrome,uint32_t target_el) {gen_a64_set_pc_im (s->pc - offset); -gen_exception (excp, syndrome); +gen_exception (excp, syndrome, target_el); s->is_jmp =DISAS_EXC ; }
@@ -245,7 +248,8 @@ static void gen_step_complete_exception(DisasContext *s)* of the exception, and our syndrome information is always correct. */ gen_ss_advance (s); -gen_exception (EXCP_UDEF ,syn_swstep (s->ss_same_el,1 , s->is_ldex)); +gen_exception (EXCP_UDEF ,syn_swstep (s->ss_same_el,1 , s->is_ldex), +default_exception_el (s)); s->is_jmp =DISAS_EXC ; }
@@ -292,7 +296,8 @@ static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)static void unallocated_encoding (DisasContext *s) {/* Unallocated and reserved encodings are uncategorized */ -gen_exception_insn (s,4 ,EXCP_UDEF ,syn_uncategorized ()); +gen_exception_insn (s,4 ,EXCP_UDEF ,syn_uncategorized (), +default_exception_el (s)); }#define unsupported_encoding (s, insn) \
@@ -971,7 +976,8 @@ static inline bool fp_access_check(DisasContext *s)return true; } -gen_exception_insn (s,4 ,EXCP_UDEF ,syn_fp_access_trap (1 ,0xe , false)); +gen_exception_insn (s,4 ,EXCP_UDEF ,syn_fp_access_trap (1 ,0xe , false), +default_exception_el (s));return false; }
@@ -1498,7 +1504,8 @@ static void disas_exc(DisasContext *s, uint32_t insn)switch (op2_ll) {case 1 :gen_ss_advance (s); -gen_exception_insn (s,0 ,EXCP_SWI ,syn_aa64_svc (imm16)); +gen_exception_insn (s,0 ,EXCP_SWI ,syn_aa64_svc (imm16), +default_exception_el (s));break ;case 2 :if (s->current_el ==0 ) {
@@ -1511,7 +1518,7 @@ static void disas_exc(DisasContext *s, uint32_t insn)gen_a64_set_pc_im (s->pc -4 );gen_helper_pre_hvc (cpu_env);gen_ss_advance (s); -gen_exception_insn (s,0 ,EXCP_HVC ,syn_aa64_hvc (imm16)); +gen_exception_insn (s,0 ,EXCP_HVC ,syn_aa64_hvc (imm16),2 );break ;case 3 :if (s->current_el ==0 ) {
@@ -1523,7 +1530,7 @@ static void disas_exc(DisasContext *s, uint32_t insn)gen_helper_pre_smc (cpu_env, tmp);tcg_temp_free_i32 (tmp);gen_ss_advance (s); -gen_exception_insn (s,0 ,EXCP_SMC ,syn_aa64_smc (imm16)); +gen_exception_insn (s,0 ,EXCP_SMC ,syn_aa64_smc (imm16),3 );break ;default :unallocated_encoding (s);
@@ -1536,7 +1543,8 @@ static void disas_exc(DisasContext *s, uint32_t insn)break ; }/* BRK */ -gen_exception_insn (s,4 ,EXCP_BKPT ,syn_aa64_bkpt (imm16)); +gen_exception_insn (s,4 ,EXCP_BKPT ,syn_aa64_bkpt (imm16), +default_exception_el (s));break ;case 2 :if (op2_ll !=0 ) {
@@ -10936,6 +10944,7 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu, dc->condjmp =0 ; dc->aarch64 =1 ; + dc->el3_is_aa64 =arm_el_is_aa64 (env,3 ); dc->thumb =0 ; dc->bswap_code =0 ; dc->condexec_mask =0 ;
@@ -11031,7 +11040,8 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,* bits should be zero. */ assert (num_insns ==0 ); -gen_exception (EXCP_UDEF ,syn_swstep (dc->ss_same_el,0 ,0 )); +gen_exception (EXCP_UDEF ,syn_swstep (dc->ss_same_el,0 ,0 ), +default_exception_el (dc)); dc->is_jmp =DISAS_EXC ;break ; }
target-arm/translate.c +42 -23
177 lines not on this page · raw message
target-arm/translate.h +15 -0
@@ -23,6 +23,7 @@ typedef struct DisasContext {ARMMMUIdx mmu_idx;/* MMU index to use for normal loads/stores */ bool ns;/* Use non-secure CPREG bank on access */ bool cpacr_fpen;/* FP enabled via CPACR.FPEN */ +bool el3_is_aa64;/* Flag indicating whether EL3 is AArch64 or not */ bool vfp_enabled;/* FP enabled via FPSCR.EN */ int vec_len;int vec_stride;
@@ -73,6 +74,20 @@ static inline int get_mem_index(DisasContext *s)return s->mmu_idx; } +/* Function used to determine the target exception EL when otherwise not known +* or default. +*/ +static inline int default_exception_el (DisasContext *s) +{ +/* If we are coming from secure EL0 in a system with a 32-bit EL3, then +* there is no secure EL1, so we route exceptions to EL3. Otherwise, +* exceptions can only be routed to ELs above 1, so we target the higher of +* 1 or the current EL. +*/ +return (s->mmu_idx == ARMMMUIdx_S1SE0 && !s->el3_is_aa64) + ?3 :MAX (1 , s->current_el); +} +/* target-specific extra values for is_jmp */ /* These instructions trap after executing, so the A32/T32 decoder must * defer them until after the conditional execution state has been updated.
Signature · 1 line
1.9.1
PATCH 2/14 target-arm: Extend helpers to route exceptions
In reply to Peter MaydellFrom: Greg Bellows <[email protected]>
Updated the various helper routines to set the target EL as needed using a dedicated function.
Message-id: [email protected]
--- target-arm/op_helper.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
target-arm/op_helper.c +21 -0
@@ -33,6 +33,20 @@ static void raise_exception(CPUARMState *env, int tt)cpu_loop_exit (cs); } +static int exception_target_el (CPUARMState *env) +{ +int target_el =MAX (1 ,arm_current_el (env)); + +/* No such thing as secure EL1 if EL3 is aarch32, so update the target EL +* to EL3 in this case. +*/ +if (arm_is_secure (env) && !arm_el_is_aa64 (env,3 ) && target_el ==1 ) { + target_el =3 ; + } + +return target_el; +} +uint32_t HELPER (neon_tbl )(CPUARMState *env,uint32_t ireg,uint32_t def,uint32_t rn,uint32_t maxindex) {
@@ -306,6 +320,7 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)if (arm_feature (env,ARM_FEATURE_XSCALE ) && ri->cp <14 &&extract32 (env->cp15.c15_cpar, ri->cp,1 ) ==0 ) { env->exception.syndrome = syndrome; + env->exception.target_el =exception_target_el (env);raise_exception (env,EXCP_UDEF ); }
@@ -318,9 +333,11 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)return ;case CP_ACCESS_TRAP : env->exception.syndrome = syndrome; + env->exception.target_el =exception_target_el (env);break ;case CP_ACCESS_TRAP_UNCATEGORIZED : env->exception.syndrome =syn_uncategorized (); + env->exception.target_el =exception_target_el (env);break ;default :g_assert_not_reached ();
@@ -363,6 +380,7 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)* to catch that case at translate time. */ if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) { + env->exception.target_el =exception_target_el (env);raise_exception (env,EXCP_UDEF ); }
@@ -422,6 +440,7 @@ void HELPER(pre_hvc)(CPUARMState *env)if (undef) { env->exception.syndrome =syn_uncategorized (); + env->exception.target_el =exception_target_el (env);raise_exception (env,EXCP_UDEF ); } }
@@ -452,11 +471,13 @@ void HELPER(pre_smc)(CPUARMState *env, uint32_t syndrome) }else if (!secure && cur_el ==1 && (env->cp15.hcr_el2 &HCR_TSC )) {/* In NS EL1, HCR controlled routing to EL2 has priority over SMD. */ env->exception.syndrome = syndrome; + env->exception.target_el =2 ;raise_exception (env,EXCP_HYP_TRAP ); }if (undef) { env->exception.syndrome =syn_uncategorized (); + env->exception.target_el =exception_target_el (env);raise_exception (env,EXCP_UDEF ); } }
Signature · 1 line
1.9.1
PATCH 3/14 target-arm: Set correct syndrome for faults on MSR DAIF*, imm
In reply to Peter MaydellIf the SCTLR.UMA trap bit is set then attempts by EL0 to update the PSTATE DAIF bits via "MSR DAIFSet, imm" and "MSR DAIFClr, imm" instructions will raise an exception. We were failing to set the syndrome information for this exception, which meant that it would be reported as a repeat of whatever the previous exception was. Set the correct syndrome information.
--- target-arm/op_helper.c | 3 +++ 1 file changed, 3 insertions(+)
target-arm/op_helper.c +3 -0
@@ -381,6 +381,9 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)*/ if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) { env->exception.target_el =exception_target_el (env); + env->exception.syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), +extract32 (op,3 ,3 ),4 , +0x1f , imm,0 );raise_exception (env,EXCP_UDEF ); }
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 03/14] target-arm: Set correct syndrome for faults on MSR DAIF*, imm
Quoted 15 lines · Peter Maydell
If the SCTLR.UMA trap bit is set then attempts by EL0 to update the PSTATE DAIF bits via "MSR DAIFSet, imm" and "MSR DAIFClr, imm" instructions will raise an exception. We were failing to set the syndrome information for this exception, which meant that it would be reported as a repeat of whatever the previous exception was. Set the correct syndrome information.
--- target-arm/op_helper.c | 3 +++ 1 file changed, 3 insertions(+)target-arm/op_helper.c +0
-0
target-arm/op_helper.c void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm) · line 386
Quoted 6 lines
target-arm/op_helper.c +3
-0@@ -381,6 +381,9 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)*/ if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) { env->exception.target_el =exception_target_el (env); + env->exception.syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), +extract32 (op,3 ,3 ),4 , +0x1f , imm,0 );
Did you possibly reverse the argument order of 0x1f and imm?
Cheers,
Edgar
Quoted 6 lines
target-arm/op_helper.c +0
-0raise_exception (env,EXCP_UDEF ); }Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 03/14] target-arm: Set correct syndrome for faults on MSR DAIF*, imm
Quoted 11 lines · Edgar E. Iglesias
Quoted 10 lines · Peter Maydell
If the SCTLR.UMA trap bit is set then attempts by EL0 to update the PSTATE DAIF bits via "MSR DAIFSet, imm" and "MSR DAIFClr, imm" instructions will raise an exception. We were failing to set the syndrome information for this exception, which meant that it would be reported as a repeat of whatever the previous exception was. Set the correct syndrome information.
--- target-arm/op_helper.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 13 lines
target-arm/op_helper.c void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm) · line 386
Quoted 11 lines
target-arm/op_helper.c +3
-0@@ -381,6 +381,9 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)*/ if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) { env->exception.target_el =exception_target_el (env); + env->exception.syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), +extract32 (op,3 ,3 ),4 , +0x1f , imm,0 );Did you possibly reverse the argument order of
0x1fand imm?
Ah, you're right; I was confused because the argument order of our syn_aa64_sysregtrap() and the pseudocode AArch64.SystemRegisterTrap is different (the latter follows the field order in the syndrome register and ours doesn't).
-- PMM
Re: [Qemu-devel] [PATCH 03/14] target-arm: Set correct syndrome for faults on MSR DAIF*, imm
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Edgar E. Iglesias
target-arm/op_helper.c void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm) · line 386
Quoted 7 lines
target-arm/op_helper.c +3
-0@@ -381,6 +381,9 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)*/ if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) { env->exception.target_el =exception_target_el (env); + env->exception.syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), +extract32 (op,3 ,3 ),4 , +0x1f , imm,0 );Did you possibly reverse the argument order of
0x1fand imm?
Quoted 4 lines
Ah, you're right; I was confused because the argument order of our
syn_aa64_sysregtrap()and the pseudocode AArch64.SystemRegisterTrap is different (the latter follows the field order in the syndrome register and ours doesn't).
I also managed to forget the signoff:
If this is the only fix in this series (I think you have one or two patches still left to review) then I propose to add it as I put the patches in target-arm.next:
- 0x1f, imm, 0);
+ imm, 0x1f, 0);
thanks
-- PMM
Edgar E. Iglesias
Reviewed-byRe: [Qemu-devel] [PATCH 03/14] target-arm: Set correct syndrome for faults on MSR DAIF*, imm
Quoted 24 lines · Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Edgar E. Iglesias
target-arm/op_helper.c void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm) · line 386
Quoted 7 lines
target-arm/op_helper.c +3
-0@@ -381,6 +381,9 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)*/ if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) { env->exception.target_el =exception_target_el (env); + env->exception.syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), +extract32 (op,3 ,3 ),4 , +0x1f , imm,0 );Did you possibly reverse the argument order of
0x1fand imm?Quoted 4 lines
Ah, you're right; I was confused because the argument order of our
syn_aa64_sysregtrap()and the pseudocode AArch64.SystemRegisterTrap is different (the latter follows the field order in the syndrome register and ours doesn't).I also managed to forget the signoff:
Signed-off-by Peter Maydell <[email protected]>If this is the only fix in this series (I think you have one or two patches still left to review) then I propose to add it as I put the patches in target-arm.next:
Review
Quoted 2 lines
(quoted diff) +1
-1- 0x1f, imm, 0); + imm, 0x1f, 0);
Yes, with these changes:
One of the patches had a missing target_el assigment for CP_ACCESS_TRAP_UNCATEGORIZED that I commented on a while back.
I'll have a look again.
Thanks,
Edgar
Quoted 3 lines
thanks
-- PMM
Re: [Qemu-devel] [PATCH 03/14] target-arm: Set correct syndrome for faults on MSR DAIF*, imm
Quoted 2 lines · Edgar E. Iglesias
One of the patches had a missing
target_elassigment forCP_ACCESS_TRAP_UNCATEGORIZEDthat I commented on a while back.
That's fixed in this series, I think.
Patches in this series I don't think I've seen a review or ack for:
target-arm: Allow cp access functions to indicate traps to EL2 or EL3
target-arm: Add AArch64 CPTR registers
target-arm: Extend FP checks to use an EL
thanks
-- PMM
PATCH 4/14 target-arm: Move setting of exception info into tlb_fill
In reply to Peter MaydellMove the code which sets exception information out of arm_cpu_handle_mmu_fault and into tlb_fill. tlb_fill is the only caller which wants to raise_exception() so it makes more sense for it to handle the whole of the exception setup.
As part of this cleanup, move the user-mode-only implementation function for the handle_mmu_fault CPU method into cpu.c so we don't need to make it globally visible, and rename the softmmu-only utility function arm_cpu_handle_mmu_fault to arm_tlb_fill so it's clear that it's not the same thing.
--- target-arm/cpu.c | 17 +++++++++++++++++ target-arm/cpu.h | 2 -- target-arm/helper.c | 47 +++++++---------------------------------------- target-arm/internals.h | 3 +++ target-arm/op_helper.c | 27 +++++++++++++++++++++++++-- 5 files changed, 52 insertions(+), 44 deletions(-)
target-arm/cpu.c +17 -0
@@ -1197,6 +1197,23 @@ static Property arm_cpu_properties[] = { DEFINE_PROP_END_OF_LIST() }; +#ifdef CONFIG_USER_ONLY +static int arm_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw, +int mmu_idx) +{ +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env; + + env->exception.vaddress = address; +if (rw ==2 ) { + cs->exception_index =EXCP_PREFETCH_ABORT ; + }else { + cs->exception_index =EXCP_DATA_ABORT ; + } +return 1 ; +} +#endif +static void arm_cpu_class_init (ObjectClass *oc,void *data) {ARMCPUClass *acc =ARM_CPU_CLASS (oc);
target-arm/cpu.h +0 -2
@@ -504,8 +504,6 @@ static inline bool is_a64(CPUARMState *env)is returned if the signal was handled by the virtual CPU. */ int cpu_arm_signal_handler (int host_signum,void *pinfo,void *puc); -int arm_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int rw, -int mmu_idx);/** * pmccntr_sync
target-arm/helper.c +7 -40
71 lines not on this page · raw message
target-arm/internals.h +3 -0
@@ -387,4 +387,7 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type);void arm_handle_psci_call (ARMCPU *cpu);#endif +/* Do a page table walk and add page to TLB if possible */ +int arm_tlb_fill (CPUState *cpu,vaddr address,int rw,int mmu_idx); +#endif
target-arm/op_helper.c +25 -2
@@ -80,16 +80,39 @@ void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, {int ret; - ret =arm_cpu_handle_mmu_fault (cs, addr, is_write, mmu_idx); + ret =arm_tlb_fill (cs, addr, is_write, mmu_idx);if (unlikely (ret)) {ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env; +uint32_t syn, exc; +bool same_el = (arm_current_el (env) !=0 );if (retaddr) {/* now we have a real cpu fault */ cpu_restore_state (cs, retaddr); } -raise_exception (env, cs->exception_index); + +/* AArch64 syndrome does not have an LPAE bit */ + syn = ret & ~(1 <<9 ); + +/* For insn and data aborts we assume there is no instruction syndrome +* information; this is always true for exceptions reported to EL1. +*/ +if (is_write ==2 ) { + syn =syn_insn_abort (same_el,0 ,0 , syn); + exc =EXCP_PREFETCH_ABORT ; + }else { + syn =syn_data_abort (same_el,0 ,0 ,0 , is_write ==1 , syn); +if (is_write ==1 &&arm_feature (env,ARM_FEATURE_V6 )) { + ret |= (1 <<11 ); + } + exc =EXCP_DATA_ABORT ; + } + + env->exception.syndrome = syn; + env->exception.vaddress = addr; + env->exception.fsr = ret; +raise_exception (env, exc); } }#endif
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 04/14] target-arm: Move setting of exception info into tlb_fill
Quoted 6 lines · Peter Maydell
Move the code which sets exception information out of
arm_cpu_handle_mmu_faultand intotlb_fill.tlb_fillis the only caller which wants toraise_exception()so it makes more sense for it to handle the whole of the exception setup.
Quoted 6 lines
As part of this cleanup, move the user-mode-only implementation function for the
handle_mmu_faultCPU method intocpu.cso we don't need to make it globally visible, and rename the softmmu-only utility functionarm_cpu_handle_mmu_faulttoarm_tlb_fillso it's clear that it's not the same thing.
Quoted 191 lines
Signed-off-by Peter Maydell <[email protected]>--- target-arm/cpu.c | 17 +++++++++++++++++ target-arm/cpu.h | 2 -- target-arm/helper.c | 47 +++++++---------------------------------------- target-arm/internals.h | 3 +++ target-arm/op_helper.c | 27 +++++++++++++++++++++++++-- 5 files changed, 52 insertions(+), 44 deletions(-)target-arm/cpu.c +17
-0@@ -1197,6 +1197,23 @@ static Property arm_cpu_properties[] = { DEFINE_PROP_END_OF_LIST() }; +#ifdef CONFIG_USER_ONLY +static int arm_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw, +int mmu_idx) +{ +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env; + + env->exception.vaddress = address; +if (rw ==2 ) { + cs->exception_index =EXCP_PREFETCH_ABORT ; + }else { + cs->exception_index =EXCP_DATA_ABORT ; + } +return 1 ; +} +#endif +static void arm_cpu_class_init (ObjectClass *oc,void *data) {ARMCPUClass *acc =ARM_CPU_CLASS (oc);target-arm/cpu.h +0
-2@@ -504,8 +504,6 @@ static inline bool is_a64(CPUARMState *env)is returned if the signal was handled by the virtual CPU. */ int cpu_arm_signal_handler (int host_signum,void *pinfo,void *puc); -int arm_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int rw, -int mmu_idx);/** * pmccntr_sync target-arm/helper.c +7
-40@@ -4047,21 +4047,6 @@ uint32_t HELPER(rbit)(uint32_t x)#if defined(CONFIG_USER_ONLY ) -int arm_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw, -int mmu_idx) -{ -ARMCPU *cpu =ARM_CPU (cs); -CPUARMState *env = &cpu->env; - - env->exception.vaddress = address; -if (rw ==2 ) { - cs->exception_index =EXCP_PREFETCH_ABORT ; - }else { - cs->exception_index =EXCP_DATA_ABORT ; - } -return 1 ; -} -/* These should probably raise undefined insn exceptions. */ void HELPER (v7m_msr )(CPUARMState *env,uint32_t reg,uint32_t val) {@@ -5826,8 +5811,12 @@ static inline int get_phys_addr(CPUARMState *env, target_ulong address, } } -int arm_cpu_handle_mmu_fault (CPUState *cs,vaddr address, -int access_type,int mmu_idx) +/* Walk the page table and (if the mapping exists) add the page +* to the TLB. Return 0 on success, or an ARM DFSR/IFSR fault +* register format value on failure. +*/ +int arm_tlb_fill (CPUState *cs,vaddr address, +int access_type,int mmu_idx) {ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env;@@ -5835,8 +5824,6 @@ int arm_cpu_handle_mmu_fault(CPUState *cs, vaddr address,target_ulong page_size;int prot;int ret; -uint32_t syn; -bool same_el = (arm_current_el (env) !=0 );MemTxAttrs attrs = {}; ret = get_phys_addr(env, address, access_type, mmu_idx, &phys_addr,@@ -5850,27 +5837,7 @@ int arm_cpu_handle_mmu_fault(CPUState *cs, vaddr address,return 0 ; } -/* AArch64 syndrome does not have an LPAE bit */ - syn = ret & ~(1 <<9 ); - -/* For insn and data aborts we assume there is no instruction syndrome -* information; this is always true for exceptions reported to EL1. -*/ -if (access_type ==2 ) { - syn =syn_insn_abort (same_el,0 ,0 , syn); - cs->exception_index =EXCP_PREFETCH_ABORT ; - }else { - syn =syn_data_abort (same_el,0 ,0 ,0 , access_type ==1 , syn); -if (access_type ==1 &&arm_feature (env,ARM_FEATURE_V6 )) { - ret |= (1 <<11 ); - } - cs->exception_index =EXCP_DATA_ABORT ; - } - - env->exception.syndrome = syn; - env->exception.vaddress = address; - env->exception.fsr = ret; -return 1 ; +return ret; }hwaddr arm_cpu_get_phys_page_debug (CPUState *cs,vaddr addr)target-arm/internals.h +3
-0@@ -387,4 +387,7 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type);void arm_handle_psci_call (ARMCPU *cpu);#endif +/* Do a page table walk and add page to TLB if possible */ +int arm_tlb_fill (CPUState *cpu,vaddr address,int rw,int mmu_idx); +#endif target-arm/op_helper.c +25
-2@@ -80,16 +80,39 @@ void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, {int ret; - ret =arm_cpu_handle_mmu_fault (cs, addr, is_write, mmu_idx); + ret =arm_tlb_fill (cs, addr, is_write, mmu_idx);if (unlikely (ret)) {ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env; +uint32_t syn, exc; +bool same_el = (arm_current_el (env) !=0 );if (retaddr) {/* now we have a real cpu fault */ cpu_restore_state (cs, retaddr); } -raise_exception (env, cs->exception_index); + +/* AArch64 syndrome does not have an LPAE bit */ + syn = ret & ~(1 <<9 ); + +/* For insn and data aborts we assume there is no instruction syndrome +* information; this is always true for exceptions reported to EL1. +*/ +if (is_write ==2 ) { + syn =syn_insn_abort (same_el,0 ,0 , syn); + exc =EXCP_PREFETCH_ABORT ; + }else { + syn =syn_data_abort (same_el,0 ,0 ,0 , is_write ==1 , syn); +if (is_write ==1 &&arm_feature (env,ARM_FEATURE_V6 )) { + ret |= (1 <<11 ); + } + exc =EXCP_DATA_ABORT ; + } + + env->exception.syndrome = syn; + env->exception.vaddress = addr; + env->exception.fsr = ret; +raise_exception (env, exc); } }#endif Signature · 1 line
1.9.1
PATCH 5/14 target-arm: Set exception target EL in tlb_fill
In reply to Peter MaydellSet the exception target EL for MMU faults in tlb_fill.
--- target-arm/op_helper.c | 1 + 1 file changed, 1 insertion(+)
target-arm/op_helper.c +1 -0
@@ -110,6 +110,7 @@ void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, } env->exception.syndrome = syn; + env->exception.target_el =exception_target_el (env); env->exception.vaddress = addr; env->exception.fsr = ret;raise_exception (env, exc);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 05/14] target-arm: Set exception target EL in tlb_fill
Quoted 3 lines · Peter Maydell
Set the exception target EL for MMU faults in
tlb_fill.Signed-off-by Peter Maydell <[email protected]>
Quoted 19 lines
--- target-arm/op_helper.c | 1 + 1 file changed, 1 insertion(+)target-arm/op_helper.c +1
-0@@ -110,6 +110,7 @@ void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, } env->exception.syndrome = syn; + env->exception.target_el =exception_target_el (env); env->exception.vaddress = addr; env->exception.fsr = ret;raise_exception (env, exc);Signature · 1 line
1.9.1
PATCH 6/14 target-arm: Make raise_exception() take syndrome and target EL
In reply to Peter MaydellRather than making every caller of raise_exception set the syndrome and target EL by hand, make these arguments to raise_exception() and have that do the job.
--- target-arm/op_helper.c | 68 +++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 40 deletions(-)
target-arm/op_helper.c +28 -40
@@ -24,12 +24,15 @@#define SIGNBIT (uint32_t)0x80000000#define SIGNBIT64 ((uint64_t)1 << 63) -static void raise_exception (CPUARMState *env,int tt) +static void raise_exception (CPUARMState *env,uint32_t excp, +uint32_t syndrome,uint32_t target_el) { -ARMCPU *cpu =arm_env_get_cpu (env); -CPUState *cs =CPU (cpu); +CPUState *cs =CPU (arm_env_get_cpu (env)); - cs->exception_index = tt; +assert (!excp_is_internal (excp)); + cs->exception_index = excp; + env->exception.syndrome = syndrome; + env->exception.target_el = target_el;cpu_loop_exit (cs); }
@@ -109,11 +112,9 @@ void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, exc = EXCP_DATA_ABORT; } - env->exception.syndrome = syn; - env->exception.target_el =exception_target_el (env); env->exception.vaddress = addr; env->exception.fsr = ret; -raise_exception (env, exc); +raise_exception (env, exc, syn,exception_target_el (env)); } }#endif
@@ -286,13 +287,7 @@ void HELPER(exception_internal)(CPUARMState *env, uint32_t excp)void HELPER (exception_with_syndrome )(CPUARMState *env,uint32_t excp,uint32_t syndrome,uint32_t target_el) { -CPUState *cs =CPU (arm_env_get_cpu (env)); - -assert (!excp_is_internal (excp)); - cs->exception_index = excp; - env->exception.syndrome = syndrome; - env->exception.target_el = target_el; -cpu_loop_exit (cs); +raise_exception (env, excp, syndrome, target_el); }uint32_t HELPER (cpsr_read )(CPUARMState *env)
@@ -343,9 +338,7 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)if (arm_feature (env,ARM_FEATURE_XSCALE ) && ri->cp <14 &&extract32 (env->cp15.c15_cpar, ri->cp,1 ) ==0 ) { - env->exception.syndrome = syndrome; - env->exception.target_el =exception_target_el (env); -raise_exception (env,EXCP_UDEF ); +raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); }if (!ri->accessfn) {
@@ -356,17 +349,15 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)case CP_ACCESS_OK :return ;case CP_ACCESS_TRAP : - env->exception.syndrome = syndrome; - env->exception.target_el =exception_target_el (env);break ;case CP_ACCESS_TRAP_UNCATEGORIZED : - env->exception.syndrome =syn_uncategorized (); - env->exception.target_el =exception_target_el (env); + syndrome =syn_uncategorized ();break ;default :g_assert_not_reached (); } -raise_exception (env,EXCP_UDEF ); + +raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); }void HELPER (set_cp_reg )(CPUARMState *env,void *rip,uint32_t value)
@@ -404,11 +395,10 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)* to catch that case at translate time. */ if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) { - env->exception.target_el =exception_target_el (env); - env->exception.syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), -extract32 (op,3 ,3 ),4 , -0x1f , imm,0 ); -raise_exception (env,EXCP_UDEF ); +uint32_t syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), +extract32 (op,3 ,3 ),4 , +0x1f , imm,0 ); +raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); }switch (op) {
@@ -466,9 +456,8 @@ void HELPER(pre_hvc)(CPUARMState *env) }if (undef) { - env->exception.syndrome =syn_uncategorized (); - env->exception.target_el =exception_target_el (env); -raise_exception (env,EXCP_UDEF ); +raise_exception (env,EXCP_UDEF ,syn_uncategorized (), +exception_target_el (env)); } }
@@ -497,15 +486,12 @@ void HELPER(pre_smc)(CPUARMState *env, uint32_t syndrome) undef = true; }else if (!secure && cur_el ==1 && (env->cp15.hcr_el2 &HCR_TSC )) {/* In NS EL1, HCR controlled routing to EL2 has priority over SMD. */ - env->exception.syndrome = syndrome; - env->exception.target_el =2 ; -raise_exception (env,EXCP_HYP_TRAP ); +raise_exception (env,EXCP_HYP_TRAP , syndrome,2 ); }if (undef) { - env->exception.syndrome =syn_uncategorized (); - env->exception.target_el =exception_target_el (env); -raise_exception (env,EXCP_UDEF ); +raise_exception (env,EXCP_UDEF ,syn_uncategorized (), +exception_target_el (env)); } }
@@ -798,14 +784,15 @@ void arm_debug_excp_handler(CPUState *cs)bool wnr = (wp_hit->flags &BP_WATCHPOINT_HIT_WRITE ) !=0 ;bool same_el =arm_debug_target_el (env) ==arm_current_el (env); - env->exception.syndrome =syn_watchpoint (same_el,0 , wnr);if (extended_addresses_enabled (env)) { env->exception.fsr = (1 <<9 ) |0x22 ; }else { env->exception.fsr =0x2 ; } env->exception.vaddress = wp_hit->hitaddr; -raise_exception (env,EXCP_DATA_ABORT ); +raise_exception (env,EXCP_DATA_ABORT , +syn_watchpoint (same_el,0 , wnr), +arm_debug_target_el (env)); }else {cpu_resume_from_signal (cs,NULL ); }
@@ -813,14 +800,15 @@ void arm_debug_excp_handler(CPUState *cs) }else {if (check_breakpoints (cpu)) {bool same_el = (arm_debug_target_el (env) ==arm_current_el (env)); - env->exception.syndrome =syn_breakpoint (same_el);if (extended_addresses_enabled (env)) { env->exception.fsr = (1 <<9 ) |0x22 ; }else { env->exception.fsr =0x2 ; }/* FAR is UNKNOWN, so doesn't need setting */ -raise_exception (env,EXCP_PREFETCH_ABORT ); +raise_exception (env,EXCP_PREFETCH_ABORT , +syn_breakpoint (same_el), +arm_debug_target_el (env)); } } }
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 06/14] target-arm: Make raise_exception() take syndrome and target EL
Quoted 5 lines · Peter Maydell
Rather than making every caller of
raise_exceptionset the syndrome and target EL by hand, make these arguments toraise_exception()and have that do the job.Signed-off-by Peter Maydell <[email protected]>
Quoted 174 lines
--- target-arm/op_helper.c | 68 +++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 40 deletions(-)target-arm/op_helper.c +28
-40@@ -24,12 +24,15 @@#define SIGNBIT (uint32_t)0x80000000#define SIGNBIT64 ((uint64_t)1 << 63) -static void raise_exception (CPUARMState *env,int tt) +static void raise_exception (CPUARMState *env,uint32_t excp, +uint32_t syndrome,uint32_t target_el) { -ARMCPU *cpu =arm_env_get_cpu (env); -CPUState *cs =CPU (cpu); +CPUState *cs =CPU (arm_env_get_cpu (env)); - cs->exception_index = tt; +assert (!excp_is_internal (excp)); + cs->exception_index = excp; + env->exception.syndrome = syndrome; + env->exception.target_el = target_el;cpu_loop_exit (cs); }@@ -109,11 +112,9 @@ void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, exc = EXCP_DATA_ABORT; } - env->exception.syndrome = syn; - env->exception.target_el =exception_target_el (env); env->exception.vaddress = addr; env->exception.fsr = ret; -raise_exception (env, exc); +raise_exception (env, exc, syn,exception_target_el (env)); } }#endif @@ -286,13 +287,7 @@ void HELPER(exception_internal)(CPUARMState *env, uint32_t excp)void HELPER (exception_with_syndrome )(CPUARMState *env,uint32_t excp,uint32_t syndrome,uint32_t target_el) { -CPUState *cs =CPU (arm_env_get_cpu (env)); - -assert (!excp_is_internal (excp)); - cs->exception_index = excp; - env->exception.syndrome = syndrome; - env->exception.target_el = target_el; -cpu_loop_exit (cs); +raise_exception (env, excp, syndrome, target_el); }uint32_t HELPER (cpsr_read )(CPUARMState *env)@@ -343,9 +338,7 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)if (arm_feature (env,ARM_FEATURE_XSCALE ) && ri->cp <14 &&extract32 (env->cp15.c15_cpar, ri->cp,1 ) ==0 ) { - env->exception.syndrome = syndrome; - env->exception.target_el =exception_target_el (env); -raise_exception (env,EXCP_UDEF ); +raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); }if (!ri->accessfn) {@@ -356,17 +349,15 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)case CP_ACCESS_OK :return ;case CP_ACCESS_TRAP : - env->exception.syndrome = syndrome; - env->exception.target_el =exception_target_el (env);break ;case CP_ACCESS_TRAP_UNCATEGORIZED : - env->exception.syndrome =syn_uncategorized (); - env->exception.target_el =exception_target_el (env); + syndrome =syn_uncategorized ();break ;default :g_assert_not_reached (); } -raise_exception (env,EXCP_UDEF ); + +raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); }void HELPER (set_cp_reg )(CPUARMState *env,void *rip,uint32_t value)@@ -404,11 +395,10 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)* to catch that case at translate time. */ if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) { - env->exception.target_el =exception_target_el (env); - env->exception.syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), -extract32 (op,3 ,3 ),4 , -0x1f , imm,0 ); -raise_exception (env,EXCP_UDEF ); +uint32_t syndrome =syn_aa64_sysregtrap (0 ,extract32 (op,0 ,3 ), +extract32 (op,3 ,3 ),4 , +0x1f , imm,0 ); +raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); }switch (op) {@@ -466,9 +456,8 @@ void HELPER(pre_hvc)(CPUARMState *env) }if (undef) { - env->exception.syndrome =syn_uncategorized (); - env->exception.target_el =exception_target_el (env); -raise_exception (env,EXCP_UDEF ); +raise_exception (env,EXCP_UDEF ,syn_uncategorized (), +exception_target_el (env)); } }@@ -497,15 +486,12 @@ void HELPER(pre_smc)(CPUARMState *env, uint32_t syndrome) undef = true; }else if (!secure && cur_el ==1 && (env->cp15.hcr_el2 &HCR_TSC )) {/* In NS EL1, HCR controlled routing to EL2 has priority over SMD. */ - env->exception.syndrome = syndrome; - env->exception.target_el =2 ; -raise_exception (env,EXCP_HYP_TRAP ); +raise_exception (env,EXCP_HYP_TRAP , syndrome,2 ); }if (undef) { - env->exception.syndrome =syn_uncategorized (); - env->exception.target_el =exception_target_el (env); -raise_exception (env,EXCP_UDEF ); +raise_exception (env,EXCP_UDEF ,syn_uncategorized (), +exception_target_el (env)); } }@@ -798,14 +784,15 @@ void arm_debug_excp_handler(CPUState *cs)bool wnr = (wp_hit->flags &BP_WATCHPOINT_HIT_WRITE ) !=0 ;bool same_el =arm_debug_target_el (env) ==arm_current_el (env); - env->exception.syndrome =syn_watchpoint (same_el,0 , wnr);if (extended_addresses_enabled (env)) { env->exception.fsr = (1 <<9 ) |0x22 ; }else { env->exception.fsr =0x2 ; } env->exception.vaddress = wp_hit->hitaddr; -raise_exception (env,EXCP_DATA_ABORT ); +raise_exception (env,EXCP_DATA_ABORT , +syn_watchpoint (same_el,0 , wnr), +arm_debug_target_el (env)); }else {cpu_resume_from_signal (cs,NULL ); }@@ -813,14 +800,15 @@ void arm_debug_excp_handler(CPUState *cs) }else {if (check_breakpoints (cpu)) {bool same_el = (arm_debug_target_el (env) ==arm_current_el (env)); - env->exception.syndrome =syn_breakpoint (same_el);if (extended_addresses_enabled (env)) { env->exception.fsr = (1 <<9 ) |0x22 ; }else { env->exception.fsr =0x2 ; }/* FAR is UNKNOWN, so doesn't need setting */ -raise_exception (env,EXCP_PREFETCH_ABORT ); +raise_exception (env,EXCP_PREFETCH_ABORT , +syn_breakpoint (same_el), +arm_debug_target_el (env)); } } }Signature · 1 line
1.9.1
PATCH 7/14 target-arm: Update interrupt handling to use target EL
In reply to Peter MaydellFrom: Greg Bellows <[email protected]>
Updated the interrupt handling to utilize and report through the target EL exception field. This includes consolidating and cleaning up code where needed. Target EL is now calculated once in arm_cpu_exec_interrupt() and do_interrupt was updated to use the target_el exception field. The necessary code from arm_excp_target_el() was merged in where needed and the function removed.
Message-id: [email protected]
--- target-arm/cpu.c | 61 +++++++++++++++++++++++++++++++++---------------- target-arm/cpu.h | 7 +++--- target-arm/helper-a64.c | 2 +- target-arm/helper.c | 41 ++++----------------------------- 4 files changed, 50 insertions(+), 61 deletions(-)
target-arm/cpu.c +41 -20
@@ -206,31 +206,52 @@ static void arm_cpu_reset(CPUState *s)bool arm_cpu_exec_interrupt (CPUState *cs,int interrupt_request) {CPUClass *cc =CPU_GET_CLASS (cs); +CPUARMState *env = cs->env_ptr; +uint32_t cur_el =arm_current_el (env); +bool secure =arm_is_secure (env); +uint32_t target_el; +uint32_t excp_idx;bool ret = false; -if (interrupt_request &CPU_INTERRUPT_FIQ - &&arm_excp_unmasked (cs,EXCP_FIQ )) { - cs->exception_index =EXCP_FIQ ; - cc->do_interrupt (cs); - ret = true; +if (interrupt_request &CPU_INTERRUPT_FIQ ) { + excp_idx =EXCP_FIQ ; + target_el =arm_phys_excp_target_el (cs, excp_idx, cur_el, secure); +if (arm_excp_unmasked (cs, excp_idx, target_el)) { + cs->exception_index = excp_idx; + env->exception.target_el = target_el; + cc->do_interrupt (cs); + ret = true; + } } -if (interrupt_request &CPU_INTERRUPT_HARD - &&arm_excp_unmasked (cs,EXCP_IRQ )) { - cs->exception_index =EXCP_IRQ ; - cc->do_interrupt (cs); - ret = true; +if (interrupt_request &CPU_INTERRUPT_HARD ) { + excp_idx =EXCP_IRQ ; + target_el =arm_phys_excp_target_el (cs, excp_idx, cur_el, secure); +if (arm_excp_unmasked (cs, excp_idx, target_el)) { + cs->exception_index = excp_idx; + env->exception.target_el = target_el; + cc->do_interrupt (cs); + ret = true; + } } -if (interrupt_request &CPU_INTERRUPT_VIRQ - &&arm_excp_unmasked (cs,EXCP_VIRQ )) { - cs->exception_index =EXCP_VIRQ ; - cc->do_interrupt (cs); - ret = true; +if (interrupt_request &CPU_INTERRUPT_VIRQ ) { + excp_idx =EXCP_VIRQ ; + target_el =1 ; +if (arm_excp_unmasked (cs, excp_idx, target_el)) { + cs->exception_index = excp_idx; + env->exception.target_el = target_el; + cc->do_interrupt (cs); + ret = true; + } } -if (interrupt_request &CPU_INTERRUPT_VFIQ - &&arm_excp_unmasked (cs,EXCP_VFIQ )) { - cs->exception_index =EXCP_VFIQ ; - cc->do_interrupt (cs); - ret = true; +if (interrupt_request &CPU_INTERRUPT_VFIQ ) { + excp_idx =EXCP_VFIQ ; + target_el =1 ; +if (arm_excp_unmasked (cs, excp_idx, target_el)) { + cs->exception_index = excp_idx; + env->exception.target_el = target_el; + cc->do_interrupt (cs); + ret = true; + } }return ret;
target-arm/cpu.h +4 -3
@@ -1000,7 +1000,8 @@ static inline bool access_secure_reg(CPUARMState *env) (_val))void arm_cpu_list (FILE *f,fprintf_function cpu_fprintf); -unsigned int arm_excp_target_el (CPUState *cs,unsigned int excp_idx); +uint32_t arm_phys_excp_target_el (CPUState *cs,uint32_t excp_idx, +uint32_t cur_el,bool secure);/* Interface between CPU and Interrupt controller. */ void armv7m_nvic_set_pending (void *opaque,int irq);
@@ -1482,11 +1483,11 @@ 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) +static inline bool arm_excp_unmasked (CPUState *cs,unsigned int excp_idx, +unsigned int target_el) {CPUARMState *env = cs->env_ptr;unsigned int cur_el =arm_current_el (env); -unsigned int target_el =arm_excp_target_el (cs, excp_idx);bool secure =arm_is_secure (env);uint32_t scr;uint32_t hcr;
target-arm/helper-a64.c +1 -1
@@ -463,7 +463,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs) {ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env; -unsigned int new_el =arm_excp_target_el (cs, cs->exception_index); +unsigned int new_el = env->exception.target_el;target_ulong addr = env->cp15.vbar_el[new_el];unsigned int new_mode =aarch64_pstate_mode (new_el, true);
target-arm/helper.c +4 -37
59 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 8/14 target-arm: Allow cp access functions to indicate traps to EL2 or EL3
In reply to Peter MaydellSome coprocessor access functions will need to indicate that the instruction should trap to EL2 or EL3 rather than the default target exception level; add corresponding CPAccessResult enum entries and handling code.
--- target-arm/cpu.h | 6 +++++- target-arm/op_helper.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-)
target-arm/cpu.h +5 -1
@@ -1252,7 +1252,8 @@ typedef enum CPAccessResult {/* Access fails due to a configurable trap or enable which would * result in a categorized exception syndrome giving information about * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6, -* 0xc or 0x18). +* 0xc or 0x18). The exception is taken to the usual target EL (EL1 or +* PL1 if in EL0, otherwise to the current EL). */ CP_ACCESS_TRAP = 1,/* Access fails and results in an exception syndrome 0x0 ("uncategorized").
@@ -1260,6 +1261,9 @@ typedef enum CPAccessResult {* result in this failure is specifically defined by the architecture. */ CP_ACCESS_TRAP_UNCATEGORIZED =2 , +/* As CP_ACCESS_TRAP, but for traps directly to EL2 or EL3 */ +CP_ACCESS_TRAP_EL2 =3 , +CP_ACCESS_TRAP_EL3 =4 , } CPAccessResult;/* Access functions for coprocessor registers. These cannot fail and
target-arm/op_helper.c +13 -1
@@ -335,6 +335,7 @@ void HELPER(set_user_reg)(CPUARMState *env, uint32_t regno, uint32_t val)void HELPER (access_check_cp_reg )(CPUARMState *env,void *rip,uint32_t syndrome) {const ARMCPRegInfo *ri = rip; +int target_el;if (arm_feature (env,ARM_FEATURE_XSCALE ) && ri->cp <14 &&extract32 (env->cp15.c15_cpar, ri->cp,1 ) ==0 ) {
@@ -349,6 +350,17 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)case CP_ACCESS_OK :return ;case CP_ACCESS_TRAP : + target_el =exception_target_el (env); +break ; +case CP_ACCESS_TRAP_EL2 : +/* Requesting a trap to EL2 when we're in EL3 or S-EL0/1 is +* a bug in the access function. +*/ +assert (!arm_is_secure (env) && !arm_current_el (env) ==3 ); + target_el =2 ; +break ; +case CP_ACCESS_TRAP_EL3 : + target_el =3 ;break ;case CP_ACCESS_TRAP_UNCATEGORIZED : syndrome =syn_uncategorized ();
@@ -357,7 +369,7 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)g_assert_not_reached (); } -raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); +raise_exception (env,EXCP_UDEF , syndrome, target_el); }void HELPER (set_cp_reg )(CPUARMState *env,void *rip,uint32_t value)
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 08/14] target-arm: Allow cp access functions to indicate traps to EL2 or EL3
Quoted 55 lines · Peter Maydell
Some coprocessor access functions will need to indicate that the instruction should trap to EL2 or EL3 rather than the default target exception level; add corresponding CPAccessResult enum entries and handling code.
Signed-off-by Peter Maydell <[email protected]>--- target-arm/cpu.h | 6 +++++- target-arm/op_helper.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-)target-arm/cpu.h +5
-1@@ -1252,7 +1252,8 @@ typedef enum CPAccessResult {/* Access fails due to a configurable trap or enable which would * result in a categorized exception syndrome giving information about * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6, -* 0xc or 0x18). +* 0xc or 0x18). The exception is taken to the usual target EL (EL1 or +* PL1 if in EL0, otherwise to the current EL). */ CP_ACCESS_TRAP = 1,/* Access fails and results in an exception syndrome 0x0 ("uncategorized"). @@ -1260,6 +1261,9 @@ typedef enum CPAccessResult {* result in this failure is specifically defined by the architecture. */ CP_ACCESS_TRAP_UNCATEGORIZED =2 , +/* As CP_ACCESS_TRAP, but for traps directly to EL2 or EL3 */ +CP_ACCESS_TRAP_EL2 =3 , +CP_ACCESS_TRAP_EL3 =4 , } CPAccessResult;/* Access functions for coprocessor registers. These cannot fail and target-arm/op_helper.c +5
-0@@ -335,6 +335,7 @@ void HELPER(set_user_reg)(CPUARMState *env, uint32_t regno, uint32_t val)void HELPER (access_check_cp_reg )(CPUARMState *env,void *rip,uint32_t syndrome) {const ARMCPRegInfo *ri = rip; +int target_el;if (arm_feature (env,ARM_FEATURE_XSCALE ) && ri->cp <14 &&extract32 (env->cp15.c15_cpar, ri->cp,1 ) ==0 ) {@@ -349,6 +350,17 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)case CP_ACCESS_OK :return ;case CP_ACCESS_TRAP : + target_el =exception_target_el (env); +break ; +case CP_ACCESS_TRAP_EL2 : +/* Requesting a trap to EL2 when we're in EL3 or S-EL0/1 is
target-arm/op_helper.c void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome) · line 366
Quoted 10 lines
target-arm/op_helper.c +7
-0+* a bug in the access function. +*/ +assert (!arm_is_secure (env) && !arm_current_el (env) ==3 ); + target_el =2 ; +break ; +case CP_ACCESS_TRAP_EL3 : + target_el =3 ;break ;case CP_ACCESS_TRAP_UNCATEGORIZED : syndrome =syn_uncategorized ();
It looks like you need a:target_el = exception_target_el(env);
here, no?
Quoted 12 lines
target-arm/op_helper.c +1
-1@@ -357,7 +369,7 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)g_assert_not_reached (); } -raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); +raise_exception (env,EXCP_UDEF , syndrome, target_el); }void HELPER (set_cp_reg )(CPUARMState *env,void *rip,uint32_t value)Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 08/14] target-arm: Allow cp access functions to indicate traps to EL2 or EL3
Quoted 8 lines · Edgar E. Iglesias
Quoted 2 lines · Peter Maydell
case CP_ACCESS_TRAP_UNCATEGORIZED: syndrome = syn_uncategorized();It looks like you need a:
target_el=exception_target_el(env);here, no?
Oops, yes.
-- PMM
Re: [Qemu-devel] [PATCH 08/14] target-arm: Allow cp access functions to indicate traps to EL2 or EL3
In reply to Peter MaydellQuoted 55 lines · Peter Maydell
Some coprocessor access functions will need to indicate that the instruction should trap to EL2 or EL3 rather than the default target exception level; add corresponding CPAccessResult enum entries and handling code.
Signed-off-by Peter Maydell <[email protected]>--- target-arm/cpu.h | 6 +++++- target-arm/op_helper.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-)target-arm/cpu.h +5
-1@@ -1252,7 +1252,8 @@ typedef enum CPAccessResult {/* Access fails due to a configurable trap or enable which would * result in a categorized exception syndrome giving information about * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6, -* 0xc or 0x18). +* 0xc or 0x18). The exception is taken to the usual target EL (EL1 or +* PL1 if in EL0, otherwise to the current EL). */ CP_ACCESS_TRAP = 1,/* Access fails and results in an exception syndrome 0x0 ("uncategorized"). @@ -1260,6 +1261,9 @@ typedef enum CPAccessResult {* result in this failure is specifically defined by the architecture. */ CP_ACCESS_TRAP_UNCATEGORIZED =2 , +/* As CP_ACCESS_TRAP, but for traps directly to EL2 or EL3 */ +CP_ACCESS_TRAP_EL2 =3 , +CP_ACCESS_TRAP_EL3 =4 , } CPAccessResult;/* Access functions for coprocessor registers. These cannot fail and target-arm/op_helper.c +5
-0@@ -335,6 +335,7 @@ void HELPER(set_user_reg)(CPUARMState *env, uint32_t regno, uint32_t val)void HELPER (access_check_cp_reg )(CPUARMState *env,void *rip,uint32_t syndrome) {const ARMCPRegInfo *ri = rip; +int target_el;if (arm_feature (env,ARM_FEATURE_XSCALE ) && ri->cp <14 &&extract32 (env->cp15.c15_cpar, ri->cp,1 ) ==0 ) {@@ -349,6 +350,17 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)case CP_ACCESS_OK :return ;case CP_ACCESS_TRAP : + target_el =exception_target_el (env); +break ; +case CP_ACCESS_TRAP_EL2 : +/* Requesting a trap to EL2 when we're in EL3 or S-EL0/1 is
target-arm/op_helper.c void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome) · line 366
Quoted 10 lines
target-arm/op_helper.c +7
-0+* a bug in the access function. +*/ +assert (!arm_is_secure (env) && !arm_current_el (env) ==3 ); + target_el =2 ; +break ; +case CP_ACCESS_TRAP_EL3 : + target_el =3 ;break ;case CP_ACCESS_TRAP_UNCATEGORIZED : syndrome =syn_uncategorized ();
Here it was, this needs target_el = exception_target_el(env);
With that change:
Cheers,
Edgar
Quoted 12 lines
target-arm/op_helper.c +1
-1@@ -357,7 +369,7 @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome)g_assert_not_reached (); } -raise_exception (env,EXCP_UDEF , syndrome,exception_target_el (env)); +raise_exception (env,EXCP_UDEF , syndrome, target_el); }void HELPER (set_cp_reg )(CPUARMState *env,void *rip,uint32_t value)Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 08/14] target-arm: Allow cp access functions to indicate traps to EL2 or EL3
Quoted 6 lines · Edgar E. Iglesias
Quoted 4 lines · Peter Maydell
Some coprocessor access functions will need to indicate that the instruction should trap to EL2 or EL3 rather than the default target exception level; add corresponding CPAccessResult enum entries and handling code.
Quoted 7 lines
Quoted 2 lines
case CP_ACCESS_TRAP_UNCATEGORIZED: syndrome = syn_uncategorized();Here it was, this needs
target_el=exception_target_el(env);With that change:
Reviewed-by Edgar E. Iglesias <[email protected]>
Ah, I fixed this up in my working copy when you reviewed it, but forgot to say so on list! No wonder I was confused...
-- PMM
PATCH 9/14 target-arm: Add AArch64 CPTR registers
In reply to Peter MaydellFrom: Greg Bellows <[email protected]>
Adds CPTR_EL2/3 system registers definitions and access function.
[PMM: merge CPTR_EL2 and HCPTR definitions into a single
def using STATE_BOTH;
don't use readfn/writefn to implement RAZ/WI registers; don't use accessfn for the no-EL2 CPTR_EL2;
fix cpacr_access logic to catch EL2 accesses to CPACR being trapped to EL3;
use new CP_ACCESS_TRAP_EL[23] rather than setting exception.target_el directly]
--- target-arm/cpu.h | 5 +++++ target-arm/helper.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-)
target-arm/cpu.h +5 -0
@@ -197,6 +197,7 @@ typedef struct CPUARMState {uint64_t sctlr_el[4 ]; };uint64_t cpacr_el1;/* Architectural feature access control register */ +uint64_t cptr_el[4 ];/* ARMv8 feature trap registers */ uint32_t c1_xscaleauxcr;/* XScale auxiliary control register. */ uint64_t sder;/* Secure debug enable register. */ uint32_t nsacr;/* Non-secure access control register. */
@@ -568,6 +569,10 @@ void pmccntr_sync(CPUARMState *env);#define SCTLR_AFE (1U << 29)#define SCTLR_TE (1U << 30) +#define CPTR_TCPAC (1U << 31) +#define CPTR_TTA (1U << 20) +#define CPTR_TFP (1U << 10) +#define CPSR_M (0x1fU)#define CPSR_T (1U << 5)#define CPSR_F (1U << 6)
target-arm/helper.c +39 -1
@@ -592,6 +592,33 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri, env->cp15.cpacr_el1 = value; } +static CPAccessResult cpacr_access (CPUARMState *env,const ARMCPRegInfo *ri) +{ +if (arm_feature (env,ARM_FEATURE_V8 )) { +/* Check if CPACR accesses are to be trapped to EL2 */ +if (arm_current_el (env) ==1 && + (env->cp15.cptr_el[2 ] &CPTR_TCPAC ) && !arm_is_secure (env)) { +return CP_ACCESS_TRAP_EL2 ; +/* Check if CPACR accesses are to be trapped to EL3 */ + }else if (arm_current_el (env) <3 && + (env->cp15.cptr_el[3 ] &CPTR_TCPAC )) { +return CP_ACCESS_TRAP_EL3 ; + } + } + +return CP_ACCESS_OK ; +} + +static CPAccessResult cptr_access (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* Check if CPTR accesses are set to trap to EL3 */ +if (arm_current_el (env) ==2 && (env->cp15.cptr_el[3 ] &CPTR_TCPAC )) { +return CP_ACCESS_TRAP_EL3 ; + } + +return CP_ACCESS_OK ; +} +static const ARMCPRegInfo v6_cp_reginfo[] = {/* prefetch by MVA in v6, NOP in v7 */ { .name ="MVA_prefetch" ,
@@ -614,7 +641,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { { .name = "WFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 1, .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, }, { .name = "CPACR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, - .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 2, + .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 2, .accessfn = cpacr_access, .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.cpacr_el1), .resetvalue = 0, .writefn = cpacr_write }, REGINFO_SENTINEL
@@ -2481,6 +2508,9 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 0, .access = PL2_RW, .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore }, + { .name = "CPTR_EL2", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2, + .access = PL2_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, REGINFO_SENTINEL };
@@ -2548,6 +2578,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 6, .crn = 4, .crm = 1, .opc2 = 0, .access = PL3_RW, .type = ARM_CP_ALIAS, .fieldoffset = offsetof(CPUARMState, sp_el[2]) }, + { .name = "CPTR_EL2", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2, + .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]) }, REGINFO_SENTINEL };
@@ -2609,6 +2643,10 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .access = PL3_RW, .writefn = vbar_write, .fieldoffset = offsetof(CPUARMState, cp15.vbar_el[3]), .resetvalue = 0 }, + { .name = "CPTR_EL3", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 1, .opc2 = 2, + .access = PL3_RW, .accessfn = cptr_access, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[3]) },REGINFO_SENTINEL };
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 09/14] target-arm: Add AArch64 CPTR registers
Quoted 13 lines · Peter Maydell
From: Greg Bellows <[email protected]>
Adds CPTR_EL2/3 system registers definitions and access function.
Signed-off-by Greg Bellows <[email protected]>[PMM: merge
CPTR_EL2and HCPTR definitions into a single
def usingSTATE_BOTH;
don't use readfn/writefn to implement RAZ/WI registers; don't use accessfn for the no-EL2CPTR_EL2;
fixcpacr_accesslogic to catch EL2 accesses to CPACR being trapped to EL3;
use new CP_ACCESS_TRAP_EL[23] rather than setting exception.target_el directly]
Quoted 1 line
Signed-off-by Peter Maydell <[email protected]>
Quoted 110 lines
--- target-arm/cpu.h | 5 +++++ target-arm/helper.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-)target-arm/cpu.h +5
-0@@ -197,6 +197,7 @@ typedef struct CPUARMState {uint64_t sctlr_el[4 ]; };uint64_t cpacr_el1;/* Architectural feature access control register */ +uint64_t cptr_el[4 ];/* ARMv8 feature trap registers */ uint32_t c1_xscaleauxcr;/* XScale auxiliary control register. */ uint64_t sder;/* Secure debug enable register. */ uint32_t nsacr;/* Non-secure access control register. */ @@ -568,6 +569,10 @@ void pmccntr_sync(CPUARMState *env);#define SCTLR_AFE (1U << 29)#define SCTLR_TE (1U << 30) +#define CPTR_TCPAC (1U << 31) +#define CPTR_TTA (1U << 20) +#define CPTR_TFP (1U << 10) +#define CPSR_M (0x1fU)#define CPSR_T (1U << 5)#define CPSR_F (1U << 6)target-arm/helper.c +39
-1@@ -592,6 +592,33 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri, env->cp15.cpacr_el1 = value; } +static CPAccessResult cpacr_access (CPUARMState *env,const ARMCPRegInfo *ri) +{ +if (arm_feature (env,ARM_FEATURE_V8 )) { +/* Check if CPACR accesses are to be trapped to EL2 */ +if (arm_current_el (env) ==1 && + (env->cp15.cptr_el[2 ] &CPTR_TCPAC ) && !arm_is_secure (env)) { +return CP_ACCESS_TRAP_EL2 ; +/* Check if CPACR accesses are to be trapped to EL3 */ + }else if (arm_current_el (env) <3 && + (env->cp15.cptr_el[3 ] &CPTR_TCPAC )) { +return CP_ACCESS_TRAP_EL3 ; + } + } + +return CP_ACCESS_OK ; +} + +static CPAccessResult cptr_access (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* Check if CPTR accesses are set to trap to EL3 */ +if (arm_current_el (env) ==2 && (env->cp15.cptr_el[3 ] &CPTR_TCPAC )) { +return CP_ACCESS_TRAP_EL3 ; + } + +return CP_ACCESS_OK ; +} +static const ARMCPRegInfo v6_cp_reginfo[] = {/* prefetch by MVA in v6, NOP in v7 */ { .name ="MVA_prefetch" ,@@ -614,7 +641,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { { .name = "WFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 1, .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, }, { .name = "CPACR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, - .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 2, + .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 2, .accessfn = cpacr_access, .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.cpacr_el1), .resetvalue = 0, .writefn = cpacr_write }, REGINFO_SENTINEL@@ -2481,6 +2508,9 @@ static const ARMCPRegInfo v8_el3_no_el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 0, .access = PL2_RW, .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore }, + { .name = "CPTR_EL2", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2, + .access = PL2_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, REGINFO_SENTINEL };@@ -2548,6 +2578,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 6, .crn = 4, .crm = 1, .opc2 = 0, .access = PL3_RW, .type = ARM_CP_ALIAS, .fieldoffset = offsetof(CPUARMState, sp_el[2]) }, + { .name = "CPTR_EL2", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2, + .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]) }, REGINFO_SENTINEL };@@ -2609,6 +2643,10 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .access = PL3_RW, .writefn = vbar_write, .fieldoffset = offsetof(CPUARMState, cp15.vbar_el[3]), .resetvalue = 0 }, + { .name = "CPTR_EL3", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 1, .opc2 = 2, + .access = PL3_RW, .accessfn = cptr_access, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[3]) },REGINFO_SENTINEL };Signature · 1 line
1.9.1
PATCH 10/14 target-arm: Make singlestate TB flags common between AArch32/64
In reply to Peter MaydellCurrently we keep the TB flags PSTATE_SS and SS_ACTIVE in different bit positions for AArch64 and AArch32. Replace these separate definitions with a single common flag in the upper part of the flags word.
--- target-arm/cpu.h | 69 ++++++++++++++++++---------------------------- target-arm/translate-a64.c | 4 +-- 2 files changed, 29 insertions(+), 44 deletions(-)
target-arm/cpu.h +27 -42
@@ -1737,6 +1737,10 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_AARCH64_STATE_MASK (1U << ARM_TBFLAG_AARCH64_STATE_SHIFT)#define ARM_TBFLAG_MMUIDX_SHIFT 28#define ARM_TBFLAG_MMUIDX_MASK (0x7 << ARM_TBFLAG_MMUIDX_SHIFT) +#define ARM_TBFLAG_SS_ACTIVE_SHIFT 27 +#define ARM_TBFLAG_SS_ACTIVE_MASK (1 << ARM_TBFLAG_SS_ACTIVE_SHIFT) +#define ARM_TBFLAG_PSTATE_SS_SHIFT 26 +#define ARM_TBFLAG_PSTATE_SS_MASK (1 << ARM_TBFLAG_PSTATE_SS_SHIFT)/* Bit usage when in AArch32 state: */ #define ARM_TBFLAG_THUMB_SHIFT 0
@@ -1753,10 +1757,6 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_BSWAP_CODE_MASK (1 << ARM_TBFLAG_BSWAP_CODE_SHIFT)#define ARM_TBFLAG_CPACR_FPEN_SHIFT 17#define ARM_TBFLAG_CPACR_FPEN_MASK (1 << ARM_TBFLAG_CPACR_FPEN_SHIFT) -#define ARM_TBFLAG_SS_ACTIVE_SHIFT 18 -#define ARM_TBFLAG_SS_ACTIVE_MASK (1 << ARM_TBFLAG_SS_ACTIVE_SHIFT) -#define ARM_TBFLAG_PSTATE_SS_SHIFT 19 -#define ARM_TBFLAG_PSTATE_SS_MASK (1 << ARM_TBFLAG_PSTATE_SS_SHIFT)/* We store the bottom two bits of the CPAR as TB flags and handle * checks on the other bits at runtime */
@@ -1772,16 +1772,16 @@ static inline bool arm_singlestep_active(CPUARMState *env)/* Bit usage when in AArch64 state */ #define ARM_TBFLAG_AA64_FPEN_SHIFT 2#define ARM_TBFLAG_AA64_FPEN_MASK (1 << ARM_TBFLAG_AA64_FPEN_SHIFT) -#define ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT 3 -#define ARM_TBFLAG_AA64_SS_ACTIVE_MASK (1 << ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT) -#define ARM_TBFLAG_AA64_PSTATE_SS_SHIFT 4 -#define ARM_TBFLAG_AA64_PSTATE_SS_MASK (1 << ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)/* some convenience accessor macros */ #define ARM_TBFLAG_AARCH64_STATE (F ) \ (((F) & ARM_TBFLAG_AARCH64_STATE_MASK) >> ARM_TBFLAG_AARCH64_STATE_SHIFT)#define ARM_TBFLAG_MMUIDX (F ) \ (((F) & ARM_TBFLAG_MMUIDX_MASK) >> ARM_TBFLAG_MMUIDX_SHIFT) +#define ARM_TBFLAG_SS_ACTIVE (F ) \ + (((F) & ARM_TBFLAG_SS_ACTIVE_MASK) >> ARM_TBFLAG_SS_ACTIVE_SHIFT) +#define ARM_TBFLAG_PSTATE_SS (F ) \ + (((F) & ARM_TBFLAG_PSTATE_SS_MASK) >> ARM_TBFLAG_PSTATE_SS_SHIFT)#define ARM_TBFLAG_THUMB (F ) \ (((F) & ARM_TBFLAG_THUMB_MASK) >> ARM_TBFLAG_THUMB_SHIFT)#define ARM_TBFLAG_VECLEN (F ) \
@@ -1796,18 +1796,10 @@ static inline bool arm_singlestep_active(CPUARMState *env) (((F) & ARM_TBFLAG_BSWAP_CODE_MASK) >> ARM_TBFLAG_BSWAP_CODE_SHIFT)#define ARM_TBFLAG_CPACR_FPEN (F ) \ (((F) & ARM_TBFLAG_CPACR_FPEN_MASK) >> ARM_TBFLAG_CPACR_FPEN_SHIFT) -#define ARM_TBFLAG_SS_ACTIVE (F ) \ - (((F) & ARM_TBFLAG_SS_ACTIVE_MASK) >> ARM_TBFLAG_SS_ACTIVE_SHIFT) -#define ARM_TBFLAG_PSTATE_SS (F ) \ - (((F) & ARM_TBFLAG_PSTATE_SS_MASK) >> ARM_TBFLAG_PSTATE_SS_SHIFT)#define ARM_TBFLAG_XSCALE_CPAR (F ) \ (((F) & ARM_TBFLAG_XSCALE_CPAR_MASK) >> ARM_TBFLAG_XSCALE_CPAR_SHIFT)#define ARM_TBFLAG_AA64_FPEN (F ) \ (((F) & ARM_TBFLAG_AA64_FPEN_MASK) >> ARM_TBFLAG_AA64_FPEN_SHIFT) -#define ARM_TBFLAG_AA64_SS_ACTIVE (F ) \ - (((F) & ARM_TBFLAG_AA64_SS_ACTIVE_MASK) >> ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT) -#define ARM_TBFLAG_AA64_PSTATE_SS (F ) \ - (((F) & ARM_TBFLAG_AA64_PSTATE_SS_MASK) >> ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)#define ARM_TBFLAG_NS (F ) \ (((F) & ARM_TBFLAG_NS_MASK) >> ARM_TBFLAG_NS_SHIFT)
@@ -1829,19 +1821,6 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,if (fpen ==3 || (fpen ==1 &&arm_current_el (env) !=0 )) { *flags |=ARM_TBFLAG_AA64_FPEN_MASK ; } -/* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine -* states defined in the ARM ARM for software singlestep: -* SS_ACTIVE PSTATE.SS State -* 0 x Inactive (the TB flag for SS is always 0) -* 1 0 Active-pending -* 1 1 Active-not-pending -*/ -if (arm_singlestep_active (env)) { - *flags |=ARM_TBFLAG_AA64_SS_ACTIVE_MASK ; -if (env->pstate &PSTATE_SS ) { - *flags |=ARM_TBFLAG_AA64_PSTATE_SS_MASK ; - } - } }else { *pc = env->regs[15 ]; *flags = (env->thumb <<ARM_TBFLAG_THUMB_SHIFT )
@@ -1859,24 +1838,30 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,if (fpen ==3 || (fpen ==1 &&arm_current_el (env) !=0 )) { *flags |=ARM_TBFLAG_CPACR_FPEN_MASK ; } -/* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine -* states defined in the ARM ARM for software singlestep: -* SS_ACTIVE PSTATE.SS State -* 0 x Inactive (the TB flag for SS is always 0) -* 1 0 Active-pending -* 1 1 Active-not-pending -*/ -if (arm_singlestep_active (env)) { - *flags |=ARM_TBFLAG_SS_ACTIVE_MASK ; -if (env->uncached_cpsr &PSTATE_SS ) { - *flags |=ARM_TBFLAG_PSTATE_SS_MASK ; - } - } *flags |= (extract32 (env->cp15.c15_cpar,0 ,2 ) <<ARM_TBFLAG_XSCALE_CPAR_SHIFT ); } *flags |= (cpu_mmu_index (env) <<ARM_TBFLAG_MMUIDX_SHIFT ); +/* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine +* states defined in the ARM ARM for software singlestep: +* SS_ACTIVE PSTATE.SS State +* 0 x Inactive (the TB flag for SS is always 0) +* 1 0 Active-pending +* 1 1 Active-not-pending +*/ +if (arm_singlestep_active (env)) { + *flags |=ARM_TBFLAG_SS_ACTIVE_MASK ; +if (is_a64 (env)) { +if (env->pstate &PSTATE_SS ) { + *flags |=ARM_TBFLAG_PSTATE_SS_MASK ; + } + }else { +if (env->uncached_cpsr &PSTATE_SS ) { + *flags |=ARM_TBFLAG_PSTATE_SS_MASK ; + } + } + } *cs_base =0 ; }
target-arm/translate-a64.c +2 -2
@@ -10975,8 +10975,8 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,* emit code to generate a software step exception * end the TB */ - dc->ss_active =ARM_TBFLAG_AA64_SS_ACTIVE (tb->flags); - dc->pstate_ss =ARM_TBFLAG_AA64_PSTATE_SS (tb->flags); + dc->ss_active =ARM_TBFLAG_SS_ACTIVE (tb->flags); + dc->pstate_ss =ARM_TBFLAG_PSTATE_SS (tb->flags); dc->is_ldex = false; dc->ss_same_el = (arm_debug_target_el (env) == dc->current_el);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 10/14] target-arm: Make singlestate TB flags common between AArch32/64
Quoted 6 lines · Peter Maydell
Currently we keep the TB flags
PSTATE_SSandSS_ACTIVEin different bit positions for AArch64 and AArch32. Replace these separate definitions with a single common flag in the upper part of the flags word.Signed-off-by Peter Maydell <[email protected]>
Quoted 153 lines
--- target-arm/cpu.h | 69 ++++++++++++++++++---------------------------- target-arm/translate-a64.c | 4 +-- 2 files changed, 29 insertions(+), 44 deletions(-)target-arm/cpu.h +27
-42@@ -1737,6 +1737,10 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_AARCH64_STATE_MASK (1U << ARM_TBFLAG_AARCH64_STATE_SHIFT)#define ARM_TBFLAG_MMUIDX_SHIFT 28#define ARM_TBFLAG_MMUIDX_MASK (0x7 << ARM_TBFLAG_MMUIDX_SHIFT) +#define ARM_TBFLAG_SS_ACTIVE_SHIFT 27 +#define ARM_TBFLAG_SS_ACTIVE_MASK (1 << ARM_TBFLAG_SS_ACTIVE_SHIFT) +#define ARM_TBFLAG_PSTATE_SS_SHIFT 26 +#define ARM_TBFLAG_PSTATE_SS_MASK (1 << ARM_TBFLAG_PSTATE_SS_SHIFT)/* Bit usage when in AArch32 state: */ #define ARM_TBFLAG_THUMB_SHIFT 0@@ -1753,10 +1757,6 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_BSWAP_CODE_MASK (1 << ARM_TBFLAG_BSWAP_CODE_SHIFT)#define ARM_TBFLAG_CPACR_FPEN_SHIFT 17#define ARM_TBFLAG_CPACR_FPEN_MASK (1 << ARM_TBFLAG_CPACR_FPEN_SHIFT) -#define ARM_TBFLAG_SS_ACTIVE_SHIFT 18 -#define ARM_TBFLAG_SS_ACTIVE_MASK (1 << ARM_TBFLAG_SS_ACTIVE_SHIFT) -#define ARM_TBFLAG_PSTATE_SS_SHIFT 19 -#define ARM_TBFLAG_PSTATE_SS_MASK (1 << ARM_TBFLAG_PSTATE_SS_SHIFT)/* We store the bottom two bits of the CPAR as TB flags and handle * checks on the other bits at runtime */ @@ -1772,16 +1772,16 @@ static inline bool arm_singlestep_active(CPUARMState *env)/* Bit usage when in AArch64 state */ #define ARM_TBFLAG_AA64_FPEN_SHIFT 2#define ARM_TBFLAG_AA64_FPEN_MASK (1 << ARM_TBFLAG_AA64_FPEN_SHIFT) -#define ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT 3 -#define ARM_TBFLAG_AA64_SS_ACTIVE_MASK (1 << ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT) -#define ARM_TBFLAG_AA64_PSTATE_SS_SHIFT 4 -#define ARM_TBFLAG_AA64_PSTATE_SS_MASK (1 << ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)/* some convenience accessor macros */ #define ARM_TBFLAG_AARCH64_STATE (F ) \ (((F) & ARM_TBFLAG_AARCH64_STATE_MASK) >> ARM_TBFLAG_AARCH64_STATE_SHIFT)#define ARM_TBFLAG_MMUIDX (F ) \ (((F) & ARM_TBFLAG_MMUIDX_MASK) >> ARM_TBFLAG_MMUIDX_SHIFT) +#define ARM_TBFLAG_SS_ACTIVE (F ) \ + (((F) & ARM_TBFLAG_SS_ACTIVE_MASK) >> ARM_TBFLAG_SS_ACTIVE_SHIFT) +#define ARM_TBFLAG_PSTATE_SS (F ) \ + (((F) & ARM_TBFLAG_PSTATE_SS_MASK) >> ARM_TBFLAG_PSTATE_SS_SHIFT)#define ARM_TBFLAG_THUMB (F ) \ (((F) & ARM_TBFLAG_THUMB_MASK) >> ARM_TBFLAG_THUMB_SHIFT)#define ARM_TBFLAG_VECLEN (F ) \@@ -1796,18 +1796,10 @@ static inline bool arm_singlestep_active(CPUARMState *env) (((F) & ARM_TBFLAG_BSWAP_CODE_MASK) >> ARM_TBFLAG_BSWAP_CODE_SHIFT)#define ARM_TBFLAG_CPACR_FPEN (F ) \ (((F) & ARM_TBFLAG_CPACR_FPEN_MASK) >> ARM_TBFLAG_CPACR_FPEN_SHIFT) -#define ARM_TBFLAG_SS_ACTIVE (F ) \ - (((F) & ARM_TBFLAG_SS_ACTIVE_MASK) >> ARM_TBFLAG_SS_ACTIVE_SHIFT) -#define ARM_TBFLAG_PSTATE_SS (F ) \ - (((F) & ARM_TBFLAG_PSTATE_SS_MASK) >> ARM_TBFLAG_PSTATE_SS_SHIFT)#define ARM_TBFLAG_XSCALE_CPAR (F ) \ (((F) & ARM_TBFLAG_XSCALE_CPAR_MASK) >> ARM_TBFLAG_XSCALE_CPAR_SHIFT)#define ARM_TBFLAG_AA64_FPEN (F ) \ (((F) & ARM_TBFLAG_AA64_FPEN_MASK) >> ARM_TBFLAG_AA64_FPEN_SHIFT) -#define ARM_TBFLAG_AA64_SS_ACTIVE (F ) \ - (((F) & ARM_TBFLAG_AA64_SS_ACTIVE_MASK) >> ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT) -#define ARM_TBFLAG_AA64_PSTATE_SS (F ) \ - (((F) & ARM_TBFLAG_AA64_PSTATE_SS_MASK) >> ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)#define ARM_TBFLAG_NS (F ) \ (((F) & ARM_TBFLAG_NS_MASK) >> ARM_TBFLAG_NS_SHIFT)@@ -1829,19 +1821,6 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,if (fpen ==3 || (fpen ==1 &&arm_current_el (env) !=0 )) { *flags |=ARM_TBFLAG_AA64_FPEN_MASK ; } -/* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine -* states defined in the ARM ARM for software singlestep: -* SS_ACTIVE PSTATE.SS State -* 0 x Inactive (the TB flag for SS is always 0) -* 1 0 Active-pending -* 1 1 Active-not-pending -*/ -if (arm_singlestep_active (env)) { - *flags |=ARM_TBFLAG_AA64_SS_ACTIVE_MASK ; -if (env->pstate &PSTATE_SS ) { - *flags |=ARM_TBFLAG_AA64_PSTATE_SS_MASK ; - } - } }else { *pc = env->regs[15 ]; *flags = (env->thumb <<ARM_TBFLAG_THUMB_SHIFT )@@ -1859,24 +1838,30 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,if (fpen ==3 || (fpen ==1 &&arm_current_el (env) !=0 )) { *flags |=ARM_TBFLAG_CPACR_FPEN_MASK ; } -/* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine -* states defined in the ARM ARM for software singlestep: -* SS_ACTIVE PSTATE.SS State -* 0 x Inactive (the TB flag for SS is always 0) -* 1 0 Active-pending -* 1 1 Active-not-pending -*/ -if (arm_singlestep_active (env)) { - *flags |=ARM_TBFLAG_SS_ACTIVE_MASK ; -if (env->uncached_cpsr &PSTATE_SS ) { - *flags |=ARM_TBFLAG_PSTATE_SS_MASK ; - } - } *flags |= (extract32 (env->cp15.c15_cpar,0 ,2 ) <<ARM_TBFLAG_XSCALE_CPAR_SHIFT ); } *flags |= (cpu_mmu_index (env) <<ARM_TBFLAG_MMUIDX_SHIFT ); +/* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine +* states defined in the ARM ARM for software singlestep: +* SS_ACTIVE PSTATE.SS State +* 0 x Inactive (the TB flag for SS is always 0) +* 1 0 Active-pending +* 1 1 Active-not-pending +*/ +if (arm_singlestep_active (env)) { + *flags |=ARM_TBFLAG_SS_ACTIVE_MASK ; +if (is_a64 (env)) { +if (env->pstate &PSTATE_SS ) { + *flags |=ARM_TBFLAG_PSTATE_SS_MASK ; + } + }else { +if (env->uncached_cpsr &PSTATE_SS ) { + *flags |=ARM_TBFLAG_PSTATE_SS_MASK ; + } + } + } *cs_base =0 ; }target-arm/translate-a64.c +2
-2@@ -10975,8 +10975,8 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,* emit code to generate a software step exception * end the TB */ - dc->ss_active =ARM_TBFLAG_AA64_SS_ACTIVE (tb->flags); - dc->pstate_ss =ARM_TBFLAG_AA64_PSTATE_SS (tb->flags); + dc->ss_active =ARM_TBFLAG_SS_ACTIVE (tb->flags); + dc->pstate_ss =ARM_TBFLAG_PSTATE_SS (tb->flags); dc->is_ldex = false; dc->ss_same_el = (arm_debug_target_el (env) == dc->current_el);Signature · 1 line
1.9.1
PATCH 11/14 target-arm: Extend FP checks to use an EL
In reply to Peter MaydellFrom: Greg Bellows <[email protected]>
Extend the ARM disassemble context to take a target exception EL instead of a boolean enable. This change reverses the polarity of the check making a value of 0 indicate floating point enabled (no exception).
[PMM: Use a common TB flag field for AArch32 and AArch64;
CPTR_EL2 exists in v7; CPTR_EL2 should trap for EL2 accesses; CPTR_EL2 should not trap for secure accesses; CPTR_EL3 should trap for EL3 accesses; CPACR traps for secure accesses should trap to EL3 if EL3 is AArch32]
--- target-arm/cpu.h | 92 +++++++++++++++++++++++++++++++++++----------- target-arm/translate-a64.c | 8 ++-- target-arm/translate.c | 17 ++++----- target-arm/translate.h | 2 +- 4 files changed, 82 insertions(+), 37 deletions(-)
target-arm/cpu.h +70 -22
@@ -1741,6 +1741,9 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_SS_ACTIVE_MASK (1 << ARM_TBFLAG_SS_ACTIVE_SHIFT)#define ARM_TBFLAG_PSTATE_SS_SHIFT 26#define ARM_TBFLAG_PSTATE_SS_MASK (1 << ARM_TBFLAG_PSTATE_SS_SHIFT) +/* Target EL if we take a floating-point-disabled exception */ +#define ARM_TBFLAG_FPEXC_EL_SHIFT 24 +#define ARM_TBFLAG_FPEXC_EL_MASK (0x3 << ARM_TBFLAG_FPEXC_EL_SHIFT)/* Bit usage when in AArch32 state: */ #define ARM_TBFLAG_THUMB_SHIFT 0
@@ -1755,8 +1758,6 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_CONDEXEC_MASK (0xff << ARM_TBFLAG_CONDEXEC_SHIFT)#define ARM_TBFLAG_BSWAP_CODE_SHIFT 16#define ARM_TBFLAG_BSWAP_CODE_MASK (1 << ARM_TBFLAG_BSWAP_CODE_SHIFT) -#define ARM_TBFLAG_CPACR_FPEN_SHIFT 17 -#define ARM_TBFLAG_CPACR_FPEN_MASK (1 << ARM_TBFLAG_CPACR_FPEN_SHIFT)/* We store the bottom two bits of the CPAR as TB flags and handle * checks on the other bits at runtime */
@@ -1769,9 +1770,7 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_NS_SHIFT 22#define ARM_TBFLAG_NS_MASK (1 << ARM_TBFLAG_NS_SHIFT) -/* Bit usage when in AArch64 state */ -#define ARM_TBFLAG_AA64_FPEN_SHIFT 2 -#define ARM_TBFLAG_AA64_FPEN_MASK (1 << ARM_TBFLAG_AA64_FPEN_SHIFT) +/* Bit usage when in AArch64 state: currently we have no A64 specific bits */ /* some convenience accessor macros */ #define ARM_TBFLAG_AARCH64_STATE (F ) \
@@ -1782,6 +1781,8 @@ static inline bool arm_singlestep_active(CPUARMState *env) (((F) & ARM_TBFLAG_SS_ACTIVE_MASK) >> ARM_TBFLAG_SS_ACTIVE_SHIFT)#define ARM_TBFLAG_PSTATE_SS (F ) \ (((F) & ARM_TBFLAG_PSTATE_SS_MASK) >> ARM_TBFLAG_PSTATE_SS_SHIFT) +#define ARM_TBFLAG_FPEXC_EL (F ) \ + (((F) & ARM_TBFLAG_FPEXC_EL_MASK) >> ARM_TBFLAG_FPEXC_EL_SHIFT)#define ARM_TBFLAG_THUMB (F ) \ (((F) & ARM_TBFLAG_THUMB_MASK) >> ARM_TBFLAG_THUMB_SHIFT)#define ARM_TBFLAG_VECLEN (F ) \
@@ -1794,33 +1795,82 @@ static inline bool arm_singlestep_active(CPUARMState *env) (((F) & ARM_TBFLAG_CONDEXEC_MASK) >> ARM_TBFLAG_CONDEXEC_SHIFT)#define ARM_TBFLAG_BSWAP_CODE (F ) \ (((F) & ARM_TBFLAG_BSWAP_CODE_MASK) >> ARM_TBFLAG_BSWAP_CODE_SHIFT) -#define ARM_TBFLAG_CPACR_FPEN (F ) \ - (((F) & ARM_TBFLAG_CPACR_FPEN_MASK) >> ARM_TBFLAG_CPACR_FPEN_SHIFT)#define ARM_TBFLAG_XSCALE_CPAR (F ) \ (((F) & ARM_TBFLAG_XSCALE_CPAR_MASK) >> ARM_TBFLAG_XSCALE_CPAR_SHIFT) -#define ARM_TBFLAG_AA64_FPEN (F ) \ - (((F) & ARM_TBFLAG_AA64_FPEN_MASK) >> ARM_TBFLAG_AA64_FPEN_SHIFT)#define ARM_TBFLAG_NS (F ) \ (((F) & ARM_TBFLAG_NS_MASK) >> ARM_TBFLAG_NS_SHIFT) -static inline void cpu_get_tb_cpu_state (CPUARMState *env,target_ulong *pc, -target_ulong *cs_base,int *flags) +/* Return the exception level to which FP-disabled exceptions should +* be taken, or 0 if FP is enabled. +*/ +static inline int fp_exception_el (CPUARMState *env) {int fpen; +int cur_el =arm_current_el (env); -if (arm_feature (env,ARM_FEATURE_V6 )) { - fpen =extract32 (env->cp15.cpacr_el1,20 ,2 ); - }else { -/* CPACR doesn't exist before v6, so VFP is always accessible */ - fpen =3 ; +/* CPACR and the CPTR registers don't exist before v6, so FP is +* always accessible +*/ +if (!arm_feature (env,ARM_FEATURE_V6 )) { +return 0 ; + } + +/* The CPACR controls traps to EL1, or PL1 if we're 32 bit: +* 0, 2 : trap EL0 and EL1/PL1 accesses +* 1 : trap only EL0 accesses +* 3 : trap no accesses +*/ + fpen =extract32 (env->cp15.cpacr_el1,20 ,2 ); +switch (fpen) { +case 0 : +case 2 : +if (cur_el ==0 || cur_el ==1 ) { +/* Trap to PL1, which might be EL1 or EL3 */ +if (arm_is_secure (env) && !arm_el_is_aa64 (env,3 )) { +return 3 ; + } +return 1 ; + } +if (cur_el ==3 && !is_a64 (env)) { +/* Secure PL1 running at EL3 */ +return 3 ; + } +break ; +case 1 : +if (cur_el ==0 ) { +return 1 ; + } +break ; +case 3 : +break ; + } + +/* For the CPTR registers we don't need to guard with an ARM_FEATURE +* check because zero bits in the registers mean "don't trap". +*/ + +/* CPTR_EL2 : present in v7VE or v8 */ +if (cur_el <=2 &&extract32 (env->cp15.cptr_el[2 ],10 ,1 ) + &&arm_is_secure_below_el3 (env)) { +/* Trap FP ops at EL2, NS-EL1 or NS-EL0 to EL2 */ +return 2 ; + } + +/* CPTR_EL3 : present in v8 */ +if (extract32 (env->cp15.cptr_el[3 ],10 ,1 )) { +/* Trap all FP ops to EL3 */ +return 3 ; } +return 0 ; +} + +static inline void cpu_get_tb_cpu_state (CPUARMState *env,target_ulong *pc, +target_ulong *cs_base,int *flags) +{if (is_a64 (env)) { *pc = env->pc; *flags =ARM_TBFLAG_AARCH64_STATE_MASK ; -if (fpen ==3 || (fpen ==1 &&arm_current_el (env) !=0 )) { - *flags |=ARM_TBFLAG_AA64_FPEN_MASK ; - } }else { *pc = env->regs[15 ]; *flags = (env->thumb <<ARM_TBFLAG_THUMB_SHIFT )
@@ -1835,9 +1885,6 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, || arm_el_is_aa64(env, 1)) { *flags |=ARM_TBFLAG_VFPEN_MASK ; } -if (fpen ==3 || (fpen ==1 &&arm_current_el (env) !=0 )) { - *flags |=ARM_TBFLAG_CPACR_FPEN_MASK ; - } *flags |= (extract32 (env->cp15.c15_cpar,0 ,2 ) <<ARM_TBFLAG_XSCALE_CPAR_SHIFT ); }
@@ -1862,6 +1909,7 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, } } } + *flags |=fp_exception_el (env) <<ARM_TBFLAG_FPEXC_EL_SHIFT ; *cs_base =0 ; }
target-arm/translate-a64.c +4 -4
@@ -412,7 +412,7 @@ static TCGv_i64 read_cpu_reg_sp(DisasContext *s, int reg, int sf)static inline void assert_fp_access_checked (DisasContext *s) {#ifdef CONFIG_DEBUG_TCG -if (unlikely (!s->fp_access_checked || !s->cpacr_fpen)) { +if (unlikely (!s->fp_access_checked || s->fp_excp_el)) {fprintf (stderr,"target-arm: FP access check missing for " "instruction 0x%08x\n" , s->insn);abort ();
@@ -972,12 +972,12 @@ static inline bool fp_access_check(DisasContext *s)assert (!s->fp_access_checked); s->fp_access_checked = true; -if (s->cpacr_fpen) { +if (!s->fp_excp_el) {return true; }gen_exception_insn (s,4 ,EXCP_UDEF ,syn_fp_access_trap (1 ,0xe , false), -default_exception_el (s)); + s->fp_excp_el);return false; }
@@ -10954,7 +10954,7 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,#if !defined(CONFIG_USER_ONLY ) dc->user = (dc->current_el ==0 );#endif - dc->cpacr_fpen =ARM_TBFLAG_AA64_FPEN (tb->flags); + dc->fp_excp_el =ARM_TBFLAG_FPEXC_EL (tb->flags); dc->vec_len =0 ; dc->vec_stride =0 ; dc->cp_regs = cpu->cp_regs;
target-arm/translate.c +7 -10
@@ -3044,10 +3044,9 @@ static int disas_vfp_insn(DisasContext *s, uint32_t insn)* for invalid encodings; we will generate incorrect syndrome information * for attempts to execute invalid vfp/neon encodings with FP disabled. */ -if (!s->cpacr_fpen) { +if (s->fp_excp_el) {gen_exception_insn (s,4 ,EXCP_UDEF , -syn_fp_access_trap (1 ,0xe , s->thumb), -default_exception_el (s)); +syn_fp_access_trap (1 ,0xe , s->thumb), s->fp_excp_el);return 0 ; }
@@ -4363,10 +4362,9 @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn)* for invalid encodings; we will generate incorrect syndrome information * for attempts to execute invalid vfp/neon encodings with FP disabled. */ -if (!s->cpacr_fpen) { +if (s->fp_excp_el) {gen_exception_insn (s,4 ,EXCP_UDEF , -syn_fp_access_trap (1 ,0xe , s->thumb), -default_exception_el (s)); +syn_fp_access_trap (1 ,0xe , s->thumb), s->fp_excp_el);return 0 ; }
@@ -5102,10 +5100,9 @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)* for invalid encodings; we will generate incorrect syndrome information * for attempts to execute invalid vfp/neon encodings with FP disabled. */ -if (!s->cpacr_fpen) { +if (s->fp_excp_el) {gen_exception_insn (s,4 ,EXCP_UDEF , -syn_fp_access_trap (1 ,0xe , s->thumb), -default_exception_el (s)); +syn_fp_access_trap (1 ,0xe , s->thumb), s->fp_excp_el);return 0 ; }
@@ -11082,7 +11079,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu, dc->user = (dc->current_el ==0 );#endif dc->ns =ARM_TBFLAG_NS (tb->flags); - dc->cpacr_fpen =ARM_TBFLAG_CPACR_FPEN (tb->flags); + dc->fp_excp_el =ARM_TBFLAG_FPEXC_EL (tb->flags); dc->vfp_enabled =ARM_TBFLAG_VFPEN (tb->flags); dc->vec_len =ARM_TBFLAG_VECLEN (tb->flags); dc->vec_stride =ARM_TBFLAG_VECSTRIDE (tb->flags);
target-arm/translate.h +1 -1
@@ -22,7 +22,7 @@ typedef struct DisasContext {#endif ARMMMUIdx mmu_idx;/* MMU index to use for normal loads/stores */ bool ns;/* Use non-secure CPREG bank on access */ -bool cpacr_fpen;/* FP enabled via CPACR.FPEN */ +int fp_excp_el;/* FP exception EL or 0 if enabled */ bool el3_is_aa64;/* Flag indicating whether EL3 is AArch64 or not */ bool vfp_enabled;/* FP enabled via FPSCR.EN */ int vec_len;
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 11/14] target-arm: Extend FP checks to use an EL
Quoted 125 lines · Peter Maydell
From: Greg Bellows <[email protected]>
Extend the ARM disassemble context to take a target exception EL instead of a boolean enable. This change reverses the polarity of the check making a value of 0 indicate floating point enabled (no exception).
Signed-off-by Greg Bellows <[email protected]>[PMM: Use a common TB flag field for AArch32 and AArch64;
CPTR_EL2exists in v7;CPTR_EL2should trap for EL2 accesses;CPTR_EL2should not trap for secure accesses;CPTR_EL3should trap for EL3 accesses; CPACR traps for secure accesses should trap to EL3 if EL3 is AArch32]Signed-off-by Peter Maydell <[email protected]>--- target-arm/cpu.h | 92 +++++++++++++++++++++++++++++++++++----------- target-arm/translate-a64.c | 8 ++-- target-arm/translate.c | 17 ++++----- target-arm/translate.h | 2 +- 4 files changed, 82 insertions(+), 37 deletions(-)target-arm/cpu.h +45
-16@@ -1741,6 +1741,9 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_SS_ACTIVE_MASK (1 << ARM_TBFLAG_SS_ACTIVE_SHIFT)#define ARM_TBFLAG_PSTATE_SS_SHIFT 26#define ARM_TBFLAG_PSTATE_SS_MASK (1 << ARM_TBFLAG_PSTATE_SS_SHIFT) +/* Target EL if we take a floating-point-disabled exception */ +#define ARM_TBFLAG_FPEXC_EL_SHIFT 24 +#define ARM_TBFLAG_FPEXC_EL_MASK (0x3 << ARM_TBFLAG_FPEXC_EL_SHIFT)/* Bit usage when in AArch32 state: */ #define ARM_TBFLAG_THUMB_SHIFT 0@@ -1755,8 +1758,6 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_CONDEXEC_MASK (0xff << ARM_TBFLAG_CONDEXEC_SHIFT)#define ARM_TBFLAG_BSWAP_CODE_SHIFT 16#define ARM_TBFLAG_BSWAP_CODE_MASK (1 << ARM_TBFLAG_BSWAP_CODE_SHIFT) -#define ARM_TBFLAG_CPACR_FPEN_SHIFT 17 -#define ARM_TBFLAG_CPACR_FPEN_MASK (1 << ARM_TBFLAG_CPACR_FPEN_SHIFT)/* We store the bottom two bits of the CPAR as TB flags and handle * checks on the other bits at runtime */ @@ -1769,9 +1770,7 @@ static inline bool arm_singlestep_active(CPUARMState *env)#define ARM_TBFLAG_NS_SHIFT 22#define ARM_TBFLAG_NS_MASK (1 << ARM_TBFLAG_NS_SHIFT) -/* Bit usage when in AArch64 state */ -#define ARM_TBFLAG_AA64_FPEN_SHIFT 2 -#define ARM_TBFLAG_AA64_FPEN_MASK (1 << ARM_TBFLAG_AA64_FPEN_SHIFT) +/* Bit usage when in AArch64 state: currently we have no A64 specific bits */ /* some convenience accessor macros */ #define ARM_TBFLAG_AARCH64_STATE (F ) \@@ -1782,6 +1781,8 @@ static inline bool arm_singlestep_active(CPUARMState *env) (((F) & ARM_TBFLAG_SS_ACTIVE_MASK) >> ARM_TBFLAG_SS_ACTIVE_SHIFT)#define ARM_TBFLAG_PSTATE_SS (F ) \ (((F) & ARM_TBFLAG_PSTATE_SS_MASK) >> ARM_TBFLAG_PSTATE_SS_SHIFT) +#define ARM_TBFLAG_FPEXC_EL (F ) \ + (((F) & ARM_TBFLAG_FPEXC_EL_MASK) >> ARM_TBFLAG_FPEXC_EL_SHIFT)#define ARM_TBFLAG_THUMB (F ) \ (((F) & ARM_TBFLAG_THUMB_MASK) >> ARM_TBFLAG_THUMB_SHIFT)#define ARM_TBFLAG_VECLEN (F ) \@@ -1794,33 +1795,82 @@ static inline bool arm_singlestep_active(CPUARMState *env) (((F) & ARM_TBFLAG_CONDEXEC_MASK) >> ARM_TBFLAG_CONDEXEC_SHIFT)#define ARM_TBFLAG_BSWAP_CODE (F ) \ (((F) & ARM_TBFLAG_BSWAP_CODE_MASK) >> ARM_TBFLAG_BSWAP_CODE_SHIFT) -#define ARM_TBFLAG_CPACR_FPEN (F ) \ - (((F) & ARM_TBFLAG_CPACR_FPEN_MASK) >> ARM_TBFLAG_CPACR_FPEN_SHIFT)#define ARM_TBFLAG_XSCALE_CPAR (F ) \ (((F) & ARM_TBFLAG_XSCALE_CPAR_MASK) >> ARM_TBFLAG_XSCALE_CPAR_SHIFT) -#define ARM_TBFLAG_AA64_FPEN (F ) \ - (((F) & ARM_TBFLAG_AA64_FPEN_MASK) >> ARM_TBFLAG_AA64_FPEN_SHIFT)#define ARM_TBFLAG_NS (F ) \ (((F) & ARM_TBFLAG_NS_MASK) >> ARM_TBFLAG_NS_SHIFT) -static inline void cpu_get_tb_cpu_state (CPUARMState *env,target_ulong *pc, -target_ulong *cs_base,int *flags) +/* Return the exception level to which FP-disabled exceptions should +* be taken, or 0 if FP is enabled. +*/ +static inline int fp_exception_el (CPUARMState *env) {int fpen; +int cur_el =arm_current_el (env); -if (arm_feature (env,ARM_FEATURE_V6 )) { - fpen =extract32 (env->cp15.cpacr_el1,20 ,2 ); - }else { -/* CPACR doesn't exist before v6, so VFP is always accessible */ - fpen =3 ; +/* CPACR and the CPTR registers don't exist before v6, so FP is +* always accessible +*/ +if (!arm_feature (env,ARM_FEATURE_V6 )) { +return 0 ; + } + +/* The CPACR controls traps to EL1, or PL1 if we're 32 bit: +* 0, 2 : trap EL0 and EL1/PL1 accesses +* 1 : trap only EL0 accesses +* 3 : trap no accesses +*/ + fpen =extract32 (env->cp15.cpacr_el1,20 ,2 ); +switch (fpen) { +case 0 : +case 2 : +if (cur_el ==0 || cur_el ==1 ) { +/* Trap to PL1, which might be EL1 or EL3 */ +if (arm_is_secure (env) && !arm_el_is_aa64 (env,3 )) { +return 3 ; + } +return 1 ; + } +if (cur_el ==3 && !is_a64 (env)) { +/* Secure PL1 running at EL3 */ +return 3 ; + } +break ; +case 1 : +if (cur_el ==0 ) { +return 1 ; + } +break ; +case 3 :
target-arm/cpu.h static inline bool arm_singlestep_active(CPUARMState *env) · line 1854
Quoted 10 lines
target-arm/cpu.h +10
-0+break ; + } + +/* For the CPTR registers we don't need to guard with an ARM_FEATURE +* check because zero bits in the registers mean "don't trap". +*/ + +/* CPTR_EL2 : present in v7VE or v8 */ +if (cur_el <=2 &&extract32 (env->cp15.cptr_el[2 ],10 ,1 ) + &&arm_is_secure_below_el3 (env)) {
I think this should be !arm_is_secure_below_el3(env)
Also the ARMv7 manual, the part describing CPACR cpn bits, indicates that HCTPR has prio over CPACR. I didn't find any thing like that for ARMv8... There might be a difference between v8/v7 here, do you know?
Cheers,
Edgar
Quoted 148 lines
target-arm/cpu.h +15
-6+/* Trap FP ops at EL2, NS-EL1 or NS-EL0 to EL2 */ +return 2 ; + } + +/* CPTR_EL3 : present in v8 */ +if (extract32 (env->cp15.cptr_el[3 ],10 ,1 )) { +/* Trap all FP ops to EL3 */ +return 3 ; } +return 0 ; +} + +static inline void cpu_get_tb_cpu_state (CPUARMState *env,target_ulong *pc, +target_ulong *cs_base,int *flags) +{if (is_a64 (env)) { *pc = env->pc; *flags =ARM_TBFLAG_AARCH64_STATE_MASK ; -if (fpen ==3 || (fpen ==1 &&arm_current_el (env) !=0 )) { - *flags |=ARM_TBFLAG_AA64_FPEN_MASK ; - } }else { *pc = env->regs[15 ]; *flags = (env->thumb <<ARM_TBFLAG_THUMB_SHIFT )@@ -1835,9 +1885,6 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, || arm_el_is_aa64(env, 1)) { *flags |=ARM_TBFLAG_VFPEN_MASK ; } -if (fpen ==3 || (fpen ==1 &&arm_current_el (env) !=0 )) { - *flags |=ARM_TBFLAG_CPACR_FPEN_MASK ; - } *flags |= (extract32 (env->cp15.c15_cpar,0 ,2 ) <<ARM_TBFLAG_XSCALE_CPAR_SHIFT ); }@@ -1862,6 +1909,7 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, } } } + *flags |=fp_exception_el (env) <<ARM_TBFLAG_FPEXC_EL_SHIFT ; *cs_base =0 ; }target-arm/translate-a64.c +4
-4@@ -412,7 +412,7 @@ static TCGv_i64 read_cpu_reg_sp(DisasContext *s, int reg, int sf)static inline void assert_fp_access_checked (DisasContext *s) {#ifdef CONFIG_DEBUG_TCG -if (unlikely (!s->fp_access_checked || !s->cpacr_fpen)) { +if (unlikely (!s->fp_access_checked || s->fp_excp_el)) {fprintf (stderr,"target-arm: FP access check missing for " "instruction 0x%08x\n" , s->insn);abort ();@@ -972,12 +972,12 @@ static inline bool fp_access_check(DisasContext *s)assert (!s->fp_access_checked); s->fp_access_checked = true; -if (s->cpacr_fpen) { +if (!s->fp_excp_el) {return true; }gen_exception_insn (s,4 ,EXCP_UDEF ,syn_fp_access_trap (1 ,0xe , false), -default_exception_el (s)); + s->fp_excp_el);return false; }@@ -10954,7 +10954,7 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,#if !defined(CONFIG_USER_ONLY ) dc->user = (dc->current_el ==0 );#endif - dc->cpacr_fpen =ARM_TBFLAG_AA64_FPEN (tb->flags); + dc->fp_excp_el =ARM_TBFLAG_FPEXC_EL (tb->flags); dc->vec_len =0 ; dc->vec_stride =0 ; dc->cp_regs = cpu->cp_regs;target-arm/translate.c +7
-10@@ -3044,10 +3044,9 @@ static int disas_vfp_insn(DisasContext *s, uint32_t insn)* for invalid encodings; we will generate incorrect syndrome information * for attempts to execute invalid vfp/neon encodings with FP disabled. */ -if (!s->cpacr_fpen) { +if (s->fp_excp_el) {gen_exception_insn (s,4 ,EXCP_UDEF , -syn_fp_access_trap (1 ,0xe , s->thumb), -default_exception_el (s)); +syn_fp_access_trap (1 ,0xe , s->thumb), s->fp_excp_el);return 0 ; }@@ -4363,10 +4362,9 @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn)* for invalid encodings; we will generate incorrect syndrome information * for attempts to execute invalid vfp/neon encodings with FP disabled. */ -if (!s->cpacr_fpen) { +if (s->fp_excp_el) {gen_exception_insn (s,4 ,EXCP_UDEF , -syn_fp_access_trap (1 ,0xe , s->thumb), -default_exception_el (s)); +syn_fp_access_trap (1 ,0xe , s->thumb), s->fp_excp_el);return 0 ; }@@ -5102,10 +5100,9 @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)* for invalid encodings; we will generate incorrect syndrome information * for attempts to execute invalid vfp/neon encodings with FP disabled. */ -if (!s->cpacr_fpen) { +if (s->fp_excp_el) {gen_exception_insn (s,4 ,EXCP_UDEF , -syn_fp_access_trap (1 ,0xe , s->thumb), -default_exception_el (s)); +syn_fp_access_trap (1 ,0xe , s->thumb), s->fp_excp_el);return 0 ; }@@ -11082,7 +11079,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu, dc->user = (dc->current_el ==0 );#endif dc->ns =ARM_TBFLAG_NS (tb->flags); - dc->cpacr_fpen =ARM_TBFLAG_CPACR_FPEN (tb->flags); + dc->fp_excp_el =ARM_TBFLAG_FPEXC_EL (tb->flags); dc->vfp_enabled =ARM_TBFLAG_VFPEN (tb->flags); dc->vec_len =ARM_TBFLAG_VECLEN (tb->flags); dc->vec_stride =ARM_TBFLAG_VECSTRIDE (tb->flags);target-arm/translate.h +1
-1@@ -22,7 +22,7 @@ typedef struct DisasContext {#endif ARMMMUIdx mmu_idx;/* MMU index to use for normal loads/stores */ bool ns;/* Use non-secure CPREG bank on access */ -bool cpacr_fpen;/* FP enabled via CPACR.FPEN */ +int fp_excp_el;/* FP exception EL or 0 if enabled */ bool el3_is_aa64;/* Flag indicating whether EL3 is AArch64 or not */ bool vfp_enabled;/* FP enabled via FPSCR.EN */ int vec_len;Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 11/14] target-arm: Extend FP checks to use an EL
Quoted 10 lines · Edgar E. Iglesias
target-arm/cpu.h static inline bool arm_singlestep_active(CPUARMState *env) · line 1854
Quoted 7 lines · Peter Maydell
target-arm/cpu.h +7
-0+/* For the CPTR registers we don't need to guard with an ARM_FEATURE +* check because zero bits in the registers mean "don't trap". +*/ + +/* CPTR_EL2 : present in v7VE or v8 */ +if (cur_el <=2 &&extract32 (env->cp15.cptr_el[2 ],10 ,1 ) + &&arm_is_secure_below_el3 (env)) {I think this should be !arm_is_secure_below_el3(env)
Yes.
Quoted 3 lines
Also the ARMv7 manual, the part describing CPACR cpn bits, indicates that HCTPR has prio over CPACR. I didn't find any thing like that for ARMv8... There might be a difference between v8/v7 here, do you know?
For v8, this is described in "G1.11.2 Exception priority order" I think:
exceptions taken to EL1 because of configurable access to insns are item 8, which has higher priority than HCPTR traps (item 10). This matches the code I have in this patch.
I believe that v7 is the same, and the v7 ARM ARM is just slightly confusingly worded. The HCPTR documentation says that setting TCPn to 1 traps "any otherwise-valid Non-secure access to CPn". The CheckAdvSIMDOrVFPEnabled() pseudocode also clearly checks CPACR first and HCPTR second.
-- PMM
Edgar E. Iglesias
Reviewed-byRe: [Qemu-devel] [PATCH 11/14] target-arm: Extend FP checks to use an EL
Quoted 23 lines · Peter Maydell
Quoted 10 lines · Edgar E. Iglesias
target-arm/cpu.h static inline bool arm_singlestep_active(CPUARMState *env) · line 1854
Quoted 7 lines · Peter Maydell
target-arm/cpu.h +7
-0+/* For the CPTR registers we don't need to guard with an ARM_FEATURE +* check because zero bits in the registers mean "don't trap". +*/ + +/* CPTR_EL2 : present in v7VE or v8 */ +if (cur_el <=2 &&extract32 (env->cp15.cptr_el[2 ],10 ,1 ) + &&arm_is_secure_below_el3 (env)) {I think this should be !arm_is_secure_below_el3(env)
Yes.
Quoted 3 lines
Also the ARMv7 manual, the part describing CPACR cpn bits, indicates that HCTPR has prio over CPACR. I didn't find any thing like that for ARMv8... There might be a difference between v8/v7 here, do you know?
For v8, this is described in "G1.11.2 Exception priority order" I think:
exceptions taken to EL1 because of configurable access to insns are item 8, which has higher priority than HCPTR traps (item 10). This matches the code I have in this patch.
Quoted 5 lines
I believe that v7 is the same, and the v7 ARM ARM is just slightly confusingly worded. The HCPTR documentation says that setting TCPn to 1 traps "any otherwise-valid Non-secure access to CPn". The
CheckAdvSIMDOrVFPEnabled()pseudocode also clearly checks CPACR first and HCPTR second.
Thanks for clarifying that. With the !arm_is_secure_below_el3(env) change:
Cheers,
Edgar
Re: [Qemu-devel] [PATCH 11/14] target-arm: Extend FP checks to use an EL
Quoted 4 lines · Edgar E. Iglesias
Thanks for clarifying that. With the !arm_is_secure_below_el3(env) change:
Reviewed-by Edgar E. Iglesias <[email protected]>
Thanks. Since there have only been a few trivial fixups I've applied the series to target-arm.next.
-- PMM
PATCH 12/14 target-arm: Move TB flags down to fill gap
In reply to Peter MaydellDeleting the now-unused ARM_TBFLAG_CPACR_FPEN left a gap in the bit usage; move the following ARM_TBFLAG_XSCALE_CPAR and ARM_TBFLAG_NS_SHIFT down 3 bits to fill the gap.
--- target-arm/cpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target-arm/cpu.h +2 -2
@@ -1761,13 +1761,13 @@ static inline bool arm_singlestep_active(CPUARMState *env)/* We store the bottom two bits of the CPAR as TB flags and handle * checks on the other bits at runtime */ -#define ARM_TBFLAG_XSCALE_CPAR_SHIFT 20 +#define ARM_TBFLAG_XSCALE_CPAR_SHIFT 17#define ARM_TBFLAG_XSCALE_CPAR_MASK (3 << ARM_TBFLAG_XSCALE_CPAR_SHIFT)/* Indicates whether cp register reads and writes by guest code should access * the secure or nonsecure bank of banked registers; note that this is not * the same thing as the current security state of the processor! */ -#define ARM_TBFLAG_NS_SHIFT 22 +#define ARM_TBFLAG_NS_SHIFT 19#define ARM_TBFLAG_NS_MASK (1 << ARM_TBFLAG_NS_SHIFT)/* Bit usage when in AArch64 state: currently we have no A64 specific bits */
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 12/14] target-arm: Move TB flags down to fill gap
Quoted 5 lines · Peter Maydell
Deleting the now-unused
ARM_TBFLAG_CPACR_FPENleft a gap in the bit usage; move the followingARM_TBFLAG_XSCALE_CPARandARM_TBFLAG_NS_SHIFTdown 3 bits to fill the gap.Signed-off-by Peter Maydell <[email protected]>
Quoted 27 lines
--- target-arm/cpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target-arm/cpu.h +2
-2@@ -1761,13 +1761,13 @@ static inline bool arm_singlestep_active(CPUARMState *env)/* We store the bottom two bits of the CPAR as TB flags and handle * checks on the other bits at runtime */ -#define ARM_TBFLAG_XSCALE_CPAR_SHIFT 20 +#define ARM_TBFLAG_XSCALE_CPAR_SHIFT 17#define ARM_TBFLAG_XSCALE_CPAR_MASK (3 << ARM_TBFLAG_XSCALE_CPAR_SHIFT)/* Indicates whether cp register reads and writes by guest code should access * the secure or nonsecure bank of banked registers; note that this is not * the same thing as the current security state of the processor! */ -#define ARM_TBFLAG_NS_SHIFT 22 +#define ARM_TBFLAG_NS_SHIFT 19#define ARM_TBFLAG_NS_MASK (1 << ARM_TBFLAG_NS_SHIFT)/* Bit usage when in AArch64 state: currently we have no A64 specific bits */ Signature · 1 line
1.9.1
PATCH 13/14 target-arm: Don't halt on WFI unless we don't have any work
In reply to Peter MaydellJust NOP the WFI instruction if we have work to do. This doesn't make much difference currently (though it does avoid jumping out to the top level loop and immediately restarting), but the distinction between "halt" and "don't halt" will become more important when the decision to halt requires us to trap to a higher exception level instead.
--- target-arm/op_helper.c | 7 +++++++ target-arm/translate-a64.c | 4 ++++ target-arm/translate.c | 4 ++++ 3 files changed, 15 insertions(+)
target-arm/op_helper.c +7 -0
@@ -252,6 +252,13 @@ void HELPER(wfi)(CPUARMState *env) {CPUState *cs =CPU (arm_env_get_cpu (env)); +if (cpu_has_work (cs)) { +/* Don't bother to go into our "low power state" if +* we would just wake up immediately. +*/ +return ; + } + cs->exception_index =EXCP_HLT ; cs->halted =1 ;cpu_loop_exit (cs);
target-arm/translate-a64.c +4 -0
@@ -11113,6 +11113,10 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,*/ gen_a64_set_pc_im (dc->pc);gen_helper_wfi (cpu_env); +/* The helper doesn't necessarily throw an exception, but we +* must go back to the main loop to check for interrupts anyway. +*/ +tcg_gen_exit_tb (0 );break ; } }
target-arm/translate.c +4 -0
@@ -11351,6 +11351,10 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,break ;case DISAS_WFI :gen_helper_wfi (cpu_env); +/* The helper doesn't necessarily throw an exception, but we +* must go back to the main loop to check for interrupts anyway. +*/ +tcg_gen_exit_tb (0 );break ;case DISAS_WFE :gen_helper_wfe (cpu_env);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 13/14] target-arm: Don't halt on WFI unless we don't have any work
Quoted 9 lines · Peter Maydell
Just NOP the WFI instruction if we have work to do. This doesn't make much difference currently (though it does avoid jumping out to the top level loop and immediately restarting), but the distinction between "halt" and "don't halt" will become more important when the decision to halt requires us to trap to a higher exception level instead.
Suggested-by Edgar E. Iglesias <[email protected]>Signed-off-by Peter Maydell <[email protected]>
Quoted 57 lines
--- target-arm/op_helper.c | 7 +++++++ target-arm/translate-a64.c | 4 ++++ target-arm/translate.c | 4 ++++ 3 files changed, 15 insertions(+)target-arm/op_helper.c +7
-0@@ -252,6 +252,13 @@ void HELPER(wfi)(CPUARMState *env) {CPUState *cs =CPU (arm_env_get_cpu (env)); +if (cpu_has_work (cs)) { +/* Don't bother to go into our "low power state" if +* we would just wake up immediately. +*/ +return ; + } + cs->exception_index =EXCP_HLT ; cs->halted =1 ;cpu_loop_exit (cs);target-arm/translate-a64.c +4
-0@@ -11113,6 +11113,10 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,*/ gen_a64_set_pc_im (dc->pc);gen_helper_wfi (cpu_env); +/* The helper doesn't necessarily throw an exception, but we +* must go back to the main loop to check for interrupts anyway. +*/ +tcg_gen_exit_tb (0 );break ; } }target-arm/translate.c +4
-0@@ -11351,6 +11351,10 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,break ;case DISAS_WFI :gen_helper_wfi (cpu_env); +/* The helper doesn't necessarily throw an exception, but we +* must go back to the main loop to check for interrupts anyway. +*/ +tcg_gen_exit_tb (0 );break ;case DISAS_WFE :gen_helper_wfe (cpu_env);Signature · 1 line
1.9.1
PATCH 14/14 target-arm: Add WFx instruction trap support
In reply to Peter MaydellFrom: Greg Bellows <[email protected]>
Add support for trapping WFI and WFE instructions to the proper EL when SCTLR/SCR/HCR settings apply.
[PMM: removed unnecessary tweaking of syn_wfx() prototype;
use raise_exception();
don't trap on WFE (and add comment explaining why not); remove unnecessary ARM_FEATURE checks;
trap to EL3, not EL1, if in S-EL0 and SCTLR check fires]
--- target-arm/op_helper.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-)
target-arm/op_helper.c +59 -1
@@ -248,9 +248,60 @@ uint32_t HELPER(usat16)(CPUARMState *env, uint32_t x, uint32_t shift)return res; } +/* Function checks whether WFx (WFI/WFE) instructions are set up to be trapped. +* The function returns the target EL (1-3) if the instruction is to be trapped; +* otherwise it returns 0 indicating it is not trapped. +*/ +static inline int check_wfx_trap (CPUARMState *env,bool is_wfe) +{ +int cur_el =arm_current_el (env); +uint64_t mask; + +/* If we are currently in EL0 then we need to check if SCTLR is set up for +* WFx instructions being trapped to EL1. These trap bits don't exist in v7. +*/ +if (cur_el <1 &&arm_feature (env,ARM_FEATURE_V8 )) { +int target_el; + + mask = is_wfe ? SCTLR_nTWE : SCTLR_nTWI; +if (arm_is_secure_below_el3 (env) && !arm_el_is_aa64 (env,3 )) { +/* Secure EL0 and Secure PL1 is at EL3 */ + target_el =3 ; + }else { + target_el =1 ; + } + +if (!(env->cp15.sctlr_el[target_el] & mask)) { +return target_el; + } + } + +/* We are not trapping to EL1; trap to EL2 if HCR_EL2 requires it +* No need for ARM_FEATURE check as if HCR_EL2 doesn't exist the +* bits will be zero indicating no trap. +*/ +if (cur_el <2 && !arm_is_secure (env)) { + mask = (is_wfe) ?HCR_TWE :HCR_TWI ; +if (env->cp15.hcr_el2 & mask) { +return 2 ; + } + } + +/* We are not trapping to EL1 or EL2; trap to EL3 if SCR_EL3 requires it */ +if (cur_el <3 ) { + mask = (is_wfe) ?SCR_TWE :SCR_TWI ; +if (env->cp15.scr_el3 & mask) { +return 3 ; + } + } + +return 0 ; +} +void HELPER (wfi )(CPUARMState *env) {CPUState *cs =CPU (arm_env_get_cpu (env)); +int target_el =check_wfx_trap (env, false);if (cpu_has_work (cs)) {/* Don't bother to go into our "low power state" if
@@ -259,6 +310,11 @@ void HELPER(wfi)(CPUARMState *env)return ; } +if (target_el) { + env->pc -=4 ; +raise_exception (env,EXCP_UDEF ,syn_wfx (1 ,0xe ,0 ), target_el); + } + cs->exception_index =EXCP_HLT ; cs->halted =1 ;cpu_loop_exit (cs);
@@ -269,7 +325,9 @@ void HELPER(wfe)(CPUARMState *env)CPUState *cs =CPU (arm_env_get_cpu (env));/* Don't actually halt the CPU, just yield back to top -* level loop +* level loop. This is not going into a "low power state" +* (ie halting until some event occurs), so we never take +* a configurable trap to a different exception level. */ cs->exception_index =EXCP_YIELD ;cpu_loop_exit (cs);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 14/14] target-arm: Add WFx instruction trap support
Quoted 5 lines · Peter Maydell
From: Greg Bellows <[email protected]>
Add support for trapping WFI and WFE instructions to the proper EL when SCTLR/SCR/HCR settings apply.
Quoted 7 lines
Signed-off-by Greg Bellows <[email protected]>[PMM: removed unnecessary tweaking of
syn_wfx()prototype;
useraise_exception();
don't trap on WFE (and add comment explaining why not); remove unnecessaryARM_FEATUREchecks;
trap to EL3, not EL1, if in S-EL0 and SCTLR check fires]Signed-off-by Peter Maydell <[email protected]>
Quoted 95 lines
--- target-arm/op_helper.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-)target-arm/op_helper.c +59
-1@@ -248,9 +248,60 @@ uint32_t HELPER(usat16)(CPUARMState *env, uint32_t x, uint32_t shift)return res; } +/* Function checks whether WFx (WFI/WFE) instructions are set up to be trapped. +* The function returns the target EL (1-3) if the instruction is to be trapped; +* otherwise it returns 0 indicating it is not trapped. +*/ +static inline int check_wfx_trap (CPUARMState *env,bool is_wfe) +{ +int cur_el =arm_current_el (env); +uint64_t mask; + +/* If we are currently in EL0 then we need to check if SCTLR is set up for +* WFx instructions being trapped to EL1. These trap bits don't exist in v7. +*/ +if (cur_el <1 &&arm_feature (env,ARM_FEATURE_V8 )) { +int target_el; + + mask = is_wfe ? SCTLR_nTWE : SCTLR_nTWI; +if (arm_is_secure_below_el3 (env) && !arm_el_is_aa64 (env,3 )) { +/* Secure EL0 and Secure PL1 is at EL3 */ + target_el =3 ; + }else { + target_el =1 ; + } + +if (!(env->cp15.sctlr_el[target_el] & mask)) { +return target_el; + } + } + +/* We are not trapping to EL1; trap to EL2 if HCR_EL2 requires it +* No need for ARM_FEATURE check as if HCR_EL2 doesn't exist the +* bits will be zero indicating no trap. +*/ +if (cur_el <2 && !arm_is_secure (env)) { + mask = (is_wfe) ?HCR_TWE :HCR_TWI ; +if (env->cp15.hcr_el2 & mask) { +return 2 ; + } + } + +/* We are not trapping to EL1 or EL2; trap to EL3 if SCR_EL3 requires it */ +if (cur_el <3 ) { + mask = (is_wfe) ?SCR_TWE :SCR_TWI ; +if (env->cp15.scr_el3 & mask) { +return 3 ; + } + } + +return 0 ; +} +void HELPER (wfi )(CPUARMState *env) {CPUState *cs =CPU (arm_env_get_cpu (env)); +int target_el =check_wfx_trap (env, false);if (cpu_has_work (cs)) {/* Don't bother to go into our "low power state" if @@ -259,6 +310,11 @@ void HELPER(wfi)(CPUARMState *env)return ; } +if (target_el) { + env->pc -=4 ; +raise_exception (env,EXCP_UDEF ,syn_wfx (1 ,0xe ,0 ), target_el); + } + cs->exception_index =EXCP_HLT ; cs->halted =1 ;cpu_loop_exit (cs);@@ -269,7 +325,9 @@ void HELPER(wfe)(CPUARMState *env)CPUState *cs =CPU (arm_env_get_cpu (env));/* Don't actually halt the CPU, just yield back to top -* level loop +* level loop. This is not going into a "low power state" +* (ie halting until some event occurs), so we never take +* a configurable trap to a different exception level. */ cs->exception_index =EXCP_YIELD ;cpu_loop_exit (cs);Signature · 1 line
1.9.1