grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix infinite loop in grub_pit_wait()


From: Christian Franke
Subject: [PATCH] Fix infinite loop in grub_pit_wait()
Date: Thu, 07 Aug 2008 17:32:42 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 SeaMonkey/1.1.11

grub2 from current SVN hangs if run in VirtualPC, the problem was introduced with 'svn diff -r 1779:1780'.

Here is a proposed fix.

Christian

2008-08-07  Christian Franke  <address@hidden>

        * kern/i386/pit.c (TIMER2_SPEAKER): New define.
        (TIMER2_GATE): Likewise.
        (grub_pit_wait): Add enable/disable of the timer2 gate
        bit of port 0x61. This fixes a possible infinite loop.


diff --git a/kern/i386/pit.c b/kern/i386/pit.c
index d0a6eda..a3fab26 100644
--- a/kern/i386/pit.c
+++ b/kern/i386/pit.c
@@ -28,13 +28,26 @@
 #define TIMER_ENABLE_LSB       0x20
 #define TIMER_ENABLE_MSB       0x10
 #define TIMER2_LATCH           0x20
+#define TIMER2_SPEAKER         0x02
+#define TIMER2_GATE            0x01
 
 void
 grub_pit_wait (grub_uint16_t tics)
 {
+  /* Disable timer2 gate and speaker.  */
+  grub_outb (grub_inb (TIMER2_REG_LATCH) & ~ (TIMER2_SPEAKER | TIMER2_GATE), 
TIMER2_REG_LATCH);
+
+  /* Set tics.  */
   grub_outb (TIMER2_SELECT | TIMER_ENABLE_LSB | TIMER_ENABLE_MSB, 
TIMER_REG_COMMAND);
   grub_outb (tics & 0xff, TIMER2_REG_CONTROL);
   grub_outb (tics >> 8, TIMER2_REG_CONTROL);
 
+  /* Enable timer2 gate, keep speaker disabled.  */
+  grub_outb ((grub_inb (TIMER2_REG_LATCH) & ~ TIMER2_SPEAKER) | TIMER2_GATE, 
TIMER2_REG_LATCH);
+
+  /* Wait.  */
   while ((grub_inb (TIMER2_REG_LATCH) & TIMER2_LATCH) == 0x00);
+
+  /* Disable timer2 gate and speaker.  */
+  grub_outb (grub_inb (TIMER2_REG_LATCH) & ~ (TIMER2_SPEAKER | TIMER2_GATE), 
TIMER2_REG_LATCH);
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]