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