Module Name: src Committed By: imil Date: Mon Feb 24 07:18:02 UTC 2025
Modified Files: src/sys/arch/x86/isa: clock.c Log Message: Check for RTC presence to avoid hang with QEMU microvm and rtc=off parameter. Test bits 0-6 of MC146818's Register D, which must be 0 according to the specification. This prevents a later hang in rtcget() when no RTC is present. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/isa/clock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/x86/isa/clock.c diff -u src/sys/arch/x86/isa/clock.c:1.41 src/sys/arch/x86/isa/clock.c:1.42 --- src/sys/arch/x86/isa/clock.c:1.41 Wed Jan 25 15:54:52 2023 +++ src/sys/arch/x86/isa/clock.c Mon Feb 24 07:18:02 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.41 2023/01/25 15:54:52 riastradh Exp $ */ +/* $NetBSD: clock.c,v 1.42 2025/02/24 07:18:02 imil Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -121,7 +121,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.41 2023/01/25 15:54:52 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.42 2025/02/24 07:18:02 imil Exp $"); /* #define CLOCKDEBUG */ /* #define CLOCK_PARANOIA */ @@ -327,6 +327,14 @@ startrtclock(void) { int s; + /* + * Check that RTC is present, bits 0 to 6 of register D are + * read-only and must be 0. At least on QEMU/microvm, when + * rtc=off, all bits are set to 1 + */ + if ((mc146818_read(NULL, MC_REGD) & 0x7f) != 0) + return; + if (!rtclock_init) initrtclock(TIMER_FREQ);