Annotation of sys/arch/mvme68k/stand/libsa/clock.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: clock.c,v 1.4 2003/08/20 00:26:00 deraadt Exp $ */
! 2:
! 3: #include <sys/types.h>
! 4: #include <machine/prom.h>
! 5:
! 6: #include "stand.h"
! 7: #include "libsa.h"
! 8:
! 9: /*
! 10: * BCD to decimal and decimal to BCD.
! 11: */
! 12: #define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf))
! 13: #define TOBCD(x) (((x) / 10 * 16) + ((x) % 10))
! 14:
! 15: #define SECDAY (24 * 60 * 60)
! 16: #define SECYR (SECDAY * 365)
! 17: #define LEAPYEAR(y) (((y) & 3) == 0)
! 18: #define YEAR0 68
! 19:
! 20:
! 21: /*
! 22: * This code is defunct after 2068.
! 23: * Will Unix still be here then??
! 24: */
! 25: const short dayyr[12] =
! 26: {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
! 27:
! 28: static u_long
! 29: chiptotime(int sec, int min, int hour, int day, int mon, int year)
! 30: {
! 31: register int days, yr;
! 32:
! 33: sec = FROMBCD(sec);
! 34: min = FROMBCD(min);
! 35: hour = FROMBCD(hour);
! 36: day = FROMBCD(day);
! 37: mon = FROMBCD(mon);
! 38: year = FROMBCD(year) + YEAR0;
! 39: if (year < 70)
! 40: year = 70;
! 41:
! 42: /* simple sanity checks */
! 43: if (year < 70 || mon < 1 || mon > 12 || day < 1 || day > 31)
! 44: return (0);
! 45: days = 0;
! 46: for (yr = 70; yr < year; yr++)
! 47: days += LEAPYEAR(yr) ? 366 : 365;
! 48: days += dayyr[mon - 1] + day - 1;
! 49: if (LEAPYEAR(yr) && mon > 2)
! 50: days++;
! 51: /* now have days since Jan 1, 1970; the rest is easy... */
! 52: return (days * SECDAY + hour * 3600 + min * 60 + sec);
! 53: }
! 54:
! 55: time_t
! 56: getsecs(void)
! 57: {
! 58: struct mvmeprom_time m;
! 59:
! 60: mvmeprom_rtc_rd(&m);
! 61: return (chiptotime(m.sec_BCD, m.min_BCD, m.hour_BCD, m.day_BCD,
! 62: m.month_BCD, m.year_BCD));
! 63: }
CVSweb