Skip to contentSkip to conversation

target-arm: Fix errors in writes to generic timer control registers

PATCH New Peter Maydell 1 participant 1 message Jun 3, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-arm: Fix errors in writes to generic timer control registers

The code for handling writes to the generic timer control registers had several bugs:
* ISTATUS (bit 2) is read-only but we forced it to zero on any write
* the check for "was IMASK (bit 1) toggled?" incorrectly used '&' where it should be '^'
* the handling of IMASK was inverted: we should set the IRQ if ISTATUS is set and IMASK is clear, not if both are set

The combination of these bugs meant that when running a Linux guest that uses the generic timers we would fairly quickly end up either forgetting that the timer output should be asserted, or failing to set the IRQ when the timer was unmasked. The result is that the guest never gets any more timer interrupts.

---
Rob: I think this is what was causing the hangs you were seeing with 64-bit SMP; let me know if there are still problems there even with this fix.

 target-arm/helper.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target-arm/helper.c +3 -3
index ec031f5..2576c13 100644
@@ -1040,16 +1040,16 @@ static void gt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri,
     int timeridx = ri->crm & 1;
     uint32_t oldval = env->cp15.c14_timer[timeridx].ctl;
 
-    env->cp15.c14_timer[timeridx].ctl = value & 3;
+    env->cp15.c14_timer[timeridx].ctl = deposit64(oldval, 0, 2, value);
     if ((oldval ^ value) & 1) {
         /* Enable toggled */
         gt_recalc_timer(cpu, timeridx);
-    } else if ((oldval & value) & 2) {
+    } else if ((oldval ^ value) & 2) {
         /* IMASK toggled: don't need to recalculate,
          * just set the interrupt line based on ISTATUS
          */
         qemu_set_irq(cpu->gt_timer_outputs[timeridx],
-                     (oldval & 4) && (value & 2));
+                     (oldval & 4) && !(value & 2));
     }
 }
 
Signature · 1 line
1.9.2