xref: /original-bsd/sys/tahoe/tahoe/clock.c (revision 95407d66)
1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)clock.c	7.4 (Berkeley) 12/16/90
8  */
9 
10 #include "sys/param.h"
11 #include "sys/time.h"
12 #include "sys/kernel.h"
13 
14 #include "../include/pte.h"
15 #include "../include/cpu.h"
16 #include "../include/mtpr.h"
17 #include "../include/clock.h"
18 #include "cp.h"
19 
20 /*
21  * Machine-dependent clock routines.
22  *
23  * Startrtclock restarts the real-time clock, which provides
24  * hardclock interrupts to kern_clock.c.
25  *
26  * Inittodr initializes any time of day hardware which provides
27  * date functions.  Its primary function is to use some file
28  * system information in case the hardare clock lost state.
29  */
30 
31 /*
32  * Start the real-time clock by initializing the
33  * interval timer on the console processor card
34  * according to hz.
35  */
36 startrtclock()
37 {
38 	register int t;
39 	static struct cphdr cpclock;	/* must be in data space */
40 
41 	cpclock.cp_unit = CPCLOCK;
42 	cpclock.cp_comm = CPWRITE;
43 	if (hz == 0) {
44 		extern int tickadj;		/* XXX */
45 		hz = 60;
46 		tick = 1000000 / hz;
47 		tickadj = 240000 / (60 * hz);
48 		printf("clock set to %dhz\n", hz);
49 	}
50 	cpclock.cp_count = hztocount(hz);
51 	if (cnlast) {
52 		/* try to insure last cmd was taken by cp */
53 		for (t = 30000; (cnlast->cp_unit&CPTAKE) == 0 && t > 0; t--)
54 			uncache(&cnlast->cp_unit);
55 		cnlast = 0;
56 	}
57 	mtpr(CPMDCB, kvtophys(&cpclock));
58 	for (t = 30000; (cpclock.cp_unit&CPDONE) == 0 && t > 0; t--)
59 		uncache(&cpclock.cp_unit);
60 }
61 
62 /*
63  * Initialze the time of day register, based on
64  * the time base which is, e.g. from a filesystem.
65  */
66 inittodr(base)
67 	time_t base;
68 {
69 
70 	if (base < 5*SECYR) {
71 		printf("WARNING: preposterous time in file system ");
72 		time.tv_sec = 6*SECYR + 186*SECDAY + SECDAY/2;
73 	} else
74 		time.tv_sec = base;
75 	printf("CHECK AND RESET THE DATE!\n");
76 }
77