1 1.4 tsutsui /* $NetBSD: getsecs.c,v 1.4 2009/01/12 11:32:44 tsutsui 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.4 tsutsui #include <lib/libsa/net.h> 9 1.1 perry 10 1.1 perry #include "libi386.h" 11 1.1 perry 12 1.3 christos static inline u_long bcd2dec(u_long); 13 1.2 drochner 14 1.1 perry static inline u_long 15 1.3 christos bcd2dec(u_long arg) 16 1.1 perry { 17 1.3 christos return (arg >> 4) * 10 + (arg & 0x0f); 18 1.1 perry } 19 1.1 perry 20 1.4 tsutsui satime_t 21 1.3 christos 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.4 tsutsui 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.3 christos return sec; 41 1.1 perry } 42