From sawada@zoo.ncl.omron.co.jp  Wed Jun  7 19:02:20 1995
Received: from ocgw.ig.omron.co.jp (ocgw.ig.omron.co.jp [202.32.89.10])
          by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id TAA26603
          for <freebsd-gnats-submit@freebsd.org>; Wed, 7 Jun 1995 19:02:16 -0700
Received: from localhost by ocgw.ig.omron.co.jp (8.6.5/2.8Wb-ocgw)
	id LAA23540; Thu, 8 Jun 1995 11:02:07 +0900
Received: from ocgwin.ig.omron.co.jp(192.168.254.20) by ocgw.ig.omron.co.jp via smap (V1.3)
	id sma023535; Thu Jun  8 11:01:53 1995
Received: by ocgwin.ig.omron.co.jp (8.6.8+2.4Wb-o2.0/2.8Wb-ocgwin)
	id LAA18853; Thu, 8 Jun 1995 11:01:48 +0900
Received: from annyeong.zoo.ncl.omron.co.jp (annyeong.zoo.ncl.omron.co.jp [133.210.12.13]) by azalea.zoo.ncl.omron.co.jp (8.6.9+2.4Wb3/3.3W9azalea-1.0) with SMTP id LAA28549; Thu, 8 Jun 1995 11:01:51 +0900
Message-Id: <199506080201.LAA28549@azalea.zoo.ncl.omron.co.jp>
Date: Thu, 08 Jun 1995 11:01:50 +0900
From: Akira SAWADA <sawada@zoo.ncl.omron.co.jp>
Reply-To: sawada@zoo.ncl.omron.co.jp
To: FreeBSD-gnats-submit@freebsd.org
Cc: sawada@zoo.ncl.omron.co.jp
Subject: bug in checking RTC status at initialization
X-Send-Pr-Version: 3.2

>Number:         498
>Category:       i386
>Synopsis:       bug in checking RTC status at initialization
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs (FreeBSD bugs mailing list)
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun  7 19:10:02 1995
>Closed-Date:    Thu Jun 8 20:29:36 PDT 1995
>Last-Modified:
>Originator:     Akira SAWADA
>Release:        FreeBSD 2.0.950412-SNAP i386
>Organization:
OMRON Corporation
>Environment:

IBM PS/55 note

>Description:

At boot time, kernel always says:
Invalid time in real time clock.
Check and reset the date immediately!

In inittodr() of sys/i386/isa/clock.c:
        /* Look if we have a RTC present and the time is valid */
        if (rtcin(RTC_STATUSD) != RTCSD_PWR)
                goto wrong_time;

This RTC status check is failed,
because rtcin(RTC_STATUSD) returns 0x82.

In sys/i386/isa/rtc.h:
#define RTC_STATUSD     0x0d    /* status register D (R) Lost Power */
#define  RTCSD_PWR       0x80   /* clock lost power */

To check the RTC status, 
we should check only the MSB bit of rtcin(RTC_STATUSD).
According to the system manual of PS/55 note,
the lower 7 bits are system reserved.

>How-To-Repeat:

Always at boot time.

>Fix:

The above line:
        if (rtcin(RTC_STATUSD) != RTCSD_PWR)
shuould be
        if ((rtcin(RTC_STATUSD) & RTCSD_PWR) != RTCSD_PWR)
or
        if (!(rtcin(RTC_STATUSD) & RTCSD_PWR))

The corresponding lines in NetBSD-current are here:

(in rtcget() of sys/arch/i386/isa/clock.c)
        if (mc146818_read(NULL, MC_REGD) & MC_REGD_VRT == 0) /* XXX softc */
                return (-1);

(in sys/dev/ic/mc146818.h)
#define MC_REGD         0xd     /* Control register D */

/*       MC_REGD_UNUSED 0x7f    UNUSED */
#define  MC_REGD_VRT    0x80    /* Valid RAM and Time bit */

Thanks in advance.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: davidg 
State-Changed-When: Thu Jun 8 20:29:36 PDT 1995 
State-Changed-Why:  
The code was indeed wrong and the suggested change was made in 
rev 1.34.2.1. 
>Unformatted:


