mirror of
https://github.com/opnsense/src.git
synced 2026-04-15 14:29:58 -04:00
Introduce a boot environment variable (clock_compat_osf1) which can
be set to 1 to make FreeBSD and Tru64 coexist peacefully on a dual boot system and not clobber each other's year in the TOY clock. (Tru64 uses an offset 52 years higher than one would expect) Obtained from: NetBSD MFC After: 1 week
This commit is contained in:
parent
b8ea5f7f0f
commit
cd4e23cead
2 changed files with 28 additions and 13 deletions
|
|
@ -70,6 +70,17 @@
|
|||
#define SECDAY ((unsigned)(24*SECHOUR)) /* seconds per day */
|
||||
#define SECYR ((unsigned)(365*SECDAY)) /* seconds per common year */
|
||||
|
||||
/*
|
||||
* According to OSF/1's /usr/sys/include/arch/alpha/clock.h,
|
||||
* the console adjusts the RTC years 13..19 to 93..99 and
|
||||
* 20..40 to 00..20. (historical reasons?)
|
||||
* DEC Unix uses an offset to the year to stay outside
|
||||
* the dangerous area for the next couple of years.
|
||||
*/
|
||||
#define UNIX_YEAR_OFFSET 52 /* 41=>1993, 12=>2064 */
|
||||
|
||||
static int clock_year_offset = 0;
|
||||
|
||||
/*
|
||||
* 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
|
||||
* can use a simple formula for leap years.
|
||||
|
|
@ -472,7 +483,7 @@ inittodr(base)
|
|||
register int days, yr;
|
||||
struct clocktime ct;
|
||||
time_t deltat;
|
||||
int badbase;
|
||||
int badbase, clock_compat_osf1;
|
||||
int s;
|
||||
struct timespec ts;
|
||||
|
||||
|
|
@ -484,9 +495,22 @@ inittodr(base)
|
|||
} else
|
||||
badbase = 0;
|
||||
|
||||
if (getenv_int("clock_compat_osf1", &clock_compat_osf1)) {
|
||||
if (clock_compat_osf1)
|
||||
clock_year_offset = UNIX_YEAR_OFFSET;
|
||||
}
|
||||
|
||||
CLOCK_GET(clockdev, base, &ct);
|
||||
clockinitted = 1;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("readclock: %d/%d/%d/%d/%d/%d\n", ct.year, ct.mon, ct.day,
|
||||
ct.hour, ct.min, ct.sec);
|
||||
#endif
|
||||
ct.year += clock_year_offset;
|
||||
if (ct.year < 70)
|
||||
ct.year += 100;
|
||||
|
||||
/* simple sanity checks */
|
||||
if (ct.year < 70 || ct.mon < 1 || ct.mon > 12 || ct.day < 1 ||
|
||||
ct.day > 31 || ct.hour > 23 || ct.min > 59 || ct.sec > 59) {
|
||||
|
|
@ -595,6 +619,7 @@ resettodr()
|
|||
ct.min = t / SECMIN;
|
||||
ct.sec = t % SECMIN;
|
||||
|
||||
ct.year = (ct.year - clock_year_offset) % 100;
|
||||
CLOCK_SET(clockdev, &ct);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,13 +84,6 @@ mcclock_get(device_t dev, time_t base, struct clocktime *ct)
|
|||
ct->day = regs[MC_DOM];
|
||||
ct->mon = regs[MC_MONTH];
|
||||
ct->year = regs[MC_YEAR];
|
||||
/*
|
||||
* This chip is not y2k compliant- If it's less than
|
||||
* 70, we're clearly past the year 2000.
|
||||
*/
|
||||
if (ct->year < 70) {
|
||||
ct->year += 100;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -112,11 +105,8 @@ mcclock_set(device_t dev, struct clocktime *ct)
|
|||
regs[MC_DOW] = ct->dow;
|
||||
regs[MC_DOM] = ct->day;
|
||||
regs[MC_MONTH] = ct->mon;
|
||||
/*
|
||||
* This chip is not y2k compliant- write it with
|
||||
* no more than two digits.
|
||||
*/
|
||||
regs[MC_YEAR] = ct->year % 100;
|
||||
regs[MC_YEAR] = ct->year;
|
||||
|
||||
s = splclock();
|
||||
MC146818_PUTTOD(dev, ®s);
|
||||
splx(s);
|
||||
|
|
|
|||
Loading…
Reference in a new issue