Index: /trunk/src/VBox/Devices/PC/DevPit-i8254.cpp
===================================================================
--- /trunk/src/VBox/Devices/PC/DevPit-i8254.cpp	(revision 35852)
+++ /trunk/src/VBox/Devices/PC/DevPit-i8254.cpp	(revision 35853)
@@ -254,5 +254,5 @@
     case 4:
     case 5:
-        out = (d == s->count);
+        out = (d != s->count);
         break;
     }
@@ -395,10 +395,20 @@
             next_time = base + s->count;
         break;
+    /* Modes 4 and 5 generate a short pulse at the end of the time delay. This
+     * is similar to mode 2, except modes 4/5 aren't periodic. We use the same
+     * optimization - only use one timer callback and pulse the IRQ.
+     * Note: Tickless Linux kernels use PIT mode 4 with 'nolapic'.
+     */
     case 4:
     case 5:
+#ifdef VBOX
+        if (d <= s->count)
+            next_time = s->count;
+#else
         if (d < s->count)
             next_time = s->count;
         else if (d == s->count)
             next_time = s->count + 1;
+#endif
         else
             return -1;
@@ -438,15 +448,24 @@
         pDevIns = s->CTX_SUFF(pPit)->pDevIns;
 
-        if (EFFECTIVE_MODE(s->mode) == 2 && in_timer)
+        switch (EFFECTIVE_MODE(s->mode))
         {
-            /* We just flip-flop the irq level to save that extra timer call, which
-             * isn't generally required (we haven't served it for years). However,
-             * the pulse is only generated when running on the timer callback (and
-             * thus on the trailing edge of the output signal pulse).
-             */
-            PDMDevHlpISASetIrq(pDevIns, s->irq, PDM_IRQ_LEVEL_FLIP_FLOP);
-
-        } else
-            PDMDevHlpISASetIrq(pDevIns, s->irq, irq_level);
+            case 2:
+            case 4:
+            case 5:
+                /* We just flip-flop the IRQ line to save an extra timer call,
+                 * which isn't generally required. However, the pulse is only
+                 * generated when running on the timer callback (and thus on
+                 * the trailing edge of the output signal pulse).
+                 */
+                if (in_timer)
+                {
+                    PDMDevHlpISASetIrq(pDevIns, s->irq, PDM_IRQ_LEVEL_FLIP_FLOP);
+                    break;
+                }
+                /* Else fall through! */
+            default:
+                PDMDevHlpISASetIrq(pDevIns, s->irq, irq_level);
+                break;
+        }
     }
 
