1 1.1.1.1.18.1 thorpej /* $NetBSD: getsecs.c,v 1.1.1.1.18.1 1999/06/21 00:50:04 thorpej 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.1 perry 9 1.1 perry #include "libi386.h" 10 1.1 perry 11 1.1 perry extern int biosgetrtc __P((u_long*)); 12 1.1 perry 13 1.1.1.1.18.1 thorpej static inline u_long bcd2dec __P((u_long)); 14 1.1.1.1.18.1 thorpej 15 1.1 perry static inline u_long 16 1.1 perry bcd2dec(arg) 17 1.1.1.1.18.1 thorpej u_long arg; 18 1.1 perry { 19 1.1.1.1.18.1 thorpej return ((arg >> 4) * 10 + (arg & 0x0f)); 20 1.1 perry } 21 1.1 perry 22 1.1 perry time_t 23 1.1 perry getsecs() { 24 1.1.1.1.18.1 thorpej /* 25 1.1.1.1.18.1 thorpej * Return the current time in seconds 26 1.1.1.1.18.1 thorpej */ 27 1.1.1.1.18.1 thorpej 28 1.1.1.1.18.1 thorpej u_long t; 29 1.1.1.1.18.1 thorpej time_t sec; 30 1.1.1.1.18.1 thorpej 31 1.1.1.1.18.1 thorpej if (biosgetrtc(&t)) 32 1.1.1.1.18.1 thorpej panic("RTC invalid"); 33 1.1.1.1.18.1 thorpej 34 1.1.1.1.18.1 thorpej sec = bcd2dec(t & 0xff); 35 1.1.1.1.18.1 thorpej sec *= 60; 36 1.1.1.1.18.1 thorpej t >>= 8; 37 1.1.1.1.18.1 thorpej sec += bcd2dec(t & 0xff); 38 1.1.1.1.18.1 thorpej sec *= 60; 39 1.1.1.1.18.1 thorpej t >>= 8; 40 1.1.1.1.18.1 thorpej sec += bcd2dec(t & 0xff); 41 1.1 perry 42 1.1.1.1.18.1 thorpej return (sec); 43 1.1 perry } 44