target/arm: Fix some Neon trapping corner cases
cover target/arm: Fix some Neon trapping corner cases
There are a couple of corner cases in trapping of A32 Neon insns that have been kicking around as issues in the bug tracker for ages; I got round to fixing them today. They're related in that they both need us to distinguish Neon from VFP insns at the point of checking for traps.
The first one is a bug, where we aren't reporting the correct syndrome information for A32 VFP and Neon insns that are trapped to AArch32 EL2. These have COPROC and TA fields in the syndrome which we weren't filling in correctly. (When the trap goes to AArch64 EL2, the fields are RES0, which we do get right.) It's pretty obscure, though, and I know of no guest software which might actually care about distinguishing Neon from VFP insns in the hyp trap handler, so I don't think it worth backporting to stable.
The second one is a missing optional feature: there is a CPACR.ASEDIS bit that lets software force Neon insns to UNDEF, and also a hyp trap bit HCPTR.TACE that lets the hypervisor force Neon insns to trap to it. These are architecturally optional but in practice implemented on all CPUs except for the Cortex-A8.
The third one is another missing optional feature: CPACR.D32DIS lets software force VFP (not Neon) insns that use D16..D31 to trap. This is rather obscure as it goes away in v8A, and of the CPUs we implement it's only present in the Cortex-A7 and Cortex-A9.
-- PMM
Peter Maydell (11):
target/arm: Separate out Neon from VFP access checks target/arm: Separate syndrome functions for A32 and A64 target/arm: Report correct syndrome to AArch32 EL2 for trapped
Neon/VFP insns
target/arm: Define fields for NSACR
target/arm: Handle NSACR.NSASEDIS in CPACR accesses target/arm: Handle NSACR.NSASEDIS in HCPTR accesses target/arm: Update confusing comment in cpacr_write() target/arm: Add new feature ARM_FEATURE_NO_NEON_TRAPS target/arm: Implement CPACR.ASEDIS and HCPTR.TASE target/arm: Pull VFP "can we use D16-D31" checks out into a function target/arm: Implement CPACR.D32DIS
target/arm/cpu.c | 2 +- target/arm/cpu.h | 16 ++++ target/arm/helper.c | 93 +++++++++++++++++++---- target/arm/internals.h | 8 ++ target/arm/syndrome.h | 28 +++++-- target/arm/tcg/cpu32-system.c | 4 + target/arm/tcg/hflags.c | 93 +++++++++++++++++++++++ target/arm/tcg/translate-a32.h | 1 + target/arm/tcg/translate-a64.c | 2 +- target/arm/tcg/translate-neon.c | 74 +++++++++--------- target/arm/tcg/translate-vfp.c | 131 +++++++++++++++++++++----------- target/arm/tcg/translate.c | 2 + target/arm/tcg/translate.h | 2 + 13 files changed, 351 insertions(+), 105 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/11 target/arm: Separate out Neon from VFP access checks
Currently we use vfp_access_check() for AArch32 VFP and Neon instructions. This is not quite right:
* there are optional CPACR.ASEDIS and HCPTR.TASE controls that allow trapping of just the Neon and not VFP instructions
* Neon instructions are supposed to report a slightly different syndrome in HCR when they trap to AArch32 EL2
As a preliminary refactor so we have somewhere we can make this distinction, separate out Neon access checks into a separate neon_access_check(), which initially just calls vfp_access_check().
The set of insns this needs to cover are those described in section E1.3.9 of the DDI0487M.b Arm ARM. For us this corresponds to everything in neon-dp.decode and neon-ls.decode and thus in translate-neon.c, plus three insns that we handle in translate-vfp.c:
- VDUP (general-purpose register)
- VMOV (general-purpose register to scalar) byte and halfword
- VMOV (scalar to general-purpose register) byte and halfword
(which are the ones in that file with ARM_FEATURE_NEON checks).
--- target/arm/tcg/translate-a32.h | 1 + target/arm/tcg/translate-neon.c | 74 ++++++++++++++++----------------- target/arm/tcg/translate-vfp.c | 33 +++++++++++---- 3 files changed, 62 insertions(+), 46 deletions(-)
target/arm/tcg/translate-a32.h +1 -0
@@ -33,6 +33,7 @@ void load_reg_var(DisasContext *s, TCGv_i32 var, int reg);void arm_gen_condlabel (DisasContext *s);bool vfp_access_check (DisasContext *s);bool vfp_access_check_m (DisasContext *s,bool skip_context_update); +bool neon_access_check (DisasContext *s);void read_neon_element32 (TCGv_i32 dest,int reg,int ele,MemOp memop);void read_neon_element64 (TCGv_i64 dest,int reg,int ele,MemOp memop);void write_neon_element32 (TCGv_i32 src,int reg,int ele,MemOp memop);
target/arm/tcg/translate-neon.c +37 -37
296 lines not on this page · raw message
target/arm/tcg/translate-vfp.c +24 -9
@@ -303,6 +303,17 @@ bool vfp_access_check(DisasContext *s) } } +/* +* Access check for Neon; this is for instructions which can be +* trapped by CPACR.ASEDIS and HCPTR.TASE. Support for those traps +* is optional and we currently do not implement them, so this +* is identical to a VFP access check for now. +*/ +bool neon_access_check (DisasContext *s) +{ +return vfp_access_check (s); +} +static bool trans_VSEL (DisasContext *s,arg_VSEL *a) {uint32_t rd, rn, rm;
@@ -620,15 +631,17 @@ static bool trans_VMOV_to_gp(DisasContext *s, arg_VMOV_to_gp *a) {/* VMOV scalar to general purpose register */ TCGv_i32 tmp; +bool insn_is_neon = false;/* * SIZE == MO_32 is a VFP instruction; otherwise NEON. MVE has * all sizes, whether the CPU has fp or not. */ if (!dc_isar_feature (aa32_mve, s)) { -if (a->size ==MO_32 - ? !dc_isar_feature (aa32_fpsp_v2, s) - : !arm_dc_feature (s,ARM_FEATURE_NEON )) { + insn_is_neon = a->size !=MO_32 ; +if (insn_is_neon + ? !arm_dc_feature (s,ARM_FEATURE_NEON ) + : !dc_isar_feature (aa32_fpsp_v2, s)) {return false; } }
@@ -644,7 +657,7 @@ static bool trans_VMOV_to_gp(DisasContext *s, arg_VMOV_to_gp *a) } } -if (!vfp_access_check (s)) { +if (!(insn_is_neon ?neon_access_check (s) :vfp_access_check (s))) {return true; }
@@ -665,15 +678,17 @@ static bool trans_VMOV_from_gp(DisasContext *s, arg_VMOV_from_gp *a) {/* VMOV general purpose register to scalar */ TCGv_i32 tmp; +bool insn_is_neon = false;/* * SIZE == MO_32 is a VFP instruction; otherwise NEON. MVE has * all sizes, whether the CPU has fp or not. */ if (!dc_isar_feature (aa32_mve, s)) { -if (a->size ==MO_32 - ? !dc_isar_feature (aa32_fpsp_v2, s) - : !arm_dc_feature (s,ARM_FEATURE_NEON )) { + insn_is_neon = a->size !=MO_32 ; +if (insn_is_neon + ? !arm_dc_feature (s,ARM_FEATURE_NEON ) + : !dc_isar_feature (aa32_fpsp_v2, s)) {return false; } }
@@ -689,7 +704,7 @@ static bool trans_VMOV_from_gp(DisasContext *s, arg_VMOV_from_gp *a) } } -if (!vfp_access_check (s)) { +if (!(insn_is_neon ?neon_access_check (s) :vfp_access_check (s))) {return true; }
@@ -736,7 +751,7 @@ static bool trans_VDUP(DisasContext *s, arg_VDUP *a) size =2 ; } -if (!vfp_access_check (s)) { +if (!neon_access_check (s)) {return true; }
Signature · 1 line
2.43.0
Re: [PATCH 01/11] target/arm: Separate out Neon from VFP access checks
Quoted 20 lines · Peter Maydell
Currently we use
vfp_access_check()for AArch32 VFP and Neon instructions. This is not quite right:
* there are optional CPACR.ASEDIS and HCPTR.TASE controls that allow trapping of just the Neon and not VFP instructions
* Neon instructions are supposed to report a slightly different syndrome in HCR when they trap to AArch32 EL2As a preliminary refactor so we have somewhere we can make this distinction, separate out Neon access checks into a separate
neon_access_check(), which initially just callsvfp_access_check().The set of insns this needs to cover are those described in section E1.3.9 of the DDI0487M.b Arm ARM. For us this corresponds to everything in neon-dp.decode and neon-ls.decode and thus in
translate-neon.c, plus three insns that we handle intranslate-vfp.c:
- VDUP (general-purpose register)
- VMOV (general-purpose register to scalar) byte and halfword
- VMOV (scalar to general-purpose register) byte and halfword
(which are the ones in that file withARM_FEATURE_NEONchecks).
Quoted 6 lines
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/translate-a32.h | 1 + target/arm/tcg/translate-neon.c | 74 ++++++++++++++++----------------- target/arm/tcg/translate-vfp.c | 33 +++++++++++---- 3 files changed, 62 insertions(+), 46 deletions(-)
r~
PATCH 2/11 target/arm: Separate syndrome functions for A32 and A64
In reply to Peter MaydellCurrently we have one syn_fp_access_trap() which we use for fp traps from A64 and from VFP and Neon A32. This means that A64 has to specify arguments that are always fixed for it (coproc and is_16bit) and A32 can't specify arguments it needs to (TA).
Split it up into syn_a64_fp_access_trap() and syn_a32_fp_access_trap(). This is a refactor with no behavioural change.
--- target/arm/syndrome.h | 28 ++++++++++++++++++++++------ target/arm/tcg/translate-a64.c | 2 +- target/arm/tcg/translate-vfp.c | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-)
target/arm/syndrome.h +22 -6
@@ -345,21 +345,37 @@ static inline uint32_t syn_cp15_rrt_trap(int cv, int cond, int opc1, int crm,/* * ISS encoding for an exception from an access to a register of -* instruction resulting from the FPEN or TFP traps. +* instruction resulting from the FPEN or TFP traps. Note that +* the TA and COPROC fields are only valid when an AArch32 insn +* traps to AArch32 EL2; they are RES0 for traps to AArch64. */ -FIELD(FP_ISS, COPROC, 0, 4) /* ARMv7 only */ +FIELD(FP_ISS, COPROC, 0, 4) +FIELD(FP_ISS, TA, 5, 1) FIELD(FP_ISS, COND, 20, 4) FIELD(FP_ISS, CV, 24, 1) -static inline uint32_t syn_fp_access_trap (int cv,int cond,bool is_16bit, -int coproc) +static inline uint32_t syn_a64_fp_access_trap (int cv,int cond) { -/* AArch32 FP trap or any AArch64 FP/SIMD trap: TA == 0 */ +/* AArch64 FP/SIMD trap: TA and coproc are RES0, insn is 64 bits */ uint32_t res =syn_set_ec (0 ,EC_ADVSIMDFPACCESSTRAP ); - res =FIELD_DP32 (res,SYNDROME ,IL , !is_16bit); + res =FIELD_DP32 (res,SYNDROME ,IL ,1 ); res =FIELD_DP32 (res,FP_ISS ,CV , cv); res =FIELD_DP32 (res,FP_ISS ,COND , cond); + +return res; +} + +static inline uint32_t syn_a32_fp_access_trap (int cv,int cond, +int ta,int coproc) +{ +/* AArch32 VFP or Neon trap: TA and coproc valid, insn is 64 bits */ +uint32_t res =syn_set_ec (0 ,EC_ADVSIMDFPACCESSTRAP ); + res =FIELD_DP32 (res,SYNDROME ,IL ,1 ); + + res =FIELD_DP32 (res,FP_ISS ,CV , cv); + res =FIELD_DP32 (res,FP_ISS ,COND , cond); + res =FIELD_DP32 (res,FP_ISS ,TA , ta); res =FIELD_DP32 (res,FP_ISS ,COPROC , coproc);return res;
target/arm/tcg/translate-a64.c +1 -1
@@ -1439,7 +1439,7 @@ static bool fp_access_check_only(DisasContext *s) s->fp_access_checked =-1 ;gen_exception_insn_el (s,0 ,EXCP_UDEF , -syn_fp_access_trap (1 ,0xe , false,0 ), +syn_a64_fp_access_trap (1 ,0xe ), s->fp_excp_el);return false; }
target/arm/tcg/translate-vfp.c +1 -1
@@ -228,7 +228,7 @@ static bool vfp_access_check_a(DisasContext *s, bool ignore_vfp_enabled)* this field to 0xA. */ int coproc =arm_dc_feature (s,ARM_FEATURE_V8 ) ?0 :0xa ; -uint32_t syn =syn_fp_access_trap (1 ,0xe , false, coproc); +uint32_t syn =syn_a32_fp_access_trap (1 ,0xe ,0 , coproc);gen_exception_insn_el (s,0 ,EXCP_UDEF , syn, s->fp_excp_el);return false;
Signature · 1 line
2.43.0
Re: [PATCH 02/11] target/arm: Separate syndrome functions for A32 and A64
Quoted 9 lines · Peter Maydell
Currently we have one
syn_fp_access_trap()which we use for fp traps from A64 and from VFP and Neon A32. This means that A64 has to specify arguments that are always fixed for it (coproc andis_16bit) and A32 can't specify arguments it needs to (TA).Split it up into
syn_a64_fp_access_trap()andsyn_a32_fp_access_trap(). This is a refactor with no behavioural change.
Quoted 6 lines
Signed-off-by Peter Maydell<[email protected]>--- target/arm/syndrome.h | 28 ++++++++++++++++++++++------ target/arm/tcg/translate-a64.c | 2 +- target/arm/tcg/translate-vfp.c | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-)
r~
PATCH 3/11 target/arm: Report correct syndrome to AArch32 EL2 for trapped Neon/VFP insns
In reply to Peter MaydellWhen an AArch32 Neon or VFP insn is trapped to AArch64 EL2, bits [19:0] of the syndrome in ESR_EL2 are RES0. However, when it is trapped to AArch32 EL2, the HSR syndrome information defines some extra fields:
[5] : TA
[3:0] : coproc
where the TA bit is 1 for a trapped Neon insn and 0 for a trapped VFP insn, and the coproc field is 0b1010 when TA is 0, and 0 when TA is 1.
We attempted to address this in commit fa33eead ("target/arm: Add coproc parameter to syn_fp_access_trap"), but got it wrong: we thought the RES0 condition was "is v8A" rather than "is EL2 AArch32", and we made all insns be TA=0 coproc = 0b1010 rather than only the VFP ones. Correct the condition we use to decide the coproc and TA fields. We set these fields unconditionally; later on in arm_cpu_do_interrupt_aarch64() we will squash them to zero if we are taking the exception to AArch64.
NB: there is some disagreement between different revisions of the Arm ARM about the exact handling of 'coproc':
* the v8A Arm ARM text says coproc is 0b1010 when TA is 1
* the v8A Arm ARM pseudocode in AArch32_CheckFPAdvSIMDTrap() sets coproc to 0b1010 when TA is 0
* the v7A Arm ARM text says coproc is 0b1010 when TA is 0
* the v7A Arm ARM pseudocode sets coproc to 0b1010 when TA is 0
The v7A Arm ARM pseudocode also disagrees with the v7A text, v8A text and v8A pseudocode in only setting TA to 1 for traps caused by HCPTR.TASE; the others set Ta for all trapped AdvSIMD insns (i.e. including traps caused by HCPTR.TCP10).
We assume that the v8A pseudocode is incorrect about coproc (as it is the odd one out) and that the v7A pseudocode is incorrect about when TA is set (again, as it is the odd one out).
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/1153
--- target/arm/tcg/translate-vfp.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
target/arm/tcg/translate-vfp.c +17 -12
@@ -216,19 +216,20 @@ static void gen_update_fp_context(DisasContext *s)* whether VFP is enabled via FPEXC.EN: this should be true for FMXR/FMRX * accesses to FPSID, FPEXC, MVFR0, MVFR1, MVFR2, and false for all other insns. */ -static bool vfp_access_check_a (DisasContext *s,bool ignore_vfp_enabled) +static bool vfp_access_check_a (DisasContext *s,bool ignore_vfp_enabled, +bool is_neon) {if (s->fp_excp_el) {/* -* The full syndrome is only used for HSR when HCPTR traps: -* For v8, when TA==0, coproc is RES0. -* For v7, any use of a Floating-point instruction or access -* to a Floating-point Extension register that is trapped to -* Hyp mode because of a trap configured in the HCPTR sets -* this field to 0xA. +* The full syndrome is only used for HSR when HCPTR traps. +* When trapping to AArch64, the TA and coproc fields are RES0 +* (we will squash them in arm_cpu_do_interrupt_aarch64()). +* When trapping to AArch32: +* - for VFP insns, TA=0 and coproc = 0b1010 +* - for Neon insns, TA=1 and coproc = 0 */ -int coproc =arm_dc_feature (s,ARM_FEATURE_V8 ) ?0 :0xa ; -uint32_t syn =syn_a32_fp_access_trap (1 ,0xe ,0 , coproc); +int coproc = is_neon ?0 :0xa ; +uint32_t syn =syn_a32_fp_access_trap (1 ,0xe , is_neon, coproc);gen_exception_insn_el (s,0 ,EXCP_UDEF , syn, s->fp_excp_el);return false;
@@ -299,7 +300,7 @@ bool vfp_access_check(DisasContext *s)if (arm_dc_feature (s,ARM_FEATURE_M )) {return vfp_access_check_m (s, false); }else { -return vfp_access_check_a (s, false); +return vfp_access_check_a (s, false, false); } }
@@ -311,7 +312,11 @@ bool vfp_access_check(DisasContext *s)*/ bool neon_access_check (DisasContext *s) { -return vfp_access_check (s); +if (arm_dc_feature (s,ARM_FEATURE_M )) { +return vfp_access_check_m (s, false); + }else { +return vfp_access_check_a (s, false, true); + } }static bool trans_VSEL (DisasContext *s,arg_VSEL *a)
@@ -822,7 +827,7 @@ static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a)* Call vfp_access_check_a() directly, because we need to tell * it to ignore FPEXC.EN for some register accesses. */ -if (!vfp_access_check_a (s, ignore_vfp_enabled)) { +if (!vfp_access_check_a (s, ignore_vfp_enabled, false)) {return true; }
Signature · 1 line
2.43.0
Re: [PATCH 03/11] target/arm: Report correct syndrome to AArch32 EL2 for trapped Neon/VFP insns
Quoted 37 lines · Peter Maydell
When an AArch32 Neon or VFP insn is trapped to AArch64 EL2, bits [19:0] of the syndrome in
ESR_EL2are RES0. However, when it is trapped to AArch32 EL2, the HSR syndrome information defines some extra fields:
[5] : TA
[3:0] : coprocwhere the TA bit is 1 for a trapped Neon insn and 0 for a trapped VFP insn, and the coproc field is 0b1010 when TA is 0, and 0 when TA is 1.
We attempted to address this in commit
fa33eead("target/arm: Add coproc parameter tosyn_fp_access_trap"), but got it wrong: we thought the RES0 condition was "is v8A" rather than "is EL2 AArch32", and we made all insns be TA=0 coproc = 0b1010 rather than only the VFP ones. Correct the condition we use to decide the coproc and TA fields. We set these fields unconditionally; later on inarm_cpu_do_interrupt_aarch64()we will squash them to zero if we are taking the exception to AArch64.NB: there is some disagreement between different revisions of the Arm ARM about the exact handling of 'coproc':
* the v8A Arm ARM text says coproc is 0b1010 when TA is 1
* the v8A Arm ARM pseudocode inAArch32_CheckFPAdvSIMDTrap()sets coproc to 0b1010 when TA is 0
* the v7A Arm ARM text says coproc is 0b1010 when TA is 0
* the v7A Arm ARM pseudocode sets coproc to 0b1010 when TA is 0The v7A Arm ARM pseudocode also disagrees with the v7A text, v8A text and v8A pseudocode in only setting TA to 1 for traps caused by HCPTR.TASE; the others set Ta for all trapped AdvSIMD insns (i.e. including traps caused by HCPTR.TCP10).
We assume that the v8A pseudocode is incorrect about coproc (as it is the odd one out) and that the v7A pseudocode is incorrect about when TA is set (again, as it is the odd one out).
Quoted 5 lines
Resolves:https://gitlab.com/qemu-project/qemu/-/work_items/1153
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/translate-vfp.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
r~
PATCH 4/11 target/arm: Define fields for NSACR
In reply to Peter MaydellCurrently we handle cp15.nsacr with raw bit numbers in the few places we need to work with it. We're about to add some more uses of this field, so define its fields with the FIELD macro and use the macros in the places that were previously using bit numbers.
--- target/arm/cpu.c | 2 +- target/arm/helper.c | 10 +++++----- target/arm/internals.h | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-)
target/arm/cpu.c +1 -1
@@ -777,7 +777,7 @@ void arm_emulate_firmware_reset(CPUState *cpustate, int target_el)/* Put CPU into non-secure state */ env->cp15.scr_el3 |=SCR_NS ;/* Set NSACR.{CP11,CP10} so NS can access the FPU */ - env->cp15.nsacr |=3 <<10 ; + env->cp15.nsacr |=R_NSACR_CP10_MASK |R_NSACR_CP11_MASK ; }if (have_el2 && target_el <2 ) {
target/arm/helper.c +5 -5
@@ -587,7 +587,7 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,* is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00. */ if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && - !arm_is_secure (env) && !extract32 (env->cp15.nsacr,10 ,1 )) { + !arm_is_secure (env) && !FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { mask =R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ; value = (value & ~mask) | (env->cp15.cpacr_el1 & mask); }
@@ -604,7 +604,7 @@ static uint64_t cpacr_read(CPUARMState *env, const ARMCPRegInfo *ri)uint64_t value = env->cp15.cpacr_el1;if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && - !arm_is_secure (env) && !extract32 (env->cp15.nsacr,10 ,1 )) { + !arm_is_secure (env) && !FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { value = ~(R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ); }return value;
@@ -4082,7 +4082,7 @@ static void cptr_el2_write(CPUARMState *env, const ARMCPRegInfo *ri,* is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1. */ if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && - !arm_is_secure (env) && !extract32 (env->cp15.nsacr,10 ,1 )) { + !arm_is_secure (env) && !FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) {uint64_t mask =R_HCPTR_TCP11_MASK |R_HCPTR_TCP10_MASK ; value = (value & ~mask) | (env->cp15.cptr_el[2 ] & mask); }
@@ -4098,7 +4098,7 @@ static uint64_t cptr_el2_read(CPUARMState *env, const ARMCPRegInfo *ri)uint64_t value = env->cp15.cptr_el[2 ];if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && - !arm_is_secure (env) && !extract32 (env->cp15.nsacr,10 ,1 )) { + !arm_is_secure (env) && !FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { value |=R_HCPTR_TCP11_MASK |R_HCPTR_TCP10_MASK ; }return value;
@@ -10033,7 +10033,7 @@ int fp_exception_el(CPUARMState *env, int cur_el)*/ if ((arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && cur_el <=2 && !arm_is_secure_below_el3 (env))) { -if (!extract32 (env->cp15.nsacr,10 ,1 )) { +if (!FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) {/* FP insns act as UNDEF */ return cur_el ==2 ?2 :1 ; }
target/arm/internals.h +8 -0
@@ -135,6 +135,14 @@ FIELD(CPACR_EL1, FPEN, 20, 2) FIELD(CPACR_EL1, SMEN, 24, 2)FIELD (CPACR_EL1 ,TTA ,28 ,1 )/* matches CPACR.TRCDIS */ +/* Bit definitions for NSACR (AArch32 only) */ +FIELD(NSACR, CP10, 10, 1) +FIELD(NSACR, CP11, 11, 1) +FIELD(NSACR, NSD32DIS, 14, 1) /* v7; RES0 in v8 */ +FIELD(NSACR, NSASEDIS, 15, 1) +FIELD(NSACR, RFR, 19, 1) /* v7; RES0 in v8 */ +FIELD (NSACR ,NSTRCDIS ,20 ,1 ) + /* Bit definitions for HCPTR (AArch32 only) */ FIELD(HCPTR, TCP10, 10, 1)FIELD (HCPTR ,TCP11 ,11 ,1 )
Signature · 1 line
2.43.0
Re: [PATCH 04/11] target/arm: Define fields for NSACR
Quoted 11 lines · Peter Maydell
Currently we handle cp15.nsacr with raw bit numbers in the few places we need to work with it. We're about to add some more uses of this field, so define its fields with the FIELD macro and use the macros in the places that were previously using bit numbers.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/cpu.c | 2 +- target/arm/helper.c | 10 +++++----- target/arm/internals.h | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-)
r~
PATCH 5/11 target/arm: Handle NSACR.NSASEDIS in CPACR accesses
In reply to Peter MaydellIn cpacr_read() and cpacr_write() we have code that implements the "CPACR.{cp10,cp11} behave as RAZ/WI from NonSecure when NSACR.cp10 is 0" behaviour. There is a similar requirement for CPACR.ASEDIS: if NSACR.NSASEDIS is 1 then CPACR.ASEDIS behaves as RAO/WI in NS.
This doesn't matter to us yet because we don't currently implement ASEDIS or NSASEDIS. But we're about to do that, so add the handling to cpacr_read() and cpacr_write().
--- target/arm/helper.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
target/arm/helper.c +19 -5
@@ -585,11 +585,19 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,/* * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00. +* Similarly, if NSACR.NSASEDIS is 1 then CPACR.ASEDIS ignores writes +* and reads as 1. */ if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && - !arm_is_secure (env) && !FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { - mask =R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ; - value = (value & ~mask) | (env->cp15.cpacr_el1 & mask); + !arm_is_secure (env)) { +if (!FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { + mask =R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ; + value = (value & ~mask) | (env->cp15.cpacr_el1 & mask); + } +if (FIELD_EX32 (env->cp15.nsacr,NSACR ,NSASEDIS )) { + mask =R_CPACR_ASEDIS_MASK ; + value = (value & ~mask) | (env->cp15.cpacr_el1 & mask); + } } env->cp15.cpacr_el1 = value;
@@ -600,12 +608,18 @@ static uint64_t cpacr_read(CPUARMState *env, const ARMCPRegInfo *ri)/* * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00. +* Similarly NSACR.NSASEDIS makes CPACR.ASEDIS read as 1. */ uint64_t value = env->cp15.cpacr_el1;if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && - !arm_is_secure (env) && !FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { - value = ~(R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ); + !arm_is_secure (env)) { +if (!FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { + value = ~(R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ); + } +if (FIELD_EX32 (env->cp15.nsacr,NSACR ,NSASEDIS )) { + value |=R_CPACR_ASEDIS_MASK ; + } }return value; }
Signature · 1 line
2.43.0
Re: [PATCH 05/11] target/arm: Handle NSACR.NSASEDIS in CPACR accesses
Quoted 5 lines · Peter Maydell
In
cpacr_read()andcpacr_write()we have code that implements the "CPACR.{cp10,cp11} behave as RAZ/WI from NonSecure when NSACR.cp10 is 0" behaviour. There is a similar requirement for CPACR.ASEDIS: if NSACR.NSASEDIS is 1 then CPACR.ASEDIS behaves as RAO/WI in NS.
Quoted 8 lines
This doesn't matter to us yet because we don't currently implement ASEDIS or NSASEDIS. But we're about to do that, so add the handling to
cpacr_read()andcpacr_write().Signed-off-by Peter Maydell<[email protected]>--- target/arm/helper.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
r~
PATCH 6/11 target/arm: Handle NSACR.NSASEDIS in HCPTR accesses
In reply to Peter MaydellIn cptr_el2_read() and cptr_el2_write() we have code that implements the "HCPTR.{TCP10,TCP11} behave as RAO/WI from NonSecure when NSACR.cp10 is 0" behaviour. There is a similar requirement for HCPTR.TASE: if NSACR.NSASEDIS is 1 then CPACR.ASEDIS behaves as RAO/WI in NS.
This doesn't matter to us yet because we don't currently implement ASEDIS or NSASEDIS. But we're about to do that, so add the handling to cptr_el2_read() and cptr_el2_write().
--- target/arm/helper.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
target/arm/helper.c +18 -5
@@ -4094,11 +4094,18 @@ static void cptr_el2_write(CPUARMState *env, const ARMCPRegInfo *ri,/* * For A-profile AArch32 EL3, if NSACR.CP10 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1. +* Similarly, if NSACR.NSASEDIS is 1 then HCPTR.TASE behaves as RAO/WI. */ if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && - !arm_is_secure (env) && !FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { -uint64_t mask =R_HCPTR_TCP11_MASK |R_HCPTR_TCP10_MASK ; - value = (value & ~mask) | (env->cp15.cptr_el[2 ] & mask); + !arm_is_secure (env)) { +if (!FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { +uint64_t mask =R_HCPTR_TCP11_MASK |R_HCPTR_TCP10_MASK ; + value = (value & ~mask) | (env->cp15.cptr_el[2 ] & mask); + } +if (FIELD_EX32 (env->cp15.nsacr,NSACR ,NSASEDIS )) { +uint64_t mask =R_HCPTR_TASE_MASK ; + value = (value & ~mask) | (env->cp15.cptr_el[2 ] & mask); + } } env->cp15.cptr_el[2 ] = value; }
@@ -4108,12 +4115,18 @@ static uint64_t cptr_el2_read(CPUARMState *env, const ARMCPRegInfo *ri)/* * For A-profile AArch32 EL3, if NSACR.CP10 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1. +* Similarly, if NSACR.NSASEDIS is 1 then HCPTR.TASE behaves as RAO/WI. */ uint64_t value = env->cp15.cptr_el[2 ];if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && - !arm_is_secure (env) && !FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { - value |=R_HCPTR_TCP11_MASK |R_HCPTR_TCP10_MASK ; + !arm_is_secure (env)) { +if (!FIELD_EX32 (env->cp15.nsacr,NSACR ,CP10 )) { + value |=R_HCPTR_TCP11_MASK |R_HCPTR_TCP10_MASK ; + } +if (!FIELD_EX32 (env->cp15.nsacr,NSACR ,NSASEDIS )) { + value |=R_HCPTR_TASE_MASK ; + } }return value; }
Signature · 1 line
2.43.0
Re: [PATCH 06/11] target/arm: Handle NSACR.NSASEDIS in HCPTR accesses
Quoted 5 lines · Peter Maydell
In
cptr_el2_read()andcptr_el2_write()we have code that implements the "HCPTR.{TCP10,TCP11} behave as RAO/WI from NonSecure when NSACR.cp10 is 0" behaviour. There is a similar requirement for HCPTR.TASE: if NSACR.NSASEDIS is 1 then CPACR.ASEDIS behaves as RAO/WI in NS.
Quoted 8 lines
This doesn't matter to us yet because we don't currently implement ASEDIS or NSASEDIS. But we're about to do that, so add the handling to
cptr_el2_read()andcptr_el2_write().Signed-off-by Peter Maydell<[email protected]>--- target/arm/helper.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
r~
PATCH 7/11 target/arm: Update confusing comment in cpacr_write()
In reply to Peter MaydellIn cpacr_write() a comment says "In ARMv8 most bits of CPACR_EL1 are RES0", and the mask value is left at 0, implying that we enforce those RES0 bits. In fact we only enforce RES0 when ARM_FEATURE_V8 is not implemented, and for v8 and up we allow the guest to write any bits. The addition of architectural features in v8 and v9 has also resulted in the addition of new bits to CPACR_EL1, so "most bits are RES0" isn't really true any more.
Update the comment to be a bit clearer.
--- target/arm/helper.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
target/arm/helper.c +11 -1
@@ -551,7 +551,17 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri, {uint32_t mask =0 ; -/* In ARMv8 most bits of CPACR_EL1 are RES0. */ +/* +* The AArch64 view of CPACR_EL1 has a different layout to the old +* AArch32 one. We also need to permit the old AArch32 bits to be +* read and written so that an AArch64 EL2 hypervisor can set up +* the register for an AArch32 EL1 guest. So we choose not to +* enforce any RAZ/WI or RAO/WI bits for v8 based on feature +* presence/absence. +* +* For v7 the situation is a bit simpler and there we do choose to +* enforce RAZ/WI and RAO/WI. +*/ if (!arm_feature (env,ARM_FEATURE_V8 )) {/* * ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
Signature · 1 line
2.43.0
Re: [PATCH 07/11] target/arm: Update confusing comment in cpacr_write()
Quoted 8 lines · Peter Maydell
In
cpacr_write()a comment says "In ARMv8 most bits ofCPACR_EL1are RES0", and the mask value is left at 0, implying that we enforce those RES0 bits. In fact we only enforce RES0 whenARM_FEATURE_V8is not implemented, and for v8 and up we allow the guest to write any bits. The addition of architectural features in v8 and v9 has also resulted in the addition of new bits toCPACR_EL1, so "most bits are RES0" isn't really true any more.
Quoted 6 lines
Update the comment to be a bit clearer.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/helper.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
r~
PATCH 8/11 target/arm: Add new feature ARM_FEATURE_NO_NEON_TRAPS
In reply to Peter MaydellThe traps configurable via CPACR.ASEDIS and HCPTR.TASE that trap only Neon instructions are unfortunately IMPDEF about whether they are implemented or not, and there is no ID register field that identifies whether they are present. In practice, they are present on every implementation I have checked except for the Cortex-A8 (which was the first CPU with Neon).
Add a new feature ARM_FEATURE_NO_NEON_TRAPS which we set on the Cortex-A8, and make the CPACR.ASEDIS and HCPTR.TASE bits RAZ/WI unless the CPU has ARM_FEATURE_NEON and not ARM_FEATURE_NO_NEON_TRAPS.
The negative sense of the feature bit is a little awkward, but this lets us set it only on the single odd-one-out CPU rather than having to set it on every other CPU we implement.
--- target/arm/cpu.h | 6 ++++++ target/arm/helper.c | 17 +++++++++++++++-- target/arm/tcg/cpu32-system.c | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-)
target/arm/cpu.h +6 -0
@@ -2171,6 +2171,12 @@ enum arm_features {* CPU types added in future. */ ARM_FEATURE_BACKCOMPAT_CNTFRQ ,/* 62.5MHz timer default */ +/* +* ARM_FEATURE_NO_NEON_TRAPS should be set if the CPU does *not* +* implement the CPACR.ASEDIS and HCPTR.TASE bits for trapping +* Neon but not VFP. This seems to be true only for Cortex-A8. +*/ + ARM_FEATURE_NO_NEON_TRAPS, };static inline int arm_feature (const CPUARMState *env,int feature)
target/arm/helper.c +15 -2
@@ -570,14 +570,20 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,*/ if (cpu_isar_feature (aa32_vfp_simd,env_archcpu (env))) {/* VFP coprocessor: cp10 & cp11 [23:20] */ - mask |=R_CPACR_ASEDIS_MASK | -R_CPACR_D32DIS_MASK | + mask |=R_CPACR_D32DIS_MASK |R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ;if (!arm_feature (env,ARM_FEATURE_NEON )) {/* ASEDIS [31] bit is RAO/WI */ value |=R_CPACR_ASEDIS_MASK ; + mask |=R_CPACR_ASEDIS_MASK ; + }else if (!arm_feature (env,ARM_FEATURE_NO_NEON_TRAPS )) { +/* +* bit is present unless CPU doesn't implement ASEDIS +* (in which case it is RAZ/WI; this is the Cortex-A8) +*/ + mask |=R_CPACR_ASEDIS_MASK ; }/*
@@ -4101,6 +4107,13 @@ uint64_t arm_hcrx_el2_eff(CPUARMState *env)static void cptr_el2_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) { +if (arm_feature (env,ARM_FEATURE_NO_NEON_TRAPS )) { +/* +* If CPU doesn't implement HCPTR.TASE it's RAZ/WI. Note that +* NSACR.NSASEDIS being 1 overrides this. +*/ + value &= ~R_HCPTR_TASE_MASK ; + }/* * For A-profile AArch32 EL3, if NSACR.CP10 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
target/arm/tcg/cpu32-system.c +2 -0
@@ -245,6 +245,8 @@ static void cortex_a8_initfn(Object *obj) cpu->dtb_compatible ="arm,cortex-a8" ;set_feature (&cpu->env,ARM_FEATURE_V7 );set_feature (&cpu->env,ARM_FEATURE_NEON ); +/* The Cortex-A8 doesn't have CPACR.ASEDIS and HCPTR.TASE */ +set_feature (&cpu->env,ARM_FEATURE_NO_NEON_TRAPS );set_feature (&cpu->env,ARM_FEATURE_THUMB2EE );set_feature (&cpu->env,ARM_FEATURE_DUMMY_C15_REGS );set_feature (&cpu->env,ARM_FEATURE_EL3 );
Signature · 1 line
2.43.0
Re: [PATCH 08/11] target/arm: Add new feature ARM_FEATURE_NO_NEON_TRAPS
Quoted 1 line · Peter Maydell
+ } else if (!arm_feature(env,
ARM_FEATURE_NO_NEON_TRAPS)) {
Is the double negative really worth being able to limit the addition of the new feature to cortex-a8?
Otherwise,
r~
Re: [PATCH 08/11] target/arm: Add new feature ARM_FEATURE_NO_NEON_TRAPS
Quoted 6 lines · Richard Henderson
Quoted 1 line · Peter Maydell
+ } else if (!arm_feature(env,
ARM_FEATURE_NO_NEON_TRAPS)) {Is the double negative really worth being able to limit the addition of the new feature to cortex-a8?
Yeah, I was kind of on the fence about it myself. It's not so much the adding an extra ARM_FEATURE_NEON_TRAPS line to all our existing CPU types as also needing to do it on every new one we add in future -- having the default be the setting that's most likely to be correct for a new CPU felt a little better. But I suppose everybody cuts and pastes from an existing CPU type when adding a new one, so there's not much in it, and we're probably better keeping the feature as a simple "does this CPU have this" positive-sense one.
-- PMM
PATCH 9/11 target/arm: Implement CPACR.ASEDIS and HCPTR.TASE
In reply to Peter MaydellWhen executing at AArch32, there are optional trap bits for Neon instructions in CPACR and HCPTR. We don't currently implement these.
Now we have a separate code path for access checks for Neon insns, we can straightforwardly add the check there. We need to track the target EL for Neon-specific trapping in a new TB flag.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/1499
--- target/arm/cpu.h | 6 +++ target/arm/tcg/hflags.c | 73 ++++++++++++++++++++++++++++++++++ target/arm/tcg/translate-vfp.c | 16 ++++++-- target/arm/tcg/translate.c | 1 + target/arm/tcg/translate.h | 1 + 5 files changed, 94 insertions(+), 3 deletions(-)
target/arm/cpu.h +6 -0
@@ -2499,6 +2499,12 @@ FIELD(TBFLAG_A32, NS, 10, 1)* This requires an SME trap from AArch32 mode when using NEON. */ FIELD (TBFLAG_A32 ,SME_TRAP_NONSTREAMING ,11 ,1 ) +/* +* Target EL for a Neon-disabled exception via CPACR.ASEDIS, HCPTR.TASE. +* If FPEXC_EL indicates a trap to a lower EL than this, that will +* take precedence. + */ +FIELD (TBFLAG_A32 ,NEONEXC_EL ,12 ,2 )/* * Bit usage when in AArch32 state, for M-profile only.
target/arm/tcg/hflags.c +73 -0
85 lines not on this page · raw message
target/arm/tcg/translate-vfp.c +13 -3
@@ -306,15 +306,25 @@ bool vfp_access_check(DisasContext *s)/* * Access check for Neon; this is for instructions which can be -* trapped by CPACR.ASEDIS and HCPTR.TASE. Support for those traps -* is optional and we currently do not implement them, so this -* is identical to a VFP access check for now. +* trapped by CPACR.ASEDIS and HCPTR.TASE. */ bool neon_access_check (DisasContext *s) {if (arm_dc_feature (s,ARM_FEATURE_M )) {return vfp_access_check_m (s, false); }else { +/* +* If the Neon-specific trap bits request a trap to a lower EL +* than the general FP trap bits, the trap to the lower EL +* has priority. +*/ +if (s->neon_excp_el && + (!s->fp_excp_el || s->neon_excp_el < s->fp_excp_el)) { +uint32_t syn =syn_a32_fp_access_trap (1 ,0xe ,1 ,0 ); + +gen_exception_insn_el (s,0 ,EXCP_UDEF , syn, s->neon_excp_el); +return false; + }return vfp_access_check_a (s, false, true); } }
target/arm/tcg/translate.c +1 -0
@@ -6375,6 +6375,7 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) dc->vec_stride =EX_TBFLAG_A32 (tb_flags,VECSTRIDE ); dc->sme_trap_nonstreaming =EX_TBFLAG_A32 (tb_flags,SME_TRAP_NONSTREAMING ); + dc->neon_excp_el =EX_TBFLAG_A32 (tb_flags,NEONEXC_EL ); } dc->lse2 = false;/* applies only to aarch64 */ dc->cp_regs = cpu->cp_regs;
target/arm/tcg/translate.h +1 -0
@@ -88,6 +88,7 @@ typedef struct DisasContext {int sve_excp_el;/* SVE exception EL or 0 if enabled */ int sme_excp_el;/* SME exception EL or 0 if enabled */ int zt0_excp_el;/* ZT0 exception EL or 0 if enabled */ +int neon_excp_el;/* A32 Neon exception EL or 0 if enabled */ int vl;/* current vector length in bytes */ int svl;/* current streaming vector length in bytes */ int max_svl;/* maximum implemented streaming vector length */
Signature · 1 line
2.43.0
Re: [PATCH 09/11] target/arm: Implement CPACR.ASEDIS and HCPTR.TASE
Quoted 6 lines · Peter Maydell
target/arm/tcg/hflags.c +6
-0+static int neon_exception_el (CPUARMState *env,int cur_el) +{ +/* +* Return the EL to trap to for A32 Neon specific traps +* (CPACR.ASEDIS and HCPTR.TASE). In the pseudocode these +* are checked in the same function as the more general trap
target/arm/tcg/hflags.c static bool sme_fa64(CPUARMState *env, int el) · line 182
Quoted 10 lines
target/arm/tcg/hflags.c +10
-0+* bits that we handle in fp_exception_el(). Fortunately it +* is always the case that if the trap/enable bits specify +* taking an exception to different ELs for the Neon-specific +* insns and the general fp insns then the trap to the lower +* of the two ELs has priority, so we can calculate the two +* target ELs separately and pick the right destination later. +* Compare AArch32_CheckAdvSIMDOrFPEnabled(). +*/ +uint64_t hcr_el2 =arm_hcr_el2_eff (env); +bool cpacr_asedis =FIELD_EX64 (env->cp15.cpacr_el1,CPACR ,ASEDIS );
CPACR.AESDIS overlaps CPACR_EL1.TCPAC, so we're missing a check for arm_el_is_aa64(env, 1), when cur_el == 0.
Quoted 17 lines
target/arm/tcg/hflags.c +17
-0+bool hcptr_tase =FIELD_EX64 (env->cp15.cptr_el[2 ],HCPTR ,TASE ); + +if (arm_feature (env,ARM_FEATURE_NO_NEON_TRAPS )) { +/* This CPU doesn't implement the trap bits (Cortex-A8) */ +return 0 ; + } + +/* +* CPACR doesn't exist before v6, but neither does Neon, so we can +* assume that if we're testing this then the trap exists. +*/ + +if (arm_feature (env,ARM_FEATURE_EL2 ) &&arm_el_is_aa64 (env,2 )) { +/* +* The AArch64 CPTR_EL2 has no equivalent to HCPTR.TASE; only +* an AArch32 EL2 can trap Neon specifically. +*/
target/arm/tcg/hflags.c static bool sme_fa64(CPUARMState *env, int el) · line 209
Quoted 10 lines
target/arm/tcg/hflags.c +10
-0+ hcptr_tase = false; + } + +/* +* NSACR.NSASEDIS makes the effective values of HCPTR.TASE and +* CPACR.ASEDIS be 1 in NonSecure state. NSACR has no +* effect unless EL3 exists and is AArch32. +*/ +if ((arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && + cur_el <=2 && !arm_is_secure_below_el3 (env))) {
Note extra ().
Quoted 10 lines
target/arm/tcg/hflags.c +10
-0+if (FIELD_EX32 (env->cp15.nsacr,NSACR ,NSASEDIS )) { + cpacr_asedis = true; + hcptr_tase = true; + } + } + +/* CPACR is ignored if E2H+TGE are both set */ +if ((hcr_el2 & (HCR_E2H |HCR_TGE )) != (HCR_E2H |HCR_TGE )) { +if (cpacr_asedis) { + if (!arm_el_is_aa64(env, 3)
target/arm/tcg/hflags.c static bool sme_fa64(CPUARMState *env, int el) · line 229
Quoted 10 lines
target/arm/tcg/hflags.c +10
-0+ && (cur_el == 3 || arm_is_secure_below_el3(env))) { +/* Trap from Secure PL0 or PL1 to Secure PL1 */ +return 3 ; + } +if (cur_el <=1 ) { +/* trap from EL0 or EL1 to EL1 */ +return 1 ; + } + } + }
I wonder if some reorg is in order.
bool cpacr_aesdis = FIELD_EX64(...);
bool hcptr_tase = FIELD_EX64(...);
if (arm_el_is_aa64(env, 3)) {
if (arm_el_is_aa64(env, 2)) {
/* CPTR_EL2 has no equivalent to HCPTR.TASE */
hcptr_tase = false;
}
if (arm_el_is_aa64(env, 1)) {
/* CPACR_EL1 has no equivalent to CPACR.AESDIS */
cpacr_aesdis = false;
}
} else if (cur_el == 3 || arm_is_secure_below_el3(env)) {
if (cpacr_aesdis) {
/* Trap from Secure PL0 or PL1 to Secure PL1 */
return 3;
}
} else if (arm_feature(env, ARM_FEATURE_EL3)) {
if (FIELD_EX32(env->cp15.nsacr, NSACR, NSASEDIS)) {
cpacr_asedis = true;
hcptr_tase = true;
}
}
if (cur_el <= 1 && cpacr_asedis) {
return 1;
}
if (cur_el <= 2 && hcptr_tase) {
return 2;
}
return 0;
/* TODO since arm_el_is_aa64 is non-trivial, perhaps */
switch (arm_min_aa64_el(env)) {
case 1:
cpacr_aesdis = false;
/* fall through */
case 2:
hcptr_tase = false;
break;
case -1: /* !arm_feature(ARM_FEATURE_AARCH64) */
...
}r~
PATCH 10/11 target/arm: Pull VFP "can we use D16-D31" checks out into a function
In reply to Peter MaydellCurrently we directly call dc_isar_feature(aa32_simd_r32, s) for VFP insns that use D16-D31 to see if they should UNDEF. For some v7A CPUs (Cortex-A7, Cortex-A9) there is also a CPACR.D32DIS trap bit that will make VFP (and only VFP, not Neon) insns using D16-D31 UNDEF.
Pull out a function vfp_d16_d31_ok() that currently just does the feature check but which will provide us a place where we can make this check. Since D32DIS takes precedence over traps to EL2 and EL3 and simply makes the insns UNDEF, we are OK to do this early rather than having to wait until vfp_access_check().
--- target/arm/tcg/translate-vfp.c | 61 ++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 25 deletions(-)
target/arm/tcg/translate-vfp.c +36 -25
@@ -207,6 +207,17 @@ static void gen_update_fp_context(DisasContext *s) } } +/* +* Return true if a VFP insn is OK to access D16..D31, false if +* it should UNDEF. This checks whether the D16-D31 regs are +* implemented by the CPU. Eventually we will also check CPACR.D32DIS. +* Note that Neon insns accessing D16..D31 do not need to check D32DIS. +*/ +static bool vfp_d16_d31_ok (DisasContext *s) +{ +return dc_isar_feature (aa32_simd_r32, s); +} +/* * Check that VFP access is enabled, A-profile specific version. *
@@ -347,7 +358,7 @@ static bool trans_VSEL(DisasContext *s, arg_VSEL *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (sz ==3 && !dc_isar_feature (aa32_simd_r32, s) && +if (sz ==3 && !vfp_d16_d31_ok (s) && ((a->vm | a->vn | a->vd) &0x10 )) {return false; }
@@ -473,7 +484,7 @@ static bool trans_VRINT(DisasContext *s, arg_VRINT *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (sz ==3 && !dc_isar_feature (aa32_simd_r32, s) && +if (sz ==3 && !vfp_d16_d31_ok (s) && ((a->vm | a->vd) &0x10 )) {return false; }
@@ -541,7 +552,7 @@ static bool trans_VCVT(DisasContext *s, arg_VCVT *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (sz ==3 && !dc_isar_feature (aa32_simd_r32, s) && (a->vm &0x10 )) { +if (sz ==3 && !vfp_d16_d31_ok (s) && (a->vm &0x10 )) {return false; }
@@ -662,7 +673,7 @@ static bool trans_VMOV_to_gp(DisasContext *s, arg_VMOV_to_gp *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vn &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vn &0x10 )) {return false; }
@@ -709,7 +720,7 @@ static bool trans_VMOV_from_gp(DisasContext *s, arg_VMOV_from_gp *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vn &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vn &0x10 )) {return false; }
@@ -745,7 +756,7 @@ static bool trans_VDUP(DisasContext *s, arg_VDUP *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vn &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vn &0x10 )) {return false; }
@@ -1030,7 +1041,7 @@ static bool trans_VMOV_64_dp(DisasContext *s, arg_VMOV_64_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vm &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vm &0x10 )) {return false; }
@@ -1132,7 +1143,7 @@ static bool trans_VLDR_VSTR_dp(DisasContext *s, arg_VLDR_VSTR_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vd &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vd &0x10 )) {return false; }
@@ -1261,7 +1272,7 @@ static bool trans_VLDM_VSTM_dp(DisasContext *s, arg_VLDM_VSTM_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vd + n) >16 ) { +if (!vfp_d16_d31_ok (s) && (a->vd + n) >16 ) {return false; }
@@ -1513,7 +1524,7 @@ static bool do_vfp_3op_dp(DisasContext *s, VFPGen3OpDPFn *fn, }/* UNDEF accesses to D16-D31 if they don't exist */ -if (!dc_isar_feature (aa32_simd_r32, s) && ((vd | vn | vm) &0x10 )) { +if (!vfp_d16_d31_ok (s) && ((vd | vn | vm) &0x10 )) {return false; }
@@ -1685,7 +1696,7 @@ static bool do_vfp_2op_dp(DisasContext *s, VFPGen2OpDPFn *fn, int vd, int vm)/* Note that the caller must check the aa32_fpdp_v2 feature. */ /* UNDEF accesses to D16-D31 if they don't exist */ -if (!dc_isar_feature (aa32_simd_r32, s) && ((vd | vm) &0x10 )) { +if (!vfp_d16_d31_ok (s) && ((vd | vm) &0x10 )) {return false; }
@@ -2252,7 +2263,7 @@ static bool do_vfm_dp(DisasContext *s, arg_VFMA_dp *a, bool neg_n, bool neg_d) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && +if (!vfp_d16_d31_ok (s) && ((a->vd | a->vn | a->vm) &0x10 )) {return false; }
@@ -2380,7 +2391,7 @@ static bool trans_VMOV_imm_dp(DisasContext *s, arg_VMOV_imm_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (vd &0x10 )) { +if (!vfp_d16_d31_ok (s) && (vd &0x10 )) {return false; }
@@ -2555,7 +2566,7 @@ static bool trans_VCMP_dp(DisasContext *s, arg_VCMP_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && ((a->vd | a->vm) &0x10 )) { +if (!vfp_d16_d31_ok (s) && ((a->vd | a->vm) &0x10 )) {return false; }
@@ -2621,7 +2632,7 @@ static bool trans_VCVT_f64_f16(DisasContext *s, arg_VCVT_f64_f16 *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vd &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vd &0x10 )) {return false; }
@@ -2702,7 +2713,7 @@ static bool trans_VCVT_f16_f64(DisasContext *s, arg_VCVT_f16_f64 *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vm &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vm &0x10 )) {return false; }
@@ -2777,7 +2788,7 @@ static bool trans_VRINTR_dp(DisasContext *s, arg_VRINTR_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && ((a->vd | a->vm) &0x10 )) { +if (!vfp_d16_d31_ok (s) && ((a->vd | a->vm) &0x10 )) {return false; }
@@ -2856,7 +2867,7 @@ static bool trans_VRINTZ_dp(DisasContext *s, arg_VRINTZ_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && ((a->vd | a->vm) &0x10 )) { +if (!vfp_d16_d31_ok (s) && ((a->vd | a->vm) &0x10 )) {return false; }
@@ -2930,7 +2941,7 @@ static bool trans_VRINTX_dp(DisasContext *s, arg_VRINTX_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && ((a->vd | a->vm) &0x10 )) { +if (!vfp_d16_d31_ok (s) && ((a->vd | a->vm) &0x10 )) {return false; }
@@ -2956,7 +2967,7 @@ static bool trans_VCVT_sp(DisasContext *s, arg_VCVT_sp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vd &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vd &0x10 )) {return false; }
@@ -2982,7 +2993,7 @@ static bool trans_VCVT_dp(DisasContext *s, arg_VCVT_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vm &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vm &0x10 )) {return false; }
@@ -3063,7 +3074,7 @@ static bool trans_VCVT_int_dp(DisasContext *s, arg_VCVT_int_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vd &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vd &0x10 )) {return false; }
@@ -3100,7 +3111,7 @@ static bool trans_VJCVT(DisasContext *s, arg_VJCVT *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vm &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vm &0x10 )) {return false; }
@@ -3240,7 +3251,7 @@ static bool trans_VCVT_fix_dp(DisasContext *s, arg_VCVT_fix_dp *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vd &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vd &0x10 )) {return false; }
@@ -3369,7 +3380,7 @@ static bool trans_VCVT_dp_int(DisasContext *s, arg_VCVT_dp_int *a) }/* UNDEF accesses to D16-D31 if they don't exist. */ -if (!dc_isar_feature (aa32_simd_r32, s) && (a->vm &0x10 )) { +if (!vfp_d16_d31_ok (s) && (a->vm &0x10 )) {return false; }
Signature · 1 line
2.43.0
Re: [PATCH 10/11] target/arm: Pull VFP "can we use D16-D31" checks out into a function
Quoted 12 lines · Peter Maydell
Currently we directly call
dc_isar_feature(aa32_simd_r32, s)for VFP insns that use D16-D31 to see if they should UNDEF. For some v7A CPUs (Cortex-A7, Cortex-A9) there is also a CPACR.D32DIS trap bit that will make VFP (and only VFP, not Neon) insns using D16-D31 UNDEF.Pull out a function
vfp_d16_d31_ok()that currently just does the feature check but which will provide us a place where we can make this check. Since D32DIS takes precedence over traps to EL2 and EL3 and simply makes the insns UNDEF, we are OK to do this early rather than having to wait untilvfp_access_check().
Quoted 4 lines
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/translate-vfp.c | 61 ++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 25 deletions(-)
r~
PATCH 11/11 target/arm: Implement CPACR.D32DIS
In reply to Peter MaydellOn some v7A CPUs, CPACR.D32DIS is a bit allowing the guest to make VFP instructions that touch registers D16..D31 UNDEF. Whether the CPU implements this or not is IMPDEF, and the only two CPUs we implement which have this are the Cortex-A7 and Cortex-A9. In v8A the bit is no longer defined at all.
Since the only kind of trapping that needs to be done is a simple UNDEF, this is straightforward enough to implement.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/1499
--- target/arm/cpu.h | 4 ++++ target/arm/helper.c | 19 ++++++++++++++++--- target/arm/tcg/cpu32-system.c | 2 ++ target/arm/tcg/hflags.c | 20 ++++++++++++++++++++ target/arm/tcg/translate-vfp.c | 4 ++-- target/arm/tcg/translate.c | 1 + target/arm/tcg/translate.h | 1 + 7 files changed, 46 insertions(+), 5 deletions(-)
target/arm/cpu.h +4 -0
@@ -2177,6 +2177,8 @@ enum arm_features {* Neon but not VFP. This seems to be true only for Cortex-A8. */ ARM_FEATURE_NO_NEON_TRAPS , +/* Does the CPU implement CPACR.D32DIS ? */ + ARM_FEATURE_D32DIS, };static inline int arm_feature (const CPUARMState *env,int feature)
@@ -2505,6 +2507,8 @@ FIELD(TBFLAG_A32, SME_TRAP_NONSTREAMING, 11, 1)* take precedence. */ FIELD (TBFLAG_A32 ,NEONEXC_EL ,12 ,2 ) +/* Should VFP insns touching D16..D31 UNDEF? (CPACR.D32DIS) */ +FIELD (TBFLAG_A32 ,D32DIS ,14 ,1 )/* * Bit usage when in AArch32 state, for M-profile only.
target/arm/helper.c +16 -3
@@ -570,8 +570,7 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,*/ if (cpu_isar_feature (aa32_vfp_simd,env_archcpu (env))) {/* VFP coprocessor: cp10 & cp11 [23:20] */ - mask |=R_CPACR_D32DIS_MASK | -R_CPACR_CP11_MASK | + mask |=R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ;if (!arm_feature (env,ARM_FEATURE_NEON )) {
@@ -593,6 +592,13 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,if (!cpu_isar_feature (aa32_simd_r32,env_archcpu (env))) {/* D32DIS [30] is RAO/WI if D16-31 are not implemented. */ value |=R_CPACR_D32DIS_MASK ; + mask |=R_CPACR_D32DIS_MASK ; + }else if (arm_feature (env,ARM_FEATURE_D32DIS )) { +/* +* Bit is present unless CPU doesn't implement D32DIS, +* in which case it is RAZ/WI. +*/ + mask |=R_CPACR_D32DIS_MASK ; } } value &= mask;
@@ -602,7 +608,7 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,* For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00. * Similarly, if NSACR.NSASEDIS is 1 then CPACR.ASEDIS ignores writes -* and reads as 1. +* and reads as 1, and NSACR.NSD32DIS makes CPACR.D32DIS behave as RAO/WI. */ if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && !arm_is_secure (env)) {
@@ -614,6 +620,10 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri, mask =R_CPACR_ASEDIS_MASK ; value = (value & ~mask) | (env->cp15.cpacr_el1 & mask); } +if (FIELD_EX32 (env->cp15.nsacr,NSACR ,NSD32DIS )) { + mask =R_CPACR_D32DIS_MASK ; + value = (value & ~mask) | (env->cp15.cpacr_el1 & mask); + } } env->cp15.cpacr_el1 = value;
@@ -636,6 +646,9 @@ static uint64_t cpacr_read(CPUARMState *env, const ARMCPRegInfo *ri)if (FIELD_EX32 (env->cp15.nsacr,NSACR ,NSASEDIS )) { value |=R_CPACR_ASEDIS_MASK ; } +if (FIELD_EX32 (env->cp15.nsacr,NSACR ,NSD32DIS )) { + value |=R_CPACR_D32DIS_MASK ; + } }return value; }
target/arm/tcg/cpu32-system.c +2 -0
@@ -327,6 +327,7 @@ static void cortex_a9_initfn(Object *obj)*/ set_feature (&cpu->env,ARM_FEATURE_V7MP );set_feature (&cpu->env,ARM_FEATURE_CBAR ); +set_feature (&cpu->env,ARM_FEATURE_D32DIS ); cpu->midr =0x410fc090 ; cpu->reset_fpsid =0x41033090 ; cpu->isar.mvfr0 =0x11110222 ;
@@ -393,6 +394,7 @@ static void cortex_a7_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_EL2 );set_feature (&cpu->env,ARM_FEATURE_EL3 );set_feature (&cpu->env,ARM_FEATURE_PMU ); +set_feature (&cpu->env,ARM_FEATURE_D32DIS ); cpu->midr =0x410fc075 ; cpu->reset_fpsid =0x41023075 ; cpu->isar.mvfr0 =0x10110222 ;
target/arm/tcg/hflags.c +20 -0
@@ -235,6 +235,24 @@ static int neon_exception_el(CPUARMState *env, int cur_el)return 0 ; } +static bool arm_d32dis (CPUARMState *env,int cur_el) +{ +bool cpacr_d32dis =FIELD_EX64 (env->cp15.cpacr_el1,CPACR ,D32DIS ); + +if (!arm_feature (env,ARM_FEATURE_D32DIS )) { +return false; + } + +/* If NSACR.NSD32DIS is set, CPACR.D32DIS acts as 1 in NonSecure */ +if ((arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && + cur_el <=2 && !arm_is_secure_below_el3 (env))) { +if (FIELD_EX32 (env->cp15.nsacr,NSACR ,NSD32DIS )) { + cpacr_d32dis = true; + } + } +return cpacr_d32dis; +} +static CPUARMTBFlags rebuild_hflags_a32 (CPUARMState *env,int fp_el,ARMMMUIdx mmu_idx) {
@@ -282,6 +300,8 @@ static CPUARMTBFlags rebuild_hflags_a32(CPUARMState *env, int fp_el,DP_TBFLAG_A32 (flags,NEONEXC_EL ,neon_exception_el (env, el)); +DP_TBFLAG_A32 (flags,D32DIS ,arm_d32dis (env, el)); +return rebuild_hflags_common_32 (env, fp_el, mmu_idx, flags); }
target/arm/tcg/translate-vfp.c +2 -2
@@ -210,12 +210,12 @@ static void gen_update_fp_context(DisasContext *s)/* * Return true if a VFP insn is OK to access D16..D31, false if * it should UNDEF. This checks whether the D16-D31 regs are -* implemented by the CPU. Eventually we will also check CPACR.D32DIS. +* implemented by the CPU, and whether CPACR.D32DIS permits access. * Note that Neon insns accessing D16..D31 do not need to check D32DIS. */ static bool vfp_d16_d31_ok (DisasContext *s) { -return dc_isar_feature (aa32_simd_r32, s); +return dc_isar_feature (aa32_simd_r32, s) && !s->d32dis; }/*
target/arm/tcg/translate.c +1 -0
@@ -6376,6 +6376,7 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) dc->sme_trap_nonstreaming =EX_TBFLAG_A32 (tb_flags,SME_TRAP_NONSTREAMING ); dc->neon_excp_el =EX_TBFLAG_A32 (tb_flags,NEONEXC_EL ); + dc->d32dis =EX_TBFLAG_A32 (tb_flags,D32DIS ); } dc->lse2 = false;/* applies only to aarch64 */ dc->cp_regs = cpu->cp_regs;
target/arm/tcg/translate.h +1 -0
@@ -94,6 +94,7 @@ typedef struct DisasContext {int max_svl;/* maximum implemented streaming vector length */ int max_any_vl;/* maximum implemented vector length */ bool vfp_enabled;/* FP enabled via FPSCR.EN */ +bool d32dis;/* VFP D16-D31 disabled via CPACR.D32DIS */ int vec_len;int vec_stride;bool v7m_handler_mode;
Signature · 1 line
2.43.0
Re: [PATCH 11/11] target/arm: Implement CPACR.D32DIS
Quoted 11 lines · Peter Maydell
On some v7A CPUs, CPACR.D32DIS is a bit allowing the guest to make VFP instructions that touch registers D16..D31 UNDEF. Whether the CPU implements this or not is IMPDEF, and the only two CPUs we implement which have this are the Cortex-A7 and Cortex-A9. In v8A the bit is no longer defined at all.
Since the only kind of trapping that needs to be done is a simple UNDEF, this is straightforward enough to implement.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/1499
Signed-off-by Peter Maydell <[email protected]>
Quoted 9 lines
--- target/arm/cpu.h | 4 ++++ target/arm/helper.c | 19 ++++++++++++++++--- target/arm/tcg/cpu32-system.c | 2 ++ target/arm/tcg/hflags.c | 20 ++++++++++++++++++++ target/arm/tcg/translate-vfp.c | 4 ++-- target/arm/tcg/translate.c | 1 + target/arm/tcg/translate.h | 1 + 7 files changed, 46 insertions(+), 5 deletions(-)
target/arm/tcg/translate-vfp.c static void gen_update_fp_context(DisasContext *s) · line 219
Quoted 13 lines
target/arm/tcg/translate-vfp.c +2
-2@@ -210,12 +210,12 @@ static void gen_update_fp_context(DisasContext *s)/* * Return true if a VFP insn is OK to access D16..D31, false if * it should UNDEF. This checks whether the D16-D31 regs are -* implemented by the CPU. Eventually we will also check CPACR.D32DIS. +* implemented by the CPU, and whether CPACR.D32DIS permits access. * Note that Neon insns accessing D16..D31 do not need to check D32DIS. */ static bool vfp_d16_d31_ok (DisasContext *s) { -return dc_isar_feature (aa32_simd_r32, s); +return dc_isar_feature (aa32_simd_r32, s) && !s->d32dis; }
Not that it matters much, but if we stored
s->invalid_dreg_mask = (d16_d31_ok ? 0 : 0x10);
and pass in the mask of regs like so:
static bool vfp_dregs_ok(DisasContext *s, int mask)
{
return !(mask & s->invalid_dreg_mask);
}- if (!dc_isar_feature(aa32_simd_r32, s) && ((vd | vm) & 0x10)) {
+ if (!vfp_dregs_ok(s, vd | vm)) {
then we eliminate a couple of branches and some boilerplate.
r~
Re: [PATCH 11/11] target/arm: Implement CPACR.D32DIS
Quoted 53 lines · Richard Henderson
Quoted 11 lines · Peter Maydell
On some v7A CPUs, CPACR.D32DIS is a bit allowing the guest to make VFP instructions that touch registers D16..D31 UNDEF. Whether the CPU implements this or not is IMPDEF, and the only two CPUs we implement which have this are the Cortex-A7 and Cortex-A9. In v8A the bit is no longer defined at all.
Since the only kind of trapping that needs to be done is a simple UNDEF, this is straightforward enough to implement.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/1499
Signed-off-by Peter Maydell <[email protected]>Quoted 9 lines
--- target/arm/cpu.h | 4 ++++ target/arm/helper.c | 19 ++++++++++++++++--- target/arm/tcg/cpu32-system.c | 2 ++ target/arm/tcg/hflags.c | 20 ++++++++++++++++++++ target/arm/tcg/translate-vfp.c | 4 ++-- target/arm/tcg/translate.c | 1 + target/arm/tcg/translate.h | 1 + 7 files changed, 46 insertions(+), 5 deletions(-)Reviewed-by Richard Henderson <[email protected]>target/arm/tcg/translate-vfp.c static void gen_update_fp_context(DisasContext *s) · line 219
Quoted 13 lines
target/arm/tcg/translate-vfp.c +2
-2@@ -210,12 +210,12 @@ static void gen_update_fp_context(DisasContext *s)/* * Return true if a VFP insn is OK to access D16..D31, false if * it should UNDEF. This checks whether the D16-D31 regs are -* implemented by the CPU. Eventually we will also check CPACR.D32DIS. +* implemented by the CPU, and whether CPACR.D32DIS permits access. * Note that Neon insns accessing D16..D31 do not need to check D32DIS. */ static bool vfp_d16_d31_ok (DisasContext *s) { -return dc_isar_feature (aa32_simd_r32, s); +return dc_isar_feature (aa32_simd_r32, s) && !s->d32dis; }Not that it matters much, but if we stored
s->invalid_dreg_mask = (d16_d31_ok ? 0 : 0x10);and pass in the mask of regs like so:
static bool
vfp_dregs_ok(DisasContext *s, int mask){ return !(mask & s->invalid_dreg_mask); }(quoted diff) +1
-1- if (!dc_isar_feature(aa32_simd_r32, s) && ((vd | vm) & 0x10)) { + if (!vfp_dregs_ok(s, vd | vm)) {
Quoted 1 line
then we eliminate a couple of branches and some boilerplate.
Mmm. We'd need to have separate masks for vfp and neon, though, otherwise somebody is going to be tempted to change all the uses in translate-neon.c to use this function.
-- PMM
Quoted 27 lines · Peter Maydell
There are a couple of corner cases in trapping of A32 Neon insns that have been kicking around as issues in the bug tracker for ages; I got round to fixing them today. They're related in that they both need us to distinguish Neon from VFP insns at the point of checking for traps.
The first one is a bug, where we aren't reporting the correct syndrome information for A32 VFP and Neon insns that are trapped to AArch32 EL2. These have COPROC and TA fields in the syndrome which we weren't filling in correctly. (When the trap goes to AArch64 EL2, the fields are RES0, which we do get right.) It's pretty obscure, though, and I know of no guest software which might actually care about distinguishing Neon from VFP insns in the hyp trap handler, so I don't think it worth backporting to stable.
The second one is a missing optional feature: there is a CPACR.ASEDIS bit that lets software force Neon insns to UNDEF, and also a hyp trap bit HCPTR.TACE that lets the hypervisor force Neon insns to trap to it. These are architecturally optional but in practice implemented on all CPUs except for the Cortex-A8.
The third one is another missing optional feature: CPACR.D32DIS lets software force VFP (not Neon) insns that use D16..D31 to trap. This is rather obscure as it goes away in v8A, and of the CPUs we implement it's only present in the Cortex-A7 and Cortex-A9.
Quoted 8 lines
-- PMM
Peter Maydell (11):
target/arm: Separate out Neon from VFP access checks target/arm: Separate syndrome functions for A32 and A64 target/arm: Report correct syndrome to AArch32 EL2 for trapped
Neon/VFP insns
target/arm: Define fields for NSACR
I'm going to take these four patches into target-arm.next, since the "wrong syndrome" is a bug, and the fourth patch is an uncontroversial little cleanup.
Quoted 7 lines
target/arm: Handle NSACR.NSASEDIS in CPACR accesses target/arm: Handle NSACR.NSASEDIS in HCPTR accesses target/arm: Update confusing comment in
cpacr_write()target/arm: Add new featureARM_FEATURE_NO_NEON_TRAPStarget/arm: Implement CPACR.ASEDIS and HCPTR.TASE target/arm: Pull VFP "can we use D16-D31" checks out into a function target/arm: Implement CPACR.D32DIS
These ones had review issues I need to address, and they're more on the "feature" side than the "bug fix" side, so they've missed the boat for 11.1. I'll do a v2 at some point so we can get them into 11.2.
thanks
-- PMM