/* clock.c 6.1 83/07/29 */
#include "../vax/clock.h"
* Machine-dependent clock routines.
* Startrtclock restarts the real-time clock, which provides
* hardclock interrupts to kern_clock.c.
* Inittodr initializes the time of day hardware which provides
* date functions. Its primary function is to use some file
* system information in case the hardare clock lost state.
* Resettodr restores the time of day hardware after a time change.
* Start the real-time clock.
mtpr(ICCS
, ICCS_RUN
+ICCS_IE
+ICCS_TRANS
+ICCS_INT
+ICCS_ERR
);
* Initialze the time of day register, based on the time base which is, e.g.
* from a filesystem. Base provides the time to within six months,
* and the time of year clock provides the rest.
register u_int todr
= mfpr(TODR
);
printf("WARNING: preposterous time in file system");
time
.tv_sec
= 6*SECYR
+ 186*SECDAY
+ SECDAY
/2;
* TODRZERO is base used by VMS, which runs on local time.
printf("WARNING: todr too small");
* Believe the time in the file system for lack of
* anything better, resetting the TODR.
* Sneak to within 6 month of the time in the filesystem,
* by starting with the time of the year suggested by the TODR,
* and advancing through succesive years. Adding the number of
* seconds in the current year takes us to the end of the current year
* and then around into the next year to the same position.
time
.tv_sec
= (todr
-TODRZERO
)/100;
while (time
.tv_sec
< base
-SECYR
/2) {
* See if we gained/lost two or more days;
* if so, assume something is amiss.
deltat
= time
.tv_sec
- base
;
printf("WARNING: clock %s %d days",
time
.tv_sec
< base
? "lost" : "gained", deltat
/ SECDAY
);
printf(" -- CHECK AND RESET THE DATE!\n");
* Reset the TODR based on the time value; used when the TODR
* has a preposterous value and also when the time is reset
* by the stime system call. Also called when the TODR goes past
* TODRZERO + 100*(SECYEAR+2*SECDAY) (e.g. on Jan 2 just after midnight)
* to wrap the TODR around.
u_int yrtime
= time
.tv_sec
;
* Whittle the time down to an offset in the current year,
* by subtracting off whole years as long as possible.
mtpr(TODR
, TODRZERO
+ yrtime
*100);