From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 08/42] target/arm: Honour M-profile FP enable bits
Date: Mon, 29 Apr 2019 17:59:56 +0100 [thread overview]
Message-ID: <20190429170030.11323-9-peter.maydell@linaro.org> (raw)
In-Reply-To: <20190429170030.11323-1-peter.maydell@linaro.org>
Like AArch64, M-profile floating point has no FPEXC enable
bit to gate floating point; so always set the VFPEN TB flag.
M-profile also has CPACR and NSACR similar to A-profile;
they behave slightly differently:
* the CPACR is banked between Secure and Non-Secure
* if the NSACR forces a trap then this is taken to
the Secure state, not the Non-Secure state
Honour the CPACR and NSACR settings. The NSACR handling
requires us to borrow the exception.target_el field
(usually meaningless for M profile) to distinguish the
NOCP UsageFault taken to Secure state from the more
usual fault taken to the current security state.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20190416125744.27770-6-peter.maydell@linaro.org
---
target/arm/helper.c | 55 +++++++++++++++++++++++++++++++++++++++---
target/arm/translate.c | 10 ++++++--
2 files changed, 60 insertions(+), 5 deletions(-)
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 57ef75b3fcb..c3d5fe09cdc 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -7556,6 +7556,25 @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx,
return target_el;
}
+/*
+ * Return true if the v7M CPACR permits access to the FPU for the specified
+ * security state and privilege level.
+ */
+static bool v7m_cpacr_pass(CPUARMState *env, bool is_secure, bool is_priv)
+{
+ switch (extract32(env->v7m.cpacr[is_secure], 20, 2)) {
+ case 0:
+ case 2: /* UNPREDICTABLE: we treat like 0 */
+ return false;
+ case 1:
+ return is_priv;
+ case 3:
+ return true;
+ default:
+ g_assert_not_reached();
+ }
+}
+
static bool v7m_stack_write(ARMCPU *cpu, uint32_t addr, uint32_t value,
ARMMMUIdx mmu_idx, bool ignfault)
{
@@ -8815,9 +8834,23 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_UNDEFINSTR_MASK;
break;
case EXCP_NOCP:
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure);
- env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_NOCP_MASK;
+ {
+ /*
+ * NOCP might be directed to something other than the current
+ * security state if this fault is because of NSACR; we indicate
+ * the target security state using exception.target_el.
+ */
+ int target_secstate;
+
+ if (env->exception.target_el == 3) {
+ target_secstate = M_REG_S;
+ } else {
+ target_secstate = env->v7m.secure;
+ }
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, target_secstate);
+ env->v7m.cfsr[target_secstate] |= R_V7M_CFSR_NOCP_MASK;
break;
+ }
case EXCP_INVSTATE:
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure);
env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVSTATE_MASK;
@@ -12751,6 +12784,22 @@ int fp_exception_el(CPUARMState *env, int cur_el)
return 0;
}
+ if (arm_feature(env, ARM_FEATURE_M)) {
+ /* CPACR can cause a NOCP UsageFault taken to current security state */
+ if (!v7m_cpacr_pass(env, env->v7m.secure, cur_el != 0)) {
+ return 1;
+ }
+
+ if (arm_feature(env, ARM_FEATURE_M_SECURITY) && !env->v7m.secure) {
+ if (!extract32(env->v7m.nsacr, 10, 1)) {
+ /* FP insns cause a NOCP UsageFault taken to Secure */
+ return 3;
+ }
+ }
+
+ return 0;
+ }
+
/* The CPACR controls traps to EL1, or PL1 if we're 32 bit:
* 0, 2 : trap EL0 and EL1/PL1 accesses
* 1 : trap only EL0 accesses
@@ -12938,7 +12987,7 @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,
flags = FIELD_DP32(flags, TBFLAG_A32, SCTLR_B, arm_sctlr_b(env));
flags = FIELD_DP32(flags, TBFLAG_A32, NS, !access_secure_reg(env));
if (env->vfp.xregs[ARM_VFP_FPEXC] & (1 << 30)
- || arm_el_is_aa64(env, 1)) {
+ || arm_el_is_aa64(env, 1) || arm_feature(env, ARM_FEATURE_M)) {
flags = FIELD_DP32(flags, TBFLAG_A32, VFPEN, 1);
}
flags = FIELD_DP32(flags, TBFLAG_A32, XSCALE_CPAR, env->cp15.c15_cpar);
diff --git a/target/arm/translate.c b/target/arm/translate.c
index a9784535069..6a11921d0b8 100644
--- a/target/arm/translate.c
+++ b/target/arm/translate.c
@@ -3399,8 +3399,14 @@ static int disas_vfp_insn(DisasContext *s, uint32_t insn)
* for attempts to execute invalid vfp/neon encodings with FP disabled.
*/
if (s->fp_excp_el) {
- gen_exception_insn(s, 4, EXCP_UDEF,
- syn_fp_access_trap(1, 0xe, false), s->fp_excp_el);
+ if (arm_dc_feature(s, ARM_FEATURE_M)) {
+ gen_exception_insn(s, 4, EXCP_NOCP, syn_uncategorized(),
+ s->fp_excp_el);
+ } else {
+ gen_exception_insn(s, 4, EXCP_UDEF,
+ syn_fp_access_trap(1, 0xe, false),
+ s->fp_excp_el);
+ }
return 0;
}
--
2.20.1
next prev parent reply other threads:[~2019-04-29 17:01 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-29 16:59 [Qemu-devel] [PULL 00/42] target-arm queue Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 01/42] hw/arm/smmuv3: Remove SMMUNotifierNode Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 02/42] hw/ssi/xilinx_spips: Avoid variable length array Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 03/42] configure: Remove --source-path option Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 04/42] target/arm: Make sure M-profile FPSCR RES0 bits are not settable Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 05/42] hw/intc/armv7m_nvic: Allow reading of M-profile MVFR* registers Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 06/42] target/arm: Implement dummy versions of M-profile FP-related registers Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 07/42] target/arm: Disable most VFP sysregs for M-profile Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` Peter Maydell [this message]
2019-04-29 16:59 ` [Qemu-devel] [PULL 08/42] target/arm: Honour M-profile FP enable bits Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 09/42] target/arm: Decode FP instructions for M profile Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 10/42] target/arm: Clear CONTROL_S.SFPA in SG insn if FPU present Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 16:59 ` [Qemu-devel] [PULL 11/42] target/arm: Handle SFPA and FPCA bits in reads and writes of CONTROL Peter Maydell
2019-04-29 16:59 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 12/42] target/arm/helper: don't return early for STKOF faults during stacking Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 13/42] target/arm: Handle floating point registers in exception entry Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 14/42] target/arm: Implement v7m_update_fpccr() Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 15/42] target/arm: Clear CONTROL.SFPA in BXNS and BLXNS Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 16/42] target/arm: Clean excReturn bits when tail chaining Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 17/42] target/arm: Allow for floating point in callee stack integrity check Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 18/42] target/arm: Handle floating point registers in exception return Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 19/42] target/arm: Move NS TBFLAG from bit 19 to bit 6 Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 20/42] target/arm: Overlap VECSTRIDE and XSCALE_CPAR TB flags Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 21/42] target/arm: Set FPCCR.S when executing M-profile floating point insns Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 22/42] target/arm: Activate M-profile floating point context when FPCCR.ASPEN is set Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 23/42] target/arm: New helper function arm_v7m_mmu_idx_all() Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 24/42] target/arm: New function armv7m_nvic_set_pending_lazyfp() Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 25/42] target/arm: Add lazy-FP-stacking support to v7m_stack_write() Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 26/42] target/arm: Implement M-profile lazy FP state preservation Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 27/42] target/arm: Implement VLSTM for v7M CPUs with an FPU Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 28/42] target/arm: Implement VLLDM " Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 29/42] target/arm: Enable FPU for Cortex-M4 and Cortex-M33 Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 30/42] hw/dma: Compile the bcm2835_dma device as common object Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 31/42] hw/arm/aspeed: Use TYPE_TMP105/TYPE_PCA9552 instead of hardcoded string Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 32/42] hw/arm/nseries: Use TYPE_TMP105 " Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 33/42] hw/display/tc6393xb: Remove unused functions Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 34/42] hw/devices: Move TC6393XB declarations into a new header Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 35/42] hw/devices: Move Blizzard " Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 36/42] hw/devices: Move CBus " Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 37/42] hw/devices: Move Gamepad " Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 38/42] hw/devices: Move TI touchscreen " Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 39/42] hw/devices: Move LAN9118 " Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 40/42] hw/net/ne2000-isa: Add guards to the header Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 41/42] hw/net/lan9118: Export TYPE_LAN9118 and use it instead of hardcoded string Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 17:00 ` [Qemu-devel] [PULL 42/42] hw/devices: Move SMSC 91C111 declaration into a new header Peter Maydell
2019-04-29 17:00 ` Peter Maydell
2019-04-29 18:10 ` [Qemu-devel] [PULL 00/42] target-arm queue Peter Maydell
2019-04-29 18:10 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190429170030.11323-9-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).