target/arm: Define fields for NSACR
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 <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20260702184019.3431139-5-peter.maydell@linaro.org
Peter Maydell committed
Jul 2, 2026 at 19:40 UTC
3455eac92d3e4b70bc222d98268f092efd4f1934
3 files changed
+14
-6
target/arm/cpu.c
+1
-1
@@ -779,7 +779,7 @@ void arm_emulate_firmware_reset(CPUState *cpustate, int target_el)
779
/* Put CPU into non-secure state */
780
env->cp15.scr_el3 |= SCR_NS;
781
/* Set NSACR.{CP11,CP10} so NS can access the FPU */
782
- env->cp15.nsacr |= 3 << 10;
782
+ env->cp15.nsacr |= R_NSACR_CP10_MASK | R_NSACR_CP11_MASK;
783
}
784
785
if (have_el2 && target_el < 2) {
target/arm/helper.c
+5
-5
@@ -590,7 +590,7 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,
590
* is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
591
*/
592
if (arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) &&
593
- !arm_is_secure(env) && !extract32(env->cp15.nsacr, 10, 1)) {
593
+ !arm_is_secure(env) && !FIELD_EX32(env->cp15.nsacr, NSACR, CP10)) {
594
mask = R_CPACR_CP11_MASK | R_CPACR_CP10_MASK;
595
value = (value & ~mask) | (env->cp15.cpacr_el1 & mask);
596
}
@@ -607,7 +607,7 @@ static uint64_t cpacr_read(CPUARMState *env, const ARMCPRegInfo *ri)
607
uint64_t value = env->cp15.cpacr_el1;
608
609
if (arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) &&
610
- !arm_is_secure(env) && !extract32(env->cp15.nsacr, 10, 1)) {
610
+ !arm_is_secure(env) && !FIELD_EX32(env->cp15.nsacr, NSACR, CP10)) {
611
value = ~(R_CPACR_CP11_MASK | R_CPACR_CP10_MASK);
612
}
613
return value;
@@ -4105,7 +4105,7 @@ static void cptr_el2_write(CPUARMState *env, const ARMCPRegInfo *ri,
4105
* is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
4106
*/
4107
if (arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) &&
4108
- !arm_is_secure(env) && !extract32(env->cp15.nsacr, 10, 1)) {
4108
+ !arm_is_secure(env) && !FIELD_EX32(env->cp15.nsacr, NSACR, CP10)) {
4109
uint64_t mask = R_HCPTR_TCP11_MASK | R_HCPTR_TCP10_MASK;
4110
value = (value & ~mask) | (env->cp15.cptr_el[2] & mask);
4111
}
@@ -4121,7 +4121,7 @@ static uint64_t cptr_el2_read(CPUARMState *env, const ARMCPRegInfo *ri)
4121
uint64_t value = env->cp15.cptr_el[2];
4122
4123
if (arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) &&
4124
- !arm_is_secure(env) && !extract32(env->cp15.nsacr, 10, 1)) {
4124
+ !arm_is_secure(env) && !FIELD_EX32(env->cp15.nsacr, NSACR, CP10)) {
4125
value |= R_HCPTR_TCP11_MASK | R_HCPTR_TCP10_MASK;
4126
}
4127
return value;
@@ -10075,7 +10075,7 @@ int fp_exception_el(CPUARMState *env, int cur_el)
10075
*/
10076
if ((arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) &&
10077
cur_el <= 2 && !arm_is_secure_below_el3(env))) {
10078
- if (!extract32(env->cp15.nsacr, 10, 1)) {
10078
+ if (!FIELD_EX32(env->cp15.nsacr, NSACR, CP10)) {
10079
/* FP insns act as UNDEF */
10080
return cur_el == 2 ? 2 : 1;
10081
}
target/arm/internals.h
+8
@@ -135,6 +135,14 @@ FIELD(CPACR_EL1, FPEN, 20, 2)
135
FIELD(CPACR_EL1, SMEN, 24, 2)
136
FIELD(CPACR_EL1, TTA, 28, 1) /* matches CPACR.TRCDIS */
137
138
+/* Bit definitions for NSACR (AArch32 only) */
139
+FIELD(NSACR, CP10, 10, 1)
140
+FIELD(NSACR, CP11, 11, 1)
141
+FIELD(NSACR, NSD32DIS, 14, 1) /* v7; RES0 in v8 */
142
+FIELD(NSACR, NSASEDIS, 15, 1)
143
+FIELD(NSACR, RFR, 19, 1) /* v7; RES0 in v8 */
144
+FIELD(NSACR, NSTRCDIS, 20, 1)
145
+
146
/* Bit definitions for HCPTR (AArch32 only) */
147
FIELD(HCPTR, TCP10, 10, 1)
148
FIELD(HCPTR, TCP11, 11, 1)