* @(#)ka630.c 7.1 (Berkeley) %G%
/* ka630.c routines for the ka630 clock chip... */
* These two fuctions handle the tod clock
* This code is defunct at the end of the century.
* Will Unix still be here then??
struct cldevice cldevice
;
struct ka630cpu ka630cpu
;
short dayyr
[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, };
/* Starts the tod clock. Called from clkstart... */
struct pte
*pte
= &Clockmap
[0];
register struct cldevice
*claddr
= &cldevice
;
struct ka630cpu
*ka630addr
= &ka630cpu
;
/* Enable system page for registers */
*(int *)pte
= PG_V
|PG_KW
|btop(0x200b8000);
*(int *)pte
= PG_V
|PG_KW
|btop(0x20080000);
* Clear restart and boot in progress flags in the CPMBX. This has
* nothing to do with the clock except that it the CPMBX reg. is a
* byte in the clock's ram.
claddr
->cpmbx
=(u_short
)((claddr
->cpmbx
&KA630CLK_LANG
)|KA630CLK_REBOOT
);
* Enable memory parity error detection. again nothing to do with the
* tod clock except for being a convenient place.
ka630addr
->ka630_mser
= KA630MSER_PAREN
;
claddr
->csr1
= KA630CLK_SET
;
while ((claddr
->csr0
& KA630CLK_UIP
) != 0)
/* If the clock is valid, use it. */
if ((claddr
->csr3
& KA630CLK_VRT
) != 0 &&
(claddr
->csr1
& KA630CLK_ENABLE
) == KA630CLK_ENABLE
) {
/* Convert yr,mon,day,hr,min,sec to sec past Jan.1, 1970. */
for (tmp1
= 70; tmp1
< claddr
->yr
; tmp1
++) {
/* I just luv leap years... */
tmp2
+= (dayyr
[claddr
->mon
-1]+claddr
->day
-1);
if (LEAPYEAR(claddr
->yr
) && claddr
->mon
> 2)
/* Finally got days past Jan. 1,1970. the rest is easy.. */
time
.tv_sec
= tmp2
*SECDAY
+claddr
->hr
*HRSEC
+
claddr
->min
*MINSEC
+claddr
->sec
;
claddr
->csr0
= KA630CLK_RATE
;
claddr
->csr1
= KA630CLK_ENABLE
;
} else if (base
< 5*SECYR
) {
printf("WARNING: preposterous time in file system\n");
time
.tv_sec
= 6*SECYR
+186*SECDAY
+SECDAY
/2;
printf("WARNING: Time set via file system\n");
/* Set the time of day clock, called via. stime system call.. */
register struct cldevice
*claddr
= &cldevice
;
claddr
->csr1
= KA630CLK_SET
;
while ((claddr
->csr0
& KA630CLK_UIP
) != 0)
/* The reverse of above, sec. past Jan. 1,1970 to yr, mon... */
tmp2
= time
.tv_sec
/HRSEC
;
tmp2
= tmp3
-dayyr
[++tmp1
];
if (LEAPYEAR(claddr
->yr
) && tmp1
> 1)
/* Finally, got the rest... */
claddr
->day
= tmp3
-dayyr
[tmp1
-1]+1;
if (LEAPYEAR(claddr
->yr
) && tmp1
> 2)
tmp2
= time
.tv_sec
-(tmp4
*SECDAY
);
claddr
->min
= tmp2
/MINSEC
;
claddr
->csr0
= KA630CLK_RATE
;
claddr
->csr1
= KA630CLK_ENABLE
;