summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-04-26 10:35:06 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-04-26 10:35:06 +0000
commit475b18b6800f10292c1c17c5d041a62c922a4497 (patch)
tree043a3a22a59573dea290dab5203652ab18860af4 /sys
parentaca69f099f7aede18763fc486641b16058601bb9 (diff)
Sanitize inittodr()/resettodr() implementation.
- move implementations next to eachother in the same file - remove pointless call to resettodr() in inittodr() - use OpenBSD define to get a minimum plausible time - if RTC time is before minimum plausible time, reject it - don't print "clock gained N days" on ramdisk Hopefully this implementation can serve as a model for unification into an MI implementation. ok mpi@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/arm64/arm64/intr.c24
-rw-r--r--sys/arch/arm64/arm64/machdep.c42
2 files changed, 33 insertions, 33 deletions
diff --git a/sys/arch/arm64/arm64/intr.c b/sys/arch/arm64/arm64/intr.c
index 8e58d14d4d9..1cc0f9bba97 100644
--- a/sys/arch/arm64/arm64/intr.c
+++ b/sys/arch/arm64/arm64/intr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: intr.c,v 1.14 2019/05/13 20:55:22 drahn Exp $ */
+/* $OpenBSD: intr.c,v 1.15 2020/04/26 10:35:05 kettenis Exp $ */
/*
* Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
*
@@ -775,28 +775,6 @@ arm_dflt_delay(u_int usecs)
}
-todr_chip_handle_t todr_handle;
-
-/*
- * 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("resettodr: failed to set time\n");
-}
-
void
setstatclockrate(int new)
{
diff --git a/sys/arch/arm64/arm64/machdep.c b/sys/arch/arm64/arm64/machdep.c
index a4ddaca8f46..5c060fa25db 100644
--- a/sys/arch/arm64/arm64/machdep.c
+++ b/sys/arch/arm64/arm64/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.44 2020/04/21 07:57:17 kettenis Exp $ */
+/* $OpenBSD: machdep.c,v 1.45 2020/04/26 10:35:05 kettenis Exp $ */
/*
* Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
*
@@ -90,19 +90,21 @@ struct uvm_constraint_range *uvm_md_constraints[] = {
/* the following is used externally (sysctl_hw) */
char machine[] = MACHINE; /* from <machine/param.h> */
-extern todr_chip_handle_t todr_handle;
int safepri = 0;
struct cpu_info cpu_info_primary;
struct cpu_info *cpu_info[MAXCPUS] = { &cpu_info_primary };
+todr_chip_handle_t todr_handle;
+
+#define MINYEAR ((OpenBSD / 100) - 1) /* minimum plausible year */
+
/*
* inittodr:
*
* Initialize time from the time-of-day register.
*/
-#define MINYEAR 2003 /* minimum plausible year */
void
inittodr(time_t base)
{
@@ -121,17 +123,15 @@ inittodr(time_t base)
if (todr_handle == NULL ||
todr_gettime(todr_handle, &rtctime) != 0 ||
- rtctime.tv_sec == 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: preposterous clock chip time\n");
- resettodr();
- }
+ 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);
@@ -152,14 +152,36 @@ inittodr(time_t base)
deltat = -deltat;
if (deltat < 2 * SECDAY)
return; /* all is well */
- printf("WARNING: clock %s %ld days\n",
+#ifndef SMALL_KERNEL
+ printf("WARNING: clock %s %lld days\n",
rtctime.tv_sec < base ? "lost" : "gained",
- (long)deltat / SECDAY);
+ (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");
+}
+
static int
atoi(const char *s)
{