Skip to content

Commit

Permalink
target/arm: Unify checking for M Main Extension in MRS/MSR
Browse files Browse the repository at this point in the history
BASEPRI, FAULTMASK, and their _NS equivalents only exist on devices with
the Main Extension.  However, the MRS instruction did not check this,
and the MSR instruction handled it inconsistently (warning BASEPRI, but
silently ignoring writes to BASEPRI_NS).  Unify this behavior and always
warn when reading or writing any of these registers if the extension is
not present.

Signed-off-by: David Reiss <dreiss@meta.com>
Message-id: 167330628518.10497.13100425787268927786-0@git.sr.ht
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
David Reiss authored and pm215 committed Jan 23, 2023
1 parent bb46133 commit 0ec69c4
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions target/arm/m_helper.c
Expand Up @@ -2465,11 +2465,17 @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
}
return env->v7m.primask[M_REG_NS];
case 0x91: /* BASEPRI_NS */
if (!arm_feature(env, ARM_FEATURE_M_MAIN)) {
goto bad_reg;
}
if (!env->v7m.secure) {
return 0;
}
return env->v7m.basepri[M_REG_NS];
case 0x93: /* FAULTMASK_NS */
if (!arm_feature(env, ARM_FEATURE_M_MAIN)) {
goto bad_reg;
}
if (!env->v7m.secure) {
return 0;
}
Expand Down Expand Up @@ -2515,8 +2521,14 @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
return env->v7m.primask[env->v7m.secure];
case 17: /* BASEPRI */
case 18: /* BASEPRI_MAX */
if (!arm_feature(env, ARM_FEATURE_M_MAIN)) {
goto bad_reg;
}
return env->v7m.basepri[env->v7m.secure];
case 19: /* FAULTMASK */
if (!arm_feature(env, ARM_FEATURE_M_MAIN)) {
goto bad_reg;
}
return env->v7m.faultmask[env->v7m.secure];
default:
bad_reg:
Expand Down Expand Up @@ -2581,13 +2593,19 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
env->v7m.primask[M_REG_NS] = val & 1;
return;
case 0x91: /* BASEPRI_NS */
if (!env->v7m.secure || !arm_feature(env, ARM_FEATURE_M_MAIN)) {
if (!arm_feature(env, ARM_FEATURE_M_MAIN)) {
goto bad_reg;
}
if (!env->v7m.secure) {
return;
}
env->v7m.basepri[M_REG_NS] = val & 0xff;
return;
case 0x93: /* FAULTMASK_NS */
if (!env->v7m.secure || !arm_feature(env, ARM_FEATURE_M_MAIN)) {
if (!arm_feature(env, ARM_FEATURE_M_MAIN)) {
goto bad_reg;
}
if (!env->v7m.secure) {
return;
}
env->v7m.faultmask[M_REG_NS] = val & 1;
Expand Down

0 comments on commit 0ec69c4

Please sign in to comment.