xref: /original-bsd/sys/tahoe/tahoe/clock.c (revision 94c97675)
1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)clock.c	7.2 (Berkeley) 06/29/88
18  */
19 
20 #include "param.h"
21 #include "time.h"
22 #include "kernel.h"
23 
24 #include "pte.h"
25 #include "cpu.h"
26 #include "mtpr.h"
27 #include "clock.h"
28 #include "cp.h"
29 
30 /*
31  * Machine-dependent clock routines.
32  *
33  * Startrtclock restarts the real-time clock, which provides
34  * hardclock interrupts to kern_clock.c.
35  *
36  * Inittodr initializes any time of day hardware which provides
37  * date functions.  Its primary function is to use some file
38  * system information in case the hardare clock lost state.
39  */
40 
41 /*
42  * Start the real-time clock by initializing the
43  * interval timer on the console processor card
44  * according to hz.
45  */
46 startrtclock()
47 {
48 	register int t;
49 	static struct cphdr cpclock;	/* must be in data space */
50 
51 	cpclock.cp_unit = CPCLOCK;
52 	cpclock.cp_comm = CPWRITE;
53 	if (hz == 0) {
54 		extern int tickadj;		/* XXX */
55 		hz = 60;
56 		tick = 1000000 / hz;
57 		tickadj = 240000 / (60 * hz);
58 		printf("clock set to %dhz\n", hz);
59 	}
60 	cpclock.cp_count = hztocount(hz);
61 	if (cnlast) {
62 		/* try to insure last cmd was taken by cp */
63 		for (t = 30000; (cnlast->cp_unit&CPTAKE) == 0 && t > 0; t--)
64 			uncache(&cnlast->cp_unit);
65 		cnlast = 0;
66 	}
67 	mtpr(CPMDCB, kvtophys(&cpclock));
68 	for (t = 30000; (cpclock.cp_unit&CPDONE) == 0 && t > 0; t--)
69 		uncache(&cpclock.cp_unit);
70 }
71 
72 /*
73  * Initialze the time of day register, based on
74  * the time base which is, e.g. from a filesystem.
75  */
76 inittodr(base)
77 	time_t base;
78 {
79 
80 	if (base < 5*SECYR) {
81 		printf("WARNING: preposterous time in file system ");
82 		time.tv_sec = 6*SECYR + 186*SECDAY + SECDAY/2;
83 	} else
84 		time.tv_sec = base;
85 	printf("CHECK AND RESET THE DATE!\n");
86 }
87