Don't use RTC to time boot menu delay.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 23 May 2010 16:40:40 +0000 (12:40 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 23 May 2010 16:40:40 +0000 (12:40 -0400)
It appears real machines sometimes have a flaky RTC, so avoid using
the RTC irq during boot.  Instead, use a delay based on the standard
timer irq.

This also optimizes CONFIG_THREAD_OPTIONROMS users as it is no longer
necessary to use preemption - the wait_irq() call handles task
switching natively.

src/clock.c
src/util.c
src/util.h

index 062658c16e2c1a1e51a8490bb553c63c7187dbf4..49ab901bbaa59a2b0b16774992a72bded895d8f7 100644 (file)
@@ -231,14 +231,18 @@ calc_future_timer_ticks(u32 count)
 {
     return (GET_BDA(timer_counter) + count + 1) % TICKS_PER_DAY;
 }
+
 // Return the timer value that is 'msecs' time in the future.
 u32
 calc_future_timer(u32 msecs)
 {
+    if (!msecs)
+        return GET_BDA(timer_counter);
     u32 kticks = DIV_ROUND_UP((u64)(msecs * PIT_TICK_RATE), PIT_TICK_INTERVAL);
     u32 ticks = DIV_ROUND_UP(kticks, 1000);
     return calc_future_timer_ticks(ticks);
 }
+
 // Check if the given timer value has passed.
 int
 check_timer(u32 end)
index b078d5f338b82b7ebecfbf131fdbdbe73907d933..b2a22f78a0e11aa6fc51a171779c72df2ca2d233 100644 (file)
@@ -244,19 +244,6 @@ strtcpy(char *dest, const char *src, size_t len)
  * Keyboard calls
  ****************************************************************/
 
-// Wait for 'usec' microseconds using (with irqs enabled) using int 1586.
-void
-biosusleep(u32 usec)
-{
-    struct bregs br;
-    memset(&br, 0, sizeof(br));
-    br.flags = F_IF;
-    br.ah = 0x86;
-    br.cx = usec >> 16;
-    br.dx = usec;
-    call16_int(0x15, &br);
-}
-
 // See if a keystroke is pending in the keyboard buffer.
 static int
 check_for_keystroke(void)
@@ -265,9 +252,7 @@ check_for_keystroke(void)
     memset(&br, 0, sizeof(br));
     br.flags = F_IF;
     br.ah = 1;
-    start_preempt();
     call16_int(0x16, &br);
-    finish_preempt();
     return !(br.flags & F_ZF);
 }
 
@@ -278,9 +263,7 @@ get_raw_keystroke(void)
     struct bregs br;
     memset(&br, 0, sizeof(br));
     br.flags = F_IF;
-    start_preempt();
     call16_int(0x16, &br);
-    finish_preempt();
     return br.ah;
 }
 
@@ -288,14 +271,12 @@ get_raw_keystroke(void)
 int
 get_keystroke(int msec)
 {
+    u32 end = calc_future_timer(msec);
     for (;;) {
         if (check_for_keystroke())
             return get_raw_keystroke();
-        if (msec <= 0)
+        if (check_timer(end))
             return -1;
-        start_preempt();
-        biosusleep(50*1000);
-        finish_preempt();
-        msec -= 50;
+        wait_irq();
     }
 }
index 09d9e4090f8ced0e2e1c67fcb0577f14fe2968f6..b475c428e1cf8b45b43dea273f44abae96c9242e 100644 (file)
@@ -193,7 +193,6 @@ void *memcpy(void *d1, const void *s1, size_t len);
 void iomemcpy(void *d, const void *s, u32 len);
 void *memmove(void *d, const void *s, size_t len);
 char *strtcpy(char *dest, const char *src, size_t len);
-void biosusleep(u32 usec);
 int get_keystroke(int msec);
 
 // stacks.c