Initial import from FreeBSD RELENG_4:
[games.git] / sys / boot / alpha / libalpha / getsecs.c
1 /*
2  * $FreeBSD: src/sys/boot/alpha/libalpha/getsecs.c,v 1.2 1999/08/28 00:39:27 peter Exp $
3  * From:        $NetBSD: getsecs.c,v 1.5 1998/01/05 07:02:49 perry Exp $        
4  */
5
6 #include <sys/param.h>
7 #include <machine/prom.h>
8 #include <machine/rpb.h>
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 }