Skip to contentSkip to conversation

nvic: Fix ARMv7M MPU_RBAR reads

PATCH In review Peter Maydell 2 participants 3 messages Nov 3, 2017 – Nov 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvic: Fix ARMv7M MPU_RBAR reads

Fix an incorrect mask expression in the handling of v7M MPU_RBAR reads that meant that we would always report the ADDR field as zero.

---
Doesn't affect v8M, which is a different codepath.

 hw/intc/armv7m_nvic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/armv7m_nvic.c +1 -1
index be46639..5d9c883 100644
@@ -977,7 +977,7 @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
         if (region >= cpu->pmsav7_dregion) {
             return 0;
         }
-        return (cpu->env.pmsav7.drbar[region] & 0x1f) | (region & 0xf);
+        return (cpu->env.pmsav7.drbar[region] & ~0x1f) | (region & 0xf);
     }
     case 0xda0: /* MPU_RASR (v7M), MPU_RLAR (v8M) */
     case 0xda8: /* MPU_RASR_A1 (v7M), MPU_RLAR_A1 (v8M) */
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Peter Maydell

Fix an incorrect mask expression in the handling of v7M MPU_RBAR reads that meant that we would always report the ADDR field as zero.

nit: you could extend that to: "..as zero because we mask it when written".

As I see you do:
cpu->env.pmsav7.drbar[region] = value & ~0x1f;

Quoted 13 lines

---
Doesn't affect v8M, which is a different codepath.

 hw/intc/armv7m_nvic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/armv7m_nvic.c +0 -0
index be46639..5d9c883 100644

hw/intc/armv7m_nvic.c static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) · line 983

Quoted 8 lines
hw/intc/armv7m_nvic.c +1 -1
@@ -977,7 +977,7 @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
         if (region >= cpu->pmsav7_dregion) {
             return 0;
         }
-        return (cpu->env.pmsav7.drbar[region] & 0x1f) | (region & 0xf);
+        return (cpu->env.pmsav7.drbar[region] & ~0x1f) | (region & 0xf);
     }
     case 0xda0: /* MPU_RASR (v7M), MPU_RLAR (v8M) */
     case 0xda8: /* MPU_RASR_A1 (v7M), MPU_RLAR_A1 (v8M) */

--
Alex Bennée

#2 lore raw
Quoted 8 lines · Alex Bennée
Quoted 2 lines · Peter Maydell

Fix an incorrect mask expression in the handling of v7M MPU_RBAR reads that meant that we would always report the ADDR field as zero.

nit: you could extend that to: "..as zero because we mask it when written".

The ADDR field is bits [31:5], so it's true even if we don't mask on writes.

thanks
-- PMM