xref: /netbsd-src/sys/arch/i386/stand/lib/getsecs.c (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /*	$NetBSD: getsecs.c,v 1.1.1.1 1997/03/14 02:40:32 perry Exp $	*/
2 
3 /* extracted from netbsd:sys/arch/i386/netboot/misc.c */
4 
5 #include <sys/types.h>
6 
7 #include <lib/libsa/stand.h>
8 
9 #include "libi386.h"
10 
11 extern int biosgetrtc __P((u_long*));
12 
13 static inline u_long
14 bcd2dec(arg)
15 u_long arg;
16 {
17   return((arg >> 4) * 10 + (arg & 0x0f));
18 }
19 
20 time_t
21 getsecs() {
22   /*
23    * Return the current time in seconds
24    */
25 
26   u_long t;
27   time_t sec;
28 
29   if(biosgetrtc(&t))
30       panic("RTC invalid");
31 
32   sec = bcd2dec(t & 0xff);
33   sec *= 60;
34   t >>= 8;
35   sec += bcd2dec(t & 0xff);
36   sec *= 60;
37   t >>= 8;
38   sec += bcd2dec(t & 0xff);
39 
40   return(sec);
41 }
42