* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)clock.c 7.3 (Berkeley) 7/9/88
* 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.
(*cpuops
->cpu_clock
->clkstartrt
)();
* 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 (if any) provides the rest.
long deltat
, badbase
= 0;
printf("WARNING: preposterous time in file system\n");
/* read the system clock anyway */
base
= 6*SECYR
+ 186*SECDAY
+ SECDAY
/2;
switch ((*cpuops
->cpu_clock
->clkread
)(base
)) {
* Believe the time in the file system for lack of
* anything better, resetting the TODR.
* 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.
(*cpuops
->cpu_clock
->clkwrite
)();
* ``Standard'' VAX clock routines.
#if VAX8600 || VAX8200 || VAX780 || VAX750 || VAX730
mtpr(ICCS
, ICCS_RUN
+ICCS_IE
+ICCS_TRANS
+ICCS_INT
+ICCS_ERR
);
#if VAX8600 || VAX780 || VAX750 || VAX730
register u_int todr
= mfpr(TODR
);
* TODRZERO is base used by VMS, which runs on local time.
printf("WARNING: todr too small");
* Sneak to within 6 months 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) {
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);
* This code is defunct after 2099.
* Will Unix still be here then??
short dayyr
[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
register struct chiptime
*c
;
/* simple sanity checks */
if (c
->year
< 70 || c
->mon
< 1 || c
->mon
> 12 ||
c
->day
< 1 || c
->day
> 31) {
printf("WARNING: preposterous clock chip time");
for (yr
= 70; yr
< c
->year
; yr
++)
days
+= LEAPYEAR(yr
) ? 366 : 365;
days
+= dayyr
[c
->mon
- 1] + c
->day
- 1;
if (LEAPYEAR(yr
) && c
->mon
> 2)
/* now have days since Jan 1, 1970; the rest is easy... */
return (days
* SECDAY
+ c
->hour
* 3600 + c
->min
* 60 + c
->sec
);
register struct chiptime
*c
;
t2
= time
.tv_sec
/ SECDAY
;
while (t2
>= 0) { /* whittle off years */
t2
-= LEAPYEAR(t
) ? 366 : 365;
/* t3 = month + day; separate */
for (t2
= 1; t2
< 12; t2
++)
if (t3
< dayyr
[t2
] + (t
&& t2
> 1))
c
->day
= t3
- dayyr
[t2
- 1] + 1;
t
= time
.tv_sec
% SECDAY
;