target/arm: Implement FEAT_UINJ
v2 cover target/arm: Implement FEAT_UINJ
Changes for v2:
- Reorganize rebuild_hflags_common*.
Trying to force a tail call for these was perhaps just confusing. Inverting the order means that we can handle initialization once in a common way, and the lifetime of some of the parameters is shortened.
- Introduce rebuild_hflags_common_aprofile.
This gives us a common place for the new UINJ test in hflags.
- Introduce check_il_uinj.
This gives us a common place for the new UINJ test in translation.
r~
Richard Henderson (14):
target/arm: Parenthesize tbflags arguments in TBFLAG macros target/arm: Reorg rebuild_hflags_common* target/arm: Split out rebuild_hflags_common_aprofile target/arm: Sort BE_DATA toward the top of rebuild_hflags_a64 target/arm: Move ID_AA64PFR2 feature tests together target/arm: Add isar_feature_aa64_uinj
target/arm: Drop U from most PSTATE bits target/arm: Clear PSTATE.UINJ when taking exceptions target/arm: Widen cpsr_{read,write}_for_spsr_elx to uint64_t target/arm: Read and write PSTATE.UINJ
target/arm: Add PSTATE.UINJ to tbflags
target/arm: Split out check_il
target/arm: Honor PSTATE.UINJ during translation target/arm: Enable FEAT_UINJ for -cpu max-v9
docs/system/arm/emulation.rst | 1 + target/arm/cpu-features.h | 26 +++++--- target/arm/cpu.h | 62 ++++++++--------- target/arm/internals.h | 7 +- target/arm/tcg/translate.h | 3 + target/arm/helper.c | 28 ++++++-- target/arm/tcg/cpu64.c | 1 + target/arm/tcg/helper-a64.c | 2 + target/arm/tcg/hflags.c | 118 ++++++++++++++++----------------- target/arm/tcg/translate-a64.c | 8 +-- target/arm/tcg/translate.c | 33 +++++---- 11 files changed, 165 insertions(+), 124 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/14 target/arm: Parenthesize tbflags arguments in TBFLAG macros
--- target/arm/cpu.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
target/arm/cpu.h +10 -10
@@ -2583,21 +2583,21 @@ FIELD(TBFLAG_A64, MTX, 49, 2)* word either is or might be 32 bits only. */ #define DP_TBFLAG_ANY (DST ,WHICH ,VAL ) \ - (DST.flags = FIELD_DP32(DST.flags, TBFLAG_ANY, WHICH, VAL)) + ((DST).flags = FIELD_DP32((DST).flags, TBFLAG_ANY, WHICH, VAL))#define DP_TBFLAG_A64 (DST ,WHICH ,VAL ) \ - (DST.flags2 = FIELD_DP64(DST.flags2, TBFLAG_A64, WHICH, VAL)) + ((DST).flags2 = FIELD_DP64((DST).flags2, TBFLAG_A64, WHICH, VAL))#define DP_TBFLAG_A32 (DST ,WHICH ,VAL ) \ - (DST.flags2 = FIELD_DP32(DST.flags2, TBFLAG_A32, WHICH, VAL)) + ((DST).flags2 = FIELD_DP32((DST).flags2, TBFLAG_A32, WHICH, VAL))#define DP_TBFLAG_M32 (DST ,WHICH ,VAL ) \ - (DST.flags2 = FIELD_DP32(DST.flags2, TBFLAG_M32, WHICH, VAL)) + ((DST).flags2 = FIELD_DP32((DST).flags2, TBFLAG_M32, WHICH, VAL))#define DP_TBFLAG_AM32 (DST ,WHICH ,VAL ) \ - (DST.flags2 = FIELD_DP32(DST.flags2, TBFLAG_AM32, WHICH, VAL)) + ((DST).flags2 = FIELD_DP32((DST).flags2, TBFLAG_AM32, WHICH, VAL)) -#define EX_TBFLAG_ANY (IN ,WHICH ) FIELD_EX32(IN.flags, TBFLAG_ANY, WHICH) -#define EX_TBFLAG_A64 (IN ,WHICH ) FIELD_EX64(IN.flags2, TBFLAG_A64, WHICH) -#define EX_TBFLAG_A32 (IN ,WHICH ) FIELD_EX32(IN.flags2, TBFLAG_A32, WHICH) -#define EX_TBFLAG_M32 (IN ,WHICH ) FIELD_EX32(IN.flags2, TBFLAG_M32, WHICH) -#define EX_TBFLAG_AM32 (IN ,WHICH ) FIELD_EX32(IN.flags2, TBFLAG_AM32, WHICH) +#define EX_TBFLAG_ANY (IN ,WHICH ) FIELD_EX32((IN).flags, TBFLAG_ANY, WHICH) +#define EX_TBFLAG_A64 (IN ,WHICH ) FIELD_EX64((IN).flags2, TBFLAG_A64, WHICH) +#define EX_TBFLAG_A32 (IN ,WHICH ) FIELD_EX32((IN).flags2, TBFLAG_A32, WHICH) +#define EX_TBFLAG_M32 (IN ,WHICH ) FIELD_EX32((IN).flags2, TBFLAG_M32, WHICH) +#define EX_TBFLAG_AM32 (IN ,WHICH ) FIELD_EX32((IN).flags2, TBFLAG_AM32, WHICH)/** * sve_vq
Signature · 1 line
2.53.0
Re: [PATCH v2 01/14] target/arm: Parenthesize tbflags arguments in TBFLAG macros
Quoted 10 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)target/arm/cpu.h +0
-0
target/arm/cpu.h FIELD(TBFLAG_A64, MTX, 49, 2) · line 2586
Quoted 5 lines
target/arm/cpu.h +1
-1@@ -2583,21 +2583,21 @@ FIELD(TBFLAG_A64, MTX, 49, 2)* word either is or might be 32 bits only. */ #define DP_TBFLAG_ANY (DST ,WHICH ,VAL ) \ - (DST.flags = FIELD_DP32(DST.flags, TBFLAG_ANY, WHICH, VAL)) + ((DST).flags = FIELD_DP32((DST).flags, TBFLAG_ANY, WHICH, VAL))
Subject mentions "tbflags arguments" but only add parenthesis to the @DST argument. I understand @WHICH and @VAL are likely safe, so simply update the subject?
PATCH v2 2/14 target/arm: Reorg rebuild_hflags_common*
In reply to Richard HendersonInvert the call ordering of rebuild_hflags_common_32 and rebuild_hflags_common vs the rest of the flags setting.
--- target/arm/tcg/hflags.c | 44 +++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-)
target/arm/tcg/hflags.c +23 -21
@@ -87,9 +87,10 @@ bool access_secure_reg(CPUARMState *env) }static CPUARMTBFlags rebuild_hflags_common (CPUARMState *env,int fp_el, -ARMMMUIdx mmu_idx, -CPUARMTBFlags flags) +ARMMMUIdx mmu_idx) { +CPUARMTBFlags flags = {}; +DP_TBFLAG_ANY (flags,FPEXC_EL , fp_el);DP_TBFLAG_ANY (flags,MMUIDX ,arm_to_core_mmu_idx (mmu_idx));
@@ -100,28 +101,27 @@ static CPUARMTBFlags rebuild_hflags_common(CPUARMState *env, int fp_el,return flags; } -static CPUARMTBFlags rebuild_hflags_common_32 (CPUARMState *env,int fp_el, -ARMMMUIdx mmu_idx, -CPUARMTBFlags flags) +static void rebuild_hflags_common_32 (CPUARMTBFlags *flags,CPUARMState *env) {bool sctlr_b =arm_sctlr_b (env);if (sctlr_b) { -DP_TBFLAG_A32 (flags,SCTLR__B ,1 ); +DP_TBFLAG_A32 (*flags,SCTLR__B ,1 ); }if (arm_cpu_data_is_big_endian_a32 (env, sctlr_b)) { -DP_TBFLAG_ANY (flags,BE_DATA ,1 ); +DP_TBFLAG_ANY (*flags,BE_DATA ,1 ); } -DP_TBFLAG_A32 (flags,NS , !access_secure_reg (env)); - -return rebuild_hflags_common (env, fp_el, mmu_idx, flags); +DP_TBFLAG_A32 (*flags,NS , !access_secure_reg (env)); }static CPUARMTBFlags rebuild_hflags_m32 (CPUARMState *env,int fp_el,ARMMMUIdx mmu_idx) { -CPUARMTBFlags flags = {}; -uint32_t ccr = env->v7m.ccr[env->v7m.secure]; +CPUARMTBFlags flags =rebuild_hflags_common (env, fp_el, mmu_idx); +uint32_t ccr; + +rebuild_hflags_common_32 (&flags, env); + ccr = env->v7m.ccr[env->v7m.secure];/* Without HaveMainExt, CCR.UNALIGN_TRP is RES1. */ if (ccr &R_V7M_CCR_UNALIGN_TRP_MASK ) {
@@ -146,8 +146,7 @@ static CPUARMTBFlags rebuild_hflags_m32(CPUARMState *env, int fp_el,if (arm_feature (env,ARM_FEATURE_M_SECURITY ) && env->v7m.secure) {DP_TBFLAG_M32 (flags,SECURE ,1 ); } - -return rebuild_hflags_common_32 (env, fp_el, mmu_idx, flags); +return flags; }/* This corresponds to the ARM pseudocode function IsFullA64Enabled(). */
@@ -277,10 +276,14 @@ static bool arm_d32dis(CPUARMState *env, int cur_el)static CPUARMTBFlags rebuild_hflags_a32 (CPUARMState *env,int fp_el,ARMMMUIdx mmu_idx) { -CPUARMTBFlags flags = {}; -int el =arm_current_el (env); -uint64_t sctlr =arm_sctlr (env, el); +CPUARMTBFlags flags =rebuild_hflags_common (env, fp_el, mmu_idx); +int el; +uint64_t sctlr; +rebuild_hflags_common_32 (&flags, env); + + el =arm_current_el (env); + sctlr =arm_sctlr (env, el);if (aprofile_require_alignment (env, el, sctlr)) {DP_TBFLAG_ANY (flags,ALIGN_MEM ,1 ); }
@@ -323,7 +326,7 @@ static CPUARMTBFlags rebuild_hflags_a32(CPUARMState *env, int fp_el,DP_TBFLAG_A32 (flags,D32DIS ,arm_d32dis (env, el)); -return rebuild_hflags_common_32 (env, fp_el, mmu_idx, flags); +return flags; }/*
@@ -392,7 +395,7 @@ static int fpmr_exception_el(CPUARMState *env, int el)static CPUARMTBFlags rebuild_hflags_a64 (CPUARMState *env,int el,int fp_el,ARMMMUIdx mmu_idx) { -CPUARMTBFlags flags = {}; +CPUARMTBFlags flags =rebuild_hflags_common (env, fp_el, mmu_idx);ARMMMUIdx stage1 =stage_1_mmu_idx (mmu_idx);uint64_t tcr =regime_tcr (env, mmu_idx);uint64_t hcr =arm_hcr_el2_eff (env);
@@ -672,8 +675,7 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,if (cpu_isar_feature (aa64_fpmr,env_archcpu (env))) {DP_TBFLAG_A64 (flags,FPMR_EL ,fpmr_exception_el (env, el)); } - -return rebuild_hflags_common (env, fp_el, mmu_idx, flags); +return flags; }static CPUARMTBFlags rebuild_hflags_internal (CPUARMState *env)
Signature · 1 line
2.53.0
Re: [PATCH v2 02/14] target/arm: Reorg rebuild_hflags_common*
Quoted 5 lines · Richard Henderson
Invert the call ordering of
rebuild_hflags_common_32andrebuild_hflags_commonvs the rest of the flags setting.Signed-off-by Richard Henderson <[email protected]>
We do have "set a TB flag and then later in the hflags calculation functions read it back" dependencies in a couple of places:
UNPRIV, ATA, FGT_ACTIVE, PSTATE_SM -- but in all four cases these flags are both set and read inside rebuild_hflags_a64(), so reordering whether we do the common flags first or last doesn't move the "read" before the "set", so it's OK.
thanks
-- PMM
PATCH v2 3/14 target/arm: Split out rebuild_hflags_common_aprofile
In reply to Richard HendersonAlignment, FGT, and IL are common to a32 and a64, though the latter comes from different places.
--- target/arm/tcg/hflags.c | 65 +++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 35 deletions(-)
target/arm/tcg/hflags.c +30 -35
@@ -114,6 +114,24 @@ static void rebuild_hflags_common_32(CPUARMTBFlags *flags, CPUARMState *env)DP_TBFLAG_A32 (*flags,NS , !access_secure_reg (env)); } +static void rebuild_hflags_common_aprofile (CPUARMTBFlags *flags, +CPUARMState *env,int el, +uint64_t sctlr,bool il) +{ +if (il) { +DP_TBFLAG_ANY (*flags,PSTATE__IL ,1 ); + } +if (aprofile_require_alignment (env, el, sctlr)) { +DP_TBFLAG_ANY (*flags,ALIGN_MEM ,1 ); + } +if (arm_fgt_active (env, el)) { +DP_TBFLAG_ANY (*flags,FGT_ACTIVE ,1 ); +if (fgt_svc (env, el)) { +DP_TBFLAG_ANY (*flags,FGT_SVC ,1 ); + } + } +} +static CPUARMTBFlags rebuild_hflags_m32 (CPUARMState *env,int fp_el,ARMMMUIdx mmu_idx) {
@@ -284,9 +302,8 @@ static CPUARMTBFlags rebuild_hflags_a32(CPUARMState *env, int fp_el, el =arm_current_el (env); sctlr =arm_sctlr (env, el); -if (aprofile_require_alignment (env, el, sctlr)) { -DP_TBFLAG_ANY (flags,ALIGN_MEM ,1 ); - } +rebuild_hflags_common_aprofile (&flags, env, el, sctlr, + env->uncached_cpsr &CPSR_IL );if (arm_el_is_aa64 (env,1 )) {DP_TBFLAG_A32 (flags,VFPEN ,1 );
@@ -297,17 +314,6 @@ static CPUARMTBFlags rebuild_hflags_a32(CPUARMState *env, int fp_el,DP_TBFLAG_A32 (flags,HSTR_ACTIVE ,1 ); } -if (arm_fgt_active (env, el)) { -DP_TBFLAG_ANY (flags,FGT_ACTIVE ,1 ); -if (fgt_svc (env, el)) { -DP_TBFLAG_ANY (flags,FGT_SVC ,1 ); - } - } - -if (env->uncached_cpsr &CPSR_IL ) { -DP_TBFLAG_ANY (flags,PSTATE__IL ,1 ); - } -/* * The SME exception we are testing for is raised via * AArch64.CheckFPAdvSIMDEnabled(), as called from
@@ -397,14 +403,17 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, {CPUARMTBFlags flags =rebuild_hflags_common (env, fp_el, mmu_idx);ARMMMUIdx stage1 =stage_1_mmu_idx (mmu_idx); -uint64_t tcr =regime_tcr (env, mmu_idx); -uint64_t hcr =arm_hcr_el2_eff (env); -uint64_t sctlr; +uint64_t sctlr =regime_sctlr (env, stage1); +uint64_t tcr, hcr;int tbii, tbid, mtx; +rebuild_hflags_common_aprofile (&flags, env, el, sctlr, + env->pstate &PSTATE_IL ); +DP_TBFLAG_ANY (flags,AARCH64_STATE ,1 );/* Get control bits for tagged addresses. */ + tcr =regime_tcr (env, mmu_idx); tbid =aa64_va_parameter_tbi (tcr, mmu_idx); tbii = tbid & ~aa64_va_parameter_tbid (tcr, mmu_idx); mtx = cpu_isar_feature(aa64_mte_mtx, env_archcpu(env)) ?
@@ -415,6 +424,7 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,DP_TBFLAG_A64 (flags,TBID , tbid);/* E2H is used by both VHE and NV2. */ + hcr =arm_hcr_el2_eff (env);if (hcr &HCR_E2H ) {DP_TBFLAG_A64 (flags,E2H ,1 ); }
@@ -465,12 +475,6 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, } } - sctlr =regime_sctlr (env, stage1); - -if (aprofile_require_alignment (env, el, sctlr)) { -DP_TBFLAG_ANY (flags,ALIGN_MEM ,1 ); - } -if (arm_cpu_data_is_big_endian_a64 (el, sctlr)) {DP_TBFLAG_ANY (flags,BE_DATA ,1 ); }
@@ -525,18 +529,9 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, } } -if (env->pstate &PSTATE_IL ) { -DP_TBFLAG_ANY (flags,PSTATE__IL ,1 ); - } - -if (arm_fgt_active (env, el)) { -DP_TBFLAG_ANY (flags,FGT_ACTIVE ,1 ); -if (FIELD_EX64 (env->cp15.fgt_exec[FGTREG_HFGITR ],HFGITR_EL2 ,ERET )) { -DP_TBFLAG_A64 (flags,TRAP_ERET ,1 ); - } -if (fgt_svc (env, el)) { -DP_TBFLAG_ANY (flags,FGT_SVC ,1 ); - } +if (EX_TBFLAG_ANY (flags,FGT_ACTIVE ) && +FIELD_EX64 (env->cp15.fgt_exec[FGTREG_HFGITR ],HFGITR_EL2 ,ERET )) { +DP_TBFLAG_A64 (flags,TRAP_ERET ,1 ); }/*
Signature · 1 line
2.53.0
Re: [PATCH v2 03/14] target/arm: Split out rebuild_hflags_common_aprofile
Quoted 6 lines · Richard Henderson
Alignment, FGT, and IL are common to a32 and a64, though the latter comes from different places.
Signed-off-by Richard Henderson <[email protected]>---
This doesn't break the set-read ordering for FGT_ACTIVE in rebuild_hflags_a64(), because it moves the set earlier than it was, so that's OK.
thanks
-- PMM
PATCH v2 4/14 target/arm: Sort BE_DATA toward the top of rebuild_hflags_a64
In reply to Richard HendersonThis is the last of the "ANY" class of flags. Sort to the top with the other "ANY" flags.
--- target/arm/tcg/hflags.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/arm/tcg/hflags.c +4 -4
@@ -412,6 +412,10 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,DP_TBFLAG_ANY (flags,AARCH64_STATE ,1 ); +if (arm_cpu_data_is_big_endian_a64 (el, sctlr)) { +DP_TBFLAG_ANY (flags,BE_DATA ,1 ); + } +/* Get control bits for tagged addresses. */ tcr =regime_tcr (env, mmu_idx); tbid =aa64_va_parameter_tbi (tcr, mmu_idx);
@@ -475,10 +479,6 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, } } -if (arm_cpu_data_is_big_endian_a64 (el, sctlr)) { -DP_TBFLAG_ANY (flags,BE_DATA ,1 ); - } -if (cpu_isar_feature (aa64_pauth,env_archcpu (env))) {/* * In order to save space in flags, we record only whether
Signature · 1 line
2.53.0
Re: [PATCH v2 04/14] target/arm: Sort BE_DATA toward the top of rebuild_hflags_a64
Quoted 7 lines · Richard Henderson
This is the last of the "ANY" class of flags. Sort to the top with the other "ANY" flags.
Signed-off-by Richard Henderson <[email protected]>--- target/arm/tcg/hflags.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
PATCH v2 5/14 target/arm: Move ID_AA64PFR2 feature tests together
In reply to Richard HendersonCurrently the MTE feature tests are clustered together, but those are spread across two ID registers. Sort the functions by ID reg and bitfield order, like most others.
--- target/arm/cpu-features.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
target/arm/cpu-features.h +10 -10
@@ -1207,16 +1207,6 @@ static inline bool isar_feature_aa64_mte3(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64PFR1 ,MTE ) >=3 ; } -static inline bool isar_feature_aa64_mteperm (const ARMISARegisters *id) -{ -return FIELD_EX64_IDREG (id,ID_AA64PFR2 ,MTEPERM ) >=1 ; -} - -static inline bool isar_feature_aa64_mte_store_only (const ARMISARegisters *id) -{ -return FIELD_EX64_IDREG (id,ID_AA64PFR2 ,MTESTOREONLY ) ==1 ; -} -static inline bool isar_feature_aa64_mte_mtx (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64PFR1 ,MTEX ) !=0 ;
@@ -1237,6 +1227,16 @@ static inline bool isar_feature_aa64_gcs(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64PFR1 ,GCS ) !=0 ; } +static inline bool isar_feature_aa64_mteperm (const ARMISARegisters *id) +{ +return FIELD_EX64_IDREG (id,ID_AA64PFR2 ,MTEPERM ) >=1 ; +} + +static inline bool isar_feature_aa64_mte_store_only (const ARMISARegisters *id) +{ +return FIELD_EX64_IDREG (id,ID_AA64PFR2 ,MTESTOREONLY ) ==1 ; +} +static inline bool isar_feature_aa64_gcie (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64PFR2 ,GCIE ) !=0 ;
Signature · 1 line
2.53.0
PATCH v2 6/14 target/arm: Add isar_feature_aa64_uinj
In reply to Richard Henderson--- target/arm/cpu-features.h | 6 ++++++ 1 file changed, 6 insertions(+)
target/arm/cpu-features.h +6 -0
@@ -290,6 +290,7 @@ FIELD(ID_AA64PFR2, MTEPERM, 0, 4) FIELD(ID_AA64PFR2, MTESTOREONLY, 4, 4) FIELD(ID_AA64PFR2, MTEFAR, 8, 4) FIELD(ID_AA64PFR2, GCIE, 12, 4) +FIELD(ID_AA64PFR2, UINJ, 16, 4) FIELD(ID_AA64PFR2, FPMR, 32, 4)FIELD (ID_AA64MMFR0 ,PARANGE ,0 ,4 )
@@ -1242,6 +1243,11 @@ static inline bool isar_feature_aa64_gcie(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64PFR2 ,GCIE ) !=0 ; } +static inline bool isar_feature_aa64_uinj (const ARMISARegisters *id) +{ +return FIELD_EX64_IDREG (id,ID_AA64PFR2 ,UINJ ) !=0 ; +} +static inline bool isar_feature_aa64_fpmr (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64PFR2 ,FPMR ) !=0 ;
Signature · 1 line
2.53.0
Re: [PATCH v2 06/14] target/arm: Add isar_feature_aa64_uinj
Quoted 5 lines · Richard Henderson
Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu-features.h | 6 ++++++ 1 file changed, 6 insertions(+)
PATCH v2 7/14 target/arm: Drop U from most PSTATE bits
In reply to Richard HendersonPSTATE is already 64-bit, but many bits are defined such that ~PSTATE_FOO accidentally clears the high bits.
Except for PSTATE_N, we can just drop the qualifier.
--- target/arm/cpu.h | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
target/arm/cpu.h +20 -20
@@ -1558,26 +1558,26 @@ void pmu_init(ARMCPU *cpu);* Only these are valid when in AArch64 mode; in * AArch32 mode SPSRs are basically CPSR-format. */ -#define PSTATE_SP (1U) -#define PSTATE_M (0xFU) -#define PSTATE_nRW (1U << 4) -#define PSTATE_F (1U << 6) -#define PSTATE_I (1U << 7) -#define PSTATE_A (1U << 8) -#define PSTATE_D (1U << 9) -#define PSTATE_BTYPE (3U << 10) -#define PSTATE_SSBS (1U << 12) -#define PSTATE_ALLINT (1U << 13) -#define PSTATE_IL (1U << 20) -#define PSTATE_SS (1U << 21) -#define PSTATE_PAN (1U << 22) -#define PSTATE_UAO (1U << 23) -#define PSTATE_DIT (1U << 24) -#define PSTATE_TCO (1U << 25) -#define PSTATE_V (1U << 28) -#define PSTATE_C (1U << 29) -#define PSTATE_Z (1U << 30) -#define PSTATE_N (1U << 31) +#define PSTATE_SP (1) +#define PSTATE_M (0xF) +#define PSTATE_nRW (1 << 4) +#define PSTATE_F (1 << 6) +#define PSTATE_I (1 << 7) +#define PSTATE_A (1 << 8) +#define PSTATE_D (1 << 9) +#define PSTATE_BTYPE (3 << 10) +#define PSTATE_SSBS (1 << 12) +#define PSTATE_ALLINT (1 << 13) +#define PSTATE_IL (1 << 20) +#define PSTATE_SS (1 << 21) +#define PSTATE_PAN (1 << 22) +#define PSTATE_UAO (1 << 23) +#define PSTATE_DIT (1 << 24) +#define PSTATE_TCO (1 << 25) +#define PSTATE_V (1 << 28) +#define PSTATE_C (1 << 29) +#define PSTATE_Z (1 << 30) +#define PSTATE_N (1ULL << 31)#define PSTATE_EXLOCK (1ULL << 34)#define PSTATE_NZCV (PSTATE_N | PSTATE_Z | PSTATE_C | PSTATE_V)#define PSTATE_DAIF (PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F)
Signature · 1 line
2.53.0
PATCH v2 8/14 target/arm: Clear PSTATE.UINJ when taking exceptions
In reply to Richard HendersonClear UINJ when taking an exception.
Clear UINJ when exception return is invalid.
In both cases, perform the clear without feature check, since the bit is otherwise RES0.
--- target/arm/cpu.h | 1 + target/arm/helper.c | 9 +++++++++ target/arm/tcg/helper-a64.c | 2 ++ 3 files changed, 12 insertions(+)
target/arm/cpu.h +1 -0
@@ -1579,6 +1579,7 @@ void pmu_init(ARMCPU *cpu);#define PSTATE_Z (1 << 30)#define PSTATE_N (1ULL << 31)#define PSTATE_EXLOCK (1ULL << 34) +#define PSTATE_UINJ (1ULL << 36)#define PSTATE_NZCV (PSTATE_N | PSTATE_Z | PSTATE_C | PSTATE_V)#define PSTATE_DAIF (PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F)#define CACHED_PSTATE_BITS (PSTATE_NZCV | PSTATE_DAIF | PSTATE_BTYPE)
target/arm/helper.c +9 -0
@@ -9606,6 +9606,15 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) env->condexec_bits =0 ; } + +/* +* R_XKSNJ: If FEAT_UINJ, PSTATE.UINJ is set to 0 *and* the resulting +* value stored in SPSR_ELx is 0. The new PSTATE is automatically +* handled by construction of a new value from 0; clear it from the +* old state and as UINJ is RES0 otherwise, skip the feature check. +*/ + old_mode &= ~PSTATE_UINJ ; + env->banked_spsr[aarch64_banked_spsr_index (new_el)] = old_mode;qemu_log_mask (CPU_LOG_INT ,"...with SPSR 0x%" PRIx64"\n" , old_mode);
target/arm/tcg/helper-a64.c +2 -0
@@ -764,10 +764,12 @@ illegal_return:* mandated behaviour: * restore NZCV and DAIF from SPSR_ELx * set PSTATE.IL +* reset PSTATE.UINJ * restore PC from ELR_ELx * no change to exception level, execution state or stack pointer */ env->pstate |=PSTATE_IL ; + env->pstate &= ~PSTATE_UINJ ; env->pc = new_pc; spsr &=PSTATE_NZCV |PSTATE_DAIF |PSTATE_ALLINT ; spsr |=pstate_read (env) & ~(PSTATE_NZCV |PSTATE_DAIF |PSTATE_ALLINT );
Signature · 1 line
2.53.0
Re: [PATCH v2 08/14] target/arm: Clear PSTATE.UINJ when taking exceptions
Quoted 6 lines · Richard Henderson
Clear UINJ when taking an exception.
Clear UINJ when exception return is invalid.In both cases, perform the clear without feature check, since the bit is otherwise RES0.
Quoted 7 lines
Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 1 + target/arm/helper.c | 9 +++++++++ target/arm/tcg/helper-a64.c | 2 ++ 3 files changed, 12 insertions(+)
PATCH v2 9/14 target/arm: Widen cpsr_{read, write}_for_spsr_elx to uint64_t
In reply to Richard HendersonWe will shortly need to handle bit 36: PSTATE.UINJ.
--- target/arm/internals.h | 4 ++-- target/arm/helper.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
target/arm/internals.h +2 -2
@@ -2016,8 +2016,8 @@ void vfp_clear_float_status_exc_flags(CPUARMState *env);*/ void vfp_set_fpcr_to_host (CPUARMState *env,uint32_t val,uint32_t mask);bool arm_pan_enabled (CPUARMState *env); -uint32_t cpsr_read_for_spsr_elx (CPUARMState *env); -void cpsr_write_from_spsr_elx (CPUARMState *env,uint32_t val); +uint64_t cpsr_read_for_spsr_elx (CPUARMState *env); +void cpsr_write_from_spsr_elx (CPUARMState *env,uint64_t val);/* Compare uint64_t for qsort and bsearch. */ int compare_u64 (const void *a,const void *b);
target/arm/helper.c +3 -3
@@ -9376,9 +9376,9 @@ static int aarch64_regnum(CPUARMState *env, int aarch32_reg) } } -uint32_t cpsr_read_for_spsr_elx (CPUARMState *env) +uint64_t cpsr_read_for_spsr_elx (CPUARMState *env) { -uint32_t ret =cpsr_read (env); +uint64_t ret =cpsr_read (env);/* Move DIT to the correct location for SPSR_ELx */ if (ret &CPSR_DIT ) {
@@ -9391,7 +9391,7 @@ uint32_t cpsr_read_for_spsr_elx(CPUARMState *env)return ret; } -void cpsr_write_from_spsr_elx (CPUARMState *env,uint32_t val) +void cpsr_write_from_spsr_elx (CPUARMState *env,uint64_t val) {uint32_t mask;
Signature · 1 line
2.53.0
PATCH v2 10/14 target/arm: Read and write PSTATE.UINJ
In reply to Richard HendersonWith FEAT_UINJ, allow PSTATE.UINJ to be set from aa64 and aa32 modes. Read the value back for SPSR_ELx from aa32 mode.
--- target/arm/internals.h | 3 +++ target/arm/helper.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
target/arm/internals.h +3 -0
@@ -1392,6 +1392,9 @@ static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id)if (isar_feature_aa64_nmi (id)) { valid |=PSTATE_ALLINT ; } +if (isar_feature_aa64_uinj (id)) { + valid |=PSTATE_UINJ ; + }return valid; }
target/arm/helper.c +11 -2
@@ -9385,8 +9385,9 @@ uint64_t cpsr_read_for_spsr_elx(CPUARMState *env) ret &= ~CPSR_DIT ; ret |=PSTATE_DIT ; } -/* Merge PSTATE.SS into SPSR_ELx */ - ret |= env->pstate &PSTATE_SS ; + +/* Merge PSTATE.{SS,UINJ} into SPSR_ELx */ + ret |= env->pstate & (PSTATE_SS |PSTATE_UINJ );return ret; }
@@ -9395,6 +9396,14 @@ void cpsr_write_from_spsr_elx(CPUARMState *env, uint64_t val) {uint32_t mask; +/* Save SPSR_ELx.UINJ into PSTATE. */ +if (unlikely (val &PSTATE_UINJ ) + &&arm_feature (env,ARM_FEATURE_AARCH64 ) + &&cpu_isar_feature (aa64_uinj,env_archcpu (env))) { + env->pstate |=PSTATE_UINJ ; + val &= ~PSTATE_UINJ ; + } +/* Save SPSR_ELx.SS into PSTATE. */ env->pstate = (env->pstate & ~PSTATE_SS ) | (val &PSTATE_SS ); val &= ~PSTATE_SS ;
Signature · 1 line
2.53.0
PATCH v2 11/14 target/arm: Add PSTATE.UINJ to tbflags
In reply to Richard Henderson--- target/arm/cpu.h | 1 + target/arm/tcg/translate.h | 2 ++ target/arm/tcg/hflags.c | 3 +++ target/arm/tcg/translate-a64.c | 1 + target/arm/tcg/translate.c | 1 + 5 files changed, 8 insertions(+)
target/arm/cpu.h +1 -0
@@ -2483,6 +2483,7 @@ FIELD(TBFLAG_ANY, ALIGN_MEM, 10, 1) FIELD(TBFLAG_ANY, PSTATE__IL, 11, 1) FIELD(TBFLAG_ANY, FGT_ACTIVE, 12, 1) FIELD(TBFLAG_ANY, FGT_SVC, 13, 1) +FIELD (TBFLAG_ANY ,PSTATE__UINJ ,14 ,1 )/* * Bit usage when in AArch32 state, both A- and M-profile.
target/arm/tcg/translate.h +2 -0
@@ -155,6 +155,8 @@ typedef struct DisasContext {bool align_mem;/* True if PSTATE.IL is set */ bool pstate_il; +/* True if PSTATE.UINJ is set */ +bool pstate_uinj;/* True if PSTATE.SM is set. */ bool pstate_sm;/* True if PSTATE.ZA is set. */
target/arm/tcg/hflags.c +3 -0
@@ -121,6 +121,9 @@ static void rebuild_hflags_common_aprofile(CPUARMTBFlags *flags,if (il) {DP_TBFLAG_ANY (*flags,PSTATE__IL ,1 ); } +if (env->pstate &PSTATE_UINJ ) { +DP_TBFLAG_ANY (*flags,PSTATE__UINJ ,1 ); + }if (aprofile_require_alignment (env, el, sctlr)) {DP_TBFLAG_ANY (*flags,ALIGN_MEM ,1 ); }
target/arm/tcg/translate-a64.c +1 -0
@@ -11028,6 +11028,7 @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, dc->fp_excp_el =EX_TBFLAG_ANY (tb_flags,FPEXC_EL ); dc->align_mem =EX_TBFLAG_ANY (tb_flags,ALIGN_MEM ); dc->pstate_il =EX_TBFLAG_ANY (tb_flags,PSTATE__IL ); + dc->pstate_uinj =EX_TBFLAG_ANY (tb_flags,PSTATE__UINJ ); dc->fgt_active =EX_TBFLAG_ANY (tb_flags,FGT_ACTIVE ); dc->fgt_svc =EX_TBFLAG_ANY (tb_flags,FGT_SVC ); dc->trap_eret =EX_TBFLAG_A64 (tb_flags,TRAP_ERET );
target/arm/tcg/translate.c +1 -0
@@ -6418,6 +6418,7 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) dc->fp_excp_el =EX_TBFLAG_ANY (tb_flags,FPEXC_EL ); dc->align_mem =EX_TBFLAG_ANY (tb_flags,ALIGN_MEM ); dc->pstate_il =EX_TBFLAG_ANY (tb_flags,PSTATE__IL ); + dc->pstate_uinj =EX_TBFLAG_ANY (tb_flags,PSTATE__UINJ ); dc->fgt_active =EX_TBFLAG_ANY (tb_flags,FGT_ACTIVE ); dc->fgt_svc =EX_TBFLAG_ANY (tb_flags,FGT_SVC );
Signature · 1 line
2.53.0
Re: [PATCH v2 11/14] target/arm: Add PSTATE.UINJ to tbflags
Quoted 9 lines · Richard Henderson
Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 1 + target/arm/tcg/translate.h | 2 ++ target/arm/tcg/hflags.c | 3 +++ target/arm/tcg/translate-a64.c | 1 + target/arm/tcg/translate.c | 1 + 5 files changed, 8 insertions(+)
PATCH v2 12/14 target/arm: Split out check_il
In reply to Richard Henderson--- target/arm/tcg/translate.h | 1 + target/arm/tcg/translate-a64.c | 7 +------ target/arm/tcg/translate.c | 28 ++++++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-)
target/arm/tcg/translate.h +1 -0
@@ -382,6 +382,7 @@ void arm_jump_cc(DisasCompare *cmp, TCGLabel *label);void arm_gen_test_cc (int cc,TCGLabel *label);MemOp pow2_align (unsigned i);void unallocated_encoding (DisasContext *s); +bool check_il (DisasContext *s);void gen_exception_internal (int excp);void gen_exception_insn_el (DisasContext *s,int64_t pc_diff,int excp,uint32_t syn,uint32_t target_el);
target/arm/tcg/translate-a64.c +1 -6
@@ -11174,12 +11174,7 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) s->fp_access_checked =0 ; s->sve_access_checked =0 ; -if (s->pstate_il) { -/* -* Illegal execution state. This has priority over BTI -* exceptions, but comes after instruction abort exceptions. -*/ -gen_exception_insn (s,0 ,EXCP_UDEF ,syn_illegalstate ()); +if (check_il (s)) {return ; }
target/arm/tcg/translate.c +16 -12
@@ -1159,6 +1159,20 @@ void unallocated_encoding(DisasContext *s)gen_exception_insn (s,0 ,EXCP_UDEF ,syn_uncategorized ()); } +/* +* These conditions have less priority than instruction abort, and thus +* must be checked after reading the instruction. They have more priority +* than the AArch64 BTI exception. +*/ +bool check_il (DisasContext *s) +{ +if (s->pstate_il) { +gen_exception_insn (s,0 ,EXCP_UDEF ,syn_illegalstate ()); +return true; + } +return false; +} +/* Force a TB lookup after an instruction that changes the CPU state. */ void gen_lookup_tb (DisasContext *s) {
@@ -6153,12 +6167,7 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)return ; } -if (s->pstate_il) { -/* -* Illegal execution state. This has priority over BTI -* exceptions, but comes after instruction abort exceptions. -*/ -gen_exception_insn (s,0 ,EXCP_UDEF ,syn_illegalstate ()); +if (check_il (s)) {return ; }
@@ -6728,12 +6737,7 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) dc->base.pc_next = pc; dc->insn = insn; -if (dc->pstate_il) { -/* -* Illegal execution state. This has priority over BTI -* exceptions, but comes after instruction abort exceptions. -*/ -gen_exception_insn (dc,0 ,EXCP_UDEF ,syn_illegalstate ()); +if (check_il (dc)) {return ; }
Signature · 1 line
2.53.0
Re: [PATCH v2 12/14] target/arm: Split out check_il
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/tcg/translate.h | 1 + target/arm/tcg/translate-a64.c | 7 +------ target/arm/tcg/translate.c | 28 ++++++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-)
PATCH v2 13/14 target/arm: Honor PSTATE.UINJ during translation
In reply to Richard Henderson--- target/arm/tcg/translate.h | 2 +- target/arm/tcg/translate-a64.c | 2 +- target/arm/tcg/translate.c | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-)
target/arm/tcg/translate.h +1 -1
@@ -382,7 +382,7 @@ void arm_jump_cc(DisasCompare *cmp, TCGLabel *label);void arm_gen_test_cc (int cc,TCGLabel *label);MemOp pow2_align (unsigned i);void unallocated_encoding (DisasContext *s); -bool check_il (DisasContext *s); +bool check_il_uinj (DisasContext *s);void gen_exception_internal (int excp);void gen_exception_insn_el (DisasContext *s,int64_t pc_diff,int excp,uint32_t syn,uint32_t target_el);
target/arm/tcg/translate-a64.c +1 -1
@@ -11174,7 +11174,7 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) s->fp_access_checked =0 ; s->sve_access_checked =0 ; -if (check_il (s)) { +if (check_il_uinj (s)) {return ; }
target/arm/tcg/translate.c +7 -3
@@ -1164,12 +1164,16 @@ void unallocated_encoding(DisasContext *s)* must be checked after reading the instruction. They have more priority * than the AArch64 BTI exception. */ -bool check_il (DisasContext *s) +bool check_il_uinj (DisasContext *s) {if (s->pstate_il) {gen_exception_insn (s,0 ,EXCP_UDEF ,syn_illegalstate ());return true; } +if (s->pstate_uinj) { +unallocated_encoding (s); +return true; + }return false; }
@@ -6167,7 +6171,7 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)return ; } -if (check_il (s)) { +if (check_il_uinj (s)) {return ; }
@@ -6737,7 +6741,7 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) dc->base.pc_next = pc; dc->insn = insn; -if (check_il (dc)) { +if (check_il_uinj (dc)) {return ; }
Signature · 1 line
2.53.0
Re: [PATCH v2 13/14] target/arm: Honor PSTATE.UINJ during translation
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/tcg/translate.h | 2 +- target/arm/tcg/translate-a64.c | 2 +- target/arm/tcg/translate.c | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-)
PATCH v2 14/14 target/arm: Enable FEAT_UINJ for -cpu max-v9
In reply to Richard Henderson--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 1 + 2 files changed, 2 insertions(+)
docs/system/arm/emulation.rst +1 -0
@@ -223,6 +223,7 @@ the following architecture extensions: - FEAT_TTL (Translation Table Level) - FEAT_TTST (Small translation tables) - FEAT_UAO (Unprivileged Access Override control) +- FEAT_UINJ (Injection of Undefined Instruction exceptions) - FEAT_VHE (Virtualization Host Extensions) - FEAT_VMID16 (16-bit VMID) - FEAT_WFxT (WFE and WFI instructions with timeout)
target/arm/tcg/cpu64.c +1 -0
@@ -1457,6 +1457,7 @@ void aarch64_max_v9_tcg_initfn(Object *obj)SET_IDREG (isar,ID_AA64PFR1 , t); t =GET_IDREG (isar,ID_AA64PFR2 ); + t =FIELD_DP64 (t,ID_AA64PFR2 ,UINJ ,1 );/* v9.0: FEAT_UINJ */ t =FIELD_DP64 (t,ID_AA64PFR2 ,FPMR ,1 );/* v9.2: FEAT_FPMR */ SET_IDREG (isar,ID_AA64PFR2 , t);
Signature · 1 line
2.53.0
Re: [PATCH v2 14/14] target/arm: Enable FEAT_UINJ for -cpu max-v9
Quoted 6 lines · Richard Henderson
Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 1 + 2 files changed, 2 insertions(+)
Peter Maydell
AppliedQuoted 12 lines · Richard Henderson
Changes for v2:
- Reorganize rebuild_hflags_common*.
Trying to force a tail call for these was perhaps just confusing. Inverting the order means that we can handle initialization once in a common way, and the lifetime of some of the parameters is shortened.
- Introducerebuild_hflags_common_aprofile.
This gives us a common place for the new UINJ test in hflags.
- Introducecheck_il_uinj.
This gives us a common place for the new UINJ test in translation.
Applied to target-arm.next, thanks.
-- PMM