xref: /netbsd-src/sys/arch/i386/stand/lib/getsecs.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: getsecs.c,v 1.3 2008/12/14 17:03:43 christos 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(u_long*);
12 
13 static inline u_long bcd2dec(u_long);
14 
15 static inline u_long
16 bcd2dec(u_long arg)
17 {
18 	return (arg >> 4) * 10 + (arg & 0x0f);
19 }
20 
21 time_t
22 getsecs(void) {
23 	/*
24 	 * Return the current time in seconds
25 	 */
26 
27 	u_long t;
28 	time_t sec;
29 
30 	if (biosgetrtc(&t))
31 		panic("RTC invalid");
32 
33 	sec = bcd2dec(t & 0xff);
34 	sec *= 60;
35 	t >>= 8;
36 	sec += bcd2dec(t & 0xff);
37 	sec *= 60;
38 	t >>= 8;
39 	sec += bcd2dec(t & 0xff);
40 
41 	return sec;
42 }
43