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 | 4 ++++ src/util.c | 25 +++---------------------- src/util.h | 1 - 3 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/src/clock.c b/src/clock.c index 062658c..49ab901 100644 --- a/src/clock.c +++ b/src/clock.c @@ -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) diff --git a/src/util.c b/src/util.c index b078d5f..b2a22f7 100644 --- a/src/util.c +++ b/src/util.c @@ -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(); } } diff --git a/src/util.h b/src/util.h index 09d9e40..b475c42 100644 --- a/src/util.h +++ b/src/util.h @@ -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