hw/ppc: fix decrementer with BookE timers
authorClément Chigot <chigot@adacore.com>
Mon, 15 Jul 2024 08:46:39 +0000 (10:46 +0200)
committerNicholas Piggin <npiggin@gmail.com>
Sun, 3 Nov 2024 23:09:21 +0000 (09:09 +1000)
The BookE decrementer stops at 0, meaning that it won't decremented
towards "negative" values. However, the current logic is inverted: decr
is updated solely when the resulting value would be negative.

Signed-off-by: Clément Chigot <chigot@adacore.com>
Fixes: 8e0a5ac87800 ("hw/ppc: Avoid decrementer rounding errors")
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
hw/ppc/ppc.c

index fde461941227ebe8b34504036a80e130e5495b72..b86b5847de6b8e8782737962b8cdf13e2301d2f7 100644 (file)
@@ -728,7 +728,9 @@ static inline int64_t __cpu_ppc_load_decr(CPUPPCState *env, int64_t now,
     int64_t decr;
 
     n = ns_to_tb(tb_env->decr_freq, now);
-    if (next > n && tb_env->flags & PPC_TIMER_BOOKE) {
+
+    /* BookE timers stop when reaching 0.  */
+    if (next < n && tb_env->flags & PPC_TIMER_BOOKE) {
         decr = 0;
     } else {
         decr = next - n;