summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/amd64/amd64/tsc.c27
-rw-r--r--sys/amd64/isa/clock.c27
-rw-r--r--sys/i386/i386/tsc.c27
-rw-r--r--sys/i386/isa/clock.c27
-rw-r--r--sys/isa/atrtc.c27
5 files changed, 110 insertions, 25 deletions
diff --git a/sys/amd64/amd64/tsc.c b/sys/amd64/amd64/tsc.c
index 9319e4c..faa38fd 100644
--- a/sys/amd64/amd64/tsc.c
+++ b/sys/amd64/amd64/tsc.c
@@ -146,6 +146,7 @@ static void (*timer_func) __P((struct clockframe *frame)) = hardclock;
#if defined(I586_CPU) || defined(I686_CPU)
static void set_i586_ctr_freq(u_int i586_freq, u_int i8254_freq);
#endif
+static void set_timer_freq(u_int freq, int intr_freq);
static void
clkintr(struct clockframe frame)
@@ -361,7 +362,7 @@ getit(void)
void
DELAY(int n)
{
- int prev_tick, tick, ticks_left, sec, usec;
+ int delta, prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@@ -378,6 +379,13 @@ DELAY(int n)
printf("DELAY(%d)...", n);
#endif
/*
+ * Guard against the timer being uninitialized if we are called
+ * early for console i/o.
+ */
+ if (timer0_max_count == 0)
+ set_timer_freq(timer_freq, hz);
+
+ /*
* Read the counter first, so that the rest of the setup overhead is
* counted. Guess the initial overhead is 20 usec (on most systems it
* takes about 1.5 usec for each of the i/o's in getit(). The loop
@@ -404,11 +412,20 @@ DELAY(int n)
#ifdef DELAYDEBUG
++getit_calls;
#endif
- if (tick > prev_tick)
- ticks_left -= prev_tick - (tick - timer0_max_count);
- else
- ticks_left -= prev_tick - tick;
+ delta = prev_tick - tick;
prev_tick = tick;
+ if (delta < 0) {
+ delta += timer0_max_count;
+ /*
+ * Guard against timer0_max_count being wrong.
+ * This shouldn't happen in normal operation,
+ * but it may happen if set_timer_freq() is
+ * traced.
+ */
+ if (delta < 0)
+ delta = 0;
+ }
+ ticks_left -= delta;
}
#ifdef DELAYDEBUG
if (state == 1)
diff --git a/sys/amd64/isa/clock.c b/sys/amd64/isa/clock.c
index 9319e4c..faa38fd 100644
--- a/sys/amd64/isa/clock.c
+++ b/sys/amd64/isa/clock.c
@@ -146,6 +146,7 @@ static void (*timer_func) __P((struct clockframe *frame)) = hardclock;
#if defined(I586_CPU) || defined(I686_CPU)
static void set_i586_ctr_freq(u_int i586_freq, u_int i8254_freq);
#endif
+static void set_timer_freq(u_int freq, int intr_freq);
static void
clkintr(struct clockframe frame)
@@ -361,7 +362,7 @@ getit(void)
void
DELAY(int n)
{
- int prev_tick, tick, ticks_left, sec, usec;
+ int delta, prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@@ -378,6 +379,13 @@ DELAY(int n)
printf("DELAY(%d)...", n);
#endif
/*
+ * Guard against the timer being uninitialized if we are called
+ * early for console i/o.
+ */
+ if (timer0_max_count == 0)
+ set_timer_freq(timer_freq, hz);
+
+ /*
* Read the counter first, so that the rest of the setup overhead is
* counted. Guess the initial overhead is 20 usec (on most systems it
* takes about 1.5 usec for each of the i/o's in getit(). The loop
@@ -404,11 +412,20 @@ DELAY(int n)
#ifdef DELAYDEBUG
++getit_calls;
#endif
- if (tick > prev_tick)
- ticks_left -= prev_tick - (tick - timer0_max_count);
- else
- ticks_left -= prev_tick - tick;
+ delta = prev_tick - tick;
prev_tick = tick;
+ if (delta < 0) {
+ delta += timer0_max_count;
+ /*
+ * Guard against timer0_max_count being wrong.
+ * This shouldn't happen in normal operation,
+ * but it may happen if set_timer_freq() is
+ * traced.
+ */
+ if (delta < 0)
+ delta = 0;
+ }
+ ticks_left -= delta;
}
#ifdef DELAYDEBUG
if (state == 1)
diff --git a/sys/i386/i386/tsc.c b/sys/i386/i386/tsc.c
index 9319e4c..faa38fd 100644
--- a/sys/i386/i386/tsc.c
+++ b/sys/i386/i386/tsc.c
@@ -146,6 +146,7 @@ static void (*timer_func) __P((struct clockframe *frame)) = hardclock;
#if defined(I586_CPU) || defined(I686_CPU)
static void set_i586_ctr_freq(u_int i586_freq, u_int i8254_freq);
#endif
+static void set_timer_freq(u_int freq, int intr_freq);
static void
clkintr(struct clockframe frame)
@@ -361,7 +362,7 @@ getit(void)
void
DELAY(int n)
{
- int prev_tick, tick, ticks_left, sec, usec;
+ int delta, prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@@ -378,6 +379,13 @@ DELAY(int n)
printf("DELAY(%d)...", n);
#endif
/*
+ * Guard against the timer being uninitialized if we are called
+ * early for console i/o.
+ */
+ if (timer0_max_count == 0)
+ set_timer_freq(timer_freq, hz);
+
+ /*
* Read the counter first, so that the rest of the setup overhead is
* counted. Guess the initial overhead is 20 usec (on most systems it
* takes about 1.5 usec for each of the i/o's in getit(). The loop
@@ -404,11 +412,20 @@ DELAY(int n)
#ifdef DELAYDEBUG
++getit_calls;
#endif
- if (tick > prev_tick)
- ticks_left -= prev_tick - (tick - timer0_max_count);
- else
- ticks_left -= prev_tick - tick;
+ delta = prev_tick - tick;
prev_tick = tick;
+ if (delta < 0) {
+ delta += timer0_max_count;
+ /*
+ * Guard against timer0_max_count being wrong.
+ * This shouldn't happen in normal operation,
+ * but it may happen if set_timer_freq() is
+ * traced.
+ */
+ if (delta < 0)
+ delta = 0;
+ }
+ ticks_left -= delta;
}
#ifdef DELAYDEBUG
if (state == 1)
diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c
index 9319e4c..faa38fd 100644
--- a/sys/i386/isa/clock.c
+++ b/sys/i386/isa/clock.c
@@ -146,6 +146,7 @@ static void (*timer_func) __P((struct clockframe *frame)) = hardclock;
#if defined(I586_CPU) || defined(I686_CPU)
static void set_i586_ctr_freq(u_int i586_freq, u_int i8254_freq);
#endif
+static void set_timer_freq(u_int freq, int intr_freq);
static void
clkintr(struct clockframe frame)
@@ -361,7 +362,7 @@ getit(void)
void
DELAY(int n)
{
- int prev_tick, tick, ticks_left, sec, usec;
+ int delta, prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@@ -378,6 +379,13 @@ DELAY(int n)
printf("DELAY(%d)...", n);
#endif
/*
+ * Guard against the timer being uninitialized if we are called
+ * early for console i/o.
+ */
+ if (timer0_max_count == 0)
+ set_timer_freq(timer_freq, hz);
+
+ /*
* Read the counter first, so that the rest of the setup overhead is
* counted. Guess the initial overhead is 20 usec (on most systems it
* takes about 1.5 usec for each of the i/o's in getit(). The loop
@@ -404,11 +412,20 @@ DELAY(int n)
#ifdef DELAYDEBUG
++getit_calls;
#endif
- if (tick > prev_tick)
- ticks_left -= prev_tick - (tick - timer0_max_count);
- else
- ticks_left -= prev_tick - tick;
+ delta = prev_tick - tick;
prev_tick = tick;
+ if (delta < 0) {
+ delta += timer0_max_count;
+ /*
+ * Guard against timer0_max_count being wrong.
+ * This shouldn't happen in normal operation,
+ * but it may happen if set_timer_freq() is
+ * traced.
+ */
+ if (delta < 0)
+ delta = 0;
+ }
+ ticks_left -= delta;
}
#ifdef DELAYDEBUG
if (state == 1)
diff --git a/sys/isa/atrtc.c b/sys/isa/atrtc.c
index 9319e4c..faa38fd 100644
--- a/sys/isa/atrtc.c
+++ b/sys/isa/atrtc.c
@@ -146,6 +146,7 @@ static void (*timer_func) __P((struct clockframe *frame)) = hardclock;
#if defined(I586_CPU) || defined(I686_CPU)
static void set_i586_ctr_freq(u_int i586_freq, u_int i8254_freq);
#endif
+static void set_timer_freq(u_int freq, int intr_freq);
static void
clkintr(struct clockframe frame)
@@ -361,7 +362,7 @@ getit(void)
void
DELAY(int n)
{
- int prev_tick, tick, ticks_left, sec, usec;
+ int delta, prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@@ -378,6 +379,13 @@ DELAY(int n)
printf("DELAY(%d)...", n);
#endif
/*
+ * Guard against the timer being uninitialized if we are called
+ * early for console i/o.
+ */
+ if (timer0_max_count == 0)
+ set_timer_freq(timer_freq, hz);
+
+ /*
* Read the counter first, so that the rest of the setup overhead is
* counted. Guess the initial overhead is 20 usec (on most systems it
* takes about 1.5 usec for each of the i/o's in getit(). The loop
@@ -404,11 +412,20 @@ DELAY(int n)
#ifdef DELAYDEBUG
++getit_calls;
#endif
- if (tick > prev_tick)
- ticks_left -= prev_tick - (tick - timer0_max_count);
- else
- ticks_left -= prev_tick - tick;
+ delta = prev_tick - tick;
prev_tick = tick;
+ if (delta < 0) {
+ delta += timer0_max_count;
+ /*
+ * Guard against timer0_max_count being wrong.
+ * This shouldn't happen in normal operation,
+ * but it may happen if set_timer_freq() is
+ * traced.
+ */
+ if (delta < 0)
+ delta = 0;
+ }
+ ticks_left -= delta;
}
#ifdef DELAYDEBUG
if (state == 1)
OpenPOWER on IntegriCloud