diff options
author | Steve Murphree <smurph@cvs.openbsd.org> | 2001-01-04 04:00:52 +0000 |
---|---|---|
committer | Steve Murphree <smurph@cvs.openbsd.org> | 2001-01-04 04:00:52 +0000 |
commit | b1b3d031415edfb48aab1793d2e15ee7848ed3d8 (patch) | |
tree | d65400dcf3927155eb10aac3429191118d64e952 /sys/arch/mvme68k | |
parent | 0c9620f6dd6ca69d903fa67f3612a5fc058d990b (diff) |
Y2K fix for TODC - Submitted by Bob Harbour. Thanks Bob!
Diffstat (limited to 'sys/arch/mvme68k')
-rw-r--r-- | sys/arch/mvme68k/dev/nvram.c | 120 |
1 files changed, 70 insertions, 50 deletions
diff --git a/sys/arch/mvme68k/dev/nvram.c b/sys/arch/mvme68k/dev/nvram.c index 95fb75eb3df..5d32e7bcf1d 100644 --- a/sys/arch/mvme68k/dev/nvram.c +++ b/sys/arch/mvme68k/dev/nvram.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nvram.c,v 1.6 2000/04/11 02:44:29 pjanzen Exp $ */ +/* $OpenBSD: nvram.c,v 1.7 2001/01/04 04:00:51 smurph Exp $ */ /* * Copyright (c) 1995 Theo de Raadt @@ -31,6 +31,11 @@ * SUCH DAMAGE. */ +/* + * 8/22/2000 BH Cleaned up year 2000 problems with calendar hardware. + * This code will break again in 2068 or so - come dance on my grave. + */ + #include <sys/param.h> #include <sys/kernel.h> #include <sys/ioctl.h> @@ -46,15 +51,15 @@ #endif struct nvramsoftc { - struct device sc_dev; - void * sc_paddr; - void * sc_vaddr; - int sc_len; + struct device sc_dev; + void * sc_paddr; + void * sc_vaddr; + int sc_len; struct clockreg *sc_regs; }; -void nvramattach __P((struct device *, struct device *, void *)); -int nvrammatch __P((struct device *, void *, void *)); +void nvramattach __P((struct device *, struct device *, void *)); +int nvrammatch __P((struct device *, void *, void *)); struct cfattach nvram_ca = { sizeof(struct nvramsoftc), nvrammatch, nvramattach @@ -66,11 +71,11 @@ struct cfdriver nvram_cd = { int nvrammatch(parent, vcf, args) - struct device *parent; - void *vcf, *args; +struct device *parent; +void *vcf, *args; { struct cfdata *cf = vcf; - struct confargs *ca = args; + struct confargs *ca = args; /*X*/ if (ca->ca_vaddr == (void *)-1) /*X*/ return (1); @@ -79,8 +84,8 @@ nvrammatch(parent, vcf, args) void nvramattach(parent, self, args) - struct device *parent, *self; - void *args; +struct device *parent, *self; +void *args; { struct confargs *ca = args; struct nvramsoftc *sc = (struct nvramsoftc *)self; @@ -92,14 +97,15 @@ nvramattach(parent, self, args) if (cputyp == CPU_147) sc->sc_len = MK48T02_SIZE; + /*X*/ if (sc->sc_vaddr == (void *)-1) /*X*/ sc->sc_vaddr = mapiodev((void *)sc->sc_paddr, -/*X*/ max(sc->sc_len, NBPG)); +/*X*/ max(sc->sc_len, NBPG)); /*X*/ if (sc->sc_vaddr == NULL) /*X*/ panic("failed to map!"); sc->sc_regs = (struct clockreg *)(sc->sc_vaddr + sc->sc_len - - sizeof(struct clockreg)); + sizeof(struct clockreg)); printf(": MK48T0%d len %d\n", sc->sc_len / 1024, sc->sc_len); } @@ -116,7 +122,7 @@ nvramattach(parent, self, args) */ void microtime(tvp) - register struct timeval *tvp; +register struct timeval *tvp; { int s = splhigh(); static struct timeval lasttime; @@ -152,11 +158,11 @@ microtime(tvp) * Will Unix still be here then?? */ const short dayyr[12] = - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; +{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; static u_long chiptotime(sec, min, hour, day, mon, year) - register int sec, min, hour, day, mon, year; +register int sec, min, hour, day, mon, year; { register int days, yr; @@ -168,38 +174,52 @@ chiptotime(sec, min, hour, day, mon, year) year = FROMBCD(year) + YEAR0; /* simple sanity checks */ - if (year < 70 || year > 164 || mon < 1 || mon > 12 || day < 1 || day > 31) + if (year>164 || mon<1 || mon>12 || day<1 || day>31) return (0); + yr = 70; days = 0; - for (yr = 70; yr < year; yr++) + + if (year < 70) { /* 2000 <= year */ + for (; yr < 100; yr++) /* deal with first 30 years */ + days += LEAPYEAR(yr) ? 366 : 365; + yr = 0; + } + + for (; yr < year; yr++) /* deal with years left */ days += LEAPYEAR(yr) ? 366 : 365; + days += dayyr[mon - 1] + day - 1; + if (LEAPYEAR(yr) && mon > 2) days++; + /* now have days since Jan 1, 1970; the rest is easy... */ return (days * SECDAY + hour * 3600 + min * 60 + sec); } struct chiptime { - int sec; - int min; - int hour; - int wday; - int day; - int mon; - int year; + int sec; + int min; + int hour; + int wday; + int day; + int mon; + int year; }; timetochip(c) - register struct chiptime *c; +register struct chiptime *c; { register int t, t2, t3, now = time.tv_sec; - /* compute the year */ + /* January 1 1970 was a Thursday (4 in unix wdays) */ + /* compute the days since the epoch */ t2 = now / SECDAY; - t3 = (t2 + 2) % 7; /* day of week */ + + t3 = (t2 + 4) % 7; /* day of week */ c->wday = TOBCD(t3 + 1); + /* compute the year */ t = 69; while (t2 >= 0) { /* whittle off years */ t3 = t2; @@ -211,7 +231,7 @@ timetochip(c) /* t3 = month + day; separate */ t = LEAPYEAR(t); for (t2 = 1; t2 < 12; t2++) - if (t3 < dayyr[t2] + (t && t2 > 1)) + if (t3 < (dayyr[t2] + ((t && (t2 > 1)) ? 1:0))) break; /* t2 is month */ @@ -232,14 +252,14 @@ timetochip(c) c->hour = TOBCD(c->hour); c->day = TOBCD(c->day); c->mon = TOBCD(c->mon); - c->year = TOBCD(c->year - YEAR0); + c->year = TOBCD((c->year - YEAR0) % 100); } /* * Set up the system's time, given a `reasonable' time value. */ inittodr(base) - time_t base; +time_t base; { struct nvramsoftc *sc = (struct nvramsoftc *) nvram_cd.cd_devs[0]; register struct clockreg *cl = sc->sc_regs; @@ -282,7 +302,7 @@ inittodr(base) if (waszero || deltat < 2 * SECDAY) return; printf("WARNING: clock %s %d days", - time.tv_sec < base ? "lost" : "gained", deltat / SECDAY); + time.tv_sec < base ? "lost" : "gained", deltat / SECDAY); } printf(" -- CHECK AND RESET THE DATE!\n"); } @@ -316,8 +336,8 @@ resettodr() /*ARGSUSED*/ int nvramopen(dev, flag, mode) - dev_t dev; - int flag, mode; +dev_t dev; +int flag, mode; { if (minor(dev) >= nvram_cd.cd_ndevs || nvram_cd.cd_devs[minor(dev)] == NULL) @@ -328,8 +348,8 @@ nvramopen(dev, flag, mode) /*ARGSUSED*/ int nvramclose(dev, flag, mode) - dev_t dev; - int flag, mode; +dev_t dev; +int flag, mode; { return (0); @@ -338,15 +358,15 @@ nvramclose(dev, flag, mode) /*ARGSUSED*/ int nvramioctl(dev, cmd, data, flag, p) - dev_t dev; - caddr_t data; - int cmd, flag; - struct proc *p; +dev_t dev; +caddr_t data; +int cmd, flag; +struct proc *p; { int unit = minor(dev); struct nvramsoftc *sc = (struct nvramsoftc *) nvram_cd.cd_devs[unit]; int error = 0; - + switch (cmd) { case MIOCGSIZ: *(int *)data = sc->sc_len; @@ -361,9 +381,9 @@ nvramioctl(dev, cmd, data, flag, p) /*ARGSUSED*/ int nvramread(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; +dev_t dev; +struct uio *uio; +int flags; { int unit = minor(dev); struct nvramsoftc *sc = (struct nvramsoftc *) nvram_cd.cd_devs[unit]; @@ -374,9 +394,9 @@ nvramread(dev, uio, flags) /*ARGSUSED*/ int nvramwrite(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; +dev_t dev; +struct uio *uio; +int flags; { int unit = minor(dev); struct nvramsoftc *sc = (struct nvramsoftc *) nvram_cd.cd_devs[unit]; @@ -391,8 +411,8 @@ nvramwrite(dev, uio, flags) */ int nvrammmap(dev, off, prot) - dev_t dev; - int off, prot; +dev_t dev; +int off, prot; { int unit = minor(dev); struct nvramsoftc *sc = (struct nvramsoftc *) nvram_cd.cd_devs[unit]; |