xref: /openbsd/sys/arch/alpha/stand/netboot/getsecs.c (revision 4bdff4be)
1 /*	$OpenBSD: getsecs.c,v 1.4 2023/01/16 07:29:35 deraadt Exp $	*/
2 
3 #include <sys/param.h>
4 #include "include/rpb.h"
5 #include "include/prom.h"
6 
7 
8 long alpha_rpcc(void);
9 
10 int
11 getsecs()
12 {
13 	static long tnsec;
14 	static long lastpcc, wrapsecs;
15 	long curpcc;
16 
17 	if (tnsec == 0) {
18 		tnsec = 1;
19 		lastpcc = alpha_rpcc() & 0xffffffff;
20 		wrapsecs = (0xffffffff /
21 		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq) + 1;
22 
23 #if 0
24 		printf("getsecs: cc freq = %d, time to wrap = %d\n",
25 		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq, wrapsecs);
26 #endif
27 	}
28 
29 	curpcc = alpha_rpcc() & 0xffffffff;
30 	if (curpcc < lastpcc)
31 		curpcc += 0x100000000;
32 
33 	tnsec += ((curpcc - lastpcc) * 1000000000) / ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq;
34 	lastpcc = curpcc;
35 
36 	return (tnsec / 1000000000);
37 }
38