All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 21/26] target/arm: New function armv7m_nvic_set_pending_lazyfp()
Date: Tue, 16 Apr 2019 13:57:39 +0100	[thread overview]
Message-ID: <20190416125744.27770-22-peter.maydell@linaro.org> (raw)
In-Reply-To: <20190416125744.27770-1-peter.maydell@linaro.org>

In the v7M architecture, if an exception is generated in the process
of doing the lazy stacking of FP registers, the handling of
possible escalation to HardFault is treated differently to the normal
approach: it works based on the saved information about exception
readiness that was stored in the FPCCR when the stack frame was
created. Provide a new function armv7m_nvic_set_pending_lazyfp()
which pends exceptions during lazy stacking, and implements
this logic.

This corresponds to the pseudocode TakePreserveFPException().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/arm/cpu.h      | 12 ++++++
 hw/intc/armv7m_nvic.c | 96 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+)

diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 0a1b82dc996..42df41b11ab 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -2009,6 +2009,18 @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure);
  * a different exception).
  */
 void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure);
+/**
+ * armv7m_nvic_set_pending_lazyfp: mark this lazy FP exception as pending
+ * @opaque: the NVIC
+ * @irq: the exception number to mark pending
+ * @secure: false for non-banked exceptions or for the nonsecure
+ * version of a banked exception, true for the secure version of a banked
+ * exception.
+ *
+ * Similar to armv7m_nvic_set_pending(), but specifically for exceptions
+ * generated in the course of lazy stacking of FP registers.
+ */
+void armv7m_nvic_set_pending_lazyfp(void *opaque, int irq, bool secure);
 /**
  * armv7m_nvic_get_pending_irq_info: return highest priority pending
  *    exception, and whether it targets Secure state
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
index 53b4631dace..fff6e694e60 100644
--- a/hw/intc/armv7m_nvic.c
+++ b/hw/intc/armv7m_nvic.c
@@ -655,6 +655,102 @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure)
     do_armv7m_nvic_set_pending(opaque, irq, secure, true);
 }
 
+void armv7m_nvic_set_pending_lazyfp(void *opaque, int irq, bool secure)
+{
+    /*
+     * Pend an exception during lazy FP stacking. This differs
+     * from the usual exception pending because the logic for
+     * whether we should escalate depends on the saved context
+     * in the FPCCR register, not on the current state of the CPU/NVIC.
+     */
+    NVICState *s = (NVICState *)opaque;
+    bool banked = exc_is_banked(irq);
+    VecInfo *vec;
+    bool targets_secure;
+    bool escalate = false;
+    /*
+     * We will only look at bits in fpccr if this is a banked exception
+     * (in which case 'secure' tells us whether it is the S or NS version).
+     * All the bits for the non-banked exceptions are in fpccr_s.
+     */
+    uint32_t fpccr_s = s->cpu->env.v7m.fpccr[M_REG_S];
+    uint32_t fpccr = s->cpu->env.v7m.fpccr[secure];
+
+    assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
+    assert(!secure || banked);
+
+    vec = (banked && secure) ? &s->sec_vectors[irq] : &s->vectors[irq];
+
+    targets_secure = banked ? secure : exc_targets_secure(s, irq);
+
+    switch (irq) {
+    case ARMV7M_EXCP_DEBUG:
+        if (!(fpccr_s & R_V7M_FPCCR_MONRDY_MASK)) {
+            /* Ignore DebugMonitor exception */
+            return;
+        }
+        break;
+    case ARMV7M_EXCP_MEM:
+        escalate = !(fpccr & R_V7M_FPCCR_MMRDY_MASK);
+        break;
+    case ARMV7M_EXCP_USAGE:
+        escalate = !(fpccr & R_V7M_FPCCR_UFRDY_MASK);
+        break;
+    case ARMV7M_EXCP_BUS:
+        escalate = !(fpccr_s & R_V7M_FPCCR_BFRDY_MASK);
+        break;
+    case ARMV7M_EXCP_SECURE:
+        escalate = !(fpccr_s & R_V7M_FPCCR_SFRDY_MASK);
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    if (escalate) {
+        /*
+         * Escalate to HardFault: faults that initially targeted Secure
+         * continue to do so, even if HF normally targets NonSecure.
+         */
+        irq = ARMV7M_EXCP_HARD;
+        if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY) &&
+            (targets_secure ||
+             !(s->cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK))) {
+            vec = &s->sec_vectors[irq];
+        } else {
+            vec = &s->vectors[irq];
+        }
+    }
+
+    if (!vec->enabled ||
+        nvic_exec_prio(s) <= exc_group_prio(s, vec->prio, secure)) {
+        if (!(fpccr_s & R_V7M_FPCCR_HFRDY_MASK)) {
+            /*
+             * We want to escalate to HardFault but the context the
+             * FP state belongs to prevents the exception pre-empting.
+             */
+            cpu_abort(&s->cpu->parent_obj,
+                      "Lockup: can't escalate to HardFault during "
+                      "lazy FP register stacking\n");
+        }
+    }
+
+    if (escalate) {
+        s->cpu->env.v7m.hfsr |= R_V7M_HFSR_FORCED_MASK;
+    }
+    if (!vec->pending) {
+        vec->pending = 1;
+        /*
+         * We do not call nvic_irq_update(), because we know our caller
+         * is going to handle causing us to take the exception by
+         * raising EXCP_LAZYFP, so raising the IRQ line would be
+         * pointless extra work. We just need to recompute the
+         * priorities so that armv7m_nvic_can_take_pending_exception()
+         * returns the right answer.
+         */
+        nvic_recompute_state(s);
+    }
+}
+
 /* Make pending IRQ active.  */
 void armv7m_nvic_acknowledge_irq(void *opaque)
 {
-- 
2.20.1

  parent reply	other threads:[~2019-04-16 12:58 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-16 12:57 [Qemu-devel] [PATCH 00/26] target/arm: Implement M profile floating point Peter Maydell
2019-04-16 12:57 ` [Qemu-devel] [PATCH 01/26] target/arm: Make sure M-profile FPSCR RES0 bits are not settable Peter Maydell
2019-04-23 17:25   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 02/26] hw/intc/armv7m_nvic: Allow reading of M-profile MVFR* registers Peter Maydell
2019-04-23 17:27   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 03/26] target/arm: Implement dummy versions of M-profile FP-related registers Peter Maydell
2019-04-23 17:55   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 04/26] target/arm: Disable most VFP sysregs for M-profile Peter Maydell
2019-04-23 18:08   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 05/26] target/arm: Honour M-profile FP enable bits Peter Maydell
2019-04-23 18:19   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 06/26] target/arm: Decode FP instructions for M profile Peter Maydell
2019-04-23 18:37   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 07/26] target/arm: Clear CONTROL_S.SFPA in SG insn if FPU present Peter Maydell
2019-04-23 20:58   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 08/26] target/arm: Handle SFPA and FPCA bits in reads and writes of CONTROL Peter Maydell
2019-04-23 21:33   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 09/26] target/arm/helper: don't return early for STKOF faults during stacking Peter Maydell
2019-04-23 21:46   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 10/26] target/arm: Handle floating point registers in exception entry Peter Maydell
2019-04-23 22:21   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 11/26] target/arm: Implement v7m_update_fpccr() Peter Maydell
2019-04-16 12:57 ` [Qemu-devel] [PATCH 12/26] target/arm: Clear CONTROL.SFPA in BXNS and BLXNS Peter Maydell
2019-04-23 22:50   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 13/26] target/arm: Clean excReturn bits when tail chaining Peter Maydell
2019-04-23 22:54   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 14/26] target/arm: Allow for floating point in callee stack integrity check Peter Maydell
2019-04-23 23:04   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 15/26] target/arm: Handle floating point registers in exception return Peter Maydell
2019-04-23 23:29   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 16/26] target/arm: Move NS TBFLAG from bit 19 to bit 6 Peter Maydell
2019-04-23 23:47   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 17/26] target/arm: Overlap VECSTRIDE and XSCALE_CPAR TB flags Peter Maydell
2019-04-23 23:51   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 18/26] target/arm: Set FPCCR.S when executing M-profile floating point insns Peter Maydell
2019-04-24  0:00   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 19/26] target/arm: Activate M-profile floating point context when FPCCR.ASPEN is set Peter Maydell
2019-04-24  0:08   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 20/26] target/arm: New helper function arm_v7m_mmu_idx_all() Peter Maydell
2019-04-24  0:12   ` Richard Henderson
2019-04-16 12:57 ` Peter Maydell [this message]
2019-04-24  1:10   ` [Qemu-devel] [PATCH 21/26] target/arm: New function armv7m_nvic_set_pending_lazyfp() Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 22/26] target/arm: Add lazy-FP-stacking support to v7m_stack_write() Peter Maydell
2019-04-24  1:27   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 23/26] target/arm: Implement M-profile lazy FP state preservation Peter Maydell
2019-04-24  2:04   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 24/26] target/arm: Implement VLSTM for v7M CPUs with an FPU Peter Maydell
2019-04-24  2:17   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 25/26] target/arm: Implement VLLDM " Peter Maydell
2019-04-24  2:21   ` Richard Henderson
2019-04-16 12:57 ` [Qemu-devel] [PATCH 26/26] target/arm: Enable FPU for Cortex-M4 and Cortex-M33 Peter Maydell
2019-04-24  2:25   ` Richard Henderson

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=20190416125744.27770-22-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.