summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/alpha/alpha/machdep.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c
index 041ea4e9dd82..8855858a52fb 100644
--- a/sys/alpha/alpha/machdep.c
+++ b/sys/alpha/alpha/machdep.c
@@ -1130,17 +1130,44 @@ bzero(void *buf, size_t len)
}
}
-/*
- * Wait "n" microseconds.
- */
void
DELAY(int n)
{
-#ifndef SIMOS
- long N = cycles_per_usec * (n);
+#ifndef SIMOS
+ unsigned long pcc0, pcc1, curcycle, cycles;
+ int usec;
+
+ if (n == 0)
+ return;
+
+ pcc0 = alpha_rpcc() & 0xffffffffUL;
+ cycles = 0;
+ usec = 0;
- while (N > 0) /* XXX */
- N -= 3; /* XXX */
+ while (usec <= n) {
+ /*
+ * Get the next CPU cycle count;
+ */
+ pcc1 = alpha_rpcc() & 0xffffffffUL;
+ if (pcc1 < pcc0) {
+ curcycle = (pcc1 + 0x100000000UL) - pcc0;
+ } else {
+ curcycle = pcc1 - pcc0;
+ }
+
+ /*
+ * We now have the number of processor cycles since we
+ * last checked. Add the current cycle count to the
+ * running total. If it's over cycles_per_usec, increment
+ * the usec counter.
+ */
+ cycles += curcycle;
+ while (cycles > cycles_per_usec) {
+ usec++;
+ cycles -= cycles_per_usec;
+ }
+ pcc0 = pcc1;
+ }
#endif
}