diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-05-16 14:44:46 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-05-16 14:44:46 +0000 |
commit | ca55818eef7945b63fe2fd6683902b7a6281ef17 (patch) | |
tree | 5f2efc756d600a861c2778d775b147c695379476 /sys/arch/sh | |
parent | e4b72d678a30243ed627b79b55f8dc6b8913bfd4 (diff) |
Make inittodr() and resettodr() MI.
ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)
Diffstat (limited to 'sys/arch/sh')
-rw-r--r-- | sys/arch/sh/sh/sh_machdep.c | 95 |
1 files changed, 1 insertions, 94 deletions
diff --git a/sys/arch/sh/sh/sh_machdep.c b/sys/arch/sh/sh/sh_machdep.c index d44965a3954..afdc4380552 100644 --- a/sys/arch/sh/sh/sh_machdep.c +++ b/sys/arch/sh/sh/sh_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sh_machdep.c,v 1.50 2020/05/11 13:27:38 kettenis Exp $ */ +/* $OpenBSD: sh_machdep.c,v 1.51 2020/05/16 14:44:45 kettenis Exp $ */ /* $NetBSD: sh3_machdep.c,v 1.59 2006/03/04 01:13:36 uwe Exp $ */ /* @@ -625,96 +625,3 @@ cpu_reset(void) #endif /* NOTREACHED */ } - - -#include <sys/timetc.h> -#include <dev/clock_subr.h> - -todr_chip_handle_t todr_handle; - -#define MINYEAR ((OpenBSD / 100) - 1) /* minimum plausible year */ - -/* - * inittodr: - * - * Initialize time from the time-of-day register. - */ -void -inittodr(time_t base) -{ - time_t deltat; - struct timeval rtctime; - struct timespec ts; - int badbase; - - if (base < (MINYEAR - 1970) * SECYR) { - printf("WARNING: preposterous time in file system\n"); - /* read the system clock anyway */ - base = (MINYEAR - 1970) * SECYR; - badbase = 1; - } else - badbase = 0; - - rtctime.tv_sec = base; - rtctime.tv_usec = 0; - - if (todr_handle == NULL || - todr_gettime(todr_handle, &rtctime) != 0 || - rtctime.tv_sec < (MINYEAR - 1970) * SECYR) { - /* - * Believe the time in the file system for lack of - * anything better, resetting the TODR. - */ - rtctime.tv_sec = base; - rtctime.tv_usec = 0; - if (todr_handle != NULL && !badbase) - printf("WARNING: bad clock chip time\n"); - ts.tv_sec = rtctime.tv_sec; - ts.tv_nsec = rtctime.tv_usec * 1000; - tc_setclock(&ts); - goto bad; - } else { - ts.tv_sec = rtctime.tv_sec; - ts.tv_nsec = rtctime.tv_usec * 1000; - tc_setclock(&ts); - } - - if (!badbase) { - /* - * See if we gained/lost two or more days; if - * so, assume something is amiss. - */ - deltat = rtctime.tv_sec - base; - if (deltat < 0) - deltat = -deltat; - if (deltat < 2 * SECDAY) - return; /* all is well */ -#ifndef SMALL_KERNEL - printf("WARNING: clock %s %lld days\n", - rtctime.tv_sec < base ? "lost" : "gained", - (long long)(deltat / SECDAY)); -#endif - } - bad: - printf("WARNING: CHECK AND RESET THE DATE!\n"); -} - -/* - * resettodr: - * - * Reset the time-of-day register with the current time. - */ -void -resettodr(void) -{ - struct timeval rtctime; - - if (time_second == 1) - return; - - microtime(&rtctime); - - if (todr_handle != NULL && - todr_settime(todr_handle, &rtctime) != 0) - printf("WARNING: can't update clock chip time\n"); -} |