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