From b7b527edfa9ec0f0672379f7ee8bc8475b73967f Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Sat, 4 Jun 2005 21:50:44 +0000 Subject: [PATCH] Fix delay(). The processor cycle counter is a 32-bit wrapping counter. Hence, mask off the upper 32 bits and deal with wrap-arounds. MFC after: 1 week --- sys/boot/alpha/libalpha/delay.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sys/boot/alpha/libalpha/delay.c b/sys/boot/alpha/libalpha/delay.c index 6e437a7f0ba9..5a81c78531d5 100644 --- a/sys/boot/alpha/libalpha/delay.c +++ b/sys/boot/alpha/libalpha/delay.c @@ -33,9 +33,12 @@ __FBSDID("$FreeBSD$"); void delay(int usecs) { - struct rpb *hwrpb = (struct rpb *)HWRPB_ADDR; - unsigned long start = alpha_rpcc(); - unsigned long end = start + (hwrpb->rpb_cc_freq * usecs) / 1000000; - while (alpha_rpcc() < end) - ; + struct rpb *hwrpb = (struct rpb *)HWRPB_ADDR; + unsigned long end, now, start; + + start = alpha_rpcc() & 0xfffffffful; + end = start + (hwrpb->rpb_cc_freq * usecs) / 1000000; + do { + now = alpha_rpcc() & 0xfffffffful; + } while (now < end || (now > start && end < start)); }