summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1996-01-08 18:50:14 +0000
committerache <ache@FreeBSD.org>1996-01-08 18:50:14 +0000
commit010b876e8e03d78ced2b27469a3c7ba90d999669 (patch)
treee6afa811bd0f4dea454b4d14c9dfe04f153f47ef
parent68695555370902143d4aa7d03e11d7ef2109e785 (diff)
downloadFreeBSD-src-010b876e8e03d78ced2b27469a3c7ba90d999669.zip
FreeBSD-src-010b876e8e03d78ced2b27469a3c7ba90d999669.tar.gz
Replace ugly year/month calculations in resettodr to more clean
variants, idea taken from NetBSD clock.c. At least year calculation was wrong, pointed by Bruce. Use different strategy to store year for BIOS without RTC_CENTURY
-rw-r--r--sys/amd64/amd64/tsc.c26
-rw-r--r--sys/amd64/isa/clock.c26
-rw-r--r--sys/i386/i386/tsc.c26
-rw-r--r--sys/i386/isa/clock.c26
-rw-r--r--sys/isa/atrtc.c26
5 files changed, 60 insertions, 70 deletions
diff --git a/sys/amd64/amd64/tsc.c b/sys/amd64/amd64/tsc.c
index 6dc5896..487e7bc 100644
--- a/sys/amd64/amd64/tsc.c
+++ b/sys/amd64/amd64/tsc.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
- * $Id: clock.c,v 1.43 1995/12/24 08:10:52 davidg Exp $
+ * $Id: clock.c,v 1.44 1996/01/04 21:11:33 wollman Exp $
*/
/*
@@ -529,27 +529,25 @@ resettodr()
/* We have now the days since 01-01-1970 in tm */
writertc(RTC_WDAY, (tm+4)%7); /* Write back Weekday */
- for (y=1970;; y++)
- if ((tm - DAYSPERYEAR - LEAPYEAR(y)) > tm)
- break;
- else
- tm -= DAYSPERYEAR + LEAPYEAR(y);
+ for (y = 1970, m = DAYSPERYEAR + LEAPYEAR(y);
+ tm >= m;
+ y++, m = DAYSPERYEAR + LEAPYEAR(y))
+ tm -= m;
/* Now we have the years in y and the day-of-the-year in tm */
- writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
#ifdef USE_RTC_CENTURY
+ writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
writertc(RTC_CENTURY, int2bcd(y/100)); /* ... and Century */
+#else
+ writertc(RTC_YEAR, int2bcd(y - 1900)); /* Write back Year */
#endif
if (LEAPYEAR(y) && (tm >= 31+29))
tm--; /* Subtract Feb-29 */
- for (m=1;; m++)
- if (tm - daysinmonth[m-1] > tm)
- break;
- else
- tm -= daysinmonth[m-1];
+ for (m = 0; tm >= daysinmonth[m]; m++)
+ tm -= daysinmonth[m];
- writertc(RTC_MONTH, int2bcd(m)); /* Write back Month */
- writertc(RTC_DAY, int2bcd(tm+1)); /* Write back Day */
+ writertc(RTC_MONTH, int2bcd(m + 1)); /* Write back Month */
+ writertc(RTC_DAY, int2bcd(tm + 1)); /* Write back Month Day */
/* Reenable RTC updates and interrupts. */
writertc(RTC_STATUSB, RTCSB_24HR | RTCSB_PINTR);
diff --git a/sys/amd64/isa/clock.c b/sys/amd64/isa/clock.c
index 6dc5896..487e7bc 100644
--- a/sys/amd64/isa/clock.c
+++ b/sys/amd64/isa/clock.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
- * $Id: clock.c,v 1.43 1995/12/24 08:10:52 davidg Exp $
+ * $Id: clock.c,v 1.44 1996/01/04 21:11:33 wollman Exp $
*/
/*
@@ -529,27 +529,25 @@ resettodr()
/* We have now the days since 01-01-1970 in tm */
writertc(RTC_WDAY, (tm+4)%7); /* Write back Weekday */
- for (y=1970;; y++)
- if ((tm - DAYSPERYEAR - LEAPYEAR(y)) > tm)
- break;
- else
- tm -= DAYSPERYEAR + LEAPYEAR(y);
+ for (y = 1970, m = DAYSPERYEAR + LEAPYEAR(y);
+ tm >= m;
+ y++, m = DAYSPERYEAR + LEAPYEAR(y))
+ tm -= m;
/* Now we have the years in y and the day-of-the-year in tm */
- writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
#ifdef USE_RTC_CENTURY
+ writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
writertc(RTC_CENTURY, int2bcd(y/100)); /* ... and Century */
+#else
+ writertc(RTC_YEAR, int2bcd(y - 1900)); /* Write back Year */
#endif
if (LEAPYEAR(y) && (tm >= 31+29))
tm--; /* Subtract Feb-29 */
- for (m=1;; m++)
- if (tm - daysinmonth[m-1] > tm)
- break;
- else
- tm -= daysinmonth[m-1];
+ for (m = 0; tm >= daysinmonth[m]; m++)
+ tm -= daysinmonth[m];
- writertc(RTC_MONTH, int2bcd(m)); /* Write back Month */
- writertc(RTC_DAY, int2bcd(tm+1)); /* Write back Day */
+ writertc(RTC_MONTH, int2bcd(m + 1)); /* Write back Month */
+ writertc(RTC_DAY, int2bcd(tm + 1)); /* Write back Month Day */
/* Reenable RTC updates and interrupts. */
writertc(RTC_STATUSB, RTCSB_24HR | RTCSB_PINTR);
diff --git a/sys/i386/i386/tsc.c b/sys/i386/i386/tsc.c
index 6dc5896..487e7bc 100644
--- a/sys/i386/i386/tsc.c
+++ b/sys/i386/i386/tsc.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
- * $Id: clock.c,v 1.43 1995/12/24 08:10:52 davidg Exp $
+ * $Id: clock.c,v 1.44 1996/01/04 21:11:33 wollman Exp $
*/
/*
@@ -529,27 +529,25 @@ resettodr()
/* We have now the days since 01-01-1970 in tm */
writertc(RTC_WDAY, (tm+4)%7); /* Write back Weekday */
- for (y=1970;; y++)
- if ((tm - DAYSPERYEAR - LEAPYEAR(y)) > tm)
- break;
- else
- tm -= DAYSPERYEAR + LEAPYEAR(y);
+ for (y = 1970, m = DAYSPERYEAR + LEAPYEAR(y);
+ tm >= m;
+ y++, m = DAYSPERYEAR + LEAPYEAR(y))
+ tm -= m;
/* Now we have the years in y and the day-of-the-year in tm */
- writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
#ifdef USE_RTC_CENTURY
+ writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
writertc(RTC_CENTURY, int2bcd(y/100)); /* ... and Century */
+#else
+ writertc(RTC_YEAR, int2bcd(y - 1900)); /* Write back Year */
#endif
if (LEAPYEAR(y) && (tm >= 31+29))
tm--; /* Subtract Feb-29 */
- for (m=1;; m++)
- if (tm - daysinmonth[m-1] > tm)
- break;
- else
- tm -= daysinmonth[m-1];
+ for (m = 0; tm >= daysinmonth[m]; m++)
+ tm -= daysinmonth[m];
- writertc(RTC_MONTH, int2bcd(m)); /* Write back Month */
- writertc(RTC_DAY, int2bcd(tm+1)); /* Write back Day */
+ writertc(RTC_MONTH, int2bcd(m + 1)); /* Write back Month */
+ writertc(RTC_DAY, int2bcd(tm + 1)); /* Write back Month Day */
/* Reenable RTC updates and interrupts. */
writertc(RTC_STATUSB, RTCSB_24HR | RTCSB_PINTR);
diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c
index 6dc5896..487e7bc 100644
--- a/sys/i386/isa/clock.c
+++ b/sys/i386/isa/clock.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
- * $Id: clock.c,v 1.43 1995/12/24 08:10:52 davidg Exp $
+ * $Id: clock.c,v 1.44 1996/01/04 21:11:33 wollman Exp $
*/
/*
@@ -529,27 +529,25 @@ resettodr()
/* We have now the days since 01-01-1970 in tm */
writertc(RTC_WDAY, (tm+4)%7); /* Write back Weekday */
- for (y=1970;; y++)
- if ((tm - DAYSPERYEAR - LEAPYEAR(y)) > tm)
- break;
- else
- tm -= DAYSPERYEAR + LEAPYEAR(y);
+ for (y = 1970, m = DAYSPERYEAR + LEAPYEAR(y);
+ tm >= m;
+ y++, m = DAYSPERYEAR + LEAPYEAR(y))
+ tm -= m;
/* Now we have the years in y and the day-of-the-year in tm */
- writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
#ifdef USE_RTC_CENTURY
+ writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
writertc(RTC_CENTURY, int2bcd(y/100)); /* ... and Century */
+#else
+ writertc(RTC_YEAR, int2bcd(y - 1900)); /* Write back Year */
#endif
if (LEAPYEAR(y) && (tm >= 31+29))
tm--; /* Subtract Feb-29 */
- for (m=1;; m++)
- if (tm - daysinmonth[m-1] > tm)
- break;
- else
- tm -= daysinmonth[m-1];
+ for (m = 0; tm >= daysinmonth[m]; m++)
+ tm -= daysinmonth[m];
- writertc(RTC_MONTH, int2bcd(m)); /* Write back Month */
- writertc(RTC_DAY, int2bcd(tm+1)); /* Write back Day */
+ writertc(RTC_MONTH, int2bcd(m + 1)); /* Write back Month */
+ writertc(RTC_DAY, int2bcd(tm + 1)); /* Write back Month Day */
/* Reenable RTC updates and interrupts. */
writertc(RTC_STATUSB, RTCSB_24HR | RTCSB_PINTR);
diff --git a/sys/isa/atrtc.c b/sys/isa/atrtc.c
index 6dc5896..487e7bc 100644
--- a/sys/isa/atrtc.c
+++ b/sys/isa/atrtc.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
- * $Id: clock.c,v 1.43 1995/12/24 08:10:52 davidg Exp $
+ * $Id: clock.c,v 1.44 1996/01/04 21:11:33 wollman Exp $
*/
/*
@@ -529,27 +529,25 @@ resettodr()
/* We have now the days since 01-01-1970 in tm */
writertc(RTC_WDAY, (tm+4)%7); /* Write back Weekday */
- for (y=1970;; y++)
- if ((tm - DAYSPERYEAR - LEAPYEAR(y)) > tm)
- break;
- else
- tm -= DAYSPERYEAR + LEAPYEAR(y);
+ for (y = 1970, m = DAYSPERYEAR + LEAPYEAR(y);
+ tm >= m;
+ y++, m = DAYSPERYEAR + LEAPYEAR(y))
+ tm -= m;
/* Now we have the years in y and the day-of-the-year in tm */
- writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
#ifdef USE_RTC_CENTURY
+ writertc(RTC_YEAR, int2bcd(y%100)); /* Write back Year */
writertc(RTC_CENTURY, int2bcd(y/100)); /* ... and Century */
+#else
+ writertc(RTC_YEAR, int2bcd(y - 1900)); /* Write back Year */
#endif
if (LEAPYEAR(y) && (tm >= 31+29))
tm--; /* Subtract Feb-29 */
- for (m=1;; m++)
- if (tm - daysinmonth[m-1] > tm)
- break;
- else
- tm -= daysinmonth[m-1];
+ for (m = 0; tm >= daysinmonth[m]; m++)
+ tm -= daysinmonth[m];
- writertc(RTC_MONTH, int2bcd(m)); /* Write back Month */
- writertc(RTC_DAY, int2bcd(tm+1)); /* Write back Day */
+ writertc(RTC_MONTH, int2bcd(m + 1)); /* Write back Month */
+ writertc(RTC_DAY, int2bcd(tm + 1)); /* Write back Month Day */
/* Reenable RTC updates and interrupts. */
writertc(RTC_STATUSB, RTCSB_24HR | RTCSB_PINTR);
OpenPOWER on IntegriCloud