[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [PATCH v2 22/26] armv7m: priority field mask
From: |
Michael Davidsaver |
Subject: |
[Qemu-arm] [PATCH v2 22/26] armv7m: priority field mask |
Date: |
Wed, 2 Dec 2015 19:18:49 -0500 |
Many v7m CPUs don't implement all of the 8 bits
of the priority fields. Typically, only the
top N bits are available. Existing practice
implies that writes to unimplemented
bits will be ignore, and read as zero.
This allows a guest to discover the implemented
bits by writing 0xff to (eg. basepri).
The value read back will have only the available
bits set.
---
hw/intc/armv7m_nvic.c | 2 ++
target-arm/cpu-qom.h | 6 ++++++
target-arm/cpu.c | 7 +++++++
target-arm/helper.c | 6 ++++--
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
index 2b42d9d..e2410a3 100644
--- a/hw/intc/armv7m_nvic.c
+++ b/hw/intc/armv7m_nvic.c
@@ -149,6 +149,8 @@ void set_prio(NVICState *s, unsigned irq, uint8_t prio)
assert(irq > 3); /* only use for configurable prios */
assert(irq < NVIC_MAX_VECTORS);
+ prio &= s->cpu->v7m_priority_mask;
+
s->vectors[irq].raw_prio = prio;
s->vectors[irq].prio_group = (prio>>(s->prigroup+1));
s->vectors[irq].prio_sub = irq + (prio & submask) * NVIC_MAX_VECTORS;
diff --git a/target-arm/cpu-qom.h b/target-arm/cpu-qom.h
index 25fb1ce..79cf591 100644
--- a/target-arm/cpu-qom.h
+++ b/target-arm/cpu-qom.h
@@ -108,6 +108,12 @@ typedef struct ARMCPU {
/* PMSAv7 MPU number of supported regions */
uint32_t pmsav7_dregion;
+ /* Some v7-M targets don't impliment the full 8 bits
+ * of the priority fields. Writes to unimplimented
+ * bits are treated as zero (guest can discover mask).
+ */
+ uint8_t v7m_priority_mask;
+
/* PSCI conduit used to invoke PSCI methods
* 0 - disabled, 1 - smc, 2 - hvc
*/
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 8b85888..27cf482 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -527,6 +527,9 @@ static Property arm_cpu_has_mpu_property =
static Property arm_cpu_pmsav7_dregion_property =
DEFINE_PROP_UINT32("pmsav7-dregion", ARMCPU, pmsav7_dregion, 16);
+static Property armv7m_priority_mask_property =
+ DEFINE_PROP_UINT8("priority-mask", ARMCPU, v7m_priority_mask, 0xff);
+
static void arm_cpu_post_init(Object *obj)
{
ARMCPU *cpu = ARM_CPU(obj);
@@ -565,6 +568,10 @@ static void arm_cpu_post_init(Object *obj)
}
}
+ if (IS_M(&cpu->env) && arm_feature(&cpu->env, ARM_FEATURE_V7)) {
+ qdev_property_add_static(DEVICE(obj), &armv7m_priority_mask_property,
+ &error_abort);
+ }
}
static void arm_cpu_finalizefn(Object *obj)
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 2661da4..c890b3a 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -7569,6 +7569,8 @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
void HELPER(v7m_msr)(CPUARMState *env, uint32_t reg, uint32_t val)
{
+ ARMCPU *cpu = arm_env_get_cpu(env);
+
if (arm_current_el(env) == 0 && reg > 7) {
/* only xPSR sub-fields may be written by unprivileged */
return;
@@ -7601,10 +7603,10 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t reg,
uint32_t val)
}
break;
case 17: /* BASEPRI */
- env->v7m.basepri = val & 0xff;
+ env->v7m.basepri = val & cpu->v7m_priority_mask;
break;
case 18: /* BASEPRI_MAX */
- val &= 0xff;
+ val &= cpu->v7m_priority_mask;
if (val != 0 && (val < env->v7m.basepri || env->v7m.basepri == 0))
env->v7m.basepri = val;
break;
--
2.1.4
- [Qemu-arm] [PATCH v2 09/26] armv7m: implement CFSR, HFSR, BFAR, and MMFAR, (continued)
- [Qemu-arm] [PATCH v2 09/26] armv7m: implement CFSR, HFSR, BFAR, and MMFAR, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 11/26] arm: gic: Remove references to NVIC, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 10/26] armv7m: auto-clear FAULTMASK, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 17/26] armv7m: mpu background miss is perm fault, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 21/26] armv7m: CONTROL<1> handling, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 16/26] armv7m: add some mpu debugging prints, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 24/26] armv7m: split armv7m_init in two parts, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 22/26] armv7m: priority field mask,
Michael Davidsaver <=
- [Qemu-arm] [PATCH v2 25/26] armv7m: remove extra cpu_reset(), Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 15/26] armv7m: add MPU to cortex-m3 and cortex-m4, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 14/26] armv7m: prevent unprivileged write to STIR, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 19/26] armv7m: mpu not allowed to map exception return codes, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 13/26] armv7m: implement CCR, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 12/26] armv7m: check exception return consistency, Michael Davidsaver, 2015/12/02
- [Qemu-arm] [PATCH v2 20/26] armv7m: observable initial register state, Michael Davidsaver, 2015/12/02