xref: /netbsd-src/sys/arch/alpha/stand/netboot/getsecs.c (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1 /*	$NetBSD: getsecs.c,v 1.9 2009/01/12 11:32:43 tsutsui Exp $	*/
2 
3 #include <sys/param.h>
4 
5 #include <netinet/in.h>
6 #include <netinet/in_systm.h>
7 
8 #include <lib/libsa/stand.h>
9 #include <lib/libsa/net.h>
10 
11 #include "include/prom.h"
12 #include "include/rpb.h"
13 
14 satime_t
15 getsecs(void)
16 {
17 	static uint64_t tnsec;
18 	static uint64_t lastpcc, wrapsecs;
19 	uint64_t curpcc;
20 
21 	if (tnsec == 0) {
22 		tnsec = 1;
23 		lastpcc = alpha_rpcc() & 0xffffffff;
24 		wrapsecs = (0xffffffff /
25 		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq) + 1;
26 
27 #if 0
28 		printf("getsecs: cc freq = %lu, time to wrap = %lu\n",
29 		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq, wrapsecs);
30 #endif
31 	}
32 
33 	curpcc = alpha_rpcc() & 0xffffffff;
34 	if (curpcc < lastpcc)
35 		curpcc += 0x100000000;
36 
37 	tnsec += ((curpcc - lastpcc) * 1000000000) / ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq;
38 	lastpcc = curpcc;
39 
40 	return (tnsec / 1000000000);
41 }
42